Search in sources :

Example 1 with IRSAConsumerContainerAdapter

use of org.eclipse.ecf.remoteservice.IRSAConsumerContainerAdapter in project ecf by eclipse.

the class RemoteServiceAdmin method importService.

private ImportRegistration importService(final EndpointDescription endpointDescription, IRemoteServiceContainer rsContainer) {
    // Get interfaces from endpoint description
    Collection<String> interfaces = endpointDescription.getInterfaces();
    Assert.isNotNull(interfaces);
    Assert.isTrue(interfaces.size() > 0);
    // Get ECF endpoint ID...if this throws IDCreateException (because the
    // local system does not have
    // namespace for creating ID, or no namespace is present in
    // endpointDescription or endpoint id,
    // then it will be caught by the caller
    ID endpointContainerID = endpointDescription.getContainerID();
    Assert.isNotNull(endpointContainerID);
    // Get connect target ID. May be null
    ID tID = endpointDescription.getConnectTargetID();
    if (tID == null)
        tID = endpointContainerID;
    final ID targetID = tID;
    // Get idFilter...also may be null
    final ID[] idFilter = getIDFilter(endpointDescription, targetID);
    // Get remote service filter
    final String rsFilter = getRemoteServiceFilter(endpointDescription);
    // IRemoteServiceReferences from query
    Collection<IRemoteServiceReference> rsRefs = new ArrayList<IRemoteServiceReference>();
    // Get IRemoteServiceContainerAdapter
    final IRemoteServiceContainerAdapter containerAdapter = rsContainer.getContainerAdapter();
    // rsContainerID
    ID rsContainerID = rsContainer.getContainer().getID();
    try {
        final IRSAConsumerContainerAdapter cca = (IRSAConsumerContainerAdapter) containerAdapter.getAdapter(IRSAConsumerContainerAdapter.class);
        // Get first interface name for service reference
        // lookup
        final String intf = interfaces.iterator().next();
        // Get/lookup remote service references
        IRemoteServiceReference[] refs = AccessController.doPrivileged(new PrivilegedExceptionAction<IRemoteServiceReference[]>() {

            public IRemoteServiceReference[] run() throws ContainerConnectException, InvalidSyntaxException {
                // If the RSAConsumerContainerAdapter is present, use it
                if (cca != null)
                    // Call importEndpoint if the IRSAConsumerContainerAdapter is present
                    return cca.importEndpoint(endpointDescription.getProperties());
                else
                    return containerAdapter.getRemoteServiceReferences(targetID, idFilter, intf, rsFilter);
            }
        });
        if (refs == null) {
            logWarning(// $NON-NLS-1$
            "doImportService", // $NON-NLS-1$
            "getRemoteServiceReferences return null for targetID=" + targetID + ",idFilter=" + // $NON-NLS-1$
            idFilter + ",intf=" + intf + ",rsFilter=" + // $NON-NLS-1$ //$NON-NLS-2$
            rsFilter + " on rsContainerID=" + // $NON-NLS-1$
            rsContainerID);
        } else
            for (int i = 0; i < refs.length; i++) rsRefs.add(refs[i]);
        // If there are several refs resulting (should not be)
        // we select the one to use
        IRemoteServiceReference selectedRsReference = selectRemoteServiceReference(rsRefs, targetID, idFilter, interfaces, rsFilter, rsContainer);
        // If none found, we obviously can't continue
        if (selectedRsReference == null)
            throw new RemoteReferenceNotFoundException(targetID, idFilter, interfaces, rsFilter);
        return new ImportRegistration(createAndRegisterProxy(endpointDescription, rsContainer, selectedRsReference));
    } catch (PrivilegedActionException e) {
        logError("importService", // $NON-NLS-1$ //$NON-NLS-2$
        "selectRemoteServiceReference returned null for rsRefs=" + rsRefs + ",targetID=" + // $NON-NLS-1$
        targetID + ",idFilter=" + idFilter + // $NON-NLS-1$ //$NON-NLS-2$
        ",interfaces=" + interfaces + ",rsFilter=" + // $NON-NLS-1$
        rsFilter + ",rsContainerID=" + rsContainerID, // $NON-NLS-1$
        e.getException());
        return new ImportRegistration(endpointDescription, e.getException());
    } catch (Exception e) {
        logError("importService", // $NON-NLS-1$ //$NON-NLS-2$
        "selectRemoteServiceReference returned null for rsRefs=" + rsRefs + ",targetID=" + // $NON-NLS-1$
        targetID + ",idFilter=" + idFilter + // $NON-NLS-1$ //$NON-NLS-2$
        ",interfaces=" + interfaces + ",rsFilter=" + // $NON-NLS-1$
        rsFilter + ",rsContainerID=" + rsContainerID, // $NON-NLS-1$
        e);
        return new ImportRegistration(endpointDescription, e);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) 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) IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRSAConsumerContainerAdapter(org.eclipse.ecf.remoteservice.IRSAConsumerContainerAdapter) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ID(org.eclipse.ecf.core.identity.ID) IRemoteServiceID(org.eclipse.ecf.remoteservice.IRemoteServiceID) UUID(java.util.UUID) StringID(org.eclipse.ecf.core.identity.StringID)

Aggregations

PrivilegedActionException (java.security.PrivilegedActionException)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)1 ID (org.eclipse.ecf.core.identity.ID)1 StringID (org.eclipse.ecf.core.identity.StringID)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IRSAConsumerContainerAdapter (org.eclipse.ecf.remoteservice.IRSAConsumerContainerAdapter)1 IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)1 IRemoteServiceID (org.eclipse.ecf.remoteservice.IRemoteServiceID)1 IRemoteServiceReference (org.eclipse.ecf.remoteservice.IRemoteServiceReference)1 BundleException (org.osgi.framework.BundleException)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceException (org.osgi.framework.ServiceException)1