Search in sources :

Example 6 with IRemoteServiceContainer

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;
}
Also used : Dictionary(java.util.Dictionary) IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) IContainerFactory(org.eclipse.ecf.core.IContainerFactory) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) Iterator(java.util.Iterator) List(java.util.List)

Example 7 with IRemoteServiceContainer

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);
}
Also used : RemoteServiceContainer(org.eclipse.ecf.remoteservice.RemoteServiceContainer) IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IContainer(org.eclipse.ecf.core.IContainer)

Example 8 with IRemoteServiceContainer

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;
}
Also used : IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ECFException(org.eclipse.ecf.core.util.ECFException) ServiceException(org.osgi.framework.ServiceException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) PrivilegedActionException(java.security.PrivilegedActionException) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException)

Example 9 with IRemoteServiceContainer

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;
}
Also used : IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)9 IContainer (org.eclipse.ecf.core.IContainer)4 ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)3 PrivilegedActionException (java.security.PrivilegedActionException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)2 ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)2 ID (org.eclipse.ecf.core.identity.ID)2 ECFException (org.eclipse.ecf.core.util.ECFException)2 IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)2 RemoteServiceContainer (org.eclipse.ecf.remoteservice.RemoteServiceContainer)2 BundleException (org.osgi.framework.BundleException)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ServiceException (org.osgi.framework.ServiceException)2 Collection (java.util.Collection)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1