Search in sources :

Example 1 with ServiceInfoFactory

use of org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory in project ecf by eclipse.

the class ServiceInfoFactoryTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    discoveryAdvertiser = getDiscoveryAdvertiser();
    Assert.isNotNull(discoveryAdvertiser);
    serviceInfoFactory = new ServiceInfoFactory();
}
Also used : ServiceInfoFactory(org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory)

Example 2 with ServiceInfoFactory

use of org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory in project ecf by eclipse.

the class Activator method start.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext )
	 */
public void start(BundleContext bundleContext) throws Exception {
    Activator.context = bundleContext;
    Activator.instance = this;
    this.exportedRegistrations = new ArrayList<ExportRegistration>();
    this.importedRegistrations = new ArrayList<ImportRegistration>();
    // start dependent bundles first
    initializeDependents();
    // initialize the RSA proxy service factory bundle...so that we
    // can get/use *that bundle's BundleContext for registering the
    // proxy ServiceFactory.
    // See osgi-dev thread here for info about this
    // approach/using the ServiceFactory extender approach for this purpose:
    // https://mail.osgi.org/pipermail/osgi-dev/2011-February/003000.html
    initializeProxyServiceFactoryBundle();
    // Start distribution providers if not already started
    initializeProviders(context.getBundle(), DistributionNamespace.DISTRIBUTION_NAMESPACE, // $NON-NLS-1$
    "Could not start distribution provider. ");
    // Start distribution providers if not already started
    initializeProviders(context.getBundle(), DiscoveryNamespace.DISCOVERY_NAMESPACE, // $NON-NLS-1$
    "Could not start discovery provider. ");
    // make remote service admin available
    rsaProps = new Properties();
    rsaProps.put(RemoteServiceAdmin.SERVICE_PROP, new Boolean(true));
    // Register Remote Service Admin factory, with rsaProps
    remoteServiceAdminRegistration = context.registerService(org.osgi.service.remoteserviceadmin.RemoteServiceAdmin.class.getName(), new ServiceFactory() {

        public Object getService(Bundle bundle, ServiceRegistration registration) {
            RemoteServiceAdmin result = null;
            synchronized (remoteServiceAdmins) {
                result = remoteServiceAdmins.get(bundle);
                if (result == null) {
                    result = new RemoteServiceAdmin(bundle, exportedRegistrations, importedRegistrations);
                    remoteServiceAdmins.put(bundle, result);
                }
            }
            return result;
        }

        public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
            synchronized (remoteServiceAdmins) {
                RemoteServiceAdmin rsa = remoteServiceAdmins.remove(bundle);
                if (rsa != null)
                    rsa.close();
            }
        }
    }, (Dictionary) rsaProps);
    ctdTracker = new ServiceTracker<ContainerTypeDescription, ContainerTypeDescription>(context, ContainerTypeDescription.class, new ServiceTrackerCustomizer<ContainerTypeDescription, ContainerTypeDescription>() {

        public ContainerTypeDescription addingService(ServiceReference<ContainerTypeDescription> reference) {
            ContainerTypeDescription ctd = null;
            if (reference != null && context != null) {
                ctd = context.getService(reference);
                if (ctd != null) {
                    // Add any new supported configs to rsaProps
                    addSupportedConfigsAndIntents(ctd);
                    if (remoteServiceAdminRegistration != null)
                        // Set the new properties for
                        // remoteServiceRegistration
                        remoteServiceAdminRegistration.setProperties(rsaProps);
                }
            }
            return ctd;
        }

        public void modifiedService(ServiceReference<ContainerTypeDescription> reference, ContainerTypeDescription service) {
        }

        public void removedService(ServiceReference<ContainerTypeDescription> reference, ContainerTypeDescription service) {
            if (remoteServiceAdminRegistration != null && service != null) {
                // Remove supported configs and intents from
                // rsaProps
                removeSupportedConfigsAndIntents(service);
                // Reset properties for remoteServiceAdmin
                remoteServiceAdminRegistration.setProperties(rsaProps);
            }
        }
    });
    ctdTracker.open();
    // create endpoint description locator
    endpointDescriptionLocator = new EndpointDescriptionLocator(context);
    // create and register endpoint description advertiser
    final Properties properties = new Properties();
    properties.put(Constants.SERVICE_RANKING, new Integer(Integer.MIN_VALUE));
    iServiceInfoFactoryRegistration = context.registerService(IServiceInfoFactory.class.getName(), new ServiceInfoFactory(), (Dictionary) properties);
    // start endpointDescriptionLocator
    endpointDescriptionLocator.start();
}
Also used : Dictionary(java.util.Dictionary) RemoteServiceAdmin(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin) EndpointDescriptionLocator(org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionLocator) ServiceFactory(org.osgi.framework.ServiceFactory) Bundle(org.osgi.framework.Bundle) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) Properties(java.util.Properties) ImportRegistration(org.osgi.service.remoteserviceadmin.ImportRegistration) ServiceReference(org.osgi.framework.ServiceReference) ExportRegistration(org.osgi.service.remoteserviceadmin.ExportRegistration) ServiceInfoFactory(org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory) IServiceInfoFactory(org.eclipse.ecf.osgi.services.remoteserviceadmin.IServiceInfoFactory) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 3 with ServiceInfoFactory

use of org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory in project ecf by eclipse.

the class EndpointDescriptionFactoryTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    discoveryAdvertiser = getDiscoveryAdvertiser();
    Assert.isNotNull(discoveryAdvertiser);
    serviceInfoFactory = new ServiceInfoFactory();
    Assert.isNotNull(serviceInfoFactory);
    discoveryLocator = getDiscoveryLocator();
    Assert.isNotNull(discoveryLocator);
    endpointDescriptionFactory = new DiscoveredEndpointDescriptionFactory();
    Assert.isNotNull(endpointDescriptionFactory);
}
Also used : ServiceInfoFactory(org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory) DiscoveredEndpointDescriptionFactory(org.eclipse.ecf.osgi.services.remoteserviceadmin.DiscoveredEndpointDescriptionFactory)

Aggregations

ServiceInfoFactory (org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory)3 Dictionary (java.util.Dictionary)1 Properties (java.util.Properties)1 ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)1 DiscoveredEndpointDescriptionFactory (org.eclipse.ecf.osgi.services.remoteserviceadmin.DiscoveredEndpointDescriptionFactory)1 EndpointDescriptionLocator (org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionLocator)1 IServiceInfoFactory (org.eclipse.ecf.osgi.services.remoteserviceadmin.IServiceInfoFactory)1 RemoteServiceAdmin (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin)1 Bundle (org.osgi.framework.Bundle)1 ServiceFactory (org.osgi.framework.ServiceFactory)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 ExportRegistration (org.osgi.service.remoteserviceadmin.ExportRegistration)1 ImportRegistration (org.osgi.service.remoteserviceadmin.ImportRegistration)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1