[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [smila-user] Call an OSGI bundle service from a pipelet

Hello Nicolo,

 

The problem is that pipelets are not meant to be started as OSGi services, but the WorkflowProcessor creates one pipelet instance per pipeline it is used in. So the instance created by the TranlatorPipelet.xml is not the same as those used in the pipeline. This means you must get the reference to the service on your own. Have a look at the MimeTypeIdentifyPipelet, for example, which uses a MimeTypeIdentifier service that is started by some other bundle, a similar piece of code should work for you, too:

 

import org.eclipse.smila.utils.service.ServiceUtils;

public String[] process(final Blackboard blackboard, final String[] recordIds) throws ProcessingException {

  final MimeTypeIdentifier identifier = getMimeTypeIdentifier();

  …

}

 

private synchronized MimeTypeIdentifier getMimeTypeIdentifier() throws ProcessingException {

  if (_mimeTypeIdentifier == null) {

    try {

      _mimeTypeIdentifier = ServiceUtils.getService(MimeTypeIdentifier.class);

    } catch (final Exception ex) {

      _log.warn("Error while waiting for MimeTypeIdentifier service to come up.", ex);

    }

    if (_mimeTypeIdentifier == null) {

      throw new ProcessingException("No MimeTypeIdentifier service available, giving up");

    }

  }

 return _mimeTypeIdentifier;

}

 

Regards,

Juergen.