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