Search in sources :

Example 26 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(final BundleContext bundleContext) throws Exception {
    Activator.context = bundleContext;
    SafeRunner.run(new ExtensionRegistryRunnable(bundleContext) {

        protected void runWithoutRegistry() throws Exception {
            bundleContext.registerService(Namespace.class, new LocalNamespace(), null);
            // $NON-NLS-1$//$NON-NLS-2$
            bundleContext.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.local", new LocalRemoteServiceContainerInstantiator(), "Local Container Instantiator", false, false), null);
        }
    });
}
Also used : LocalRemoteServiceContainerInstantiator(org.eclipse.ecf.internal.provider.local.container.LocalRemoteServiceContainerInstantiator) LocalNamespace(org.eclipse.ecf.provider.local.identity.LocalNamespace) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) ExtensionRegistryRunnable(org.eclipse.ecf.core.util.ExtensionRegistryRunnable) Namespace(org.eclipse.ecf.core.identity.Namespace) LocalNamespace(org.eclipse.ecf.provider.local.identity.LocalNamespace)

Example 27 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(final BundleContext context) throws Exception {
    this.context = context;
    SafeRunner.run(new ExtensionRegistryRunnable(context) {

        protected void runWithoutRegistry() throws Exception {
            context.registerService(Namespace.class, new DnsSdNamespace(), null);
            context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(DISCOVERY_CONTAINER_NAME_VALUE + LOCATOR, new ContainerInstantiator(), "Discovery Locator Container"), null);
            context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription(DISCOVERY_CONTAINER_NAME_VALUE + ADVERTISER, new ContainerInstantiator(), "Discovery Advertiser Container"), null);
        }
    });
    // register a managed factory for the locator service
    final Properties locCmProps = new Properties();
    locCmProps.put(Constants.SERVICE_PID, DISCOVERY_CONTAINER_NAME_VALUE + LOCATOR);
    context.registerService(ManagedServiceFactory.class.getName(), new DnsSdManagedServiceFactory(DnsSdDiscoveryLocator.class), locCmProps);
    // register the locator service
    final Properties locProps = new Properties();
    locProps.put(DISCOVERY_CONTAINER_NAME_KEY, DISCOVERY_CONTAINER_NAME_VALUE + LOCATOR);
    locProps.put(Constants.SERVICE_RANKING, new Integer(750));
    serviceRegistrations.put(null, context.registerService(IDiscoveryLocator.class.getName(), new DnsSdServiceFactory(DnsSdDiscoveryLocator.class), locProps));
    // register a managed factory for the advertiser service
    final Properties advCmProps = new Properties();
    advCmProps.put(Constants.SERVICE_PID, DISCOVERY_CONTAINER_NAME_VALUE + ADVERTISER);
    context.registerService(ManagedServiceFactory.class.getName(), new DnsSdManagedServiceFactory(DnsSdDiscoveryAdvertiser.class), advCmProps);
    // register the advertiser service
    final Properties advProps = new Properties();
    advProps.put(DISCOVERY_CONTAINER_NAME_KEY, DISCOVERY_CONTAINER_NAME_VALUE + ADVERTISER);
    advProps.put(Constants.SERVICE_RANKING, new Integer(750));
    serviceRegistrations.put(null, context.registerService(IDiscoveryAdvertiser.class.getName(), new DnsSdServiceFactory(DnsSdDiscoveryAdvertiser.class), advProps));
}
Also used : ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) ExtensionRegistryRunnable(org.eclipse.ecf.core.util.ExtensionRegistryRunnable) Properties(java.util.Properties) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ConfigurationException(org.osgi.service.cm.ConfigurationException) Namespace(org.eclipse.ecf.core.identity.Namespace) ManagedServiceFactory(org.osgi.service.cm.ManagedServiceFactory)

Example 28 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(final BundleContext context) throws Exception {
    if (ENABLED) {
        context.registerService(Namespace.class, new CompositeNamespace(), null);
        // $NON-NLS-1$ //$NON-NLS-2$
        context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.discovery.composite", new CompositeDiscoveryContainerInstantiator(), "Composite Discovery Container", true, false), null);
        // $NON-NLS-1$ //$NON-NLS-2$
        context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.singleton.discovery", new SingletonDiscoveryContainerInstantiator(), "Composite Discovery Container Locator", true, false), null);
        // $NON-NLS-1$ //$NON-NLS-2$
        context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.discovery.composite.locator", new CompositeDiscoveryContainerInstantiator(), "Composite Discovery Container Locator"), null);
        // $NON-NLS-1$ //$NON-NLS-2$
        context.registerService(ContainerTypeDescription.class, new ContainerTypeDescription("ecf.discovery.composite.advertiser", new CompositeDiscoveryContainerInstantiator(), "Composite Discovery Container Advertiser"), null);
        final Hashtable<String, Object> props = new Hashtable<String, Object>();
        props.put(IDiscoveryLocator.CONTAINER_NAME, CompositeDiscoveryContainer.NAME);
        props.put(Constants.SERVICE_RANKING, new Integer(1000));
        String[] clazzes = new String[] { IDiscoveryService.class.getName(), IDiscoveryLocator.class.getName(), IDiscoveryAdvertiser.class.getName() };
        context.registerService(clazzes, new ServiceFactory() {

            public Object getService(final Bundle bundle, final ServiceRegistration registration) {
                // register the composite discovery service)
                final CompositeDiscoveryContainer cdc;
                cdc = new CompositeDiscoveryContainer(new HashSet());
                try {
                    cdc.connect(null, null);
                } catch (final ContainerConnectException e) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    Trace.catching(Activator.PLUGIN_ID, Activator.PLUGIN_ID + "/debug/methods/catching", this.getClass(), "getService(Bundle, ServiceRegistration)", e);
                    return null;
                }
                Filter filter = null;
                // add a service listener to add/remove IDS dynamically
                try {
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                    final String filter2 = "(&(" + Constants.OBJECTCLASS + "=" + IDiscoveryAdvertiser.class.getName() + ")(!(" + IDiscoveryLocator.CONTAINER_NAME + "=" + CompositeDiscoveryContainer.NAME + ")))";
                    filter = context.createFilter(filter2);
                    context.addServiceListener(new ServiceListener() {

                        public void serviceChanged(final ServiceEvent arg0) {
                            final Object anIDS = context.getService(arg0.getServiceReference());
                            switch(arg0.getType()) {
                                case ServiceEvent.REGISTERED:
                                    cdc.addContainer(anIDS);
                                    break;
                                case ServiceEvent.UNREGISTERING:
                                    cdc.removeContainer(anIDS);
                                    break;
                                default:
                                    break;
                            }
                        }
                    }, filter2);
                } catch (final InvalidSyntaxException e) {
                // nop
                }
                // get all previously registered IDS from OSGi (but not this one)
                final ServiceTracker tracker = new ServiceTracker(context, filter, null);
                tracker.open();
                final Object[] services = tracker.getServices();
                tracker.close();
                if (services != null) {
                    for (int i = 0; i < services.length; i++) {
                        final Object obj = services[i];
                        if (obj != cdc)
                            cdc.addContainer(obj);
                    }
                }
                return cdc;
            }

            public void ungetService(final Bundle bundle, final ServiceRegistration registration, final Object service) {
                ((CompositeDiscoveryContainer) service).dispose();
            }
        }, props);
    }
}
Also used : IDiscoveryAdvertiser(org.eclipse.ecf.discovery.IDiscoveryAdvertiser) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) Hashtable(java.util.Hashtable) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) HashSet(java.util.HashSet)

Example 29 with ContainerTypeDescription

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

the class ConfigurationWizardSelectionPage method getContainerTypeDescriptionForElement.

private ContainerTypeDescription getContainerTypeDescriptionForElement(WorkbenchWizardElement element) {
    ContainerTypeDescription typeDescription = ContainerFactory.getDefault().getDescriptionByName(element.getContainerTypeName());
    if (typeDescription == null) {
        String msg = NLS.bind(Messages.ConfigurationWizardSelectionPage_ERROR_MESSAGE, element);
        setErrorMessage(msg);
        ErrorDialog.openError(getShell(), Messages.ConfigurationWizardSelectionPage_CONFIGRATION_ERROR_TITLE, Messages.ConfigurationWizardSelectionPage_CONFIGURATION_ERROR_MESSAGE, new Status(IStatus.ERROR, Activator.PLUGIN_ID, CONTAINERTYPEDESCRIPTION_ERROR_CODE, msg, null));
        return null;
    }
    return typeDescription;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription)

Example 30 with ContainerTypeDescription

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

the class RpcContainerTest method testCreateContainer2.

public void testCreateContainer2() throws Exception {
    ContainerTypeDescription description = getContainerFactory().getDescriptionByName(RpcConstants.RPC_CONTAINER_TYPE);
    IContainer container = getContainerFactory().createContainer(description, new Object[] { new URL(RpcConstants.TEST_ECHO_TARGET) });
    assertNotNull(container);
    assertTrue(container instanceof RpcClientContainer);
}
Also used : RpcClientContainer(org.eclipse.ecf.remoteservice.rpc.client.RpcClientContainer) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) IContainer(org.eclipse.ecf.core.IContainer) URL(java.net.URL)

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