Results 1 to 4 of 4

Thread: Singletons and Session scoped replicated beans

  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Unhappy Singletons and Session scoped replicated beans

    Hi! I need help to solve a clustering problem.

    I have a session scoped bean that has a property injected with a singleton bean (let's call it "the service").

    It'all right in dev env, but when I put the application on the clustered env, I get replication error as the service class is not serializable.
    The problem is the service object should not be replicated, but the replicated session object shlould be injected with the local service instance.

    I cannot figure out how to make this happen.

    Can anybody help?

    Thanks!!!!

  2. #2
    Join Date
    Jun 2008
    Location
    Springfield, MO
    Posts
    21

    Default

    Without seeing any code/config/stacktrace it'd be difficult to say. First thing, does the object that it's complaining about not being able to replicate implement Serializable?

  3. #3
    Join Date
    Feb 2010
    Posts
    2

    Default

    Quote Originally Posted by dvestal View Post
    Without seeing any code/config/stacktrace it'd be difficult to say. First thing, does the object that it's complaining about not being able to replicate implement Serializable?
    Well, I thought it was not a specific problem, I thought I needed some hot-to-do guide.

    Anyway, I'll try to give some more names.

    Bean "client", Serializable class Client, is session scoped (well, it is in a custom "process" scope that is between session and request, but it's hold in session anyway).
    Bean "server", NOT Serializable class Server, is a singleton scoped.

    Class Client has a property of type Server.

    At runtime, on a single node env, the client bean gets it own server instance without problems.

    This is also true in the cluster env, but I see errors about Server class not being Serializable.
    This is true, but I don't want the server instance to be serialized and replicated on the other node: what I expect is the client bean is replicated and injected with the server instance on the other node.

    Are my expectaions wrong?
    I believe that if each session client bean is replicated WITH its server reference, I'll come up with... several singletons on the other node! Wouldn't I?

    Thanks a lot.

  4. #4
    Join Date
    May 2009
    Posts
    2

    Default

    I think you have some misunderstanding (or no understanding) how clustering works.

    When the "client" class needs to be synchronized between nodes (the state of session changes) the clustering framework (not Spring but the app server) SERIALIZES the Session object with all of its subclasses RECURSIVELY to a bytestream and broadcasts it. On all other nodes this bytestream will be DESERIALIZED into objects and voila: the session object is replicated. So your "client" class will be serialized with ALL FIELDS RECURSIVELY. So a session scope bean not only must support Serializable, but MUST NOT CONTAIN ANY OBJECT THAT IS NOT SERIALIZABLE.

    If you need the local service object in the code of the "client" class, you cannot use Autowiring. You must explicitely ask the Service object form code via ApplicationContext's getbean. (To get the appropiate ApplicationContext instance you may need to create an ApplicationContextHolder class or something also...)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •