[jboss-cvs] JBossAS SVN: r106928 - in projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha: web and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 20 12:19:36 EDT 2010


Author: pferraro
Date: 2010-07-20 12:19:35 -0400 (Tue, 20 Jul 2010)
New Revision: 106928

Added:
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/AtomicMapEntry.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CacheInvoker.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CacheListener.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CoarseSessionAttributeStorage.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/FineSessionAttributeStorage.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/PassivationListener.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshaller.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java
   projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorage.java
Log:
[JBCLUSTER-257] Initial implementation

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/AtomicMapEntry.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/AtomicMapEntry.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/AtomicMapEntry.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import org.infinispan.atomic.AtomicMap;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public enum AtomicMapEntry
+{
+   VERSION(Integer.class), TIMESTAMP(Long.class), METADATA(DistributableSessionMetadata.class), ATTRIBUTES(Object.class);
+   
+   private Class<?> targetClass;
+   
+   private AtomicMapEntry(Class<?> targetClass)
+   {
+      this.targetClass = targetClass;
+   }
+   
+   @SuppressWarnings("unchecked")
+   public <T> T get(AtomicMap<Object, Object> data)
+   {
+      Object value = data.get(this.key());
+      
+      return (value != null) ? (T) this.targetClass.cast(value) : null;
+   }
+
+   public void put(AtomicMap<Object, Object> data, Object value)
+   {
+      if (value == null) return;
+      
+      if (!this.targetClass.isInstance(value))
+      {
+         throw new IllegalArgumentException(String.format("Attempt to put value of type %s into %s entry", value.getClass().getName(), this));
+      }
+      
+      data.put(this.key(), value);
+   }
+   
+   private Byte key()
+   {
+      return Byte.valueOf((byte) this.ordinal());
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/BatchingManagerImpl.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.TransactionManager;
+
+import org.jboss.logging.Logger;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager;
+
+/**
+ * @author Paul Ferraro
+ */
+public class BatchingManagerImpl implements BatchingManager
+{
+   private static final Logger log = Logger.getLogger(BatchingManagerImpl.class);
+   
+   private final TransactionManager tm;
+   
+   public BatchingManagerImpl(TransactionManager tm)
+   {
+      this.tm = tm;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#isBatchInProgress()
+    */
+   @Override
+   public boolean isBatchInProgress() throws Exception
+   {
+      return this.tm.getTransaction() != null;
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#startBatch()
+    */
+   @Override
+   public void startBatch() throws Exception
+   {
+      this.tm.begin();
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#setBatchRollbackOnly()
+    */
+   @Override
+   public void setBatchRollbackOnly() throws Exception
+   {
+      this.tm.setRollbackOnly();
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager#endBatch()
+    */
+   @Override
+   public void endBatch()
+   {
+      try
+      {
+         if (this.tm.getTransaction().getStatus() != Status.STATUS_MARKED_ROLLBACK)
+         {
+            this.tm.commit();
+         }
+         else
+         {
+            log.debug("endBatch(): rolling back batch");
+            
+            this.tm.rollback();
+         }
+      }
+      catch (RollbackException e)
+      {
+         // Do nothing here since cache may rollback automatically.
+         log.warn("endBatch(): rolling back transaction with exception", e);
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("endTransaction(): Caught Exception ending batch: ", e);
+      }
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CacheInvoker.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CacheInvoker.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CacheInvoker.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import org.infinispan.Cache;
+import org.infinispan.atomic.AtomicMap;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface CacheInvoker
+{
+   <R> R invoke(Operation<R> operation);
+   
+   interface Operation<R>
+   {
+      R invoke(Cache<String, AtomicMap<Object, Object>> cache);
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CacheListener.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CacheListener.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CacheListener.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import org.infinispan.atomic.AtomicMap;
+import org.infinispan.notifications.Listener;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
+import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
+import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+ at Listener
+public class CacheListener
+{
+   private final LocalDistributableSessionManager manager;
+   
+   public CacheListener(LocalDistributableSessionManager manager)
+   {
+      this.manager = manager;
+   }
+   
+   @CacheEntryRemoved
+   public void removed(CacheEntryRemovedEvent event)
+   {
+      if (event.isPre() || event.isOriginLocal()) return;
+      
+      this.manager.notifyRemoteInvalidation((String) event.getKey());
+   }
+   
+   @CacheEntryModified
+   public void modified(CacheEntryModifiedEvent event)
+   {
+      if (event.isPre() || event.isOriginLocal()) return;
+      
+      @SuppressWarnings("unchecked")
+      AtomicMap<Object, Object> data = (AtomicMap<Object, Object>) event.getValue();
+      
+      Integer version = (Integer) data.get(AtomicMapEntry.VERSION.key());
+      Long timestamp = (Long) data.get(AtomicMapEntry.TIMESTAMP.key());
+      DistributableSessionMetadata metadata = (DistributableSessionMetadata) data.get(AtomicMapEntry.METADATA.key());
+      
+      this.manager.sessionChangedInDistributedCache((String) event.getKey(), null, version.intValue(), timestamp.longValue(), metadata);
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CoarseSessionAttributeStorage.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CoarseSessionAttributeStorage.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/CoarseSessionAttributeStorage.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import java.util.Map;
+
+import org.infinispan.atomic.AtomicMap;
+import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingSessionGranularitySessionData;
+
+/**
+ * Handles session attribute load/store operations for {@link ReplicationGranularity#SESSION} distributed session managers.
+ * @author Paul Ferraro
+ */
+public class CoarseSessionAttributeStorage implements SessionAttributeStorage<OutgoingSessionGranularitySessionData>
+{
+   private final SessionAttributeMarshaller marshaller;
+   
+   public CoarseSessionAttributeStorage(SessionAttributeMarshaller marshaller)
+   {
+      this.marshaller = marshaller;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.web.tomcat.service.session.distributedcache.impl.SessionAttributeStorage#store(org.infinispan.atomic.AtomicMap, org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData)
+    */
+   @Override
+   public void store(AtomicMap<Object, Object> data, OutgoingSessionGranularitySessionData sessionData)
+   {
+      Map<String, Object> attributes = sessionData.getSessionAttributes();
+      
+      if (attributes != null)
+      {
+         AtomicMapEntry.ATTRIBUTES.put(data, this.marshaller.marshal(attributes));
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.web.tomcat.service.session.distributedcache.impl.SessionAttributeStorage#load(org.infinispan.atomic.AtomicMap)
+    */
+   @SuppressWarnings("unchecked")
+   @Override
+   public Map<String, Object> load(AtomicMap<Object, Object> data) throws Exception
+   {
+      return (Map<String, Object>) this.marshaller.unmarshal(AtomicMapEntry.ATTRIBUTES.get(data));
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerFactoryImpl.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import org.infinispan.manager.CacheContainer;
+import org.jboss.ha.ispn.CacheContainerRegistry;
+import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.TomcatClusterConfig;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.TomcatClusterDistributedCacheManagerFactory;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class DistributedCacheManagerFactoryImpl implements TomcatClusterDistributedCacheManagerFactory
+{
+   private final CacheContainerRegistry registry;
+   private volatile String cacheContainerName;
+   
+   public DistributedCacheManagerFactoryImpl(CacheContainerRegistry registry)
+   {
+      this.registry = registry;
+   }
+   
+   @Override
+   public <T extends OutgoingDistributableSessionData> DistributedCacheManager<T> getDistributedCacheManager(LocalDistributableSessionManager manager)
+   {
+      CacheContainer container = this.registry.getCacheContainer(this.cacheContainerName);
+      SessionAttributeStorage<T> storage = this.getSessionAttributeStorage(manager);
+      
+      return new DistributedCacheManagerImpl<T>(manager, container, storage, 10, 100);
+   }
+
+   @SuppressWarnings("unchecked")
+   private <T extends OutgoingDistributableSessionData> SessionAttributeStorage<T> getSessionAttributeStorage(LocalDistributableSessionManager manager)
+   {
+      SessionAttributeMarshaller marshaller = new SessionAttributeMarshallerImpl(manager);
+      ReplicationGranularity granularity = manager.getReplicationConfig().getReplicationGranularity();
+      
+      switch (granularity)
+      {
+         case SESSION:
+         {
+            return (SessionAttributeStorage<T>) new FineSessionAttributeStorage(marshaller);
+         }
+         case ATTRIBUTE:
+         {
+            return (SessionAttributeStorage<T>) new CoarseSessionAttributeStorage(marshaller);
+         }
+         case FIELD:
+         {
+            throw new IllegalArgumentException("FIELD replication granularity is no longer supported, use SESSION or ATTRIBUTE instead.");
+         }
+         default:
+         {
+            throw new IllegalArgumentException("Unknown replication granularity: " + granularity);
+         }
+      }
+   }
+
+   public String getCacheContainerName()
+   {
+      return this.cacheContainerName;
+   }
+   
+   public void setCacheContainerName(String cacheContainerName)
+   {
+      this.cacheContainerName = cacheContainerName;
+   }
+   
+   @Override
+   public TomcatClusterConfig getTomcatClusterConfig()
+   {
+      return null;
+   }
+
+   @Override
+   public void setTomcatClusterConfig(TomcatClusterConfig clusterConfig)
+   {
+   }
+   
+   @Override
+   public void start() throws Exception
+   {
+   }
+
+   @Override
+   public void stop() throws Exception
+   {
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/DistributedCacheManagerImpl.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,431 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.transaction.TransactionManager;
+
+import org.infinispan.Cache;
+import org.infinispan.atomic.AtomicHashMap;
+import org.infinispan.atomic.AtomicMap;
+import org.infinispan.config.CacheLoaderManagerConfig;
+import org.infinispan.config.Configuration;
+import org.infinispan.context.Flag;
+import org.infinispan.lifecycle.ComponentStatus;
+import org.infinispan.manager.CacheContainer;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.remoting.transport.jgroups.SuspectException;
+import org.infinispan.transaction.tm.BatchModeTransactionManager;
+import org.infinispan.util.concurrent.TimeoutException;
+import org.jboss.logging.Logger;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.BatchingManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
+
+/**
+ * @author Paul Ferraro
+ */
+public class DistributedCacheManagerImpl<T extends OutgoingDistributableSessionData> implements DistributedCacheManager<T>, CacheInvoker
+{
+   static String mask(String sessionId)
+   {
+      if (sessionId == null) return null;
+      
+      int length = sessionId.length();
+      
+      if (length <= 8) return sessionId;
+
+      return sessionId.substring(0, 2) + "****" + sessionId.substring(length - 6, length);
+   }
+
+   static RuntimeException getRuntimeException(String message, Exception e)
+   {   
+      if (e instanceof RuntimeException) return (RuntimeException) e;
+      
+      return new RuntimeException(message != null ? message : e.toString(), e);
+   }
+   
+   private Logger log = Logger.getLogger(this.getClass());
+   
+   private final LocalDistributableSessionManager manager;
+   private final CacheContainer container;
+   private final SessionAttributeStorage<T> attributeStorage;
+   private final int[] backOffIntervals;
+   
+   private Cache<String, AtomicMap<Object, Object>> cache;
+   private BatchingManager batchingManager;
+   private boolean passivationEnabled = false;
+   private Object cacheListener;
+   private Object passivationListener;
+   
+   private volatile boolean forceSynchronous = false;
+   
+   public DistributedCacheManagerImpl(LocalDistributableSessionManager manager, CacheContainer container, SessionAttributeStorage<T> attributeStorage, int... backOffIntervals)
+   {
+      this.manager = manager;
+      this.container = container;
+      this.attributeStorage = attributeStorage;
+      this.backOffIntervals = backOffIntervals;
+   }
+
+   @Override
+   public void start()
+   {
+      String hostName = this.manager.getHostName();
+      String host = (hostName == null) || hostName.isEmpty() ? "localhost" : hostName;
+      
+      // JBAS-3941 -- context path can be multi-level, but we don't
+      // want that turning into a multilevel Fqn, so escape it
+      // Use '-' which is legal in a filesystem path
+      String path = this.getContextPath();
+
+      String cacheName = host + "/" + path;
+      String templateCacheName = this.manager.getReplicationConfig().getCacheName();
+      EmbeddedCacheManager manager = (EmbeddedCacheManager) this.container.getCache().getCacheManager();
+      manager.defineConfiguration(cacheName, templateCacheName, new Configuration());
+      
+      this.cache = manager.getCache(cacheName);
+      
+      if (this.cache.getStatus() != ComponentStatus.RUNNING)
+      {
+         this.cache.start();
+      }
+      
+      TransactionManager tm = this.cache.getAdvancedCache().getTransactionManager();
+      
+      if (!(tm instanceof BatchModeTransactionManager))
+      {
+         throw new IllegalStateException("Unexpected transaction manager type: " + ((tm != null) ? tm.getClass().getName() : "null"));
+      }
+      
+      this.batchingManager = new BatchingManagerImpl(tm);
+      
+      this.cacheListener = new CacheListener(this.manager);
+      this.cache.addListener(this.cacheListener);
+      
+      if (this.manager.isPassivationEnabled())
+      {
+         this.passivationListener = new PassivationListener(this.manager);
+         this.cache.addListener(this.passivationListener);
+      }
+      
+      CacheLoaderManagerConfig loaderManagerConfig = this.cache.getConfiguration().getCacheLoaderManagerConfig();
+      
+      this.passivationEnabled = (loaderManagerConfig != null) ? loaderManagerConfig.isPassivation() && !loaderManagerConfig.isShared() : false;
+   }
+   
+   @Override
+   public void stop()
+   {
+      this.cache.removeListener(this.cacheListener);
+      
+      if (this.passivationListener != null)
+      {
+         this.cache.removeListener(this.passivationListener);
+      }
+      
+      this.cache.stop();
+   }
+
+   @Override
+   public BatchingManager getBatchingManager()
+   {
+      return this.batchingManager;
+   }
+
+   @Override
+   public void sessionCreated(String sessionId)
+   {
+      // Do nothing
+   }
+
+   @Override
+   public void storeSessionData(T sessionData)
+   {
+      final String sessionId = sessionData.getRealId();
+      
+      if (this.log.isTraceEnabled())
+      {
+         this.log.trace("putSession(): putting session " + mask(sessionId));
+      }     
+      
+      final AtomicMap<Object, Object> data = new AtomicHashMap<Object, Object>();
+      
+      AtomicMapEntry.VERSION.put(data, Integer.valueOf(sessionData.getVersion()));
+      AtomicMapEntry.METADATA.put(data, sessionData.getMetadata());
+      AtomicMapEntry.TIMESTAMP.put(data, sessionData.getTimestamp());
+      
+      this.attributeStorage.store(data, sessionData);
+      
+      CacheInvoker.Operation<Void> operation = new CacheInvoker.Operation<Void>()
+      {
+         @Override
+         public Void invoke(Cache<String, AtomicMap<Object, Object>> cache)
+         {
+            cache.put(sessionId, data);
+            
+            return null;
+         }
+      };
+      
+      this.invoke(operation);
+   }
+   
+   @Override
+   public IncomingDistributableSessionData getSessionData(String sessionId, boolean initialLoad)
+   {
+      return this.getData(sessionId, true);
+   }
+
+   @Override
+   public IncomingDistributableSessionData getSessionData(final String sessionId, String dataOwner, boolean includeAttributes)
+   {
+      return (dataOwner != null) ? this.getData(sessionId, includeAttributes) : null;
+   }
+   
+   private IncomingDistributableSessionData getData(final String sessionId, boolean includeAttributes)
+   {
+      CacheInvoker.Operation<AtomicMap<Object, Object>> operation = new CacheInvoker.Operation<AtomicMap<Object, Object>>()
+      {
+         @Override
+         public AtomicMap<Object, Object> invoke(Cache<String, AtomicMap<Object, Object>> cache)
+         {
+            return cache.get(sessionId);
+         }
+      };
+      
+      AtomicMap<Object, Object> data = this.invoke(operation);
+      
+      // If requested session is no longer in the cache; return null
+      if (data == null) return null;
+      
+      try
+      {
+         Integer version = AtomicMapEntry.VERSION.get(data);
+         Long timestamp = AtomicMapEntry.TIMESTAMP.get(data);
+         DistributableSessionMetadata metadata = AtomicMapEntry.METADATA.get(data);
+         IncomingDistributableSessionDataImpl result = new IncomingDistributableSessionDataImpl(version, timestamp, metadata);
+         
+         if (includeAttributes)
+         {
+            try
+            {
+               result.setSessionAttributes(this.attributeStorage.load(data));
+            }
+            catch (Exception e)
+            {
+               throw getRuntimeException("Failed to load session attributes for session: " + mask(sessionId), e);
+            }
+         }
+
+         return result;
+      }
+      catch (Exception e)
+      {
+         String message = String.format("Problem accessing session [%s]: %s", mask(sessionId), e.toString());
+         this.log.warn(message);
+         this.log.debug(message, e);
+         
+         // Clean up
+         this.removeSessionLocal(sessionId);
+         
+         return null;
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#removeSession(java.lang.String)
+    */
+   @Override
+   public void removeSession(final String sessionId)
+   {
+      CacheInvoker.Operation<Void> operation = new CacheInvoker.Operation<Void>()
+      {
+         @Override
+         public Void invoke(Cache<String, AtomicMap<Object, Object>> cache)
+         {
+            cache.remove(sessionId);
+            return null;
+         }
+      };
+      
+      this.invoke(operation);
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#removeSessionLocal(java.lang.String)
+    */
+   @Override
+   public void removeSessionLocal(final String sessionId)
+   {
+      CacheInvoker.Operation<Void> operation = new CacheInvoker.Operation<Void>()
+      {
+         @Override
+         public Void invoke(Cache<String, AtomicMap<Object, Object>> cache)
+         {
+            cache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).remove(sessionId);
+            return null;
+         }
+      };
+      
+      this.invoke(operation);
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#removeSessionLocal(java.lang.String, java.lang.String)
+    */
+   @Override
+   public void removeSessionLocal(String sessionId, String dataOwner)
+   {
+      if (dataOwner == null)
+      {
+         this.removeSessionLocal(sessionId);
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#evictSession(java.lang.String)
+    */
+   @Override
+   public void evictSession(final String sessionId)
+   {
+      CacheInvoker.Operation<Void> operation = new CacheInvoker.Operation<Void>()
+      {
+         @Override
+         public Void invoke(Cache<String, AtomicMap<Object, Object>> cache)
+         {
+            cache.evict(sessionId);
+            return null;
+         }
+      };
+      
+      this.invoke(operation);
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.web.tomcat.service.session.distributedcache.spi.DistributedCacheManager#evictSession(java.lang.String, java.lang.String)
+    */
+   @Override
+   public void evictSession(String sessionId, String dataOwner)
+   {
+      if (dataOwner == null)
+      {
+         this.evictSession(sessionId);
+      }
+   }
+
+   @Override
+   public Map<String, String> getSessionIds()
+   {
+      Map<String, String> result = new HashMap<String, String>();
+
+      for (String sessionId: this.cache.keySet())
+      {
+         result.put(sessionId, null);
+      }
+      
+      return result;
+   }
+
+   @Override
+   public boolean isPassivationEnabled()
+   {
+      return this.passivationEnabled;
+   }
+
+   @Override
+   public void setForceSynchronous(boolean forceSynchronous)
+   {
+      this.forceSynchronous = forceSynchronous;
+   }
+   
+   private String getContextPath()
+   {
+      String context = this.manager.getContextName();
+      
+      if (context.isEmpty() || context.equals("/")) return "ROOT";
+      
+      return context.startsWith("/") ? context.substring(1) : context;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.web.tomcat.service.session.distributedcache.impl.CacheInvoker#invoke(org.jboss.ha.web.tomcat.service.session.distributedcache.impl.CacheInvoker.Operation)
+    */
+   @Override
+   public <R> R invoke(CacheInvoker.Operation<R> operation)
+   {
+      Exception exception = null;
+
+      for (int i = 0; i <= this.backOffIntervals.length; ++i)
+      {
+         if (this.forceSynchronous)
+         {
+            this.cache.getAdvancedCache().withFlags(Flag.FORCE_SYNCHRONOUS);
+         }
+         
+         try
+         {
+            return operation.invoke(this.cache);
+         }
+         catch (TimeoutException e)
+         {
+            exception = e;
+         }
+         catch (SuspectException e)
+         {
+            exception = e;
+         }
+         
+         if (i < this.backOffIntervals.length)
+         {
+            int delay = this.backOffIntervals[i];
+            
+            try
+            {
+               if (this.log.isTraceEnabled())
+               {
+                  this.log.trace(String.format("Cache operation failed.  Retrying in %d ms", Integer.valueOf(delay)), exception);
+               }
+               
+               Thread.sleep(delay);
+            }
+            catch (InterruptedException e)
+            {
+               Thread.currentThread().interrupt();
+            }
+         }
+      }
+      
+      throw new RuntimeException(String.format("Aborting cache operation after %d retries.", Integer.valueOf(this.backOffIntervals.length + 1)), exception);
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/FineSessionAttributeStorage.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/FineSessionAttributeStorage.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/FineSessionAttributeStorage.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.infinispan.atomic.AtomicMap;
+import org.jboss.metadata.web.jboss.ReplicationGranularity;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingAttributeGranularitySessionData;
+
+/**
+ * Handles session attribute load/store operations for {@link ReplicationGranularity#ATTRIBUTE} distributed session managers.
+ * @author Paul Ferraro
+ */
+public class FineSessionAttributeStorage implements SessionAttributeStorage<OutgoingAttributeGranularitySessionData>
+{
+   private final SessionAttributeMarshaller marshaller;
+   
+   public FineSessionAttributeStorage(SessionAttributeMarshaller marshaller)
+   {
+      this.marshaller = marshaller;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.web.tomcat.service.session.distributedcache.impl.SessionAttributeStorage#store(org.infinispan.atomic.AtomicMap, org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData)
+    */
+   @Override
+   public void store(AtomicMap<Object, Object> data, OutgoingAttributeGranularitySessionData sessionData)
+   {
+      Map<String, Object> modified = sessionData.getModifiedSessionAttributes();
+      
+      if (modified != null)
+      {
+         for (Map.Entry<String, Object> entry: modified.entrySet())
+         {
+            data.put(entry.getKey(), this.marshaller.marshal(entry.getValue()));
+         }
+      }
+      
+      Set<String> removed = sessionData.getRemovedSessionAttributes();
+      
+      if (removed != null)
+      {
+         for (String attribute: removed)
+         {
+            data.remove(attribute);
+         }
+      }
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.web.tomcat.service.session.distributedcache.impl.SessionAttributeStorage#load(org.infinispan.atomic.AtomicMap)
+    */
+   @Override
+   public Map<String, Object> load(AtomicMap<Object, Object> data) throws Exception
+   {
+      Map<String, Object> map = new HashMap<String, Object>();
+      
+      for (Map.Entry<Object, Object> entry: data.entrySet())
+      {
+         Object key = entry.getKey();
+         
+         if (key instanceof String)
+         {
+            String attribute = (String) key;
+            
+            try
+            {
+               map.put(attribute, this.marshaller.unmarshal(entry.getValue()));
+            }
+            catch (RuntimeException e)
+            {
+               throw e;
+            }
+            catch (Exception e)
+            {
+               throw new Exception("Failed to unmarshal session attribute: " + attribute, e);
+            }
+         }
+      }
+      
+      return map;
+   }
+
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/IncomingDistributableSessionDataImpl.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import java.util.Map;
+
+import org.jboss.web.tomcat.service.session.distributedcache.spi.DistributableSessionMetadata;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.IncomingDistributableSessionData;
+
+/**
+ * Base implementation of {@link DistributableSessionData}.
+ * 
+ * @author Brian Stansberry
+ */
+public class IncomingDistributableSessionDataImpl implements IncomingDistributableSessionData
+{
+   private final int version;
+   private final long timestamp;
+   private final DistributableSessionMetadata metadata;
+   private Map<String, Object> attributes;
+   
+   public IncomingDistributableSessionDataImpl(Integer version, Long timestamp, DistributableSessionMetadata metadata)
+   {
+      assert version != null : "version is null";
+      assert timestamp != null : "timestamp is null";
+      assert metadata != null : "metadata is null";
+      
+      this.version = version.intValue();
+      this.timestamp = timestamp.longValue();
+      this.metadata = metadata;
+   }
+   
+   public IncomingDistributableSessionDataImpl(Integer version, Long timestamp, 
+                                              DistributableSessionMetadata metadata,
+                                              Map<String, Object> attributes)
+   {
+      if (version == null)
+         throw new IllegalStateException("version is null");
+      if (timestamp == null)
+         throw new IllegalStateException("timestamp is null");
+      if (metadata == null)
+         throw new IllegalStateException("metadata is null");
+      if (attributes == null)
+         throw new IllegalStateException("attributes is null");
+      
+      this.version = version.intValue();
+      this.timestamp = timestamp.longValue();
+      this.metadata = metadata;
+      this.attributes = attributes;
+   }
+
+   public boolean providesSessionAttributes()
+   {
+      return this.attributes != null;
+   }
+
+   public Map<String, Object> getSessionAttributes()
+   {
+      if (this.attributes == null)
+      {
+         throw new IllegalStateException("Not configured to provide session attributes");
+      }
+      
+      return attributes;
+   }   
+
+   public void setSessionAttributes(Map<String, Object> attributes)
+   {
+      this.attributes = attributes;
+   }
+   
+   public DistributableSessionMetadata getMetadata()
+   {
+      return metadata;
+   }
+
+   public long getTimestamp()
+   {
+      return timestamp;
+   }
+
+   public int getVersion()
+   {
+      return version;
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/PassivationListener.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/PassivationListener.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/PassivationListener.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import org.infinispan.notifications.Listener;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated;
+import org.infinispan.notifications.cachelistener.event.CacheEntryActivatedEvent;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+ at Listener
+public class PassivationListener
+{
+   private final LocalDistributableSessionManager manager;
+   
+   public PassivationListener(LocalDistributableSessionManager manager)
+   {
+      this.manager = manager;
+   }
+   
+   @CacheEntryActivated
+   public void activated(CacheEntryActivatedEvent event)
+   {
+      this.manager.sessionActivated();
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshaller.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshaller.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshaller.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import java.io.IOException;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public interface SessionAttributeMarshaller
+{
+   Object marshal(Object object);
+   
+   Object unmarshal(Object object) throws IOException, ClassNotFoundException;
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeMarshallerImpl.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.security.AccessController;
+
+import org.jboss.ha.framework.server.MarshalledValueHelper;
+import org.jboss.ha.framework.server.SimpleCachableMarshalledValue;
+import org.jboss.util.loading.ContextClassLoaderSwitcher;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.LocalDistributableSessionManager;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.SessionSerializationFactory;
+
+/**
+ * @author Paul Ferraro
+ *
+ */
+public class SessionAttributeMarshallerImpl implements SessionAttributeMarshaller
+{
+   private final LocalDistributableSessionManager manager;
+   
+   public SessionAttributeMarshallerImpl(LocalDistributableSessionManager manager)
+   {
+      this.manager = manager;
+   }
+   
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.web.tomcat.service.session.distributedcache.impl.SessionAttributeMarshaller#marshal(java.lang.Object)
+    */
+   @Override
+   public Object marshal(Object value)
+   {
+      // JBAS-2921 - replaced MarshalledValue calls with SessionSerializationFactory calls
+      // to allow for switching between JBossSerialization and JavaSerialization using
+      // system property -D=session.serialization.jboss=true / false
+      // MarshalledValue mv = new MarshalledValue(value);
+      if ((value == null) || MarshalledValueHelper.isTypeExcluded(value.getClass())) return value;
+
+      if (!(value instanceof Serializable))
+      {
+         throw new IllegalArgumentException(String.format("%s does not implement %s", value, Serializable.class.getName()));
+      }
+
+      return new SimpleCachableMarshalledValue((Serializable) value, SessionSerializationFactory.getObjectStreamSource(), true);
+   }
+
+   /**
+    * {@inheritDoc}
+    * @see org.jboss.ha.web.tomcat.service.session.distributedcache.impl.SessionAttributeMarshaller#unmarshal(java.lang.Object)
+    */
+   @Override
+   public Object unmarshal(Object object) throws IOException, ClassNotFoundException
+   {
+      if ((object == null) || !(object instanceof SimpleCachableMarshalledValue)) return object;
+
+      SimpleCachableMarshalledValue value = (SimpleCachableMarshalledValue) object;
+      
+      // Need to cast since ContextClassLoaderSwitcher.NewInstance does not generically implement PrivilegedAction<ContextClassLoaderSwitcher>
+      @SuppressWarnings("unchecked")
+      ContextClassLoaderSwitcher switcher = (ContextClassLoaderSwitcher) AccessController.doPrivileged(ContextClassLoaderSwitcher.INSTANTIATOR);
+      ContextClassLoaderSwitcher.SwitchContext switchContext = switcher.getSwitchContext();
+      
+      try
+      {
+         // Swap in/out the class loader for this web app. Needed only for unmarshalling.
+         switchContext.setClassLoader(this.manager.getApplicationClassLoader());
+         
+         value.setObjectStreamSource(SessionSerializationFactory.getObjectStreamSource());
+         
+         return value.get();
+      }
+      finally
+      {
+         switchContext.reset();
+      }
+   }
+}

Added: projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorage.java
===================================================================
--- projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorage.java	                        (rev 0)
+++ projects/cluster/ha-server-cache-ispn/trunk/src/main/java/org/jboss/ha/web/tomcat/service/session/distributedcache/impl/SessionAttributeStorage.java	2010-07-20 16:19:35 UTC (rev 106928)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ha.web.tomcat.service.session.distributedcache.impl;
+
+import java.util.Map;
+
+import org.infinispan.atomic.AtomicMap;
+import org.jboss.web.tomcat.service.session.distributedcache.spi.OutgoingDistributableSessionData;
+
+/**
+ * Strategy for 
+ * @author Paul Ferraro
+ */
+public interface SessionAttributeStorage<T extends OutgoingDistributableSessionData>
+{
+   void store(AtomicMap<Object, Object> data, T sessionData);
+   
+   Map<String, Object> load(AtomicMap<Object, Object> data) throws Exception;
+}



More information about the jboss-cvs-commits mailing list