本文整理匯總了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);
}
}