[infinispan-commits] Infinispan SVN: r1691 - in trunk/core/src: main/java/org/infinispan/remoting and 2 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Apr 15 07:14:34 EDT 2010


Author: galder.zamarreno at jboss.com
Date: 2010-04-15 07:14:33 -0400 (Thu, 15 Apr 2010)
New Revision: 1691

Modified:
   trunk/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java
   trunk/core/src/main/java/org/infinispan/remoting/InboundInvocationHandlerImpl.java
   trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java
   trunk/core/src/test/java/org/infinispan/statetransfer/StateTransferFunctionalTest.java
Log:
[ISPN-399] (State transfer requests for non existing caches should not throw exception) Fixed.

Modified: trunk/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java	2010-04-15 11:02:52 UTC (rev 1690)
+++ trunk/core/src/main/java/org/infinispan/marshall/jboss/JBossMarshaller.java	2010-04-15 11:14:33 UTC (rev 1691)
@@ -199,7 +199,7 @@
 
    public void finishObjectInput(ObjectInput oi) {
       try {
-         ((Unmarshaller) oi).finish();
+         if (oi != null) ((Unmarshaller) oi).finish();
       } catch (IOException e) {
       }
    }

Modified: trunk/core/src/main/java/org/infinispan/remoting/InboundInvocationHandlerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/remoting/InboundInvocationHandlerImpl.java	2010-04-15 11:02:52 UTC (rev 1690)
+++ trunk/core/src/main/java/org/infinispan/remoting/InboundInvocationHandlerImpl.java	2010-04-15 11:14:33 UTC (rev 1691)
@@ -8,6 +8,8 @@
 import org.infinispan.factories.annotations.Inject;
 import org.infinispan.factories.scopes.Scope;
 import org.infinispan.factories.scopes.Scopes;
+import org.infinispan.manager.CacheManager;
+import org.infinispan.marshall.Marshaller;
 import org.infinispan.remoting.responses.ExceptionResponse;
 import org.infinispan.remoting.responses.RequestIgnoredResponse;
 import org.infinispan.remoting.responses.Response;
@@ -18,6 +20,7 @@
 import org.infinispan.util.logging.LogFactory;
 
 import java.io.InputStream;
+import java.io.ObjectOutput;
 import java.io.OutputStream;
 
 /**
@@ -30,10 +33,12 @@
 public class InboundInvocationHandlerImpl implements InboundInvocationHandler {
    GlobalComponentRegistry gcr;
    private static final Log log = LogFactory.getLog(InboundInvocationHandlerImpl.class);
+   private Marshaller marshaller;
 
    @Inject
-   public void inject(GlobalComponentRegistry gcr) {
+   public void inject(GlobalComponentRegistry gcr, Marshaller marshaller) {
       this.gcr = gcr;
+      this.marshaller = marshaller;
    }
 
    public Response handle(CacheRpcCommand cmd) throws Throwable {
@@ -74,17 +79,27 @@
    }
 
    public void generateState(String cacheName, OutputStream o) throws StateTransferException {
-      getStateTransferManager(cacheName).generateState(o);
+      StateTransferManager manager = getStateTransferManager(cacheName);
+      if (manager == null) {
+         ObjectOutput oo = null;
+         try {
+            oo = marshaller.startObjectOutput(o, false);
+            // Not started yet, so send started flag false
+            marshaller.objectToObjectStream(false, oo);
+         } catch (Exception e) {
+            throw new StateTransferException(e);
+         } finally {
+            marshaller.finishObjectOutput(oo);
+         }
+      } else {
+         manager.generateState(o);
+      }
    }
 
    private StateTransferManager getStateTransferManager(String cacheName) throws StateTransferException {
       ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheName);
-      if (cr == null) {
-         String msg = "Cache named " + cacheName + " does not exist on this cache manager!";
-         log.info(msg);
-         throw new StateTransferException(msg);
-      }
-
+      if (cr == null)
+         return null;
       return cr.getComponent(StateTransferManager.class);
    }
 }

Modified: trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java	2010-04-15 11:02:52 UTC (rev 1690)
+++ trunk/core/src/main/java/org/infinispan/statetransfer/StateTransferManagerImpl.java	2010-04-15 11:14:33 UTC (rev 1691)
@@ -145,6 +145,9 @@
                && (txLogActivated = transactionLog.activate());
          if (log.isDebugEnabled()) log.debug("Generating state.  Can provide? {0}", canProvideState);
          oo = marshaller.startObjectOutput(out, false);
+
+         // If we can generate state, we've started up 
+         marshaller.objectToObjectStream(true, oo);
          marshaller.objectToObjectStream(canProvideState, oo);
 
          if (canProvideState) {
@@ -300,19 +303,23 @@
       ObjectInput oi = null;
       try {
          oi = marshaller.startObjectInput(in, false);
-         boolean canProvideState = (Boolean) marshaller.objectFromObjectStream(oi);
-         if (canProvideState) {
-            assertDelimited(oi);
-            if (transientState) applyInMemoryState(oi);
-            assertDelimited(oi);
-            if (persistentState) applyPersistentState(oi);
-            assertDelimited(oi);
-            applyTransactionLog(oi);
-            if (log.isDebugEnabled()) log.debug("State applied, closing object stream");
-         } else {
-            String msg = "Provider cannot provide state!";
-            if (log.isDebugEnabled()) log.debug(msg);
-            throw new StateTransferException(msg);
+         // Started flag controls whether remote cache was started and hence provided state
+         boolean started = (Boolean) marshaller.objectFromObjectStream(oi);
+         if (started) {
+            boolean canProvideState = (Boolean) marshaller.objectFromObjectStream(oi);
+            if (canProvideState) {
+               assertDelimited(oi);
+               if (transientState) applyInMemoryState(oi);
+               assertDelimited(oi);
+               if (persistentState) applyPersistentState(oi);
+               assertDelimited(oi);
+               applyTransactionLog(oi);
+               if (log.isDebugEnabled()) log.debug("State applied, closing object stream");
+            } else {
+               String msg = "Provider cannot provide state!";
+               if (log.isDebugEnabled()) log.debug(msg);
+               throw new StateTransferException(msg);
+            }
          }
       } catch (StateTransferException ste) {
          throw ste;

Modified: trunk/core/src/test/java/org/infinispan/statetransfer/StateTransferFunctionalTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/statetransfer/StateTransferFunctionalTest.java	2010-04-15 11:02:52 UTC (rev 1690)
+++ trunk/core/src/test/java/org/infinispan/statetransfer/StateTransferFunctionalTest.java	2010-04-15 11:14:33 UTC (rev 1691)
@@ -152,6 +152,24 @@
       log.info("testInitialStateTransfer end - " + testCount);
    }
 
+   public void testInitialStateTransferCacheNotPresent() throws Exception {
+      testCount++;
+      log.info("testInitialStateTransferCacheNotPresent start - " + testCount);
+      Cache<Object, Object> cache1, cache2;
+      CacheManager cacheManager1 = createCacheManager();
+      cache1 = cacheManager1.getCache(cacheName);
+      writeInitialData(cache1);
+      cache2 = createCacheManager().getCache(cacheName);
+
+      // Pause to give caches time to see each other
+      TestingUtil.blockUntilViewsReceived(60000, cache1, cache2);
+      verifyInitialData(cache2);
+
+      cacheManager1.defineConfiguration("otherCache", config.clone());
+      cacheManager1.getCache("otherCache");
+      log.info("testInitialStateTransferCacheNotPresent end - " + testCount);
+   }
+
    public void testConcurrentStateTransfer() throws Exception {
       testCount++;
       log.info("testConcurrentStateTransfer start - " + testCount);



More information about the infinispan-commits mailing list