Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Multiple OSGI Service instance(OSGI Service)
Multiple OSGI Service instance [message #733762] Wed, 05 October 2011 15:09 Go to next message
Benoit Lafleche is currently offline Benoit LaflecheFriend
Messages: 10
Registered: April 2011
Junior Member
Hi,

In VIRGO, I have a bundle which is performing some big and long tasks. All the possible tasks are defined via an Interface and the implementor is defined as an OSGI service. This service is now deployed on VIRGO.

The clients are an Eclipse RCP application and communicate to VIRGO via the Spring HttpInvoker feature.

I have a web bundle which accept the request from the Spring Http Invoker and to process the request, just redirect it to the OSGI service. For now, when more than one client is trying to perform the big task, I have a concurrency problem. What I would like is that each user session gets its own instance of the OSGI service.

Is there a way to get a different OSGI service for each user web session or this is out of the definition of an OSGI service?

Presently, we could defined a different OSGI service instance by specifying the scope="bundle" in the bean definition, but the service would be different for each client bundle! In my case, I have only one web client bundle which means the same service.

I'm trying to see if I could do something with VIRGO and Spring without having to code any pooling mechanism inside my service.

I'm still not too sure if versus using an OSGI service, I should just export the class that was providing the service, and then the web bundle will create itself a new instance of the service on demand?

Of course, the way my service is presently written and when I deployed it within my FAT eclipse RCP application, then the OSGI service is working as expected!

Thanks a lot if you have any comments or suggestions!

Benoit


Re: Multiple OSGI Service instance [message #733797 is a reply to message #733762] Wed, 05 October 2011 16:24 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
Hi Benoit,

You could take advantage of osgi ServiceFactory to create prototypes of the service

The question is why would you have a concurrency problem? Is your service statefull? What kind of concurrency problems you are running into?
You can still have a single service but use a scheduler or a task executor to offload individual tasks to a separate thread. The Callable/Runnable could become your state container in that case.

Regards,
Dmitry
Re: Multiple OSGI Service instance [message #733810 is a reply to message #733797] Wed, 05 October 2011 17:23 Go to previous messageGo to next message
Benoit Lafleche is currently offline Benoit LaflecheFriend
Messages: 10
Registered: April 2011
Junior Member
Dmitry,

I have checked the ServiceFactory, but this is creating a new service per bundle callers. Here a quote from the getService method on the ServiceFactory: Quote:
The service factory can then return a specific service object for each bundle.


while my client bundle would require one per user session.


My concurency problem is that my long task is storing data in an instance variable of the service while processing the request and the next session requesting a new task is ovewriting the data of the previous call.

I think, I have no choice and I need to write some code to manage myself the multi-users environment and probably change sligtly my service API, so the next call won't erase the data of the previous call. I was just expecting that I would be able to do it without modifying any of the code when the same application is running in a single user environment.

Merci,
Benoit
Re: Multiple OSGI Service instance [message #733815 is a reply to message #733810] Wed, 05 October 2011 17:36 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
You really do not need to have multiple instances of the service. You only need to make sure that service is stateless and the state is managed in by a state object that is unique to a call.

For example:

public T doSomeLongTask(param1, param2, paramN) {

   SomeLongTaskExecutionContext context = new SomeLongTaskExecutionContext(param1, param2, paramN);
   doSomeLongTask(context);
   return context.getResult();
}



public class SomeLongTaskExecutionContext {
   private Map someStateHolder;

   T getResult();
}


Dmitry
Re: Multiple OSGI Service instance [message #734041 is a reply to message #733810] Thu, 06 October 2011 13:37 Go to previous message
Dmitry Sklyut is currently offline Dmitry SklyutFriend
Messages: 279
Registered: January 2010
Senior Member
blaflec wrote on Wed, 05 October 2011 13:23


I have checked the ServiceFactory, but this is creating a new service per bundle callers.


Actually ServiceFactory will create/returned cached instance (based on your implementation of ServiceFactory) per bundleContext.getService() call. If you don't mind doing some manual service management and bypass SpringDM.

In you are using Spring web support - you might be able to use Spring request/session scope to create prototypes that are a bit longer lived than one call.

Previous Topic:use JSF2 with SNAPS
Next Topic:Setting a Bundle cosuming Spring AOP
Goto Forum:
  


Current Time: Sat Apr 20 00:47:48 GMT 2024

Powered by FUDForum. Page generated in 0.03963 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top