當前位置: 首頁>>代碼示例>>Java>>正文


Java ServiceListener.serviceChanged方法代碼示例

本文整理匯總了Java中org.osgi.framework.ServiceListener.serviceChanged方法的典型用法代碼示例。如果您正苦於以下問題:Java ServiceListener.serviceChanged方法的具體用法?Java ServiceListener.serviceChanged怎麽用?Java ServiceListener.serviceChanged使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.osgi.framework.ServiceListener的用法示例。


在下文中一共展示了ServiceListener.serviceChanged方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: registerService

import org.osgi.framework.ServiceListener; //導入方法依賴的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

示例2: testServiceReferenceMemberType

import org.osgi.framework.ServiceListener; //導入方法依賴的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

示例3: testUnbind

import org.osgi.framework.ServiceListener; //導入方法依賴的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

示例4: testStickinessWhenABetterServiceIsAvailable

import org.osgi.framework.ServiceListener; //導入方法依賴的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

示例5: testStickinessWhenServiceGoesDown

import org.osgi.framework.ServiceListener; //導入方法依賴的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

示例6: testListeners

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
@Test
public void testListeners() throws Exception {
  Future<PentahoCacheProvidingService> serviceFuture;

  factory.init();
  verify( bundleContext ).addServiceListener( serviceListenerCaptor.capture(), argThat( matchesFilter ) );

  serviceFuture = factory.getProviderService( MOCK_PID );
  assertThat( serviceFuture.isDone(), is( true ) );
  assertThat( serviceFuture.get( 1, TimeUnit.SECONDS ), is( providingService ) );

  ServiceListener serviceListener = serviceListenerCaptor.getValue();

  serviceListener.serviceChanged( new ServiceEvent( ServiceEvent.UNREGISTERING, serviceReference ) );

  serviceFuture = factory.getProviderService( MOCK_PID );
  assertThat( serviceFuture.isDone(), is( false ) );

  serviceListener.serviceChanged( new ServiceEvent( ServiceEvent.REGISTERED, serviceReference ) );

  serviceFuture = factory.getProviderService( MOCK_PID );
  assertThat( serviceFuture.isDone(), is( true ) );
  assertThat( serviceFuture.get( 1, TimeUnit.SECONDS ), is( providingService ) );
}
 
開發者ID:pentaho,項目名稱:pentaho-osgi-bundles,代碼行數:25,代碼來源:PentahoCacheManagerFactoryTest.java

示例7: start

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
/**
 * Called by the framework for initialisation when the Activator class is loaded.
 * The method first get a service reference on the osgi logging service, used for
 * logging whithin the bundle.
 *
 * If the method cannot get a reference to the logging service, a NullPointerException is thrown.
 * @param context
 * @throws BundleException
 */
public void start(BundleContext context) throws Exception {
	// TODO Auto-generated method stub
	Activator.bc = context;
	
	// we construct a listener to detect if the log service appear or disapear.
	String filter = "(objectclass=" + logServiceName + ")";
	ServiceListener logServiceListener = new LogServiceListener();
	try {
		bc.addServiceListener( logServiceListener, filter);
		// in case the service is already registered, we send a REGISTERED event to its listener.
		ServiceReference srLog = bc.getServiceReference( logServiceName );
		if( srLog != null ) {
			logServiceListener.serviceChanged(new ServiceEvent( ServiceEvent.REGISTERED, srLog ));
		}
	} catch ( InvalidSyntaxException e ) {
		throw new BundleException("Error in filter string while registering LogServiceListener." + e.toString());
	}
	
	piService = new PiService();
}
 
開發者ID:lathil,項目名稱:Ptoceti,代碼行數:30,代碼來源:Activator.java

示例8: start

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
/**
    * Called by the framework for initialisation when the Activator class is
    * loaded. The method first get a service reference on the osgi logging
    * service, used for logging whithin the bundle.
    * 
    * If the method cannot get a reference to the logging service, a
    * NullPointerException is thrown.
    * 
    * @param context
    * @throws BundleException
    */
   public void start(BundleContext context) throws BundleException {

Activator.bc = context;

// we construct a listener to detect if the log service appear or
// disapear.
String logFilter = "(objectclass=" + logServiceName + ")";
ServiceListener logServiceListener = new LogServiceListener();
try {
    bc.addServiceListener(logServiceListener, logFilter);
    // in case the service is already registered, we send a REGISTERED
    // event to its listener.
    ServiceReference srLog = bc.getServiceReference(logServiceName);
    if (srLog != null) {
	logServiceListener.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, srLog));
    }
} catch (InvalidSyntaxException e) {
    throw new BundleException("Error in filter string while registering LogServiceListener." + e.toString());
}

log(LogService.LOG_INFO, "Starting version " + bc.getBundle().getHeaders().get("Bundle-Version"));

influxDbFactory.start();
   }
 
開發者ID:lathil,項目名稱:Ptoceti,代碼行數:36,代碼來源:Activator.java

示例9: testMandatoryServiceUnAvailableWhileWorking

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
public void testMandatoryServiceUnAvailableWhileWorking() {
	serviceFactoryBean.setInterfaces(new Class[] { Serializable.class });
	serviceFactoryBean.afterPropertiesSet();

	Collection col = (Collection) serviceFactoryBean.getObject();

	assertFalse(col.isEmpty());
	Set listeners = bundleContext.getServiceListeners();

	ServiceListener list = (ServiceListener) listeners.iterator().next();
	list.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, ref));

	try {
		// disable filter
		col.isEmpty();
		fail("should have thrown exception");
	}
	catch (ServiceUnavailableException ex) {
		// expected
	}
}
 
開發者ID:BeamFoundry,項目名稱:spring-osgi,代碼行數:22,代碼來源:OsgiServiceCollectionProxyFactoryBeanTest.java

示例10: removeService

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
protected void removeService(Object service) {
	ServiceReference ref = new MockServiceReference();

	for (Iterator iter = services.entrySet().iterator(); iter.hasNext();) {
		Map.Entry entry = (Map.Entry) iter.next();
		if (entry.getValue().equals(service)) {
			ref = (ServiceReference) entry.getKey();
			continue;
		}
	}

	services.remove(ref);

	ServiceEvent event = new ServiceEvent(ServiceEvent.UNREGISTERING, ref);

	for (Iterator iter = context.getServiceListeners().iterator(); iter.hasNext();) {
		ServiceListener listener = (ServiceListener) iter.next();
		listener.serviceChanged(event);
	}

}
 
開發者ID:BeamFoundry,項目名稱:spring-osgi,代碼行數:22,代碼來源:AbstractOsgiCollectionTest.java

示例11: dispatchServiceRegistrationEvents

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
private static void dispatchServiceRegistrationEvents(ServiceReference[] alreadyRegistered, ServiceListener listener) {
	if (log.isTraceEnabled())
		log.trace("Calling listener for already registered services: "
				+ ObjectUtils.nullSafeToString(alreadyRegistered));

	if (alreadyRegistered != null) {
		for (int i = 0; i < alreadyRegistered.length; i++) {
			listener.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, alreadyRegistered[i]));
		}
	}
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:12,代碼來源:OsgiListenerUtils.java

示例12: testMandatoryServiceUnAvailableWhileWorking

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
public void testMandatoryServiceUnAvailableWhileWorking() {
	serviceFactoryBean.setInterfaces(new Class<?>[] { Runnable.class });
	serviceFactoryBean.afterPropertiesSet();

	Collection col = (Collection) serviceFactoryBean.getObject();

	assertFalse(col.isEmpty());
	Set listeners = bundleContext.getServiceListeners();

	ServiceListener list = (ServiceListener) listeners.iterator().next();
	// disable filter
	list.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, ref));
	col.isEmpty();
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:15,代碼來源:OsgiServiceCollectionProxyFactoryBeanTest.java

示例13: testRebindWhenServiceGoesDownButAReplacementIsFound

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
public void testRebindWhenServiceGoesDownButAReplacementIsFound() {
	interceptor.afterPropertiesSet();

	assertEquals(1, SimpleTargetSourceLifecycleListener.BIND);
	assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);

	ServiceListener sl = (ServiceListener) bundleContext.getServiceListeners().iterator().next();

	// unregister the old service
	sl.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, refs[0]));

	// a new one is found since the mock context will return one again
	assertEquals(2, SimpleTargetSourceLifecycleListener.BIND);
	assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:16,代碼來源:OsgiServiceDynamicInterceptorListenerTest.java

示例14: testRebindWhenNewServiceAppears

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
public void testRebindWhenNewServiceAppears() {
	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(2, SimpleTargetSourceLifecycleListener.BIND);
	assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:22,代碼來源:OsgiServiceDynamicInterceptorListenerTest.java

示例15: testRebindWhenNewServiceAppears

import org.osgi.framework.ServiceListener; //導入方法依賴的package包/類
public void testRebindWhenNewServiceAppears() {
	interceptor.afterPropertiesSet();

	ServiceListener sl = (ServiceListener) bundleContext.getServiceListeners().iterator().next();

	Dictionary props = new Hashtable();
	// increase service ranking
	props.put(Constants.SERVICE_RANKING, new Integer(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(2, SimpleTargetSourceLifecycleListener.BIND);
	assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
}
 
開發者ID:BeamFoundry,項目名稱:spring-osgi,代碼行數:22,代碼來源:OsgiServiceDynamicInterceptorListenerTest.java


注:本文中的org.osgi.framework.ServiceListener.serviceChanged方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。