Search in sources :

Example 31 with IRemoteServiceContainerAdapter

use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter 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 32 with IRemoteServiceContainerAdapter

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

the class ReflectiveRemoteServiceHandler method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.
	 * commands .ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    final String clazz = event.getParameter(// $NON-NLS-1$
    "org.eclipse.ecf.remoteservices.ui.commands.reflectiveMethodDialogParameter");
    final IRemoteServiceContainerAdapter adapter = RemoteServiceHandlerUtil.getActiveIRemoteServiceContainerAdapterChecked(event);
    if (adapter == null) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        null, // $NON-NLS-1$
        "Handler invocation failed", // $NON-NLS-1$
        "No container found");
        return null;
    }
    final IRemoteServiceReference[] references = RemoteServiceHandlerUtil.getActiveIRemoteServiceReferencesChecked(event);
    if (references == null || references.length == 0) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        null, // $NON-NLS-1$
        "Handler invocation failed", // $NON-NLS-1$
        "No remote service reference found");
        return null;
    }
    final IRemoteService remoteService = adapter.getRemoteService(references[0]);
    if (remoteService == null) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        null, // $NON-NLS-1$
        "Handler invocation failed", // $NON-NLS-1$
        "No remote service found");
        return null;
    }
    try {
        executeMethodInvocationDialog(Class.forName(clazz), remoteService);
    } catch (ClassNotFoundException e) {
        // $NON-NLS-1$
        MessageDialog.openError(// $NON-NLS-1$
        null, // $NON-NLS-1$
        "Handler invocation failed", e.getLocalizedMessage());
        throw new ExecutionException(e.getMessage(), e);
    }
    return null;
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 33 with IRemoteServiceContainerAdapter

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

the class DataProcessorServerApplication method start.

public Object start(IApplicationContext appContext) throws Exception {
    bundleContext = Activator.getContext();
    // Process Arguments...i.e. set queueId if specified
    processArgs(appContext);
    // Create container and connect to given queueId as message consumer
    container = getContainerManagerService().getContainerFactory().createContainer(containerType, new Object[] { queueId });
    // Get remote service container adapter
    IRemoteServiceContainerAdapter remoteServiceContainerAdapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
    // Create the data processor implementation
    dataProcessorImpl = new DataProcessorImpl(container.getID());
    // Register data processor as remote services (with queue consumer
    // container)
    dataProcessorRemoteServiceRegistration = remoteServiceContainerAdapter.registerRemoteService(new String[] { IDataProcessor.class.getName() }, dataProcessorImpl, null);
    // Report success of registration
    System.out.println("LB Server:  Data Processor Registered queue=" + queueId);
    // then just wait for service requests
    waitForDone();
    return IApplication.EXIT_OK;
}
Also used : IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)

Example 34 with IRemoteServiceContainerAdapter

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

the class RemoteServiceAdmin method exportService.

private ExportRegistration exportService(final ServiceReference serviceReference, Map<String, ?> overridingProperties, String[] exportedInterfaces, IRemoteServiceContainer rsContainer, Map<String, Object> endpointDescriptionProperties) throws Exception {
    // Create remote service properties
    Map<String, Object> remoteServiceProperties = copyNonReservedProperties(serviceReference, (Map<String, Object>) overridingProperties, new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER));
    // Added for R7 support. Copy intents and intent options to remote service
    // properties
    String[] intents = PropertiesUtil.getStringArrayWithDefault(endpointDescriptionProperties, org.osgi.service.remoteserviceadmin.RemoteConstants.REMOTE_INTENTS_SUPPORTED, new String[] {});
    remoteServiceProperties = PropertiesUtil.copyIntentProperties(endpointDescriptionProperties, intents, remoteServiceProperties);
    IRemoteServiceContainerAdapter containerAdapter = rsContainer.getContainerAdapter();
    // create serializable dictionary from remote service properties
    Dictionary rsp = PropertiesUtil.createSerializableDictionaryFromMap(remoteServiceProperties);
    // Register remote service via ECF container adapter to create
    // remote service registration
    IRemoteServiceRegistration remoteRegistration = null;
    if (containerAdapter instanceof IOSGiRemoteServiceContainerAdapter) {
        IOSGiRemoteServiceContainerAdapter osgiContainerAdapter = (IOSGiRemoteServiceContainerAdapter) containerAdapter;
        remoteRegistration = osgiContainerAdapter.registerRemoteService(exportedInterfaces, serviceReference, rsp);
    } else {
        Object service = AccessController.doPrivileged(new PrivilegedAction<Object>() {

            public Object run() {
                return getClientBundleContext().getService(serviceReference);
            }
        });
        remoteRegistration = containerAdapter.registerRemoteService(exportedInterfaces, service, rsp);
    }
    endpointDescriptionProperties.put(org.eclipse.ecf.remoteservice.Constants.SERVICE_ID, remoteRegistration.getID().getContainerRelativeID());
    if (remoteRegistration instanceof IExtendedRemoteServiceRegistration) {
        IExtendedRemoteServiceRegistration iersr = (IExtendedRemoteServiceRegistration) remoteRegistration;
        Map<String, Object> extraProperties = iersr.getExtraProperties();
        if (extraProperties != null)
            endpointDescriptionProperties = PropertiesUtil.mergeProperties(endpointDescriptionProperties, extraProperties);
    }
    // Copy only serializable properties
    endpointDescriptionProperties = PropertiesUtil.copySerializableProperties(endpointDescriptionProperties, new TreeMap<String, Object>());
    // Create ExportEndpoint/ExportRegistration
    return new ExportRegistration(new ExportEndpoint(serviceReference, new EndpointDescription(endpointDescriptionProperties), remoteRegistration, endpointDescriptionProperties));
}
Also used : Dictionary(java.util.Dictionary) IOSGiRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IOSGiRemoteServiceContainerAdapter) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) TreeMap(java.util.TreeMap) IExtendedRemoteServiceRegistration(org.eclipse.ecf.remoteservice.IExtendedRemoteServiceRegistration) IRemoteServiceRegistration(org.eclipse.ecf.remoteservice.IRemoteServiceRegistration)

Example 35 with IRemoteServiceContainerAdapter

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

the class RemoteServiceAdmin method createAndRegisterProxy.

private ImportEndpoint createAndRegisterProxy(final EndpointDescription endpointDescription, final IRemoteServiceContainer rsContainer, final IRemoteServiceReference selectedRsReference) throws Exception {
    final BundleContext proxyServiceFactoryContext = getProxyServiceFactoryContext(endpointDescription);
    if (proxyServiceFactoryContext == null)
        throw new NullPointerException(// $NON-NLS-1$
        "getProxyServiceFactoryContext returned null.  Cannot register proxy service factory");
    final IRemoteServiceContainerAdapter containerAdapter = rsContainer.getContainerAdapter();
    ID rsContainerID = rsContainer.getContainer().getID();
    // First get IRemoteService for selectedRsReference
    final IRemoteService rs = containerAdapter.getRemoteService(selectedRsReference);
    if (rs == null)
        throw new NullPointerException(// $NON-NLS-1$
        "getRemoteService returned null for selectedRsReference=" + selectedRsReference + // $NON-NLS-1$
        ",rsContainerID=" + rsContainerID);
    final Map proxyProperties = createProxyProperties(rsContainerID, endpointDescription, selectedRsReference, rs);
    // sync sref props with endpoint props
    endpointDescription.setPropertiesOverrides(proxyProperties);
    final List<String> originalTypes = endpointDescription.getInterfaces();
    final List<String> asyncServiceTypes = endpointDescription.getAsyncInterfaces();
    final List<String> serviceTypes = new ArrayList<String>(originalTypes);
    if (asyncServiceTypes != null)
        for (String ast : asyncServiceTypes) if (ast != null && !serviceTypes.contains(ast))
            serviceTypes.add(ast);
    ServiceRegistration proxyRegistration = AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {

        public ServiceRegistration run() {
            return proxyServiceFactoryContext.registerService((String[]) serviceTypes.toArray(new String[serviceTypes.size()]), createProxyServiceFactory(endpointDescription, containerAdapter, selectedRsReference, rs), (Dictionary) PropertiesUtil.createDictionaryFromMap(proxyProperties));
        }
    });
    return new ImportEndpoint(rsContainer, selectedRsReference, rs, proxyRegistration, endpointDescription);
}
Also used : Dictionary(java.util.Dictionary) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ArrayList(java.util.ArrayList) ID(org.eclipse.ecf.core.identity.ID) IRemoteServiceID(org.eclipse.ecf.remoteservice.IRemoteServiceID) UUID(java.util.UUID) StringID(org.eclipse.ecf.core.identity.StringID) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) BundleContext(org.osgi.framework.BundleContext) IExtendedRemoteServiceRegistration(org.eclipse.ecf.remoteservice.IExtendedRemoteServiceRegistration) IRemoteServiceRegistration(org.eclipse.ecf.remoteservice.IRemoteServiceRegistration) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)35 IRemoteServiceReference (org.eclipse.ecf.remoteservice.IRemoteServiceReference)16 IConcatService (org.eclipse.ecf.tests.remoteservice.IConcatService)14 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)9 IContainer (org.eclipse.ecf.core.IContainer)7 ID (org.eclipse.ecf.core.identity.ID)7 Dictionary (java.util.Dictionary)6 IRemoteServiceListener (org.eclipse.ecf.remoteservice.IRemoteServiceListener)6 IRemoteServiceEvent (org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent)6 IRemoteServiceRegisteredEvent (org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent)6 IFuture (org.eclipse.equinox.concurrent.future.IFuture)6 IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)5 RemoteServiceContainer (org.eclipse.ecf.remoteservice.RemoteServiceContainer)5 Hashtable (java.util.Hashtable)4 Properties (java.util.Properties)4 IRemoteServiceRegistration (org.eclipse.ecf.remoteservice.IRemoteServiceRegistration)4 RemoteServiceTracker (org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker)4 ArrayList (java.util.ArrayList)3 ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)3 IRemoteServiceID (org.eclipse.ecf.remoteservice.IRemoteServiceID)3