Java Code Examples for org.osgi.util.tracker.ServiceTracker#open()

The following examples show how to use org.osgi.util.tracker.ServiceTracker#open() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Activator.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * (non-Javadoc)
 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 * @param context
 * @throws Exception
 */
public void start(BundleContext context) throws Exception {
	plugin = this;
	bundleContext = context;
	// tracker the open office converter service
	String positiveFilter = new AndFilter(new EqFilter(Constants.OBJECTCLASS, Converter.class.getName()),
			new EqFilter(Converter.ATTR_TYPE, OpenOffice2Xliff.TYPE_VALUE), new EqFilter(Converter.ATTR_DIRECTION,
					Converter.DIRECTION_POSITIVE)).toString();
	positiveTracker = new ServiceTracker(context, context.createFilter(positiveFilter),
			new OpenOfficePositiveCustomizer());
	positiveTracker.open();

	String reverseFilter = new AndFilter(new EqFilter(Constants.OBJECTCLASS, Converter.class.getName()),
			new EqFilter(Converter.ATTR_TYPE, Xliff2OpenOffice.TYPE_VALUE), new EqFilter(Converter.ATTR_DIRECTION,
					Converter.DIRECTION_REVERSE)).toString();
	reverseTracker = new ServiceTracker(context, context.createFilter(reverseFilter),
			new OpenOfficeReverseCustomize());
	reverseTracker.open();
}
 
Example 2
Source File: Activator.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * (non-Javadoc)
 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 * @param context
 * @throws Exception
 */
public void start(BundleContext context) throws Exception {
	plugin = this;
	bundleContext = context;
	// tracker the rtf converter service
	String positiveFilter = new AndFilter(new EqFilter(Constants.OBJECTCLASS, Converter.class.getName()),
			new EqFilter(Converter.ATTR_TYPE, Rtf2Xliff.TYPE_VALUE), new EqFilter(Converter.ATTR_DIRECTION,
					Converter.DIRECTION_POSITIVE)).toString();
	positiveTracker = new ServiceTracker(context, context.createFilter(positiveFilter), new RtfPositiveCustomizer());
	positiveTracker.open();

	String reverseFilter = new AndFilter(new EqFilter(Constants.OBJECTCLASS, Converter.class.getName()),
			new EqFilter(Converter.ATTR_TYPE, Xliff2Rtf.TYPE_VALUE), new EqFilter(Converter.ATTR_DIRECTION,
					Converter.DIRECTION_REVERSE)).toString();
	reverseTracker = new ServiceTracker(context, context.createFilter(reverseFilter), new RtfReverseCustomize());
	reverseTracker.open();
}
 
Example 3
Source File: ConverterTracker.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The Constructor.
 * @param bundleContext
 *            插件所在的 bundle context
 * @param direction
 *            取<code>Converter.DIRECTION_POSITIVE</code>或 <code>Converter.DIRECTION_REVERSE</code>
 */
public ConverterTracker(BundleContext bundleContext, String direction) {
	this.direction = direction;
	supportTypes = new ArrayList<ConverterBean>();
	this.context = bundleContext;
	String filterStr = new AndFilter(new EqFilter(Constants.OBJECTCLASS, Converter.class.getName()), new EqFilter(
			Converter.ATTR_DIRECTION, direction)).toString();
	Filter filter = null;
	try {
		filter = context.createFilter(filterStr);
	} catch (InvalidSyntaxException e) {
		// ignore the exception
		e.printStackTrace();
	}
	if (filter != null) {
		converterServiceTracker = new ServiceTracker(context, filter, new ConverterCustomizer());
	}
	converterServiceTracker.open();
}
 
Example 4
Source File: SignedJWTAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void handleAuthenticationStarted(int tenantId) {
    BundleContext bundleContext = SignedJWTAuthenticatorServiceComponent.getBundleContext();
    if (bundleContext != null) {
        ServiceTracker tracker =
                new ServiceTracker(bundleContext,
                        AuthenticationObserver.class.getName(), null);
        tracker.open();
        Object[] services = tracker.getServices();
        if (services != null) {
            for (Object service : services) {
                ((AuthenticationObserver) service).startedAuthentication(tenantId);
            }
        }
        tracker.close();
    }
}
 
Example 5
Source File: Activator.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * (non-Javadoc)
 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
 * @param context
 * @throws Exception
 */
public void start(BundleContext context) throws Exception {
	plugin = this;
	bundleContext = context;
	// tracker the xml converter service
	String positiveFilter = new AndFilter(new EqFilter(Constants.OBJECTCLASS, Converter.class.getName()),
			new EqFilter(Converter.ATTR_TYPE, Xml2Xliff.TYPE_VALUE), new EqFilter(Converter.ATTR_DIRECTION,
					Converter.DIRECTION_POSITIVE)).toString();
	positiveTracker = new ServiceTracker(context, context.createFilter(positiveFilter), new XmlPositiveCustomizer());
	positiveTracker.open();

	String reverseFilter = new AndFilter(new EqFilter(Constants.OBJECTCLASS, Converter.class.getName()),
			new EqFilter(Converter.ATTR_TYPE, Xliff2Xml.TYPE_VALUE), new EqFilter(Converter.ATTR_DIRECTION,
					Converter.DIRECTION_REVERSE)).toString();
	reverseTracker = new ServiceTracker(context, context.createFilter(reverseFilter), new XmlReverseCustomize());
	reverseTracker.open();
}
 
Example 6
Source File: SAML2SSOAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void handleAuthenticationStarted(int tenantId) {
    BundleContext bundleContext = SAML2SSOAuthBEDataHolder.getInstance().getBundleContext();
    if (bundleContext != null) {
        ServiceTracker tracker =
                new ServiceTracker(bundleContext,
                        AuthenticationObserver.class.getName(), null);
        tracker.open();
        Object[] services = tracker.getServices();
        if (services != null) {
            for (Object service : services) {
                ((AuthenticationObserver) service).startedAuthentication(tenantId);
            }
        }
        tracker.close();
    }
}
 
Example 7
Source File: LaunchServiceTest.java    From JaxRSProviders with Apache License 2.0 6 votes vote down vote up
static <T> T getService(Class<T> clazz) {
	Bundle bundle = FrameworkUtil.getBundle(LaunchServiceTest.class);
	bundle.getBundleContext().getBundles();
	if (bundle != null) {
		ServiceTracker<T, T> st = new ServiceTracker<T, T>(bundle.getBundleContext(), clazz, null);
		st.open();
		if (st != null) {
			try {
				// give the runtime some time to startup
				return st.waitForService(500);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	return null;
}
 
Example 8
Source File: Test8.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void prepare() {
  try {
    b1 = Util.installBundle(bc, "bundleEnd101_test-1.0.0.jar");
    b2 = Util.installBundle(bc, "bundleEnd102_test-1.0.0.jar");
    b1.start();
    b2.start();
    
    tracker1 = new ServiceTracker(bc, Control101.class.getName(), null);
    tracker2 = new ServiceTracker(bc, Control102.class.getName(), null);
    tracker1.open();
    tracker2.open();
    
    tracker = new ServiceTracker(bc, Control.class.getName(), null); 
    tracker.open();
    
  } catch (BundleException e) {
    
    e.printStackTrace();
  }
}
 
Example 9
Source File: SignedJWTAuthenticator.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
private void handleAuthenticationStarted(int tenantId) {
    BundleContext bundleContext = SignedJWTAuthenticatorServiceComponent.getBundleContext();
    if (bundleContext != null) {
        ServiceTracker tracker =
                new ServiceTracker(bundleContext,
                        AuthenticationObserver.class.getName(), null);
        tracker.open();
        Object[] services = tracker.getServices();
        if (services != null) {
            for (Object service : services) {
                ((AuthenticationObserver) service).startedAuthentication(tenantId);
            }
        }
        tracker.close();
    }
}
 
Example 10
Source File: CommandProvidersService.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void open() {
  try {
    Filter filter =  Activator.bc
      .createFilter("(&" + 
                    "(" + CommandProcessor.COMMAND_SCOPE + "=*)" + 
                    "(" + CommandProcessor.COMMAND_FUNCTION + "=*)" + 
                    ")");
    
    cpTracker = new ServiceTracker(Activator.bc, 
                                   filter,
                                   null);
    cpTracker.open();
  } catch (Exception e) {
    throw new RuntimeException("Failed to init command provider tracker " + e); 
  }
  convTracker = new ServiceTracker(Activator.bc, 
                                   Converter.class.getName(),
                                   null);
  convTracker.open();
}
 
Example 11
Source File: DatabaseService.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取数据处理对象{@link DBOperator},该数据处理对象用于访问指定的数据库中的数据<br>
 * 在访问数据库时,根据不同数据库类型获取相应的处理对象.这些数据库被封装在{@link MetaData}中
 * @param metaData
 *            当前数据库的元数据,封装了连接数据库的一系列参数
 * @return 返回null时,表示未获取到数据处理对象;
 */
public static DBOperator getDBOperator(MetaData metaData) {
	DBOperator dbOperator = null;
	@SuppressWarnings({ "rawtypes", "unchecked" })
	ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
	tracker.open();
	try {
		Object[] services = tracker.getServices();
		for (Object i : services) {
			DBServiceProvider serviceProvider = (DBServiceProvider) i;
			DBOperator temp = serviceProvider.getTmDatabaseInstance();
			if (temp == null) {
				continue;
			}
			if (temp.getDbConfig().getDefaultType().equals(metaData.getDbType())) {
				dbOperator = temp;
				dbOperator.setMetaData(metaData);
			}
		}
	} finally {
		tracker.close();
	}
	return dbOperator;
}
 
Example 12
Source File: Activator.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public void start(BundleContext context) throws Exception {
	//disable the JSR99 compiler that does not work in OSGi;
	//This will convince jasper to use the JDTCompiler that invokes ecj (see JSP-21 on the glassfish bug-tracker)
	System.setProperty("org.apache.jasper.compiler.disablejsr199", Boolean.TRUE.toString());
	this.context = context;
	thisBundle = context.getBundle();
	packageAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), this);
	packageAdminTracker.open();
}
 
Example 13
Source File: AbstractCommandProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This constructor is responsible for creation and opening a tracker for {@link Parser} services.
 *
 * @param context is the {@link BundleContext}, used for creating a tracker for {@link Parser} services.
 */
@SuppressWarnings("unchecked")
public AbstractCommandProvider(BundleContext context) {
    this.bc = context;
    logger = LoggerFactory.getLogger(AbstractCommandProvider.this.getClass());
    parserTracker = new ServiceTracker(context, Parser.class.getName(), this);
    parserTracker.open();
}
 
Example 14
Source File: DatabaseService.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 通过数据库元数据库获取数据库连接,主要取数据库类型
 * @param metaData
 * @return ;
 */
public static SystemDBOperator getSysDbOperateByMetaData(MetaData metaData) {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
	tracker.open();
	try {
		Object[] services = tracker.getServices();
		for (Object i : services) {
			DBServiceProvider serviceProvider = (DBServiceProvider) i;
			SystemDBOperator temp = serviceProvider.getOperateDBInstance();
			if (temp == null) {
				continue;
			}
			MetaData tempMetaData = temp.getMetaData();
			if (tempMetaData.getDbType().equals(metaData.getDbType())) {
				tempMetaData.setDatabaseName(metaData.getDatabaseName());
				tempMetaData.setDataPath(metaData.getDataPath());
				tempMetaData.setInstance(metaData.getInstance());
				tempMetaData.setPassword(metaData.getPassword());
				tempMetaData.setPort(metaData.getPort());
				tempMetaData.setServerName(metaData.getServerName());
				tempMetaData.setTB(metaData.isTB());
				tempMetaData.setTM(metaData.isTM());
				tempMetaData.setUserName(metaData.getUserName());
				return temp;
			}
		}
	} finally {
		tracker.close();
	}
	return null;
}
 
Example 15
Source File: AbstractServerActivator.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void awaitService(BundleContext bundleContext, String filter, long timeout)
        throws InvalidSyntaxException, InterruptedException {
    Filter serviceFilter = bundleContext.createFilter(filter);
    ServiceTracker<Object, ?> tracker = new ServiceTracker<>(bundleContext, serviceFilter, null);
    tracker.open();
    Object service = tracker.waitForService(timeout);
    tracker.close();
    if (service == null) {
        throw new IllegalStateException("Expected service with filter " + filter + " was not found");
    }
}
 
Example 16
Source File: CommandProcessorImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
CommandProcessorImpl(Bundle b) {
  this.b = b;
  tioTracker = new ServiceTracker(Activator.bc, 
                                  ThreadIO.class.getName(),
                                  null);
  tioTracker.open();

  commandProviders = new CommandProvidersService();      
  commandProviders.open();
}
 
Example 17
Source File: JSCorePlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void start(BundleContext context) throws Exception // $codepro.audit.disable declaredExceptions
{
	super.start(context);
	PLUGIN = this;

	// Load JS Metadata in background
	new JSMetadataLoader().schedule();

	// Hook up tracker to proxy service
	proxyTracker = new ServiceTracker(getBundle().getBundleContext(), IProxyService.class.getName(), null);
	proxyTracker.open();
}
 
Example 18
Source File: DatabaseService.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 通过数据库元数据库获取数据库连接,主要取数据库类型
 * @param metaData
 * @return ;
 */
public static SystemDBOperator getSysDbOperateByMetaData(MetaData metaData) {
	@SuppressWarnings({ "rawtypes", "unchecked" })
	ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
	tracker.open();
	try {
		Object[] services = tracker.getServices();
		for (Object i : services) {
			DBServiceProvider serviceProvider = (DBServiceProvider) i;
			SystemDBOperator temp = serviceProvider.getOperateDBInstance();
			if (temp == null) {
				continue;
			}
			MetaData tempMetaData = temp.getMetaData();
			if (tempMetaData.getDbType().equals(metaData.getDbType())) {
				tempMetaData.setDatabaseName(metaData.getDatabaseName());
				tempMetaData.setDataPath(metaData.getDataPath());
				tempMetaData.setInstance(metaData.getInstance());
				tempMetaData.setPassword(metaData.getPassword());
				tempMetaData.setPort(metaData.getPort());
				tempMetaData.setServerName(metaData.getServerName());
				tempMetaData.setTB(metaData.isTB());
				tempMetaData.setTM(metaData.isTM());
				tempMetaData.setUserName(metaData.getUserName());
				return temp;
			}
		}
	} finally {
		tracker.close();
	}
	return null;
}
 
Example 19
Source File: KarafTestSupport.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void waitForService(String filter, long timeout) throws InvalidSyntaxException, InterruptedException {
    ServiceTracker st = new ServiceTracker(bundleContext, bundleContext.createFilter(filter), null);
    try {
        st.open();
        st.waitForService(timeout);
    } finally {
        st.close();
    }
}
 
Example 20
Source File: Activator.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void start(BundleContext context) throws Exception {
   // This �apa is needed only if you use ds equinox implementation !!!!!
   tracker = new ServiceTracker(context, Adder.class.getName(), null);
     tracker.open();
     log.info("A la escucha");
}