/**
  * ensure that the query object has a Id set. If none is provided by the client create one using
  * the pipeline name as source and a random {@link UUID} as key.
  *
  * @param workflowName pipeline name
  * @param query query recurd.
  */
 private void ensureQueryId(final String workflowName, final Record query) {
   if (query.getId() == null) {
     UUID uuid = null;
     synchronized (this) {
       uuid = UUID.randomUUID();
     }
     final Id id = IdFactory.DEFAULT_INSTANCE.createId(workflowName, uuid.toString());
     query.setId(id);
   }
 }
  /**
   * {@inheritDoc}
   *
   * @see org.eclipse.smila.search.api.SearchService#search(java.lang.String,
   *     org.eclipse.smila.datamodel.record.Record)
   */
  public SearchResult search(final String workflowName, final Record query)
      throws ProcessingException {
    try {
      final long starttime = System.nanoTime();
      ensureQueryId(workflowName, query);
      final SearchResultImpl result = new SearchResultImpl(workflowName, query);
      final Blackboard blackboard = _blackboardFactory.createTransientBlackboard();
      blackboard.setRecord(query);
      SearchMessage message = new SearchMessage(query.getId(), null);
      message = _processor.process(workflowName, blackboard, message);

      if (message.hasQuery()) {
        result.setQuery(blackboard.getRecord(message.getQuery()));
      }
      if (message.hasRecords()) {
        final Id[] ids = message.getRecords();
        final Record[] records = new Record[ids.length];
        for (int i = 0; i < ids.length; i++) {
          records[i] = blackboard.getRecord(ids[i]);
        }
        result.setRecords(records);
      }
      final long endtime = System.nanoTime();
      setRuntime(blackboard, message.getQuery(), (endtime - starttime));
      blackboard.invalidate();
      return result;
    } catch (final BlackboardAccessException ex) {
      throw new ProcessingException("Blackboard error: ", ex);
    }
  }