1 2 Previous Next 26 Replies Latest reply on Jul 17, 2004 1:34 PM by Bela Ban

    Using JBossCache with WebLogic 8.1 and WebSphere 5.1

    Chris Aakre Newbie

      I'm looking for a distributed cache I can use on JBoss 3.2.4, WebLogic 8.1 and WebSphere 5.1.

      Has anyone used JBossCache with WebLogic or WebSphere? If so, I'm curious if you ran into any issues.

      Also, is it safe to use JBossCache with asynchronous replication in an EJB container? Specifically, is it okay to use within WebLogic 8.1 and WebSphere 5.1? The JBossCache data sheet mentioned that "asynchronous replication is achieved in a separate thread"? Does this violate the EJB specification?

      Thanks in advance,
      Chris

        • 1. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
          Chris Aakre Newbie

          One followup question - does JBossCache JTA transactional caching work with WebLogic and WebSphere?

          • 2. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
            Ben Wang Master

            Chris,

            I have never tried it in both platforms. So if anyone has any experience to share, that will be awesome.

            I don't see any problem why it won't work though. The trick is to start up JBossCache instance initially (either as a in-vm static or register as a MBean). And put the tree-service.xml under your classpath.

            From my Weblogic experience, I know you can do it from the startup classes hook to initialize your cache.

            And I think (and hope :-) either TM will work with JBossCache.

            Hope this help,

            -Ben

            • 3. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
              Bela Ban Master

               

              "chrisaakre2" wrote:
              I'm looking for a distributed cache I can use on JBoss 3.2.4, WebLogic 8.1 and WebSphere 5.1.

              Has anyone used JBossCache with WebLogic or WebSphere? If so, I'm curious if you ran into any issues.

              Also, is it safe to use JBossCache with asynchronous replication in an EJB container? Specifically, is it okay to use within WebLogic 8.1 and WebSphere 5.1? The JBossCache data sheet mentioned that "asynchronous replication is achieved in a separate thread"? Does this violate the EJB specification?

              Thanks in advance,
              Chris


              Use of JBossCache within WebLogic is on the roadmap. What you have to do is to provide an implementation of ManagerLookup and set the ManagerLookupClass to its fully qualified classname.

              Regarding the spec violation: do you care ?

              Bela

              • 4. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                Bela Ban Master

                 

                "bela" wrote:
                "chrisaakre2" wrote:
                I'm looking for a distributed cache I can use on JBoss 3.2.4, WebLogic 8.1 and WebSphere 5.1.

                Has anyone used JBossCache with WebLogic or WebSphere? If so, I'm curious if you ran into any issues.

                Also, is it safe to use JBossCache with asynchronous replication in an EJB container? Specifically, is it okay to use within WebLogic 8.1 and WebSphere 5.1? The JBossCache data sheet mentioned that "asynchronous replication is achieved in a separate thread"? Does this violate the EJB specification?

                Thanks in advance,
                Chris


                Use of JBossCache within WebLogic is on the roadmap. What you have to do is to provide an implementation of ManagerLookup and set the ManagerLookupClass to its fully qualified classname.

                Regarding the spec violation: do you care ?

                Bela


                It is actually TransactionManagerLookup.
                Bela

                • 5. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                  Bela Ban Master

                   

                  "chrisaakre2" wrote:
                  One followup question - does JBossCache JTA transactional caching work with WebLogic and WebSphere?


                  It should - we support the
                  Synchronization
                  interface, not yet the
                  XAResource
                  interface.

                  I haven't tried it out yet though.

                  Bela

                  • 6. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                    Chris Aakre Newbie

                    Thanks for the replies.

                    Regarding the spec violation, it's not a problem currently provided that it doesn't adversely impact performance and scalability. It might be a issue someday if we wanted to get our application certified as J2EE compliant, but that's not in the immediate roadmap.

                    • 7. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                      Markus Plesser Newbie

                       

                      "bela" wrote:


                      Use of JBossCache within WebLogic is on the roadmap. What you have to do is to provide an implementation of ManagerLookup and set the ManagerLookupClass to its fully qualified classname.

                      Regarding the spec violation: do you care ?

                      Bela


                      I successfully got a 'generic' transaction manager lookup running that determines itself under which application server it is running (supported are jboss, weblogic, websphere, orion and others). It is derived from a code fragment from the spring framework. If there is any interest in it let me know and i can provide the sources.

                      -markus

                      • 8. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                        Bela Ban Master

                        go ahead and post it, it might use it.

                        Bela

                        • 9. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                          Markus Plesser Newbie

                          Here you go, just the package name is left out, adjust as you see fit.
                          Code is tested using Orion, OC4J, JBoss and WebSphere 5.1

                          -markus

                          import org.apache.log4j.Logger;
                          import org.jboss.cache.TransactionManagerLookup;
                          import org.jboss.cache.transaction.DummyTransactionManager;
                          
                          import javax.naming.InitialContext;
                          import javax.naming.NamingException;
                          import javax.transaction.TransactionManager;
                          import java.lang.reflect.Method;
                          
                          /**
                           * A generic class that chooses the best-fit TransactionManager
                           */
                          public class GenericTransactionManagerLookup implements TransactionManagerLookup {
                          
                           /**
                           * our logger
                           */
                           private static Logger log = Logger.getLogger( GenericTransactionManagerLookup.class );
                          
                           /**
                           * lookups performed?
                           */
                           private static boolean lookupDone = false;
                          
                           /**
                           * no lookup available?
                           */
                           private static boolean lookupFailed = false;
                          
                           /**
                           * the (final) used TransactionManager
                           */
                           private static TransactionManager tm = null;
                          
                           /**
                           * JNDI locations for TransactionManagers we know of
                           */
                           private static String[][] knownJNDIManagers = {
                           {"java:comp/UserTransaction", "Resin, Orion, JOnAS (JOTM)"},
                           {"java:/TransactionManager", "JBoss, JRun4"},
                           {"javax.transaction.TransactionManager", "BEA WebLogic"}
                           };
                          
                           /**
                           * WebSphere 5.1 TransactionManagerFactory
                           */
                           private static final String WS_FACTORY_CLASS_5_1 = "com.ibm.ws.Transaction.TransactionManagerFactory";
                          
                           /**
                           * WebSphere 5.0 TransactionManagerFactory
                           */
                           private static final String WS_FACTORY_CLASS_5_0 = "com.ibm.ejs.jts.jta.TransactionManagerFactory";
                          
                           /**
                           * WebSphere 4.0 TransactionManagerFactory
                           */
                           private static final String WS_FACTORY_CLASS_4 = "com.ibm.ejs.jts.jta.JTSXA";
                          
                           /**
                           * Get the systemwide used TransactionManager
                           *
                           * @return TransactionManager
                           */
                           public TransactionManager getTransactionManager() {
                           if( !lookupDone )
                           doLookups();
                           if( tm != null )
                           return tm;
                           if( lookupFailed ) {
                           //fall back to a dummy from JBossCache
                           tm = DummyTransactionManager.getInstance();
                           log.warn( "Falling back to DummyTransactionManager from JBossCache" );
                           }
                           return tm;
                           }
                          
                          
                           /**
                           * Try to figure out which TransactionManager to use
                           */
                           private static void doLookups() {
                           if( lookupFailed )
                           return;
                           InitialContext ctx;
                           try {
                           ctx = new InitialContext();
                           } catch( NamingException e ) {
                           log.error( "Could not create an initial JNDI context!", e );
                           lookupFailed = true;
                           return;
                           }
                           //probe jndi lookups first
                           Object jndiObject = null;
                           for( int i = 0; i < knownJNDIManagers.length; i++ ) {
                           try {
                           if( log.isDebugEnabled() ) log.debug( "Trying to lookup TransactionManager for " + knownJNDIManagers[1] );
                           jndiObject = ctx.lookup( knownJNDIManagers[0] );
                           } catch( NamingException e ) {
                           log.info( "Failed to perform a lookup for [" + knownJNDIManagers[0] + " (" + knownJNDIManagers[1] + ")]" );
                           }
                           if( jndiObject instanceof TransactionManager ) {
                           tm = (TransactionManager) jndiObject;
                           log.info( "Found TransactionManager for " + knownJNDIManagers[1] );
                           return;
                           }
                           }
                           //try to find websphere lookups since we came here
                           Class clazz;
                           try {
                           log.debug( "Trying WebSphere 5.1: " + WS_FACTORY_CLASS_5_1 );
                           clazz = Class.forName( WS_FACTORY_CLASS_5_1 );
                           log.info( "Found WebSphere 5.1: " + WS_FACTORY_CLASS_5_1 );
                           } catch( ClassNotFoundException ex ) {
                           try {
                           log.debug( "Trying WebSphere 5.0: " + WS_FACTORY_CLASS_5_0 );
                           clazz = Class.forName( WS_FACTORY_CLASS_5_0 );
                           log.info( "Found WebSphere 5.0: " + WS_FACTORY_CLASS_5_0 );
                           } catch( ClassNotFoundException ex2 ) {
                           try {
                           log.debug( "Trying WebSphere 4: " + WS_FACTORY_CLASS_4 );
                           clazz = Class.forName( WS_FACTORY_CLASS_4 );
                           log.info( "Found WebSphere 4: " + WS_FACTORY_CLASS_4 );
                           } catch( ClassNotFoundException ex3 ) {
                           log.info( "Couldn't find any WebSphere TransactionManager factory class, neither for WebSphere version 5.1 nor 5.0 nor 4" );
                           lookupFailed = true;
                           return;
                           }
                           }
                           }
                           try {
                           Method method = clazz.getMethod( "getTransactionManager"/* java 1.4: , null*/ );
                           tm = (TransactionManager) method.invoke( null /* java 1.4: ,null*/ );
                           } catch( Exception ex ) {
                           log.error( "Found WebSphere TransactionManager factory class [" + clazz.getName() +
                           "], but couldn't invoke its static 'getTransactionManager' method", ex );
                           }
                           }
                           }
                          


                          • 10. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                            Bela Ban Master

                            Thanks, I have checked it into jboss-head. I will backport it to jboss-3.2 once I release JBossCache 1.1.

                            I had to fix some index error, plus a method.invoke() args error. Could you check it out from the CVS and see whether it works with my changes ?

                            Also: if you could test whether this runs inside JBoss, then I'd replace JBossTransactionLookup with this one, making it the default TX manager lookup class.

                            Thanks,
                            Bela

                            • 11. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                              Bela Ban Master

                              Thanks, I have checked it into jboss-head. I will backport it to jboss-3.2 once I release JBossCache 1.1.

                              I had to fix some index error, plus a method.invoke() args error. Could you check it out from the CVS and see whether it works with my changes ?

                              Also: if you could test whether this runs inside JBoss, then I'd replace JBossTransactionLookup with this one, making it the default TX manager lookup class.

                              Thanks,
                              Bela

                              • 12. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                                Markus Plesser Newbie

                                You're welcome.

                                It took me some time to verify due to a deployment issue of my app on JBoss, but i can confirm now that it is working in the current jboss-head.
                                There is one issue though: The moment you modify a node during a transaction it is replicated across all members of the cluster. Once you roll it back the 'original' state is correctly restored but if you rely on a TreeCacheListener you do receive 'nodeModified()' events which in my opinion you should not before the transaction is commited.
                                Oh and pretty pretty please initialize the logger correctly in TreeCache.java - helps a lot with debugging spam ;)

                                About the errors you mentioned - the sources were written for JDK 1.5 where you have a different interface for method.invoke().

                                And there still seems to be a bug in TreeCache where i get a NullPointerException on a code that works fine with the 'production' release:
                                java.lang.NullPointerException
                                at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:3080)
                                at org.jboss.cache.TreeCache.put(TreeCache.java:1649)
                                at org.jboss.cache.TreeCache.put(TreeCache.java:1632)

                                -markus

                                • 13. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                                  Bela Ban Master

                                   

                                  "mplesser" wrote:

                                  There is one issue though: The moment you modify a node during a transaction it is replicated across all members of the cluster.

                                  Not correct: I only replicate at the end of a TX.


                                  Once you roll it back the 'original' state is correctly restored but if you rely on a TreeCacheListener you do receive 'nodeModified()' events which in my opinion you should not before the transaction is commited.


                                  You're right. This is on the todo list.


                                  Oh and pretty pretty please initialize the logger correctly in TreeCache.java - helps a lot with debugging spam ;)


                                  What do you mean ? The super class MBeanSupport initializes the logger, looks correct to me.


                                  About the errors you mentioned - the sources were written for JDK 1.5 where you have a different interface for method.invoke().


                                  Does it work with my changes ?


                                  And there still seems to be a bug in TreeCache where i get a NullPointerException on a code that works fine with the 'production' release:
                                  java.lang.NullPointerException
                                  at org.jboss.cache.TreeCache.invokeMethod(TreeCache.java:3080)
                                  at org.jboss.cache.TreeCache.put(TreeCache.java:1649)
                                  at org.jboss.cache.TreeCache.put(TreeCache.java:1632)



                                  How do you arrive at this one ?

                                  Bela

                                  • 14. Re: Using JBossCache with WebLogic 8.1 and WebSphere 5.1
                                    Markus Plesser Newbie

                                     

                                    Not correct: I only replicate at the end of a TX.

                                    You're right sorry, i just double checked again, although it is readable from the local instance outside of the transaction.

                                    What do you mean ? The super class MBeanSupport initializes the logger, looks correct to me.

                                    It does, but only if you are using it inside of JBoss. This is an issue though if used in another Application Server - only workaround for me was to declare a Logger inside TreeCache.java.

                                    Does it work with my changes ?

                                    I had a chance only to test it with OC4J and JBoss (cvs jboss-head) so far and it works.

                                    How do you arrive at this one ?

                                    it happens on a put(String,String,Vector) and only during the 'startup phase'. I use a maybe odd concept here:
                                    Whenever the coordinator receives a view-change from jgroups he issues a (rpc) method call via jgroups to all members in the cluster. The members answer using a callback to tell the coordinator what kind of node they are. This information is saved in a node in the cache from the coordinator and here is where the exception occurs.
                                    It seems to happen only when the coordinator is starting up, not upon joining of new members - which makes me think that the cache is not really completely initialized.
                                    I had no time to dig through the sources since the interceptor concept you're using is new to me and seems to be committed to cvs just recently.

                                    -markus


                                    1 2 Previous Next