use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter in project ecf by eclipse.
the class DataProcessorServiceHostApplication method start.
public Object start(IApplicationContext appContext) throws Exception {
bundleContext = Activator.getContext();
// Process Arguments...i.e. set queueId and topicId if specified, otherwise use defaults
processArgs(appContext);
// Create container of appropriate type, and with the topicId and
// queueId set
// upon construction
container = getContainerManagerService().getContainerFactory().createContainer(containerType, new Object[] { topicId, queueId });
// Get IRemoteServiceContainerAdapter
IRemoteServiceContainerAdapter remoteServiceAdapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
Properties properties = new Properties();
// This is setting (currently) magical service property that indicates
// that
// this service registration is a load balancing service host
properties.put(Constants.SERVICE_REGISTER_PROXY, "true");
// Register the remote service with the IDataProcessor interface as it's
// service registration.
// Note that the Constants.SERVICE_REGISTER_PROXY allows null to be specified
// as the registered remote service implementation.
// This object does not implement the IDataProcessor service interface,
// but it is not actually used. Rather,
// the LOAD_BALANCING_SERVICE_PROPERTY set to "true" specifies that for
// this container the remote service
// requests are proxied and forwarded to the JMS queue (where they are
// load balanced among the n servers
// that are consumers from that queue)
dataProcessorServiceHostRegistration = remoteServiceAdapter.registerRemoteService(new String[] { IDataProcessor.class.getName() }, null, properties);
System.out.println("LB Service Host: DataProcessor Registered via ECF Remote Services topic=" + topicId);
// wait for remote service requests until stopped
waitForDone();
return IApplication.EXIT_OK;
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter 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);
}
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter in project ecf by eclipse.
the class AbstractHostContainerSelector method selectExistingHostContainers.
/**
* @param serviceReference service reference
* @param overridingProperties overriding properties
* @param serviceExportedInterfaces service exported interfaces to select for
* @param serviceExportedConfigs service exported configs to select for
* @param serviceIntents service exported intents to select for
* @return Collection of existing host containers
* @since 2.0
*/
protected Collection selectExistingHostContainers(ServiceReference serviceReference, Map<String, Object> overridingProperties, String[] serviceExportedInterfaces, String[] serviceExportedConfigs, String[] serviceIntents) {
List results = new ArrayList();
// Get all existing containers
IContainer[] containers = getContainers();
// If nothing there, then return empty array
if (containers == null || containers.length == 0)
return results;
for (int i = 0; i < containers.length; i++) {
ID cID = containers[i].getID();
// $NON-NLS-1$ //$NON-NLS-2$
trace("selectExistingHostContainers", "Considering existing container=" + cID);
// Check to make sure it's a rs container adapter. If it's not go
// onto next one
IRemoteServiceContainerAdapter adapter = hasRemoteServiceContainerAdapter(containers[i]);
if (adapter == null) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
trace("selectExistingHostContainers", "Existing container=" + cID + " does not implement IRemoteServiceContainerAdapter");
continue;
}
// Get container type description and intents
ContainerTypeDescription description = getContainerTypeDescription(containers[i]);
// If it has no description go onto next
if (description == null) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
trace("selectExistingHostContainers", "Existing container=" + cID + " does not have container type description");
continue;
}
// http://bugs.eclipse.org/331532
if (!description.isServer()) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
trace("selectExistingHostContainers", "Existing container=" + cID + " is not server");
continue;
}
if (matchExistingHostContainer(serviceReference, overridingProperties, containers[i], adapter, description, serviceExportedConfigs, serviceIntents)) {
trace("selectExistingHostContainers", // $NON-NLS-1$ //$NON-NLS-2$
"INCLUDING containerID=" + containers[i].getID() + // $NON-NLS-1$
" configs=" + ((serviceExportedConfigs == null) ? "null" : // $NON-NLS-1$
Arrays.asList(serviceExportedConfigs).toString()) + // $NON-NLS-1$
" intents=" + ((serviceIntents == null) ? "null" : // $NON-NLS-1$
Arrays.asList(serviceIntents).toString()));
results.add(new RemoteServiceContainer(containers[i], adapter));
} else {
trace("selectExistingHostContainers", // $NON-NLS-1$ //$NON-NLS-2$
"EXCLUDING containerID=" + containers[i].getID() + // $NON-NLS-1$
" configs=" + ((serviceExportedConfigs == null) ? "null" : // $NON-NLS-1$
Arrays.asList(serviceExportedConfigs).toString()) + // $NON-NLS-1$
" intents=" + ((serviceIntents == null) ? "null" : // $NON-NLS-1$
Arrays.asList(serviceIntents).toString()));
}
}
return results;
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter in project ecf by eclipse.
the class Lab1Action method run.
/**
* The action has been activated. The argument of the
* method represents the 'real' action sitting
* in the workbench UI.
* @see IWorkbenchWindowActionDelegate#run
*/
public void run(IAction action) {
try {
IRemoteServiceContainerAdapter adapter = getContainerAdapter();
// Create target ID
String target = TARGET;
ID targetID = createTargetID(container, target);
// Get and resolve remote service reference
IRemoteServiceReference[] ref = adapter.getRemoteServiceReferences(targetID, org.eclipse.ecf.examples.remoteservices.common.IRemoteEnvironmentInfo.class.getName(), null);
IRemoteService svc = adapter.getRemoteService(ref[0]);
// get proxy
IRemoteEnvironmentInfo proxy = (IRemoteEnvironmentInfo) svc.getProxy();
// Call it!
String osArch = proxy.getOSArch();
// Show result
MessageDialog.openInformation(window.getShell(), "ECF Lab 1", "Target " + target + " has OS Arch=" + osArch);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter in project ecf by eclipse.
the class RemoteServiceHandlerUtil method getActiveIRemoteServiceContainerAdapterChecked.
public static IRemoteServiceContainerAdapter getActiveIRemoteServiceContainerAdapterChecked(ExecutionEvent event) throws ExecutionException {
final ID activeConnectId = getActiveConnectIDChecked(event);
final IContainer container = getContainerWithConnectID(activeConnectId);
if (container == null) {
return null;
}
final IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
return adapter;
}
Aggregations