Search in sources :

Example 21 with ContainerTypeDescription

use of org.eclipse.ecf.core.ContainerTypeDescription in project ecf by eclipse.

the class ContainerFactoryServiceCreateTest method testContainerTypeDescriptionGetName.

public void testContainerTypeDescriptionGetName() {
    final ContainerTypeDescription desc = getContainerFactoryService().getDescriptionByName(CONTAINER_TYPE_NAME);
    assertTrue(desc.getName().equals(CONTAINER_TYPE_NAME));
}
Also used : ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription)

Example 22 with ContainerTypeDescription

use of org.eclipse.ecf.core.ContainerTypeDescription in project ecf by eclipse.

the class ContainerFactoryServiceDescriptionsTest method testGetDescriptionByName.

public void testGetDescriptionByName() {
    ContainerTypeDescription desc = getFixture().getDescriptionByName(getDescription().getName());
    assertNotNull(desc);
}
Also used : ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription)

Example 23 with ContainerTypeDescription

use of org.eclipse.ecf.core.ContainerTypeDescription in project ecf by eclipse.

the class Activator method start.

/*
	 * (non-Javadoc)
	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
	 */
public void start(BundleContext context) throws Exception {
    this.context = context;
    plugin = this;
    SafeRunner.run(new ExtensionRegistryRunnable(this.context) {

        protected void runWithoutRegistry() throws Exception {
            // If we don't have a registry, then register trivial namespace
            Activator.this.context.registerService(Namespace.class, new TrivialNamespace(TrivialNamespace.NAME), null);
            // And create and register ContainerTypeDescription
            Activator.this.context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(TrivialContainerInstantiator.NAME, (IContainerInstantiator) new TrivialContainerInstantiator()), null);
        }
    });
}
Also used : TrivialNamespace(org.eclipse.ecf.examples.provider.trivial.identity.TrivialNamespace) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) ExtensionRegistryRunnable(org.eclipse.ecf.core.util.ExtensionRegistryRunnable) TrivialContainerInstantiator(org.eclipse.ecf.internal.examples.provider.trivial.container.TrivialContainerInstantiator) TrivialNamespace(org.eclipse.ecf.examples.provider.trivial.identity.TrivialNamespace) Namespace(org.eclipse.ecf.core.identity.Namespace)

Example 24 with ContainerTypeDescription

use of org.eclipse.ecf.core.ContainerTypeDescription 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 25 with ContainerTypeDescription

use of org.eclipse.ecf.core.ContainerTypeDescription in project ecf by eclipse.

the class AbstractHostContainerSelector method selectExistingHostContainers.

/**
 * @param serviceReference service reference
 * @param overridingProperties overriding properties
 * @param serviceExportedInterfaces service exported interfaces to select for
 * @param serviceExportedConfigs service exported configs to select for
 * @param serviceIntents service exported intents to select for
 * @return Collection of existing host containers
 * @since 2.0
 */
protected Collection selectExistingHostContainers(ServiceReference serviceReference, Map<String, Object> overridingProperties, String[] serviceExportedInterfaces, String[] serviceExportedConfigs, String[] serviceIntents) {
    List results = new ArrayList();
    // Get all existing containers
    IContainer[] containers = getContainers();
    // If nothing there, then return empty array
    if (containers == null || containers.length == 0)
        return results;
    for (int i = 0; i < containers.length; i++) {
        ID cID = containers[i].getID();
        // $NON-NLS-1$ //$NON-NLS-2$
        trace("selectExistingHostContainers", "Considering existing container=" + cID);
        // Check to make sure it's a rs container adapter. If it's not go
        // onto next one
        IRemoteServiceContainerAdapter adapter = hasRemoteServiceContainerAdapter(containers[i]);
        if (adapter == null) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            trace("selectExistingHostContainers", "Existing container=" + cID + " does not implement IRemoteServiceContainerAdapter");
            continue;
        }
        // Get container type description and intents
        ContainerTypeDescription description = getContainerTypeDescription(containers[i]);
        // If it has no description go onto next
        if (description == null) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            trace("selectExistingHostContainers", "Existing container=" + cID + " does not have container type description");
            continue;
        }
        // http://bugs.eclipse.org/331532
        if (!description.isServer()) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            trace("selectExistingHostContainers", "Existing container=" + cID + " is not server");
            continue;
        }
        if (matchExistingHostContainer(serviceReference, overridingProperties, containers[i], adapter, description, serviceExportedConfigs, serviceIntents)) {
            trace("selectExistingHostContainers", // $NON-NLS-1$ //$NON-NLS-2$
            "INCLUDING containerID=" + containers[i].getID() + // $NON-NLS-1$
            " configs=" + ((serviceExportedConfigs == null) ? "null" : // $NON-NLS-1$
            Arrays.asList(serviceExportedConfigs).toString()) + // $NON-NLS-1$
            " intents=" + ((serviceIntents == null) ? "null" : // $NON-NLS-1$
            Arrays.asList(serviceIntents).toString()));
            results.add(new RemoteServiceContainer(containers[i], adapter));
        } else {
            trace("selectExistingHostContainers", // $NON-NLS-1$ //$NON-NLS-2$
            "EXCLUDING containerID=" + containers[i].getID() + // $NON-NLS-1$
            " configs=" + ((serviceExportedConfigs == null) ? "null" : // $NON-NLS-1$
            Arrays.asList(serviceExportedConfigs).toString()) + // $NON-NLS-1$
            " intents=" + ((serviceIntents == null) ? "null" : // $NON-NLS-1$
            Arrays.asList(serviceIntents).toString()));
        }
    }
    return results;
}
Also used : ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) RemoteServiceContainer(org.eclipse.ecf.remoteservice.RemoteServiceContainer) IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) ArrayList(java.util.ArrayList) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ArrayList(java.util.ArrayList) List(java.util.List) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer)

Aggregations

ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)54 IContainer (org.eclipse.ecf.core.IContainer)20 List (java.util.List)5 Namespace (org.eclipse.ecf.core.identity.Namespace)5 ExtensionRegistryRunnable (org.eclipse.ecf.core.util.ExtensionRegistryRunnable)5 ArrayList (java.util.ArrayList)3 Dictionary (java.util.Dictionary)3 Properties (java.util.Properties)3 IContainerManager (org.eclipse.ecf.core.IContainerManager)3 IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)3 URI (java.net.URI)2 URL (java.net.URL)2 Hashtable (java.util.Hashtable)2 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)2 ID (org.eclipse.ecf.core.identity.ID)2 IConnectHandlerPolicy (org.eclipse.ecf.core.security.IConnectHandlerPolicy)2 RestClientContainer (org.eclipse.ecf.remoteservice.rest.client.RestClientContainer)2 RpcClientContainer (org.eclipse.ecf.remoteservice.rpc.client.RpcClientContainer)2 Bundle (org.osgi.framework.Bundle)2 ServiceFactory (org.osgi.framework.ServiceFactory)2