本文整理匯總了Java中org.osgi.framework.ServiceEvent類的典型用法代碼示例。如果您正苦於以下問題:Java ServiceEvent類的具體用法?Java ServiceEvent怎麽用?Java ServiceEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ServiceEvent類屬於org.osgi.framework包,在下文中一共展示了ServiceEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serviceChanged
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
@Override
public synchronized void serviceChanged ( final ServiceEvent event )
{
switch ( event.getType () )
{
case ServiceEvent.REGISTERED:
addReference ( event.getServiceReference () );
break;
case ServiceEvent.MODIFIED:
update ();
break;
case ServiceEvent.UNREGISTERING:
removeReference ( event.getServiceReference () );
break;
}
}
示例2: testRemoveServiceListener
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
public void testRemoveServiceListener() throws Exception {
ServiceListener listener = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
}
};
Set listeners = mock.getServiceListeners();
mock.removeServiceListener(null);
assertEquals(0, listeners.size());
mock.removeServiceListener(listener);
assertEquals(0, listeners.size());
mock.addServiceListener(listener);
assertEquals(1, listeners.size());
mock.removeServiceListener(listener);
assertEquals(0, listeners.size());
}
示例3: registerService
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
public ServiceRegistration registerService(String[] clazzes, final Object service, Dictionary properties) {
MockServiceRegistration reg = new MockServiceRegistration(properties);
MockServiceReference ref = new MockServiceReference(getBundle(), properties, reg, clazzes) {
@Override
public Object getProperty(String key) {
if (SERVICE_PROPERTY.equals(key)) {
return service;
} else {
return super.getProperty(key);
}
}
};
ServiceEvent event = new ServiceEvent(ServiceEvent.REGISTERED, ref);
for (Iterator iter = serviceListeners.iterator(); iter.hasNext();) {
ServiceListener listener = (ServiceListener) iter.next();
listener.serviceChanged(event);
}
return reg;
}
示例4: testServiceReferenceMemberType
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
public void testServiceReferenceMemberType() throws Exception {
serviceFactoryBean.setMemberType(MemberType.SERVICE_REFERENCE);
serviceFactoryBean.setInterfaces(new Class<?>[] { Runnable.class });
serviceFactoryBean.afterPropertiesSet();
Collection col = (Collection) serviceFactoryBean.getObject();
assertFalse(col.isEmpty());
assertSame(ref, col.iterator().next());
Set listeners = bundleContext.getServiceListeners();
ServiceListener list = (ServiceListener) listeners.iterator().next();
ServiceReference ref2 = new MockServiceReference();
list.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, ref2));
assertEquals(2, col.size());
Iterator iter = col.iterator();
iter.next();
assertSame(ref2, iter.next());
}
示例5: testInvocationTimeoutWhenServiceNA
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
public void testInvocationTimeoutWhenServiceNA() throws Throwable {
// service n/a
Object target = new Object();
Method m = target.getClass().getDeclaredMethod("hashCode", null);
MethodInvocation invocation = new MockMethodInvocation(m);
createInterceptor(new MockFilter(nullFilter));
ServiceEvent event = new ServiceEvent(ServiceEvent.UNREGISTERING, reference);
listener.serviceChanged(event);
interceptor.getRetryTemplate().reset(3000);
long now = System.currentTimeMillis();
try {
interceptor.invoke(invocation);
fail("should have thrown exception");
}
catch (ServiceUnavailableException ex) {
// expected
}
// service is up
interceptor.getRetryTemplate().reset(1);
assertTrue("Call did not block for 3000ms, actually blocked for " + (System.currentTimeMillis() - now) + "ms",
(System.currentTimeMillis() - now) >= 3000);
}
示例6: testUnbind
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
public void testUnbind() {
interceptor.afterPropertiesSet();
assertEquals(1, SimpleTargetSourceLifecycleListener.BIND);
assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
ServiceListener sl = (ServiceListener) bundleContext.getServiceListeners().iterator().next();
// save old ref and invalidate it so new services are not found
ServiceReference oldRef = refs[0];
refs = null;
sl.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, oldRef));
assertEquals(1, SimpleTargetSourceLifecycleListener.BIND);
assertEquals(1, SimpleTargetSourceLifecycleListener.UNBIND);
}
示例7: testStickinessWhenABetterServiceIsAvailable
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
public void testStickinessWhenABetterServiceIsAvailable() throws Exception {
interceptor.setSticky(true);
interceptor.afterPropertiesSet();
ServiceListener sl = (ServiceListener) bundleContext.getServiceListeners().iterator().next();
Dictionary props = new Hashtable();
// increase service ranking
props.put(Constants.SERVICE_RANKING, 10);
ServiceReference ref = new MockServiceReference(null, props, null);
ServiceEvent event = new ServiceEvent(ServiceEvent.REGISTERED, ref);
assertEquals(1, SimpleTargetSourceLifecycleListener.BIND);
assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
sl.serviceChanged(event);
assertEquals("the proxy is not sticky", 1, SimpleTargetSourceLifecycleListener.BIND);
assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
}
示例8: testStickinessWhenServiceGoesDown
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
public void testStickinessWhenServiceGoesDown() throws Exception {
interceptor.setSticky(true);
interceptor.afterPropertiesSet();
ServiceListener sl = (ServiceListener) bundleContext.getServiceListeners().iterator().next();
Dictionary props = new Hashtable();
// increase service ranking
props.put(Constants.SERVICE_RANKING, 10);
ServiceReference higherRankingRef = new MockServiceReference(null, props, null);
refs = new ServiceReference[] { new MockServiceReference(), higherRankingRef };
assertTrue(Arrays.equals(bundleContext.getServiceReferences((String)null, null), refs));
assertEquals(1, SimpleTargetSourceLifecycleListener.BIND);
assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
sl.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, refs[0]));
assertEquals(2, SimpleTargetSourceLifecycleListener.BIND);
assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
assertSame("incorrect backing reference selected", higherRankingRef, ((ServiceReferenceProxy) interceptor
.getServiceReference()).getTargetServiceReference());
}
示例9: testAddServiceListenerBundleContextServiceListenerString
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
/**
* Test method for
* {@link org.eclipse.gemini.blueprint.util.OsgiListenerUtils#addServiceListener(org.osgi.framework.BundleContext, org.osgi.framework.ServiceListener, java.lang.String)}.
*/
public void testAddServiceListenerBundleContextServiceListenerString() {
final List refs = new ArrayList();
ServiceListener list = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
if (ServiceEvent.REGISTERED == event.getType())
refs.add(event.getSource());
}
};
OsgiListenerUtils.addServiceListener(bundleContext, list, (String) null);
assertFalse(refs.isEmpty());
assertEquals(3, refs.size());
assertSame(ref1, refs.get(0));
assertSame(ref2, refs.get(1));
assertSame(ref3, refs.get(2));
}
示例10: testAddSingleServiceListenerBundleContextServiceListenerString
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
/**
* Test method for
* {@link org.eclipse.gemini.blueprint.util.OsgiListenerUtils#addSingleServiceListener(org.osgi.framework.BundleContext, org.osgi.framework.ServiceListener, java.lang.String)}.
*/
public void testAddSingleServiceListenerBundleContextServiceListenerString() {
final List refs = new ArrayList();
ServiceListener listener = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
if (ServiceEvent.REGISTERED == event.getType())
refs.add(event.getSource());
}
};
OsgiListenerUtils.addSingleServiceListener(bundleContext, listener, (String) null);
assertFalse(refs.isEmpty());
assertEquals(1, refs.size());
assertSame(ref1, refs.get(0));
}
示例11: testExportExisting
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
@Test
public void testExportExisting() throws Exception {
IMocksControl c = EasyMock.createControl();
RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
final ServiceReference sref = createUserService(c);
expectServiceExported(c, rsa, mockEpListenerNotifier, sref, createEndpoint());
c.replay();
EndpointRepository endpointRepo = new EndpointRepository();
endpointRepo.setNotifier(mockEpListenerNotifier);
ExportPolicy policy = new DefaultExportPolicy();
TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, syncExecutor(), policy);
exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
exportManager.add(rsa);
c.verify();
}
示例12: testExportExistingMultipleInterfaces
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
@Test
public void testExportExistingMultipleInterfaces() throws Exception {
IMocksControl c = EasyMock.createControl();
RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
List<String> exportedInterfaces = Arrays.asList("a.b.C","foo.Bar");
final ServiceReference sref = createUserService(c, exportedInterfaces);
expectServiceExported(c, rsa, mockEpListenerNotifier, sref, createEndpoint());
c.replay();
EndpointRepository endpointRepo = new EndpointRepository();
endpointRepo.setNotifier(mockEpListenerNotifier);
ExportPolicy policy = new DefaultExportPolicy();
TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, syncExecutor(), policy);
exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
exportManager.add(rsa);
c.verify();
}
示例13: testExportExistingNoExportedInterfaces
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
@Test
public void testExportExistingNoExportedInterfaces() throws Exception {
IMocksControl c = EasyMock.createControl();
RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
String exportedInterfaces = "";
final ServiceReference sref = createUserService(c, exportedInterfaces);
c.replay();
EndpointRepository endpointRepo = new EndpointRepository();
endpointRepo.setNotifier(mockEpListenerNotifier);
ExportPolicy policy = new DefaultExportPolicy();
TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, syncExecutor(), policy);
exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
exportManager.add(rsa);
c.verify();
}
示例14: RemoteServiceAdminCore
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
public RemoteServiceAdminCore(BundleContext context, BundleContext apiContext, DistributionProvider provider) {
this.bctx = context;
this.apictx = apiContext;
this.eventProducer = new EventProducer(bctx);
this.provider = provider;
// listen for exported services being unregistered so we can close the export
this.exportedServiceListener = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.UNREGISTERING) {
removeServiceExports(event.getServiceReference());
}
}
};
try {
String filter = "(" + RemoteConstants.SERVICE_EXPORTED_INTERFACES + "=*)";
context.addServiceListener(exportedServiceListener, filter);
} catch (InvalidSyntaxException ise) {
throw new RuntimeException(ise); // can never happen
}
}
示例15: serviceChanged
import org.osgi.framework.ServiceEvent; //導入依賴的package包/類
@Override
public void serviceChanged(ServiceEvent event) {
if (closed) {
return;
}
ServiceReference<?> sr = event.getServiceReference();
switch (event.getType()) {
case ServiceEvent.REGISTERED:
onServiceRegistration(sr);
break;
case ServiceEvent.MODIFIED:
onServiceUpdate(sr);
break;
case ServiceEvent.MODIFIED_ENDMATCH:
case ServiceEvent.UNREGISTERING:
onServiceDeparture(sr);
break;
}
}