use of org.eclipse.ecf.remoteservice.IRemoteServiceContainer in project ecf by eclipse.
the class AbstractConsumerContainerSelector method createAndConfigureConsumerContainer.
protected IRemoteServiceContainer createAndConfigureConsumerContainer(String[] remoteSupportedConfigs, Map remoteExportedProperties) throws SelectContainerException {
if (remoteSupportedConfigs == null || remoteSupportedConfigs.length == 0)
return null;
// Get container factory
IContainerFactory containerFactory = getContainerFactory();
if (containerFactory == null)
return null;
// Get all container type descriptions from factory
List containerTypeDescriptions = containerFactory.getDescriptions();
if (containerTypeDescriptions == null)
return null;
// Go through all containerTypeDescriptions
for (Iterator i = containerTypeDescriptions.iterator(); i.hasNext(); ) {
ContainerTypeDescription desc = (ContainerTypeDescription) i.next();
// For each one, get the localImportedConfigs for the remote
// supported configs
String[] localImportedConfigs = desc.getImportedConfigs(remoteSupportedConfigs);
// If their are some local imported configs for this description
if (localImportedConfigs != null) {
// Then get the imported config properties
Dictionary importedConfigProperties = desc.getPropertiesForImportedConfigs(localImportedConfigs, PropertiesUtil.createDictionaryFromMap(remoteExportedProperties));
// Then select a specific local imported config (typically the
// first on in the array)
String selectedConfig = selectLocalImportedConfig(localImportedConfigs, importedConfigProperties);
// If we have one to use, then create the container
if (selectedConfig != null) {
IRemoteServiceContainer rsContainer = createContainer(desc, selectedConfig, PropertiesUtil.createMapFromDictionary(importedConfigProperties));
if (rsContainer != null)
return rsContainer;
}
}
}
return null;
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainer in project ecf by eclipse.
the class AbstractHostContainerSelector method createRSContainer.
/**
* @param serviceReference serviceReference
* @param properties properties
* @param containerTypeDescription container type description
* @return IRemoteServiceContainer created remote service container
* @throws SelectContainerException if could not be created
* @since 4.6
*/
protected IRemoteServiceContainer createRSContainer(ServiceReference serviceReference, Map<String, Object> properties, ContainerTypeDescription containerTypeDescription, String[] intents) throws SelectContainerException {
trace(// $NON-NLS-1$
"createRSContainer", // $NON-NLS-1$ //$NON-NLS-2$
"Creating container instance for ref=" + serviceReference + ";properties=" + properties + ";description=" + containerTypeDescription.getName() + // $NON-NLS-1$ //$NON-NLS-2$
";intents=" + // $NON-NLS-1$
((intents == null) ? "" : Arrays.asList(intents).toString()));
IContainer container = createContainer(serviceReference, properties, containerTypeDescription, intents);
if (container == null)
return null;
IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
if (adapter == null)
throw new SelectContainerException("Container does not implement IRemoteServiceContainerAdapter", null, // $NON-NLS-1$
containerTypeDescription);
return new RemoteServiceContainer(container, adapter);
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainer in project ecf by eclipse.
the class RemoteServiceAdmin method importService.
public org.osgi.service.remoteserviceadmin.ImportRegistration importService(org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
// $NON-NLS-1$ //$NON-NLS-2$
trace("importService", "endpointDescription=" + endpointDescription);
// First, make sure that the client bundle has the IMPORT endpoint
// permission
checkEndpointPermission(endpointDescription, EndpointPermission.IMPORT);
final EndpointDescription ed = (endpointDescription instanceof EndpointDescription) ? (EndpointDescription) endpointDescription : new EndpointDescription(endpointDescription.getProperties());
// Now get IConsumerContainerSelector, to select the ECF container
// for the given endpointDescription
final IConsumerContainerSelector consumerContainerSelector = getConsumerContainerSelector();
// If there is none, then we can go no further
if (consumerContainerSelector == null) {
// $NON-NLS-1$
String errorMessage = "No consumerContainerSelector available";
// $NON-NLS-1$
logError("importService", errorMessage, new SelectContainerException(errorMessage, null, null));
// As specified in section 122.5.2, return null
return null;
}
// Select the rsContainer to handle the endpoint description
IRemoteServiceContainer rsContainer = null;
ImportRegistration importRegistration = null;
try {
rsContainer = AccessController.doPrivileged(new PrivilegedExceptionAction<IRemoteServiceContainer>() {
public IRemoteServiceContainer run() throws SelectContainerException {
return consumerContainerSelector.selectConsumerContainer(ed);
}
});
} catch (PrivilegedActionException e) {
// $NON-NLS-1$ //$NON-NLS-2$
logError("importService", "Unexpected exception in selectConsumerContainer", e.getException());
importRegistration = new ImportRegistration(ed, e.getException());
} catch (Exception e) {
// $NON-NLS-1$ //$NON-NLS-2$
logError("importService", "Unexpected exception in selectConsumerContainer", e);
importRegistration = new ImportRegistration(ed, e);
}
// If none found, log an error and return null
if (rsContainer == null && importRegistration == null) {
String errorMessage = // $NON-NLS-1$
"No remote service container selected for endpoint=" + endpointDescription + // $NON-NLS-1$
". Remote service NOT IMPORTED";
// $NON-NLS-1$
logError("importService", errorMessage, new SelectContainerException(errorMessage, null, null));
// As specified in section 122.5.2, return null
return null;
}
// registration
synchronized (importedRegistrations) {
if (importRegistration == null) {
ImportEndpoint importEndpoint = findImportEndpoint(ed);
importRegistration = ((importEndpoint != null) ? new ImportRegistration(importEndpoint) : importService(ed, rsContainer));
}
addImportRegistration(importRegistration);
}
// publish import event
publishImportEvent(importRegistration);
// $NON-NLS-1$ //$NON-NLS-2$
trace("importService", "importRegistration=" + importRegistration);
// Finally, return the importRegistration. It may be null or not.
return importRegistration;
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainer in project ecf by eclipse.
the class AbstractHostContainerSelector method createAndConfigureHostContainers.
/**
* @param serviceReference service reference
* @param properties overriding properties
* @param serviceExportedInterfaces service exported interfaces to select for
* @param requiredConfigs service exported configs to select for
* @param requiredIntents intents to select for
* @return Collection of host containers
* @throws SelectContainerException if container cannot be created or configured
* @since 2.0
*/
protected Collection createAndConfigureHostContainers(ServiceReference serviceReference, Map<String, Object> properties, String[] serviceExportedInterfaces, String[] requiredConfigs, String[] serviceIntents) throws SelectContainerException {
List results = new ArrayList();
ContainerTypeDescription[] descriptions = getContainerTypeDescriptions();
if (descriptions == null)
return Collections.EMPTY_LIST;
// If there are no required configs specified, then create any defaults
if (requiredConfigs == null || requiredConfigs.length == 0) {
createAndAddDefaultContainers(serviceReference, properties, serviceExportedInterfaces, serviceIntents, descriptions, results);
} else {
// See if we have a match
for (int i = 0; i < descriptions.length; i++) {
// $NON-NLS-1$ //$NON-NLS-2$
trace("createAndConfigureHostContainers", "Considering description=" + descriptions[i]);
IRemoteServiceContainer matchingContainer = createMatchingContainer(descriptions[i], serviceReference, properties, serviceExportedInterfaces, requiredConfigs, serviceIntents);
if (matchingContainer != null)
results.add(matchingContainer);
}
}
return results;
}
Aggregations