Search in sources :

Example 6 with RemoteServiceAdmin

use of org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin 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 7 with RemoteServiceAdmin

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

the class EndpointDiscoveryView method findImportReference.

protected ImportReference findImportReference(EndpointDescription ed) {
    RemoteServiceAdmin rsa = discovery.getRSA();
    if (rsa == null)
        return null;
    List<ImportRegistration> iRegs = rsa.getImportedRegistrations();
    for (ImportRegistration ir : iRegs) {
        ImportReference importRef = (ImportReference) ir.getImportReference();
        if (importRef != null && ed.equals(importRef.getImportedEndpoint()))
            return importRef;
    }
    return null;
}
Also used : RemoteServiceAdmin(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin) ImportReference(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportReference) ImportRegistration(org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportRegistration)

Aggregations

RemoteServiceAdmin (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin)7 EndpointDescription (org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescription)3 ImportReference (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportReference)3 ImportRegistration (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ImportRegistration)3 EndpointDescriptionRSANode (org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.EndpointDescriptionRSANode)2 ServiceIdNode (org.eclipse.ecf.remoteserviceadmin.ui.rsa.model.ServiceIdNode)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Dictionary (java.util.Dictionary)1 Properties (java.util.Properties)1 ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)1 EndpointDescriptionLocator (org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionLocator)1 EndpointDescriptionReader (org.eclipse.ecf.osgi.services.remoteserviceadmin.EndpointDescriptionReader)1 IEndpointDescriptionLocator (org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionLocator)1 IServiceInfoFactory (org.eclipse.ecf.osgi.services.remoteserviceadmin.IServiceInfoFactory)1 ExportReference (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ExportReference)1 ExportRegistration (org.eclipse.ecf.osgi.services.remoteserviceadmin.RemoteServiceAdmin.ExportRegistration)1 ServiceInfoFactory (org.eclipse.ecf.osgi.services.remoteserviceadmin.ServiceInfoFactory)1 AbstractEndpointNode (org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.AbstractEndpointNode)1 EndpointNode (org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointNode)1