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