本文整理汇总了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;
}
}