Announcement Announcement Module
Collapse
No announcement yet.
Maange beans as sessions via the container Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Maange beans as sessions via the container

    I am using Spring3.1

    My application will have kind of bean-manager.

    That manager will be able to retrieve request and on each request I need to create new instance of bean dynamically which will be initiate with it's own unique params.

    The params will be retrieved via the request method.

    This bean must be alive and work asynchronously. (For example it will listen to jms calls, execute methods by demand and so on..)

    Moreover I want to have the option to destroy beans also.

    Those bean could be resemble as sessions so when the user log off i will destroy those beans.

    I understand that I have to create some kind of bean-list or beans pool and manage it with some kind of manager.

    How can I create those beans dynamically and have them remain them alive until I destroy them?


    When I say user session - it is in the user session but it's not through web/http. the user will connect else where via some protocol and I will have to create a new session and manage it until the user log off and then I will kill the bean by myself.

    Any idea how could I implement such thing?

    * Is my case equal to stateless or statefull in EJB?

    thanks,
    ray.
    Last edited by ray.frid; Jul 9th, 2012, 03:34 AM. Reason: Making my target clear.

  • #2
    I read something about using StaticApplicationContext. mybe that would be the way?

    Comment


    • #3
      I am not sure if anyone following my Thread but I understoond that for each new bean I want to create dynamiclly I can do something like this:


      Code:
      public void createBean(String beanName, String beanParam)
      	{
      		System.out.println("beanName=" + beanName + " beanParam=" + beanParam);
      		ApplicationContext context = ApplicationContextSingleton.getApplicationContext();
      		innerContext = new StaticApplicationContext(context);
      		innerContext.registerSingleton(beanName, FixSessionBean.class);
      		configureBean(innerContext, beanName, beanParam);
      
      	}
      Code:
      public void configureBean(ApplicationContext innerContext, String beanName, String beanParam)
      	{
      		FixSessionBean fixSessionBean = (FixSessionBean) innerContext.getBean(beanName);
      		fixSessionBean.setMyProperty("32");
      	}
      and If I want to retrieve it in the future ill just use:


      Code:
      		FixSessionBean fixSessionBean = (FixSessionBean) innerContext.getBean(beanName);
      FixedSessionBean in the xml:

      Code:
      	<bean id="FixSessionBean" class="com.fixgw.beans.FixSessionBean" />

      my question is: if I use StaticApplicationContext to create new beans and manage them in the way I just show could be that in future will it harm performences/memory leaks, etc ?

      thanks,
      ray.

      Comment

      Working...
      X