Community
Participate
Working Groups
Description ----------- I've got three Bundles (RSConsumer, RSProvider and RSServices). ServiceA Interface (in RSServices bundle) does not define any method. RSConsumer listens to ServiceA via ServiceTracker and RSProvider registeres a ServiceA (-> Implementation). Distribution provider is/should be "generic" and discovery provider "jmdns". If you first start the RSConsumer and then two(!) of the RSProvider on one(!) machine (-> Configuration identical, in total three osgi instances) you get a "java.net.BindException: Address already in use: JVM_Bind" in the second provider. Shouldn't there be any form of port management? Configuration ------------- id Bundle Location State Bundle File Name 0 System Bundle ACTIVE org.eclipse.osgi_3.6.1.R36x_v20100806 1 initial@reference:file:plugins/org.eclipse.core.jobs_3.5.1.R36x_v20100824.jar/ ACTIVE org.eclipse.core.jobs_3.5.1.R36x_v20100824 2 initial@reference:file:plugins/org.eclipse.core.contenttype_3.4.100.v20100505-1235.jar/ ACTIVE org.eclipse.core.contenttype_3.4.100.v20100505-1235 3 initial@reference:file:plugins/org.eclipse.equinox.app_1.3.1.R36x_v20100803.jar/ ACTIVE org.eclipse.equinox.app_1.3.1.R36x_v20100803 4 initial@reference:file:plugins/org.apache.log4j_1.2.15.v201005080500.jar/ ACTIVE org.apache.log4j_1.2.15.v201005080500 5 initial@reference:file:plugins/org.eclipse.ecf.remoteservice_5.0.0.v20101029-1626.jar/ ACTIVE org.eclipse.ecf.remoteservice_5.0.0.v20101029-1626 6 initial@reference:file:plugins/org.eclipse.equinox.concurrent_1.0.100.v20100503.jar/ ACTIVE org.eclipse.equinox.concurrent_1.0.100.v20100503 7 initial@reference:file:plugins/org.eclipse.equinox.preferences_3.3.0.v20100503.jar/ ACTIVE org.eclipse.equinox.preferences_3.3.0.v20100503 8 initial@reference:file:plugins/org.eclipse.ecf_3.1.0.v20100529-0735.jar/ ACTIVE org.eclipse.ecf_3.1.0.v20100529-0735 9 initial@reference:file:plugins/org.eclipse.ecf.osgi.services.distribution_1.3.0.v20101029-1626.jar/ ACTIVE org.eclipse.ecf.osgi.services.distribution_1.3.0.v20101029-1626 10 initial@reference:file:plugins/org.eclipse.equinox.common_3.6.0.v20100503.jar/ ACTIVE org.eclipse.equinox.common_3.6.0.v20100503 11 initial@reference:file:plugins/org.eclipse.ecf.identity_3.1.0.v20100529-0735.jar/ ACTIVE org.eclipse.ecf.identity_3.1.0.v20100529-0735 12 initial@reference:file:../../../docs/Uni/9. Semester - WS 2010-11 - Diplomarbeit/workspace/RSServices/ ACTIVE RSServices_1.0.0.qualifier 13 initial@reference:file:plugins/org.eclipse.ecf.provider.jmdns_4.1.0.v20101029-1626.jar/ ACTIVE org.eclipse.ecf.provider.jmdns_4.1.0.v20101029-1626 14 initial@reference:file:plugins/org.eclipse.ecf.provider_4.0.0.v20101029-1626.jar/ ACTIVE org.eclipse.ecf.provider_4.0.0.v20101029-1626 15 initial@reference:file:plugins/org.eclipse.ecf.osgi.services.discovery_1.2.0.v20101029-1626.jar/ ACTIVE org.eclipse.ecf.osgi.services.discovery_1.2.0.v20101029-1626 16 initial@reference:file:plugins/org.objectweb.asm_3.2.0.v200909071300.jar/ ACTIVE org.objectweb.asm_3.2.0.v200909071300 17 initial@reference:file:plugins/org.eclipse.ecf.sharedobject_2.2.100.v20101029-1626.jar/ ACTIVE org.eclipse.ecf.sharedobject_2.2.100.v20101029-1626 18 initial@reference:file:plugins/org.eclipse.ecf.provider.remoteservice_3.4.0.v20101029-1626.jar/ ACTIVE org.eclipse.ecf.provider.remoteservice_3.4.0.v20101029-1626 19 initial@reference:file:plugins/org.eclipse.equinox.registry_3.5.0.v20100503.jar/ ACTIVE org.eclipse.equinox.registry_3.5.0.v20100503 20 initial@reference:file:../../../docs/Uni/9. Semester - WS 2010-11 - Diplomarbeit/workspace/Log4JProperties/ RESOLVED Log4JProperties_1.0.0.qualifier 21 initial@reference:file:plugins/org.eclipse.core.runtime_3.6.0.v20100505.jar/ ACTIVE org.eclipse.core.runtime_3.6.0.v20100505 22 initial@reference:file:../../../docs/Uni/9. Semester - WS 2010-11 - Diplomarbeit/workspace/RSConsumer/ ACTIVE RSConsumer_1.0.0.qualifier 23 initial@reference:file:plugins/org.eclipse.osgi.services_3.2.100.v20100503.jar/ ACTIVE org.eclipse.osgi.services_3.2.100.v20100503 24 initial@reference:file:plugins/org.eclipse.ecf.discovery_4.0.0.v20101029-1626.jar/ ACTIVE org.eclipse.ecf.discovery_4.0.0.v20101029-1626 Implementation -------------- RSProvider : Properties props = new Properties(); props.put("service.exported.interfaces", "*"); ServiceRegistration serviceARegistration = bundleContext.registerService(ServiceA.class.getName(), new ServiceAImpl(), props); RSConsumer: this.serviceATracker = new ServiceATracker(); this.serviceATracker.open(); ----- public class ServiceATracker extends ServiceTracker { private static final Logger logger = Logger.getLogger(ServiceATracker.class); public ServiceATracker() throws InvalidSyntaxException { super(Activator.getContext(), Activator.getContext().createFilter("(&(objectClass=" + ServiceA.class.getName() + ")(service.imported=*))") , null); } @Override public Object addingService(ServiceReference reference) { ServiceA serviceA = (ServiceA)Activator.getContext().getService(reference); logger.info(ServiceA.class.getName() + " has been registered!"); return serviceA; } @Override public void removedService(ServiceReference reference, Object service) { this.context.ungetService(reference); logger.info(ServiceA.class.getName() + " has been unregistered!"); } } Exception --------- [log;+0100 2010.12.04 15:39:01:112;INFO;org.eclipse.ecf.osgi.services.distribution;org.eclipse.core.runtime.Status[plugin=org.eclipse.ecf.osgi.services.distribution;code=0;message=Exception creating container from ContainerTypeDescription=ContainerTypeDescription[name=ecf.generic.server;instantiator=org.eclipse.ecf.provider.generic.GenericContainerInstantiator@4c53ab04;desc=ECF Generic Server;;severity4;exception=org.eclipse.ecf.core.ContainerCreateException: createInstance;children=[]]] [log;+0100 2010.12.04 15:39:01:115;WARNING;org.eclipse.ecf.osgi.services.distribution;org.eclipse.core.runtime.Status[plugin=org.eclipse.ecf.osgi.services.distribution;code=2;message=org.eclipse.ecf.internal.osgi.services.distribution.EventHookImpl:handleRegisteredServiceEvent:No remote service containers found for serviceReference={rsservices.ServiceA}={service.exported.interfaces=*, service.id=47}. Service NOT EXPORTED;severity2;exception=null;children=[]]] org.eclipse.ecf.core.ContainerCreateException: createInstance at org.eclipse.ecf.provider.generic.GenericContainerInstantiator.createInstance(GenericContainerInstantiator.java:158) at org.eclipse.ecf.core.ContainerFactory.createContainer(ContainerFactory.java:288) at org.eclipse.ecf.core.ContainerFactory.createContainer(ContainerFactory.java:246) at org.eclipse.ecf.osgi.services.distribution.AbstractContainerFinder.createContainer(AbstractContainerFinder.java:165) at org.eclipse.ecf.osgi.services.distribution.AbstractHostContainerFinder.createRSContainer(AbstractHostContainerFinder.java:297) at org.eclipse.ecf.osgi.services.distribution.AbstractHostContainerFinder.createDefaultRSContainers(AbstractHostContainerFinder.java:237) at org.eclipse.ecf.osgi.services.distribution.AbstractHostContainerFinder.createAndConfigureHostContainers(AbstractHostContainerFinder.java:207) at org.eclipse.ecf.osgi.services.distribution.DefaultHostContainerFinder.findHostContainers(DefaultHostContainerFinder.java:47) at org.eclipse.ecf.internal.osgi.services.distribution.EventHookImpl.findHostContainers(EventHookImpl.java:187) at org.eclipse.ecf.internal.osgi.services.distribution.EventHookImpl.handleRegisteredServiceEvent(EventHookImpl.java:101) at org.eclipse.ecf.internal.osgi.services.distribution.EventHookImpl.event(EventHookImpl.java:65) at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.notifyEventHooksPrivileged(ServiceRegistry.java:1143) at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:743) at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:711) at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130) at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:206) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:507) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:525) at rsprovider.Activator.start(Activator.java:33) at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:783) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:774) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:755) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:370) at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:374) at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1067) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:561) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:546) at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:459) at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243) at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:440) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:337) Caused by: java.net.BindException: Address already in use: JVM_Bind at java.net.PlainSocketImpl.socketBind(Native Method) at java.net.PlainSocketImpl.bind(Unknown Source) at java.net.ServerSocket.bind(Unknown Source) at java.net.ServerSocket.<init>(Unknown Source) at java.net.ServerSocket.<init>(Unknown Source) at org.eclipse.ecf.provider.comm.tcp.Server.<init>(Server.java:40) at org.eclipse.ecf.provider.generic.TCPServerSOContainerGroup.putOnTheAir(TCPServerSOContainerGroup.java:53) at org.eclipse.ecf.provider.generic.TCPServerSOContainer.<init>(TCPServerSOContainer.java:71) at org.eclipse.ecf.provider.generic.TCPServerSOContainer.<init>(TCPServerSOContainer.java:107) at org.eclipse.ecf.provider.generic.GenericContainerInstantiator.createInstance(GenericContainerInstantiator.java:153) ... 32 more
You will have to assign an unique port via the "org.eclipse.ecf.provider.generic.port" property per instance. The generic provider does not try to bind to a port dynamically (contrary to r-OSGi).
Okay, thanks: properties.put("org.eclipse.ecf.provider.generic.port", obtainPort()); And something like this: public static int obtainPort() throws IOException { ServerSocket server = new ServerSocket(0); int port = server.getLocalPort(); server.close(); return port; }
I think this should be documented. At least on the ECF Provider page at ECF Generic (http://wiki.eclipse.org/ECF_Providers#Remote_Services_.28org.eclipse.ecf.remoteservice.29). Additionaly there should be added "org.eclipse.ecf.provider.remoteservice" to Required Bundles, this is missing and not needed by other providers (right?).
(In reply to comment #3) > I think this should be documented. At least on the ECF Provider page at ECF > Generic > (http://wiki.eclipse.org/ECF_Providers#Remote_Services_.28org.eclipse.ecf.remoteservice.29). Feel free to adapt the wiki to the new properties. Btw. there are more in org.eclipse.ecf.provider.generic.TCPServerSOContainer. > Additionaly there should be added "org.eclipse.ecf.provider.remoteservice" to > Required Bundles, this is missing and not needed by other providers (right?). Why would you need to require a specific provider in your client code?
(In reply to comment #3) > I think this should be documented. At least on the ECF Provider page at ECF > Generic > (http://wiki.eclipse.org/ECF_Providers#Remote_Services_.28org.eclipse.ecf.remoteservice.29). > > Additionaly there should be added "org.eclipse.ecf.provider.remoteservice" to > Required Bundles, this is missing and not needed by other providers (right?). Hi, consider helping us document ECF. https://bugs.eclipse.org/bugs/show_bug.cgi?id=329124
For me it seems impossible with a lot of services coming and going (simultaneously) to set ports by hand. If I obtain a port and then set the property the port is still free and could be chosen by another service. The port management should be thread safe inside of the generic provider otherwise I never get out of the JVM_Bind Exceptions. Or is there any other suggestion?
(In reply to comment #6) > For me it seems impossible with a lot of services coming and going > (simultaneously) to set ports by hand. If I obtain a port and then set the > property the port is still free and could be chosen by another service. > > The port management should be thread safe inside of the generic provider > otherwise I never get out of the JVM_Bind Exceptions. > > Or is there any other suggestion? Care to provide a patch? Markus
(In reply to comment #6) > For me it seems impossible with a lot of services coming and going > (simultaneously) to set ports by hand. If I obtain a port and then set the > property the port is still free and could be chosen by another service. > > The port management should be thread safe inside of the generic provider > otherwise I never get out of the JVM_Bind Exceptions. > > Or is there any other suggestion? I guess I don't understand why it's necessary (or desirable) to have a single host expose multiple ECF generic server containers (which expose server ports)...that is...why not use a single ECF container, and expose multiple services via that single container? Alternatively, you can/could control the creation of server containers/ports...by defining your own IHostContainerFinder (in 3.4) or using the upcoming Remote Service Admin implementation...bug 324215.
(In reply to comment #8) > (In reply to comment #6) > > For me it seems impossible with a lot of services coming and going > > (simultaneously) to set ports by hand. If I obtain a port and then set the > > property the port is still free and could be chosen by another service. > > > > The port management should be thread safe inside of the generic provider > > otherwise I never get out of the JVM_Bind Exceptions. > > > > Or is there any other suggestion? > > I guess I don't understand why it's necessary (or desirable) to have a single > host expose multiple ECF generic server containers (which expose server > ports)...that is...why not use a single ECF container, and expose multiple > services via that single container? > > Alternatively, you can/could control the creation of server > containers/ports...by defining your own IHostContainerFinder (in 3.4) or using > the upcoming Remote Service Admin implementation...bug 324215. My understanding of remote services in the Specs was I just need to do the easiest to provide a remote ServiceA (set service.exported.configs and "service.exported.interfaces). So this does not work with generic provider if I register another ServiceA, it causes a JVM_Bind Exception. As user I don't bother about how many containers there are or if multiple ports are used, I just would like to have it working on its own (like r-OSGi) and e.g. CXF-DOSGi the reference implementation. One suggestion was to use the "org.eclipse.ecf.provider.generic.port" parameter for the generic case, but this is not manageable with multiple threads/bundles and uses many more ports as actually required(?). I have looked at the RSA Specs just now and have to review it later, as I am not sure where the differences in basic usage of Remote Services are.
(In reply to comment #9) <stuff deleted> > My understanding of remote services in the Specs was I just need to do the > easiest to provide a remote ServiceA (set service.exported.configs and > "service.exported.interfaces). > > So this does not work with generic provider if I register another ServiceA, it > causes a JVM_Bind Exception. As user I don't bother about how many containers > there are or if multiple ports are used, I just would like to have it working > on its own (like r-OSGi) and e.g. CXF-DOSGi the reference implementation. The spec allows configuration(provider)-specific information to be passed in service properties. One of the ECF-specific remote service properties is one that allows a specific existing container instance to be used rather than to have a new one created with each remote service registration. This service property is: "org.eclipse.ecf.containerID" and is defined in org.eclipse.ecf.osgi.services.distribution.IDistributionConstants.SERVICE_EXPORTED_CONTAINER_ID There's an example usage in org.eclipse.ecf.tests.osgi.services.distribution.AbstractRemoteServiceRegisterTest.testRegisterOnExistingServerWithContainerID() > > One suggestion was to use the "org.eclipse.ecf.provider.generic.port" parameter > for the generic case, but this is not manageable with multiple threads/bundles > and uses many more ports as actually required(?). > > I have looked at the RSA Specs just now and have to review it later, as I am > not sure where the differences in basic usage of Remote Services are. Ok. The main difference with RSA is that RSA defines some java classes that allow the export and import process for discovery and distribution to be controlled/managed in a standard way (through standard services/classes). The 'user interface' for remote services (i.e. the standardized remote service properties) are not changed. Where it's relevant to this case is that I believe you want to control the distribution process a little more than the OSGi remote service properties allow you to do...so the ECF-specific configuration and/or RSA can/could be of use.
(In reply to comment #10) > The spec allows configuration(provider)-specific information to be passed in > service properties. One of the ECF-specific remote service properties is one > that allows a specific existing container instance to be used rather than to > have a new one created with each remote service registration. This service > property is: > > "org.eclipse.ecf.containerID" and is defined in > > org.eclipse.ecf.osgi.services.distribution.IDistributionConstants.SERVICE_EXPORTED_CONTAINER_ID > > There's an example usage in > org.eclipse.ecf.tests.osgi.services.distribution.AbstractRemoteServiceRegisterTest.testRegisterOnExistingServerWithContainerID() > I don't understand why this use cases requires an ECF specific property. Shouldn't the current ECF impl of OSGi remote services just reuse an existing container in HostContainerFinder?
(In reply to comment #11) > (In reply to comment #10) > > > The spec allows configuration(provider)-specific information to be passed in > > service properties. One of the ECF-specific remote service properties is one > > that allows a specific existing container instance to be used rather than to > > have a new one created with each remote service registration. This service > > property is: > > > > "org.eclipse.ecf.containerID" and is defined in > > > > org.eclipse.ecf.osgi.services.distribution.IDistributionConstants.SERVICE_EXPORTED_CONTAINER_ID > > > > There's an example usage in > > org.eclipse.ecf.tests.osgi.services.distribution.AbstractRemoteServiceRegisterTest.testRegisterOnExistingServerWithContainerID() > > > > I don't understand why this use cases requires an ECF specific property. > Shouldn't the current ECF impl of OSGi remote services just reuse an existing > container in HostContainerFinder? Yeah...in fact come to think of it it should have that behavior already (the first registration should create the container, subsequent one should find/use it). I guess we don't understand the use case well enough...i.e. perhaps there are a number of threads registering services concurrently.
(In reply to comment #12) > (In reply to comment #11) > > (In reply to comment #10) > > > > > The spec allows configuration(provider)-specific information to be passed in > > > service properties. One of the ECF-specific remote service properties is one > > > that allows a specific existing container instance to be used rather than to > > > have a new one created with each remote service registration. This service > > > property is: > > > > > > "org.eclipse.ecf.containerID" and is defined in > > > > > > org.eclipse.ecf.osgi.services.distribution.IDistributionConstants.SERVICE_EXPORTED_CONTAINER_ID > > > > > > There's an example usage in > > > org.eclipse.ecf.tests.osgi.services.distribution.AbstractRemoteServiceRegisterTest.testRegisterOnExistingServerWithContainerID() > > > > > > > I don't understand why this use cases requires an ECF specific property. > > Shouldn't the current ECF impl of OSGi remote services just reuse an existing > > container in HostContainerFinder? > > Yeah...in fact come to think of it it should have that behavior already (the > first registration should create the container, subsequent one should find/use > it). I guess we don't understand the use case well enough...i.e. perhaps there > are a number of threads registering services concurrently. Tthis is the use case and in fact the problem.
(In reply to comment #13) > > Yeah...in fact come to think of it it should have that behavior already (the > > first registration should create the container, subsequent one should find/use > > it). I guess we don't understand the use case well enough...i.e. perhaps there > > are a number of threads registering services concurrently. > > Tthis is the use case and in fact the problem. In that case you might wanna check org.eclipse.ecf.osgi.services.distribution.DefaultHostContainerFinder for race conditions.
(In reply to comment #13) <stuff deleted> > > it). I guess we don't understand the use case well enough...i.e. perhaps there > > are a number of threads registering services concurrently. > > Tthis is the use case and in fact the problem. Ok...that clarifies things. Then for this use case, as Markus has indicated, the problem is likely the re-entrancy of the IHostContainerFinder (default implementation of DefaultHostContainerFinder class). Martin if you want to change the title of this bug, I would suggest something like: [remoteservices][osgi] host container finder should be thread safe I will fix this problem in both the 3.4 remote services implementation and the new RSA implementation (I'm still trying to decide how to migrate from the existing 'container finder' classes to the RSA classes...which duplicate the container finder functionality, but will live in a new ECF RSA implementation bundle).
(In reply to comment #15) > (In reply to comment #13) > [...] > Martin if you want to change the title of this bug, I would suggest something > like: > > [remoteservices][osgi] host container finder should be thread safe > I have changed the title. > I will fix this problem in both the 3.4 remote services implementation and the > new RSA implementation (I'm still trying to decide how to migrate from the > existing 'container finder' classes to the RSA classes...which duplicate the > container finder functionality, but will live in a new ECF RSA implementation > bundle). Just to have it clear, there are two use cases: 1) Multiple threads in one OSGi framework registering remote services concurrently 2) Multiple OSGi framework instances (on the same machine!) registering remote services "concurrently" I'm not sure about the IHostContainerFinder, does the concurrent finding/creation then cause a JVM_Bind Exception? So with the fix only one container would be created and only one port used? So there can't be any bind problems then anymore. So 1) could be fixed then, just be aware of case 2) as I also had problems with this. So bind of a port while container creation should bind directly a free port with new ServerSocket(0) and nothing like get a free port and let time pass by until binding.
Hi Martin, (In reply to comment #16) <stuff deleted> > > Just to have it clear, there are two use cases: > > 1) Multiple threads in one OSGi framework registering remote services > concurrently Ok...I can address this now with this bug. > > 2) Multiple OSGi framework instances (on the same machine!) registering remote > services "concurrently" This will require some coordination/configuration for the two (or more) framework instances. What I mean by coordination/configuration is that each framework will have to configure the host container such that it uses different ports. This will be true whether the ECF generic or the r-OSGi provider is used, as each of these (and other providers) have a default listener port (ecf's is 3282, r-osgi's is 9278. The configuration can/could be done via system properties (for either ecf generic or r-osgi), but I would suggest that it might be better to use the ECF-specific service property rather than a system property...as that gives you more flexibility. > > I'm not sure about the IHostContainerFinder, does the concurrent > finding/creation then cause a JVM_Bind Exception? The behavior of the DefaultHostContainerFinder is that *if* no matching container already exists, a new one is created (using the default port). If multiple threads access the host container finder simultaneously, it's possible that both threads would not find an existing host container, and both then try to create one using the same port. Based upon your description, I think this must be what's happening to you. >So with the fix only one > container would be created and only one port used? So there can't be any bind > problems then anymore. Right. > > So 1) could be fixed then, just be aware of case 2) as I also had problems with > this. So bind of a port while container creation should bind directly a free > port with new ServerSocket(0) and nothing like get a free port and let time > pass by until binding. Yeah...as I stated above, for 2 there will have to be some sort of configuration that is explicitly done...so that the two or more frameworks running on a single system don't try to access the same system resource (default port).
(In reply to comment #17) > Hi Martin, > > (In reply to comment #16) > <stuff deleted> > > > > Just to have it clear, there are two use cases: > > > > 1) Multiple threads in one OSGi framework registering remote services > > concurrently > > Ok...I can address this now with this bug. > > > > > 2) Multiple OSGi framework instances (on the same machine!) registering remote > > services "concurrently" > > This will require some coordination/configuration for the two (or more) > framework instances. What I mean by coordination/configuration is that each > framework will have to configure the host container such that it uses different > ports. This will be true whether the ECF generic or the r-OSGi provider is > used, as each of these (and other providers) have a default listener port > (ecf's is 3282, r-osgi's is 9278. > [...] > The behavior of the DefaultHostContainerFinder is that *if* no matching > container already exists, a new one is created (using the default port). If > multiple threads access the host container finder simultaneously, it's possible > that both threads would not find an existing host container, and both then try > to create one using the same port. Based upon your description, I think this > must be what's happening to you. I don't have this problem with r-OSGi, it is flexible "WARNING: Port 9278 already in use. This instance of R-OSGi is running on port 9279". This could also be done for generic provider (at container creation/port binding) in my opinion. It would then solve 1) and 2). So just bind a free(!) port in any case (and don't use a default). DefaultHostContainerFinder thread safe will only solve 1)! I don't seem to have problem 1)(!) with r-OSGi, so is this really about DefaultHostContainerFinder? Yes, perhaps because r-OSGi creates one default container on bundle startup...!?
(In reply to comment #18) <stuff deleted> > > to create one using the same port. Based upon your description, I think this > > must be what's happening to you. > > I don't have this problem with r-OSGi, it is flexible "WARNING: Port 9278 > already in use. This instance of R-OSGi is running on port 9279". This could > also be done for generic provider (at container creation/port binding) in my > opinion. It would then solve 1) and 2). So just bind a free(!) port in any case > (and don't use a default). DefaultHostContainerFinder thread safe will only > solve 1)! That's true. > > I don't seem to have problem 1)(!) with r-OSGi, so is this really about > DefaultHostContainerFinder? Yes, perhaps because r-OSGi creates one default > container on bundle startup...!? There are a number of use cases where the behavior that r-osgi exhibits (of just selecting the next port...i.e. 9279) creates problems. For example...which process gets which port is sensitive to the start order of the processes. This can/could/will be problematic for deployment (as opposed to development). In my opinion, it's usually better to be explicit about port/system resource selection between processes (rather than implicitly just selecting an arbitrary open port). This can be done easily with configuration (i.e. setting the port explicitly...e.g. r-osgi://host.com:8777 or ecftcp://host.com:9999/server or via the system properties). But even so, you are free to suggest and hopefully contribute an enhancement to the DefaultHostContainerFinder...so that (perhaps with some option turned on/off) it exhibits this behavior of implicitly/automatically selecting an unused port for generic server container creation. One thing to be aware of, though...with RSA the host container finder is being deprecated and replaced...with a similar service called IHostContainerSelector. It would probably be better to focus any enhancements on the RSA IHostContainerSelector rather than IHostContainerFinder.
Assigning to myself. Will address for both 3.4 host container finder as well as new rsa IHostContainerSelector.
Fix released to master. Changed both DefaultHostContainerFinder class and new/RSA HostContainerSelector class. The fix was adding the synchronized keyword to the entry point method for container finder/container selector...to prevent multiple thread from calling into the container finder/container selector simultaneously. Resolving as fixed.
*** Bug 334453 has been marked as a duplicate of this bug. ***