[jbosscache-commits] JBoss Cache SVN: r6945 - in core/branches/flat/src/main/java/org/jboss/starobrno: statetransfer and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Oct 14 13:49:31 EDT 2008


Author: mircea.markus
Date: 2008-10-14 13:49:31 -0400 (Tue, 14 Oct 2008)
New Revision: 6945

Added:
   core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/
   core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/DefaultStateTransferManager.java
   core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/StateTransferManager.java
Log:


Copied: core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/DefaultStateTransferManager.java (from rev 6897, core/branches/flat/src/main/java/org/jboss/cache/statetransfer/DefaultStateTransferManager.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/DefaultStateTransferManager.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/DefaultStateTransferManager.java	2008-10-14 17:49:31 UTC (rev 6945)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 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.starobrno.statetransfer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.RegionManager;
+import org.jboss.cache.statetransfer.StateTransferIntegrator;
+import org.jboss.cache.statetransfer.StateTransferGenerator;
+import org.jboss.cache.loader.CacheLoaderManager;
+import org.jboss.cache.marshall.Marshaller;
+import org.jboss.starobrno.marshall.NodeData;
+import org.jboss.starobrno.marshall.NodeDataMarker;
+import org.jboss.starobrno.CacheSPI;
+import org.jboss.starobrno.statetransfer.StateTransferManager;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.Start;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * The default state transfer manager to be used when using MVCC locking.
+ */
+public class DefaultStateTransferManager implements StateTransferManager
+{
+   protected final static Log log = LogFactory.getLog(DefaultStateTransferManager.class);
+   protected static final boolean trace = log.isTraceEnabled();
+
+   public static final NodeData STREAMING_DELIMITER_NODE = new NodeDataMarker();
+
+   public static final String PARTIAL_STATE_DELIMITER = "_PARTIAL_STATE_DELIMITER";
+
+   protected CacheSPI cache;
+   protected Marshaller marshaller;
+   protected RegionManager regionManager;
+   protected Configuration configuration;
+   private CacheLoaderManager cacheLoaderManager;
+   boolean fetchTransientState;
+   boolean fetchPersistentState;
+   protected long stateRetrievalTimeout;
+   protected StateTransferIntegrator integrator;
+   protected StateTransferGenerator generator;
+
+
+   @Inject
+   public void injectDependencies()
+   {
+      this.cache = cache;
+      this.regionManager = regionManager;
+      this.marshaller = marshaller;
+      this.configuration = configuration;
+      this.cacheLoaderManager = cacheLoaderManager;
+      this.integrator = integrator;
+      this.generator = generator;
+   }
+
+   @Start(priority = 14)
+   public void start()
+   {
+//      fetchTransientState = configuration.isFetchInMemoryState();
+//      fetchPersistentState = cacheLoaderManager != null && cacheLoaderManager.isFetchPersistentState();
+//      stateRetrievalTimeout = configuration.getStateRetrievalTimeout();
+   }
+
+   public void getState(ObjectOutputStream out, Fqn fqn, long timeout, boolean force, boolean suppressErrors) throws Exception
+   {
+      throw new UnsupportedOperationException("Implement me properly!");
+      /*
+
+      // can't give state for regions currently being activated/inactivated
+      boolean canProvideState = (!regionManager.isInactive(fqn) && cache.peek(fqn, false) != null);
+      if (trace) log.trace("Can provide state? " + canProvideState);
+      if (canProvideState && (fetchPersistentState || fetchTransientState))
+      {
+         marshaller.objectToObjectStream(true, out);
+         long startTime = System.currentTimeMillis();
+         InternalNode subtreeRoot = fqn.isRoot() ? cache.getRoot().getDelegationTarget() : cache.getNode(fqn).getDelegationTarget();
+
+         // we don't need READ locks for MVCC based state transfer!
+         if (log.isDebugEnabled())
+            log.debug("Generating in-memory (transient) state for subtree " + fqn);
+
+         generator.generateState(out, subtreeRoot, fetchTransientState, fetchPersistentState, suppressErrors);
+
+         if (log.isDebugEnabled())
+            log.debug("Successfully generated state in " + (System.currentTimeMillis() - startTime) + " msec");
+      }
+      else
+      {
+         marshaller.objectToObjectStream(false, out);
+         Exception e = null;
+         if (!canProvideState)
+         {
+            String exceptionMessage = "Cache instance at " + cache.getLocalAddress() + " cannot provide state for fqn " + fqn + ".";
+
+            if (regionManager.isInactive(fqn))
+            {
+               exceptionMessage += " Region for fqn " + fqn + " is inactive.";
+               e = new InactiveRegionException(exceptionMessage);
+            }
+            // this is not really an exception.  Just provide empty state. The exception is just a signal.  Yes, lousy.  - JBCACHE-1349
+            if (cache.peek(fqn, false, false) == null)
+            {
+               e = new RegionEmptyException();
+            }
+         }
+         if (!fetchPersistentState && !fetchTransientState)
+         {
+            e = new CacheException("Cache instance at " + cache.getLocalAddress() + " is not configured to provide state");
+         }
+         marshaller.objectToObjectStream(e, out);
+         if (e != null) throw e;
+      }
+      */
+   }
+
+   public void setState(ObjectInputStream in, Fqn targetRoot) throws Exception
+   {
+      throw new UnsupportedOperationException("fix me!");
+      /*
+      cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
+      NodeSPI target = cache.getNode(targetRoot);
+      if (target == null)
+      {
+         // Create the integration root, but do not replicate
+         cache.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+
+         //needed for BR state transfers
+         cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
+         cache.put(targetRoot, null);
+         cache.getInvocationContext().getOptionOverrides().setSkipCacheStatusCheck(true);
+         target = cache.getNode(targetRoot);
+      }
+      Object o = marshaller.objectFromObjectStream(in);
+      Boolean hasState = (Boolean) o;
+      if (hasState)
+      {
+         setState(in, target);
+      }
+      else
+      {
+         throw new CacheException("Cache instance at " + cache.getLocalAddress()
+               + " cannot integrate state since state provider could not provide state due to " + marshaller.objectFromObjectStream(in));
+      }
+      */
+   }
+
+   /**
+    * Set the portion of the cache rooted in <code>targetRoot</code>
+    * to match the given state. Updates the contents of <code>targetRoot</code>
+    * to reflect those in <code>new_state</code>.
+    * <p/>
+    * <strong>NOTE:</strong> This method performs no locking of nodes; it
+    * is up to the caller to lock <code>targetRoot</code> before calling
+    * this method.
+    *
+    * @param state      a serialized byte[][] array where element 0 is the
+    *                   transient state (or null) , and element 1 is the
+    *                   persistent state (or null)
+    * @param targetRoot node into which the state should be integrated
+    */
+   protected void setState(ObjectInputStream state, NodeSPI targetRoot) throws Exception
+   {
+      long startTime = System.currentTimeMillis();
+      /*
+       * Vladimir/Manik/Brian (Dec 7,2006)
+       *
+       * integrator.integrateState(in,targetRoot, cl) will call cache.put for each
+       * node read from stream. Having option override below allows nodes read
+       * to be directly stored into a tree since we bypass interceptor chain.
+       *
+       */
+      if (log.isDebugEnabled())
+         log.debug("starting state integration at node " + targetRoot + ".  Fetch Persistent State = " + fetchPersistentState);
+      integrator.integrateState(state, targetRoot.getDelegationTarget(), targetRoot.getFqn(), fetchPersistentState);
+
+      if (log.isDebugEnabled())
+         log.debug("successfully integrated state in " + (System.currentTimeMillis() - startTime) + " msec");
+   }
+}


Property changes on: core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/DefaultStateTransferManager.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Copied: core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/StateTransferManager.java (from rev 6897, core/branches/flat/src/main/java/org/jboss/cache/statetransfer/StateTransferManager.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/StateTransferManager.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/statetransfer/StateTransferManager.java	2008-10-14 17:49:31 UTC (rev 6945)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 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.starobrno.statetransfer;
+
+import org.jboss.cache.Fqn;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+/**
+ * This interface handles requests to generate or integrate state from neighbouring caches in a cluster.
+ * <p/>
+ * This has existed prior to 3.0.0 as a concrete class.  An interface was introduced in 3.0.0 to provide more flexibility
+ * in state transfer implementations.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik at jboss.org">manik at jboss.org</a>)
+ * @since 3.0
+ */
+public interface StateTransferManager
+{
+   /**
+    * Writes the state for the portion of the tree named by <code>fqn</code> to
+    * the provided OutputStream.
+    * <p/>
+    * <p/>
+    *
+    * @param out            stream to write state to
+    * @param fqn            Fqn indicating the uppermost node in the
+    *                       portion of the tree whose state should be returned.
+    * @param timeout        max number of millis this method should wait to acquire
+    *                       any locks, if necessary, on the nodes being transferred
+    * @param force          if locks are needed and cannot be acquired after
+    *                       <code>timeout</code> millis, should the lock acquisition
+    *                       be forced, and any existing transactions holding locks
+    *                       on the nodes be rolled back?
+    * @param suppressErrors if true, all exceptions are logged but not propagated.
+    * @throws Exception in event of error
+    */
+   void getState(ObjectOutputStream out, Fqn fqn, long timeout, boolean force, boolean suppressErrors) throws Exception;
+
+   /**
+    * Set the portion of the cache rooted in <code>targetRoot</code>
+    * to match the given state. Updates the contents of <code>targetRoot</code>
+    * to reflect those in <code>new_state</code>.
+    * <p/>
+    * <strong>NOTE:</strong> This method performs no locking of nodes; it
+    * is up to the caller to lock <code>targetRoot</code> before calling
+    * this method.
+    * <p/>
+    * This method will use any {@link ClassLoader} needed as defined by the active {@link org.jboss.cache.Region}
+    * in the {@link org.jboss.cache.RegionManager}, pertaining to the targetRoot passed in.
+    *
+    * @param in         an input stream containing the state
+    * @param targetRoot fqn of the node into which the state should be integrated
+    * @throws Exception In event of error
+    */
+   void setState(ObjectInputStream in, Fqn targetRoot) throws Exception;
+
+}




More information about the jbosscache-commits mailing list