Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ecf-dev] How to register a custom RegistrySharedObject Implementation

On 11/26/2018 5:08 AM, Peter Hermsdorf wrote:
Hi all,

for custom error handling (see older discussion on this list) we register a custom RegistrySharedObject implementation by overriding

protected IRemoteServiceContainer createRSContainer(
            @SuppressWarnings("rawtypes") final ServiceReference serviceReference, final Map<String, Object> properties,
            final ContainerTypeDescription containerTypeDescription)

in a custom IHostContainerSelector. After upgrading to the latest ECF release we recognized that this method is not called anymore, but the one with the added "String[] intents" argument. The implementation there seem to be very different from before so we currently don't know where to register our custom RegistrySharedObject.

Our code before (shortened):

final ID adapterID = IDFactory.getDefault().createStringID(IRemoteServiceContainerAdapter.class.getName());
final ISharedObjectManager manager = container.getSharedObjectManager();

ISharedObject so = manager.getSharedObject(adapterID);

if (so == null) {
  so = new P4RegistrySharedObject(); // <- Custom RegistrySharedObject
  manager.addSharedObject(adapterID, so, null);
}
return new RemoteServiceContainer(container, (IRemoteServiceContainerAdapter) so);

In the current implementation this code seems to be moved - somewhere in the area of AbstractHostContainerSelector.
I tried to suppy our RegistrySharedObject as argument for adapter to

return new RemoteServiceContainer(container, adapter);

but that does not seems to work as expected.

As shown the the below StackTrace below the instance of the RegistrySharedObject in the end is provided by RemoteServiceContainerAdapterFactory which is registered in

org.eclipse.ecf.internal.provider.remoteservice.Activator

as an adapter of the an IAdapterManager.
Registering an alternative Factory in the AdapterManager will probably not work, since i think i read that the first one will be returned in case there are multiple Adapters for the same id ... ?

Any hints on what is the best or expected way of registering our own Object are very welcome!


Hi Peter,

First, I assume what you are doing is to change the  behavior of the ecf.generic.server provider.   There is nothing wrong with that, but you might...at some point...wish to think about having a whole new distribution provider...with it's own config id, intents, etc.  Which is better depends upon how you want to deploy, who will have access to it, etc.  In any event, let's look at just fixing things as they are.

I think it would be easiest if instead of overriding createRSContainer that you should perhaps override this method:

org.eclipse.ecf.osgi.services.remoteserviceadmin.AbstractContainerSelector.createContainer(ServiceReference, Map<String, Object>, ContainerTypeDescription, String[])

This method can then be overridden something like this:

protected IContainer createContainer(ServiceReference serviceReference,
            Map<String, Object> properties,
            ContainerTypeDescription containerTypeDescription, String[] intents)
            throws SelectContainerException {
         // call superclass to create container instance
         IContainer container = super.createContainer(serviceReference, properties, containerTypeDescription, intents);

         // this container instance should/will have

         final ID adapterID = IDFactory.getDefault().createStringID(IRemoteServiceContainerAdapter.class.getName());
final ISharedObjectManager manager = container.getSharedObjectManager();

         // Remove any existing registry shared object

         manager.removeSharedObject(adapterID);

         // add yours

         ISharedObject  so = new P4RegistrySharedObject(); // <- Custom RegistrySharedObject
         manager.addSharedObject(adapterID, so, null);

         // and return container

         return container;

}


Does this make sense?

Scott




Thanks!
Bye Peter

The callstack for the initialization:

Thread [main] (Suspended)
                owns: RemoteServiceContainerAdapterFactory (id=358)
                owns: AuthHostContainerSelector  (id=82)
RemoteServiceContainerAdapterFactory.createAdapter(ISharedObjectContainer, Class, ID) line: 25 RemoteServiceContainerAdapterFactory(AbstractSharedObjectContainerAdapterFactory).getSharedObjectAdapter(ISharedObjectContainer, Class) line: 93 RemoteServiceContainerAdapterFactory(AbstractSharedObjectContainerAdapterFactory).getContainerAdapter(IContainer, Class) line: 51 RemoteServiceContainerAdapterFactory(AbstractContainerAdapterFactory).getAdapter(Object, Class) line: 32                 AdapterManager.getAdapter(Object, String, boolean) line: 333
                AdapterManager.loadAdapter(Object, String) line: 366
TCPServerSOContainer(SOContainer).getAdapter(Class) line: 298
AuthHostContainerSelector(AbstractContainerSelector).hasRemoteServiceContainerAdapter(IContainer) line: 70 AuthHostContainerSelector(AbstractHostContainerSelector).selectExistingHostContainers(ServiceReference, Map<String,Object>, String[], String[], String[]) line: 121 AuthHostContainerSelector(HostContainerSelector).selectHostContainers(ServiceReference, Map<String,Object>, String[], String[], String[]) line: 69 AuthHostContainerSelector.selectHostContainers(ServiceReference, Map<String,Object>, String[], String[], String[]) line: 37
                RemoteServiceAdmin$1.run() line: 300
AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: not available [native method] RemoteServiceAdmin.exportService(ServiceReference<?>, Map<String,?>) line: 298 TopologyManagerImpl(AbstractTopologyManager).handleServiceRegistering(ServiceReference) line: 466 TopologyManagerImpl(AbstractTopologyManager).handleEvent(ServiceEvent, Map) line: 425                 TopologyManagerImpl.handleEvent(ServiceEvent, Map) line: 69
BasicTopologyManager(TopologyManager).event(ServiceEvent, Map) line: 246
                ServiceRegistry$6.call(Object, ServiceRegistration<?>) line: 1238 ServiceRegistry.notifyHookPrivileged(BundleContextImpl, ServiceRegistrationImpl<?>, HookContext) line: 1280                 ServiceRegistry.notifyHooksPrivileged(HookContext) line: 1263 ServiceRegistry.notifyEventListenerHooksPrivileged(ServiceEvent, Map<BundleContext,Collection<ListenerInfo>>) line: 1235
ServiceRegistry.publishServiceEventPrivileged(ServiceEvent) line: 841
                ServiceRegistry.publishServiceEvent(ServiceEvent) line: 801
ServiceRegistrationImpl<S>.register(Dictionary<String,?>) line: 127
                ServiceRegistry.registerService(BundleContextImpl, String[], Object, Dictionary<String,?>) line: 225                 BundleContextImpl.registerService(String[], Object, Dictionary<String,?>) line: 464 InstanceProcess.registerService(ServiceComponentProp, boolean, ComponentInstanceImpl) line: 536                 InstanceProcess.buildComponents(Vector, boolean) line: 260
                Resolver.getEligible(ServiceEvent) line: 343
                SCRManager.serviceChanged(ServiceEvent) line: 222
FilteredServiceListener.serviceChanged(ServiceEvent) line: 109
                BundleContextImpl.dispatchEvent(Object, Object, int, Object) line: 914 EventManager.dispatchEvent(Set<Entry<K,V>>, EventDispatcher<K,V,E>, int, E) line: 230
ListenerQueue<K,V,E>.dispatchEventSynchronous(int, E) line: 148
ServiceRegistry.publishServiceEventPrivileged(ServiceEvent) line: 862
                ServiceRegistry.publishServiceEvent(ServiceEvent) line: 801
ServiceRegistrationImpl<S>.register(Dictionary<String,?>) line: 127
                ServiceRegistry.registerService(BundleContextImpl, String[], Object, Dictionary<String,?>) line: 225                 BundleContextImpl.registerService(String[], Object, Dictionary<String,?>) line: 464                 BundleContextImpl.registerService(String, Object, Dictionary<String,?>) line: 482                 BundleContextImpl.registerService(Class<S>, S, Dictionary<String,?>) line: 998

_______________________________________________
ecf-dev mailing list
ecf-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/ecf-dev




Back to the top