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


Java ServiceFactory类代码示例

本文整理汇总了Java中org.osgi.framework.ServiceFactory的典型用法代码示例。如果您正苦于以下问题:Java ServiceFactory类的具体用法?Java ServiceFactory怎么用?Java ServiceFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServiceFactory类属于org.osgi.framework包,在下文中一共展示了ServiceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ungetService

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public void ungetService(Bundle bundle, ServiceRegistration serviceRegistration, Object service) {

		if (log.isTraceEnabled()) {
			log.trace("Unget service called by bundle " + OsgiStringUtils.nullSafeName(bundle) + " on registration "
					+ OsgiStringUtils.nullSafeToString(serviceRegistration.getReference()));
		}

		Class<?> type = targetResolver.getType();
		// handle SF beans
		if (ServiceFactory.class.isAssignableFrom(type)) {
			ServiceFactory sf = (ServiceFactory) targetResolver.getBean();
			sf.ungetService(bundle, serviceRegistration, service);
		}

		if (createTCCLProxy) {
			synchronized (proxyCache) {
				// trigger purging of unused entries
				proxyCache.size();
			}
		}
	}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:PublishingServiceFactory.java

示例2: testPrototypeServiceFactoryDestruction

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public void testPrototypeServiceFactoryDestruction() throws Exception {
    ServiceFactory factory = new MockServiceFactory();
    String beanName = "prototype-sf";

    expect(beanFactory.isSingleton(beanName)).andReturn(false).times(2);
    expect(beanFactory.containsBean(beanName)).andReturn(true);
    expect(beanFactory.isPrototype(beanName)).andReturn(true);
    expect(beanFactory.getBean(beanName)).andReturn(factory);
    expect(beanFactory.getType(beanName)).andStubReturn((Class) factory.getClass());


    exporter.setTargetBeanName(beanName);
    exporter.setInterfaces(new Class<?>[]{Serializable.class});
    beanFactoryControl.replay();
    exporter.afterPropertiesSet();
    exporter.destroy();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:18,代码来源:OsgiServiceFactoryBeanTest.java

示例3: testServiceFactoryListener

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public void testServiceFactoryListener() throws Exception {
	listener = new OsgiServiceRegistrationListenerAdapter();
	listener.setTarget(new ServiceFactoryListener());
	listener.setRegistrationMethod("registered");
	listener.setUnregistrationMethod("unregistered");
	listener.setBeanFactory(createMockBF());
	listener.afterPropertiesSet();
	Object service = new Object();
	assertEquals(0, ServiceFactoryListener.REG_CALLS);
	assertEquals(0, ServiceFactoryListener.UNREG_CALLS);

	listener.registered(service, props);
	listener.unregistered(service, props);

	assertEquals(0, ServiceFactoryListener.REG_CALLS);
	assertEquals(0, ServiceFactoryListener.UNREG_CALLS);

	ServiceFactory factory = new MockServiceFactory();

	listener.registered(factory, props);
	listener.unregistered(factory, props);
	assertEquals(1, ServiceFactoryListener.REG_CALLS);
	assertEquals(1, ServiceFactoryListener.UNREG_CALLS);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:25,代码来源:OsgiServiceRegistrationListenerAdapterTest.java

示例4: ungetService

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
boolean ungetService(Bundle bundle) {
    synchronized (this.useCounters) {
        if (this.service == null) {
            return false;
        }
        Integer num = (Integer) this.useCounters.get(bundle);
        if (num == null) {
            return false;
        } else if (num.intValue() == 1) {
            this.useCounters.remove(bundle);
            if (this.isServiceFactory) {
                ((ServiceFactory) this.service).ungetService(bundle, this.registration, this.cachedServices.get(bundle));
                this.cachedServices.remove(bundle);
            }
            return false;
        } else {
            this.useCounters.put(bundle, Integer.valueOf(num.intValue() - 1));
            return true;
        }
    }
}
 
开发者ID:achellies,项目名称:AtlasForAndroid,代码行数:22,代码来源:ServiceReferenceImpl.java

示例5: getService

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public Object getService(Bundle bundle, ServiceRegistration serviceRegistration) {
	Object bn = getBean();
	// handle SF beans
	if (bn instanceof ServiceFactory) {
		bn = ((ServiceFactory) bn).getService(bundle, serviceRegistration);
	}

	if (createTCCLProxy) {
		// check proxy cache
		synchronized (proxyCache) {
               WeakReference value = (WeakReference) proxyCache.get(bn);
			Object proxy = null;
			if (value != null) {
				proxy = value.get();
			}				
			if (proxy == null) {
				proxy = createCLLProxy(bn);
				proxyCache.put(bn, new WeakReference(proxy));
			}
			bn = proxy;
		}
	}

	return bn;
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:26,代码来源:PublishingServiceFactory.java

示例6: registerService

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
/**
 * Registration method.
 * 
 * @param classes
 * @param serviceProperties
 * @return the ServiceRegistration
 */
ServiceRegistration registerService(Class[] classes, Dictionary serviceProperties) {
	Assert.notEmpty(
		classes,
		"at least one class has to be specified for exporting (if autoExport is enabled then maybe the object doesn't implement any interface)");

	// create an array of classnames (used for registering the service)
	String[] names = ClassUtils.toStringArray(classes);
	// sort the names in alphabetical order (eases debugging)
	Arrays.sort(names);

	log.info("Publishing service under classes [" + ObjectUtils.nullSafeToString(names) + "]");

	ServiceFactory serviceFactory = new PublishingServiceFactory(classes, target, beanFactory, targetBeanName,
		(contextClassLoader == ExportContextClassLoader.SERVICE_PROVIDER), classLoader, aopClassLoader,
		bundleContext);

	if (isBeanBundleScoped())
		serviceFactory = new OsgiBundleScope.BundleScopeServiceFactory(serviceFactory);

	return bundleContext.registerService(names, serviceFactory, serviceProperties);
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:29,代码来源:OsgiServiceFactoryBean.java

示例7: getService

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public Object getService(Bundle bundle, ServiceRegistration serviceRegistration) {
	if (log.isTraceEnabled()) {
		log.trace("Get service called by bundle " + OsgiStringUtils.nullSafeName(bundle) + " on registration "
				+ OsgiStringUtils.nullSafeToString(serviceRegistration.getReference()));
	}

	targetResolver.activate();
	Object bn = targetResolver.getBean();

	// handle SF beans
	if (bn instanceof ServiceFactory) {
		bn = ((ServiceFactory) bn).getService(bundle, serviceRegistration);
	}

	if (createTCCLProxy) {
		// check proxy cache
		synchronized (proxyCache) {
			WeakReference<Object> value = proxyCache.get(bn);
			Object proxy = null;
			if (value != null) {
				proxy = value.get();
			}
			if (proxy == null) {
				proxy = createCLLProxy(bn);
				proxyCache.put(bn, new WeakReference<Object>(proxy));
			}
			bn = proxy;
		}
	}

	return bn;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:33,代码来源:PublishingServiceFactory.java

示例8: registerService

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
/**
 * Registration method.
 * 
 * @param classes
 * @param serviceProperties
 * @return the ServiceRegistration
 */
ServiceRegistration registerService(Class<?>[] classes, final Dictionary serviceProperties) {
	Assert.notEmpty(classes, "at least one class has to be specified for exporting "
			+ "(if autoExport is enabled then maybe the object doesn't implement any interface)");

	// create an array of classnames (used for registering the service)
	final String[] names = ClassUtils.toStringArray(classes);
	// sort the names in alphabetical order (eases debugging)
	Arrays.sort(names);

	log.info("Publishing service under classes [" + ObjectUtils.nullSafeToString(names) + "]");

	ServiceFactory serviceFactory =
			new PublishingServiceFactory(resolver, classes, (ExportContextClassLoaderEnum.SERVICE_PROVIDER
					.equals(contextClassLoader)), classLoader, aopClassLoader, bundleContext);

	if (isBeanBundleScoped())
		serviceFactory = new OsgiBundleScope.BundleScopeServiceFactory(serviceFactory);

	if (System.getSecurityManager() != null) {
		AccessControlContext acc = SecurityUtils.getAccFrom(beanFactory);
		final ServiceFactory serviceFactoryFinal = serviceFactory;
		return AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {
			public ServiceRegistration run() {
				return bundleContext.registerService(names, serviceFactoryFinal, serviceProperties);
			}
		}, acc);
	} else {
		return bundleContext.registerService(names, serviceFactory, serviceProperties);
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:38,代码来源:OsgiServiceFactoryBean.java

示例9: testRegisterService

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public void testRegisterService() throws Exception {
    Class<?>[] clazz =
            new Class<?>[]{Serializable.class, HashMap.class, Cloneable.class, Map.class, LinkedHashMap.class};

    String[] names = new String[clazz.length];

    for (int i = 0; i < clazz.length; i++) {
        names[i] = clazz[i].getName();
    }

    final Properties props = new Properties();
    final ServiceRegistration reg = new MockServiceRegistration();

    exporter.setBundleContext(new MockBundleContext() {

        public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties) {
            assertTrue(service instanceof ServiceFactory);
            return reg;
        }
    });

    Object proxy = createMock(ServiceFactory.class);
    exporter.setTarget(proxy);
    exporter.setInterfaces(new Class<?>[]{ServiceFactory.class});
    String beanName = "boo";
    exporter.setTargetBeanName(beanName);

    expect(beanFactory.isSingleton(beanName)).andReturn(true);
    expect(beanFactory.isPrototype(beanName)).andReturn(false);
    expect(beanFactory.containsBean(beanName)).andReturn(true);
    expect(beanFactory.getBean(beanName)).andReturn(proxy);
    expect(beanFactory.getType(beanName)).andStubReturn((Class) ServiceFactory.class);
    beanFactoryControl.replay();

    exporter.afterPropertiesSet();
    assertSame(reg, exporter.registerService(clazz, props));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:38,代码来源:OsgiServiceFactoryBeanTest.java

示例10: testServiceFactory

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public void testServiceFactory() throws Exception {
    ServiceFactory factory = new MockServiceFactory();

    ctx = new MockBundleContext();
    exporter.setBundleContext(ctx);
    exporter.setBeanFactory(beanFactory);
    exporter.setInterfaces(new Class<?>[]{Serializable.class, Cloneable.class});
    exporter.setTarget(factory);
    beanFactoryControl.replay();
    exporter.afterPropertiesSet();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:12,代码来源:OsgiServiceFactoryBeanTest.java

示例11: testPrototypeServiceFactory

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public void testPrototypeServiceFactory() throws Exception {
    ServiceFactory factory = new MockServiceFactory();
    String beanName = "prototype-sf";
    expect(beanFactory.isSingleton(beanName)).andReturn(false);
    expect(beanFactory.isPrototype(beanName)).andReturn(true);
    expect(beanFactory.containsBean(beanName)).andReturn(true);
    expect(beanFactory.getBean(beanName)).andReturn(factory);
    expect(beanFactory.getType(beanName)).andStubReturn((Class) factory.getClass());

    exporter.setTargetBeanName(beanName);
    exporter.setInterfaces(new Class<?>[]{Serializable.class});
    beanFactoryControl.replay();
    exporter.afterPropertiesSet();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:15,代码来源:OsgiServiceFactoryBeanTest.java

示例12: testNonSingletonServiceFactoryRegistration

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public void testNonSingletonServiceFactoryRegistration() throws Exception {
    TestRegistrationListener listener = new TestRegistrationListener();

    ServiceFactory factory = new MockServiceFactory();
    String beanName = "prototype-sf";
    expect(beanFactory.isSingleton(beanName)).andReturn(false).times(3);
    expect(beanFactory.containsBean(beanName)).andReturn(true);
    expect(beanFactory.isPrototype(beanName)).andReturn(false);
    expect(beanFactory.getBean(beanName)).andReturn(factory);
    expect(beanFactory.getType(beanName)).andStubReturn((Class) factory.getClass());


    exporter.setTargetBeanName(beanName);
    exporter.setInterfaces(new Class<?>[]{Serializable.class});
    exporter.setListeners(new OsgiServiceRegistrationListener[]{listener});

    beanFactoryControl.replay();
    assertEquals(0, listener.registered.size());
    assertEquals(0, listener.unregistered.size());

    exporter.afterPropertiesSet();

    assertEquals(1, listener.registered.size());
    assertEquals(0, listener.unregistered.size());

    assertNull(listener.registered.keySet().iterator().next());
    exporter.destroy();
    assertEquals(1, listener.unregistered.size());
    assertNull(listener.unregistered.keySet().iterator().next());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:31,代码来源:OsgiServiceFactoryBeanTest.java

示例13: testExtServiceFactoryListener

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
public void testExtServiceFactoryListener() throws Exception {

		listener = new OsgiServiceRegistrationListenerAdapter();
		listener.setTarget(new ExtServiceFactoryListener());
		listener.setRegistrationMethod("registered");
		listener.setUnregistrationMethod("unregistered");
		listener.setBeanFactory(createMockBF());
		listener.afterPropertiesSet();
		Object service = new Object();
		assertEquals(0, ServiceFactoryListener.REG_CALLS);
		assertEquals(0, ServiceFactoryListener.UNREG_CALLS);

		listener.registered(service, props);
		listener.unregistered(service, props);

		assertEquals(0, ServiceFactoryListener.REG_CALLS);
		assertEquals(0, ServiceFactoryListener.UNREG_CALLS);

		ServiceFactory factory = new MockServiceFactory();

		listener.registered(factory, props);
		listener.unregistered(factory, props);

		assertEquals(1, ServiceFactoryListener.REG_CALLS);
		assertEquals(1, ServiceFactoryListener.UNREG_CALLS);

		ServiceFactory extFactory = new MockExtendedServiceFactory();

		listener.registered(extFactory, props);
		listener.unregistered(extFactory, props);

		assertEquals(3, ServiceFactoryListener.REG_CALLS);
		assertEquals(3, ServiceFactoryListener.UNREG_CALLS);
	}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:35,代码来源:OsgiServiceRegistrationListenerAdapterTest.java

示例14: getServiceAtIndex

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
private Object getServiceAtIndex(int index) {
	Object sFactory = services.get(index);
	assertNotNull(sFactory);
	assertTrue(sFactory instanceof ServiceFactory);
	ServiceFactory fact = (ServiceFactory) sFactory;
	return fact.getService(null, null);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:8,代码来源:OsgiServiceNamespaceHandlerTest.java

示例15: testAddingWithNullValues

import org.osgi.framework.ServiceFactory; //导入依赖的package包/类
@Test
public void testAddingWithNullValues() throws InvalidSyntaxException {
    IMocksControl c = EasyMock.createControl();
    DistributionProvider provider = c.createMock(DistributionProvider.class);

    ServiceReference<DistributionProvider> providerRef = c.createMock(ServiceReference.class);
    EasyMock.expect(providerRef.getProperty(RemoteConstants.REMOTE_INTENTS_SUPPORTED)).andReturn(null);
    EasyMock.expect(providerRef.getProperty(RemoteConstants.REMOTE_CONFIGS_SUPPORTED)).andReturn(null);

    BundleContext context = c.createMock(BundleContext.class);
    String filterSt = String.format("(objectClass=%s)", DistributionProvider.class.getName());
    Filter filter = FrameworkUtil.createFilter(filterSt);
    EasyMock.expect(context.createFilter(filterSt)).andReturn(filter);
    EasyMock.expect(context.getService(providerRef)).andReturn(provider);
    ServiceRegistration rsaReg = c.createMock(ServiceRegistration.class);
    EasyMock.expect(context.registerService(EasyMock.isA(String.class), EasyMock.isA(ServiceFactory.class),
                                            EasyMock.isA(Dictionary.class)))
        .andReturn(rsaReg).atLeastOnce();

    context.addServiceListener(EasyMock.isA(ServiceListener.class), EasyMock.isA(String.class));
    EasyMock.expectLastCall();

    final BundleContext apiContext = c.createMock(BundleContext.class);
    c.replay();
    DistributionProviderTracker tracker = new DistributionProviderTracker(context) {
        protected BundleContext getAPIContext() {
            return apiContext;
        };
    };
    tracker.addingService(providerRef);
    c.verify();
}
 
开发者ID:apache,项目名称:aries-rsa,代码行数:33,代码来源:DistributionProviderTrackerTest.java


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