Discussions

EJB design: Entity bean as a distributed cache -- need ideas.

  1. Goal: Cache data on the server in a clustred environment (using WebSphere v4.0)
    Plan to store the key to the data in the HttpSession, but I the data itself on the server. The app. server uses round-robin in directing requests to 2 or more physical machines.

    I envision having a session facade and a non-persistent entity bean that holds the data (or collection of data). The reason I would think of an entity bean is because of the ejb clustering. I don't need to store data in the database. How can I implement an entity bean as just a memory/temporary cache without writing anything to the database? Someone mentioned BMP, but how can I actually implement that? How would find/create/primary work in this case?

    Any other ideas/alternatives to solve this problem?

    Thanks a lot!
  2. I do not fully understand what you are trying to do...If you want to use a BMP, but still do not want to store the data in a db, all you have to do is implement a one column table for your primary key...

    You will then implement ejbLoad() to load your data from wherever you have the data and probably will not implement the ejbStore() method. Youe ejbLoad() may be called several times during a session, so be sure that the data you store within can be obtained from elsewhere.

    Hope this helps.

    -Srini Santhanam
  3. Nonpersistent entity bean[ Go to top ]

    I do not fully understand what you are trying to do...If you want to use a BMP, but still do not want to store the data in a db, all you have to do is implement a one column table for your primary key...

    >
    > You will then implement ejbLoad() to load your data from wherever you have the data and probably will not implement the ejbStore() method. Youe ejbLoad() may be called several times during a session, so be sure that the data you store within can be obtained from elsewhere.
    >
    > Hope this helps.
    >
    > -Srini Santhanam

    So I always need a table in DB when I work with entity beans, even BMP? I want to use an entity bean for it's pooling/clustering and caching. I want it to be just a cashe on the server. I don't want to use any database at all. Is this possible? Thanks.
  4. Re: Nonpersistent entity bean[ Go to top ]

    From a pure standpoint of answering your question, it is not necessary for you to have a database (or to be more precise, permanent storage) if you use BMP. Normally in BMP implementation, you write your own JDBC code (in case of using DB) to keep the EntityBean persistence. If you don't need a DB, you just write what you have to do but JDBC code.

    To be honest, I'm not a WebSphere expert, but for such a prominent product in the market, I'm sure there are ways to setup clustering so that you can handle load balance and things like that. It seems to me that using EJB clustering in your case wouldn't be the best solution. Someone else helps?
  5. Re: Nonpersistent entity bean[ Go to top ]

    From a pure standpoint of answering your question, it is not necessary for you to have a database (or to be more precise, permanent storage) if you use BMP. Normally in BMP implementation, you write your own JDBC code (in case of using DB) to keep the EntityBean persistence. If you don't need a DB, you just write what you have to do but JDBC code.

    >
    > To be honest, I'm not a WebSphere expert, but for such a prominent product in the market, I'm sure there are ways to setup clustering so that you can handle load balance and things like that. It seems to me that using EJB clustering in your case wouldn't be the best solution. Someone else helps?

    This is a good point. But what would you recommend as an alternative solution? I need to cache data somewhere so I can pass it between various components. I know that it's not recommended to store a lot of data in the HttpSession since WebSphere uses database to perform load-balancing and transfer of that data between clusters -- so it's very slow and inefficient. What would be a good solution for this problem?
  6. Re: Nonpersistent entity bean[ Go to top ]

    If you use BMP, you don't get any entity bean caching features provided by the EJB container. They are only for CMP entity beans. But anyway entity bean caching won't help much in your case.

    There are 2 alternate solutions -
    1 Use a distributed caching product like Coherence (can be expensive in terms of money)

    2 Replicate the cache on all the app server instances. In your Http session object you can keep a key to your cached data object and a revision number. Increment the revision number in the http session everytime you change this cached object. Now whenever you access the cached object, use the revision number to check if the cached copy on that app server is dirty.
  7. Hi Lenny,

    If you need to store data in a distributed (partitioned) manner across your WebSphere cluster check out Tangosol's Coherence product. Coherence is a clustered coherent in-memory caching and data management solution.

    In fact, we have an in-memory Http Session Replication module that allows for the use of non-sticky load-balancing and fault tolerance of your Http Session objects in WAS 4.0. With a FREE development license we provide the source to all the Http Session Replication modules including the WebSphere 4.0, Servlet 2.3 and Tomcat 4.0.x modules.

    Later,
    Rob Misek
    Tangosol, Inc.
    Coherence: Cluster your Work. Work your Cluster.
  8. I didn't use this product but it sounds like it suits your needs. Check it out:

    http://jakarta.apache.org/turbine/jcs/