当前位置: 首页>>代码示例>>Java>>正文


Java ServiceEvent类代码示例

本文整理汇总了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;
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:ServiceDiscoverer.java

示例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());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:MockBundleContextTest.java

示例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;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:26,代码来源:ListListenerAdapterTest.java

示例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());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:21,代码来源:OsgiServiceCollectionProxyFactoryBeanTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:27,代码来源:OsgiServiceDynamicInterceptorTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:18,代码来源:OsgiServiceDynamicInterceptorListenerTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:OsgiServiceDynamicInterceptorListenerTest.java

示例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());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:27,代码来源:OsgiServiceDynamicInterceptorListenerTest.java

示例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));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:24,代码来源:OsgiListenerUtilsTest.java

示例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));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:OsgiListenerUtilsTest.java

示例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();
}
 
开发者ID:apache,项目名称:aries-rsa,代码行数:18,代码来源:TopologyManagerExportTest.java

示例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();
}
 
开发者ID:apache,项目名称:aries-rsa,代码行数:19,代码来源:TopologyManagerExportTest.java

示例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();
}
 
开发者ID:apache,项目名称:aries-rsa,代码行数:18,代码来源:TopologyManagerExportTest.java

示例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
    }
}
 
开发者ID:apache,项目名称:aries-rsa,代码行数:21,代码来源:RemoteServiceAdminCore.java

示例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;
    }
}
 
开发者ID:primeval-io,项目名称:aspecio,代码行数:24,代码来源:ServiceWeavingManager.java


注:本文中的org.osgi.framework.ServiceEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。