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);
}
});
}
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));
}
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);
}
}
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;
}
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);
}
Aggregations