本文整理汇总了Java中org.osgi.framework.BundleContext.removeServiceListener方法的典型用法代码示例。如果您正苦于以下问题:Java BundleContext.removeServiceListener方法的具体用法?Java BundleContext.removeServiceListener怎么用?Java BundleContext.removeServiceListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.framework.BundleContext
的用法示例。
在下文中一共展示了BundleContext.removeServiceListener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: stop
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
public void stop ( final BundleContext context ) throws Exception
{
context.removeServiceListener ( this.listener );
this.itemTracker.close ();
this.poolTracker.close ();
this.handle.unregister ();
this.handle = null;
this.service.stop ();
this.service = null;
this.executor.shutdown ();
}
示例2: removeServiceListener
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
* Removes a service listener from the given bundle context. This method
* simply takes care of any exceptions that might be thrown (in case the
* context is invalid).
*
* @param context bundle context to unregister the listener from
* @param listener service listener to unregister
* @return true if the listener unregistration has succeeded, false
* otherwise (for example if the bundle context is invalid)
*/
public static boolean removeServiceListener(BundleContext context, ServiceListener listener) {
if (context == null || listener == null)
return false;
try {
context.removeServiceListener(listener);
return true;
}
catch (IllegalStateException e) {
// Bundle context is no longer valid
}
return false;
}
示例3: waitOnContextCreation
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
* Waits for a <em>Spring powered</em> bundle, given by its symbolic name,
* to be fully started.
*
* <p/>Forces the current (test) thread to wait for the a Spring application
* context to be published under the given symbolic name. This method allows
* waiting for full initialization of Spring OSGi bundles before starting
* the actual test execution.
*
* @param context bundle context to use for service lookup
* @param forBundleWithSymbolicName bundle symbolic name
* @param timeout maximum time to wait (in seconds) for the application
* context to be published
*/
protected void waitOnContextCreation(BundleContext context, String forBundleWithSymbolicName, long timeout) {
// translate from seconds to milliseconds
long time = timeout * SECOND;
// use the counter to make sure the threads block
final Counter counter = new Counter("waitForContext on bnd=" + forBundleWithSymbolicName);
counter.increment();
String filter = "(org.springframework.context.service.name=" + forBundleWithSymbolicName + ")";
ServiceListener listener = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.REGISTERED)
counter.decrement();
}
};
OsgiListenerUtils.addServiceListener(context, listener, filter);
if (logger.isDebugEnabled())
logger.debug("Start waiting for Spring/OSGi bundle=" + forBundleWithSymbolicName);
try {
if (counter.waitForZero(time)) {
waitingFailed(forBundleWithSymbolicName);
}
else if (logger.isDebugEnabled()) {
logger.debug("Found applicationContext for bundle=" + forBundleWithSymbolicName);
}
}
finally {
// inform waiting thread
context.removeServiceListener(listener);
}
}