1 2 Previous Next 20 Replies Latest reply on Mar 6, 2007 10:34 AM by brian.stansberry

    How to use JBossCache within WebSphere?

    neilkong

      Hi, I'm newby of JBossCache. Anybody know how to use JBossCache within WebSphere?
      I need instructions of configuration for JBossCache within WebSphere.

        • 1. Re: How to use JBossCache within WebSphere?
          belaban

          We get this question a lot, and I know people are running JBossCache under WebSphere.

          It would be nice if someone who successfully has JBossCache running in WS, could put together a short list of steps to do this. This could e.g. be on the wiki.
          Cheers,

          • 2. Re: How to use JBossCache within WebSphere?
            neilkong

            sounds good. Any contribution will be welcome and appreciated.

            • 3. Re: How to use JBossCache within WebSphere?

              I got it working on WebSphere 5.1.1

              Here's a couple of things you need to do

              1) Unjar the $WAS_ROOT/lib/jmxc.jar and MAKE SURE it's unsealed (check the MANIFEST) then jar it back up..

              2) Copy the necessary TreeCache Libs on $WAS_ROOT/lib/ext directory

              3) Copy your TreeCache configuration file to $WAS_ROOT/classes directory

              4) Create a Custom Service that initializes TreeCache and sticks it's reference on a Singleton.

              Note, on WebSphere, you can't stick the TreeCache onto JNDI as it's not serializable (unlike on other servers where you can if said JNDI entry is on the local server scope).. Hence, you'll have to create some sort of singleton that is initialized by the Custom Service.



              • 4. Re: How to use JBossCache within WebSphere?

                example Service

                import java.util.Properties;
                
                import javax.management.Notification;
                import javax.management.NotificationFilterSupport;
                import javax.management.NotificationListener;
                import javax.management.ObjectName;
                import javax.naming.InitialContext;
                import javax.transaction.SystemException;
                import javax.transaction.TransactionManager;
                
                import org.apache.commons.logging.Log;
                import org.apache.commons.logging.LogFactory;
                import org.jboss.cache.Fqn;
                import org.jboss.cache.PropertyConfigurator;
                import org.jboss.cache.TreeCache;
                
                import com.esri.infoservices.j2ee.jbosscache.exceptions.InvalidArgumentException;
                import com.ibm.websphere.management.AdminServiceFactory;
                import com.ibm.websphere.management.NotificationConstants;
                import com.ibm.websphere.runtime.CustomService;
                
                public class JCacheWAS51Service implements CustomService, NotificationListener {
                
                 public final static String NODE_PATH = "/GlobalCache";
                
                 private final static String CACHE_INITIALIZED_KEY = "CacheInitialized";
                
                 private TreeCache treeCache = null;
                
                 private Log logger = LogFactory.getLog(getClass());
                
                 private String jndiName = null;
                
                 public void initialize(Properties configuration) throws Exception {
                 String configFile = null;
                 logger.info("JCacheWAS51Service.initialize(): starting up.");
                 if (configuration != null && !configuration.isEmpty()) {
                 if (logger.isDebugEnabled()) {
                 configuration.list(System.out);
                 }
                 configFile = configuration.getProperty("configFile");
                 if (configFile == null || configFile.trim().length() == 0) {
                 throw new InvalidArgumentException(
                 "JCacheWAS51Service: configFile configuration property is required.");
                 }
                 logger
                 .debug("JCacheWAS51Service.initialize(): Starting up TreeCache.");
                 treeCache = new TreeCache();
                 PropertyConfigurator configurator = new PropertyConfigurator();
                 configurator.configure(treeCache, configFile);
                 treeCache.createService();
                 treeCache.startService();
                 logger
                 .debug("JCacheWAS51Service.initialize(): setting up filters to wait for WAS startup.");
                 NotificationFilterSupport filter = new NotificationFilterSupport();
                 filter.enableType(NotificationConstants.TYPE_J2EE_STATE_RUNNING);
                 ObjectName target = new ObjectName("WebSphere:*,type=Server");
                 AdminServiceFactory
                 .getAdminService()
                 .addNotificationListenerExtended(target, this, filter, null);
                 logger.info("JCacheWAS51Service.initialize(): waiting.");
                 } else {
                 logger.debug("JCacheWAS51Service.initialize(): not configured.");
                 }
                
                 }
                
                 public void shutdown() throws Exception {
                 logger
                 .info("JCacheWAS51Service.shutdown(): server is stopping, shutting down cache.");
                 if (treeCache != null) {
                 treeCache.stopService();
                 treeCache.destroyService();
                 }
                 }
                
                 public void handleNotification(Notification arg0, Object arg1) {
                 TransactionManager transaction = null;
                 logger
                 .info("JCacheWAS51Service.initialize(): server has started, creating node.");
                 try {
                 logger
                 .info("JCacheWAS51Service.handleNotification(): TreeCache, creating initial NODE_PATH ["
                 + NODE_PATH + "].");
                 transaction = treeCache.getTransactionManager();
                 transaction.begin();
                 Fqn nodeName = new Fqn(NODE_PATH);
                 Boolean initialized = (Boolean) treeCache.get(nodeName,
                 CACHE_INITIALIZED_KEY);
                 if (initialized == null || initialized == Boolean.FALSE) {
                 treeCache.put(nodeName, CACHE_INITIALIZED_KEY, Boolean.TRUE);
                 }
                 transaction.commit();
                 logger
                 .debug("JCacheWAS51Service.handleNotification: done with cache handling.");
                 } catch (Exception error) {
                 logger
                 .error("JCacheWAS51Service.handleNotification: error handling transaction, message="
                 + error.getMessage());
                 try {
                 transaction.rollback();
                 } catch (SystemException warn) {
                 logger.warn(warn);
                 }
                 }
                 }
                }
                
                


                • 5. Re: How to use JBossCache within WebSphere?
                  neilkong

                   

                  "gdaswani" wrote:
                  I got it working on WebSphere 5.1.1

                  Here's a couple of things you need to do

                  1) Unjar the $WAS_ROOT/lib/jmxc.jar and MAKE SURE it's unsealed (check the MANIFEST) then jar it back up..

                  What's this step for?

                  "gdaswani" wrote:
                  4) Create a Custom Service that initializes TreeCache and sticks it's reference on a Singleton.

                  How should the custom service looks like? Just initialize TreeCache and start service is okay?


                  • 6. Re: How to use JBossCache within WebSphere?

                    Transaction Manager Lookup - lifted off from Hibernate

                    import javax.transaction.TransactionManager;
                    
                    import org.apache.commons.logging.Log;
                    import org.apache.commons.logging.LogFactory;
                    import org.jboss.cache.TransactionManagerLookup;
                    
                    import com.esri.infoservices.j2ee.jbosscache.exceptions.InvalidArgumentException;
                    
                    public class WASTransactionManagerLookup implements TransactionManagerLookup {
                     private static final Log logger = LogFactory
                     .getLog(WASTransactionManagerLookup.class);
                    
                     private int version;
                    
                     public TransactionManager getTransactionManager() throws Exception {
                     try {
                     Class clazz;
                     try {
                     clazz = Class
                     .forName("com.ibm.ws.Transaction.TransactionManagerFactory");
                     version = 5;
                     logger.info("WebSphere 5.1");
                     } catch (Exception e) {
                     try {
                     clazz = Class
                     .forName("com.ibm.ejs.jts.jta.TransactionManagerFactory");
                     version = 5;
                     logger.info("WebSphere 5.0");
                     } catch (Exception e2) {
                     clazz = Class.forName("com.ibm.ejs.jts.jta.JTSXA");
                     version = 4;
                     logger.info("WebSphere 4");
                     }
                     }
                    
                     return (TransactionManager) clazz.getMethod(
                     "getTransactionManager", null).invoke(null, null);
                     } catch (Exception e) {
                     throw new InvalidArgumentException(
                     "Could not obtain WebSphere JTSXA instance", e);
                     }
                     }
                    
                    }
                    


                    • 7. Re: How to use JBossCache within WebSphere?

                       

                      "neilkong" wrote:


                      1) Unjar the $WAS_ROOT/lib/jmxc.jar and MAKE SURE it's unsealed (check the MANIFEST) then jar it back up..

                      What's this step for?


                      WebSphere will throw a SEALED EXCEPTION error as JBOSS-Cache has a dependency on some JMX classes which doesn't exist in the *sealed* jmxc.jar



                      • 8. Re: How to use JBossCache within WebSphere?
                        neilkong

                         

                        "gdaswani" wrote:
                        "neilkong" wrote:


                        1) Unjar the $WAS_ROOT/lib/jmxc.jar and MAKE SURE it's unsealed (check the MANIFEST) then jar it back up..

                        What's this step for?


                        WebSphere will throw a SEALED EXCEPTION error as JBOSS-Cache has a dependency on some JMX classes which doesn't exist in the *sealed* jmxc.jar


                        You mean there should be different version of jmxc.jar? I checked mine and that's a sealed jmxc.jar. Shall I get some unsealed version from somewhere?

                        • 9. Re: How to use JBossCache within WebSphere?
                          neilkong

                           

                          "gdaswani" wrote:
                          I got it working on WebSphere 5.1.1

                          Here's a couple of things you need to do

                          3) Copy your TreeCache configuration file to $WAS_ROOT/classes directory

                          Can you show me your configuration file? I got confused with that

                          what folder should I set for codebase?

                          • 10. Re: How to use JBossCache within WebSphere?
                            belaban

                            I created a wiki page for this: http://wiki.jboss.org/wiki/Wiki.jsp?page=WS.

                            Could you guys do me a favor and update it as you find out how to run JBossCache in WebSphere ?

                            Cheers,
                            Bela

                            • 11. Re: How to use JBossCache within WebSphere?
                              belaban

                              You can also use the GenericTransactionManagerLookup class, part of JBossCache, which probes for WS along the way.

                              • 12. Re: How to use JBossCache within WebSphere?

                                 

                                "neilkong" wrote:


                                You mean there should be different version of jmxc.jar? I checked mine and that's a sealed jmxc.jar. Shall I get some unsealed version from somewhere?

                                • 13. Re: How to use JBossCache within WebSphere?

                                  Okay, that reply didn't work - lol.

                                  unar the jmxc.jar that comes with WebSphere..

                                  then modify it's META-INF/MANIFEST.MF

                                  change the attribute that states

                                  Sealed: true

                                  to

                                  Sealed: false

                                  then jar it back up as jmxc.jar then copy it to the $WAS_ROOT/lib dir (overwritting the original).

                                  • 14. Re: How to use JBossCache within WebSphere?

                                    example - SYNC REPL cache..

                                    <?xml version="1.0" encoding="UTF-8"?>
                                    
                                    <!-- ===================================================================== -->
                                    <!-- -->
                                    <!-- Sample TreeCache Service Configuration -->
                                    <!-- -->
                                    <!-- ===================================================================== -->
                                    
                                    <server>
                                    
                                     <classpath codebase="./lib" archives="jboss-cache.jar, jgroups.jar" />
                                    
                                     <!-- ==================================================================== -->
                                     <!-- Defines TreeCache configuration -->
                                     <!-- ==================================================================== -->
                                    
                                     <mbean code="org.jboss.cache.TreeCache"
                                     name="jboss.cache:service=TreeCache">
                                    
                                     <depends>jboss:service=Naming</depends>
                                     <depends>jboss:service=TransactionManager</depends>
                                    
                                     <attribute name="TransactionManagerLookupClass">
                                     org.jboss.cache.GenericTransactionManagerLookup
                                     </attribute>
                                    
                                     <!--
                                     Node locking level : SERIALIZABLE
                                     REPEATABLE_READ (default)
                                     READ_COMMITTED
                                     READ_UNCOMMITTED
                                     NONE
                                     -->
                                     <attribute name="IsolationLevel">REPEATABLE_READ</attribute>
                                    
                                     <!--
                                     Valid modes are LOCAL
                                     REPL_ASYNC
                                     REPL_SYNC
                                     -->
                                     <attribute name="CacheMode">REPL_ASYNC</attribute>
                                    
                                     <attribute name="UseReplQueue">false</attribute>
                                    
                                     <attribute name="ReplQueueInterval">20000</attribute>
                                    
                                     <attribute name="ReplQueueMaxElements">5</attribute>
                                    
                                     <attribute name="ClusterName">PortalServer-Cluster</attribute>
                                    
                                     <attribute name="ClusterConfig">
                                     <config>
                                     <!-- UDP: if you have a multihomed machine,
                                     set the bind_addr attribute to the appropriate NIC IP address -->
                                     <!-- UDP: On Windows machines, because of the media sense feature
                                     being broken with multicast (even after disabling media sense)
                                     set the loopback attribute to true -->
                                     <UDP mcast_addr="230.8.8.8" mcast_port="56677"
                                     ip_ttl="32" ip_mcast="true" mcast_send_buf_size="80000"
                                     mcast_recv_buf_size="150000" ucast_send_buf_size="80000"
                                     ucast_recv_buf_size="150000" loopback="true" />
                                     <PING timeout="2000" num_initial_members="3"
                                     up_thread="false" down_thread="false" />
                                     <MERGE2 min_interval="10000" max_interval="20000" />
                                     <FD shun="true" up_thread="true" down_thread="true" />
                                     <VERIFY_SUSPECT timeout="1500" up_thread="false"
                                     down_thread="false" />
                                     <pbcast.NAKACK gc_lag="50"
                                     retransmit_timeout="600,1200,2400,4800" max_xmit_size="8192"
                                     up_thread="false" down_thread="false" />
                                     <UNICAST timeout="600,1200,2400" window_size="100"
                                     min_threshold="10" down_thread="false" />
                                     <pbcast.STABLE desired_avg_gossip="20000"
                                     up_thread="false" down_thread="false" />
                                     <FRAG frag_size="8192" down_thread="false"
                                     up_thread="false" />
                                     <pbcast.GMS join_timeout="5000"
                                     join_retry_timeout="2000" shun="true" print_local_addr="true" />
                                     <pbcast.STATE_TRANSFER up_thread="false"
                                     down_thread="false" />
                                     </config>
                                     </attribute>
                                    
                                    
                                     <!--
                                     The max amount of time (in milliseconds) we wait until the
                                     initial state (ie. the contents of the cache) are retrieved from
                                     existing members in a clustered environment
                                     -->
                                     <attribute name="InitialStateRetrievalTimeout">10000</attribute>
                                    
                                     <!--
                                     Number of milliseconds to wait until all responses for a
                                     synchronous call have been received.
                                     -->
                                     <attribute name="SyncReplTimeout">10000</attribute>
                                    
                                     <!-- Max number of milliseconds to wait for a lock acquisition -->
                                     <attribute name="LockAcquisitionTimeout">15000</attribute>
                                    
                                     <!-- Name of the eviction policy class. Not supported now. -->
                                     <attribute name="EvictionPolicyClass"></attribute>
                                    
                                     <attribute name="FetchStateOnStartup">true</attribute>
                                    
                                     </mbean>
                                    
                                    </server>
                                    


                                    1 2 Previous Next