[jbosscache-commits] JBoss Cache SVN: r5164 - in core/trunk/src/main/java/org/jboss/cache: buddyreplication and 1 other directory.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Jan 18 09:18:58 EST 2008


Author: manik.surtani at jboss.com
Date: 2008-01-18 09:18:58 -0500 (Fri, 18 Jan 2008)
New Revision: 5164

Modified:
   core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
   core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
   core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
Log:
Optimised a few things

Modified: core/trunk/src/main/java/org/jboss/cache/CacheImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2008-01-18 14:18:18 UTC (rev 5163)
+++ core/trunk/src/main/java/org/jboss/cache/CacheImpl.java	2008-01-18 14:18:58 UTC (rev 5164)
@@ -412,6 +412,9 @@
       }
 
       // these 2 components need to be started manually since they can only be started after ALL other components have started.
+      // i.e., rpcManager's start() method may do state transfers.  State transfers will rely on the interceptor chain being started.
+      // the interceptor chain cannot start until the rpcManager is started.  And similarly, the buddyManager relies on the
+      // rpcManager being started.
       if (rpcManager != null) rpcManager.start();
       if (buddyManager != null) buddyManager.init();
 

Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java	2008-01-18 14:18:18 UTC (rev 5163)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java	2008-01-18 14:18:58 UTC (rev 5164)
@@ -8,14 +8,12 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.buddyreplication.BuddyManager;
 import org.jboss.cache.config.Configuration;
 import org.jboss.cache.config.RuntimeConfig;
 import org.jboss.cache.factories.annotations.ComponentName;
 import org.jboss.cache.factories.annotations.Inject;
 import org.jboss.cache.factories.annotations.Stop;
 import org.jboss.cache.invocation.RemoteCacheInvocationDelegate;
-import org.jboss.cache.loader.CacheLoaderManager;
 import org.jboss.cache.lock.LockUtil;
 import org.jboss.cache.lock.NodeLock;
 import org.jboss.cache.lock.TimeoutException;
@@ -84,27 +82,24 @@
    private Notifier notifier;
    private CacheSPI spi;
    private boolean trace = log.isTraceEnabled();
-   private BuddyManager buddyManager;
    private RemoteCacheInvocationDelegate remoteDelegate;
-   private CacheLoaderManager cacheLoaderManager;
    private Marshaller marshaller;
    private TransactionManager txManager;
    private TransactionTable txTable;
 
+   private boolean isUsingBuddyReplication;
 
    @Inject
    private void setupDependencies(CacheMessageListener messageListener, Configuration configuration,
-                                  Notifier notifier, CacheSPI spi, BuddyManager buddyManager, Marshaller marshaller,
+                                  Notifier notifier, CacheSPI spi, Marshaller marshaller,
                                   @ComponentName("remoteDelegate")RemoteCacheInvocationDelegate remoteDelegate,
-                                  CacheLoaderManager cacheLoaderManager, TransactionTable txTable, TransactionManager txManager)
+                                  TransactionTable txTable, TransactionManager txManager)
    {
       this.messageListener = messageListener;
       this.configuration = configuration;
       this.notifier = notifier;
       this.spi = spi;
-      this.buddyManager = buddyManager;
       this.remoteDelegate = remoteDelegate;
-      this.cacheLoaderManager = cacheLoaderManager;
       this.marshaller = marshaller;
       this.txManager = txManager;
       this.txTable = txTable;
@@ -112,7 +107,7 @@
 
    // ------------ START: Lifecycle methods ------------
 
-   // This is called manually, rather than by using @Start, since it needs to be called AFTER all other components are started.
+   // TODO: This needs to be started manually for now, rather than by @Start.  See CacheImpl.internalStart()
 
    public void start()
    {
@@ -172,6 +167,8 @@
             }
             if (log.isInfoEnabled()) log.info("Cache local address is " + getLocalAddress());
       }
+
+      isUsingBuddyReplication = configuration.getBuddyReplicationConfig() != null && configuration.getBuddyReplicationConfig().isEnabled();
    }
 
    public void disconnect()
@@ -222,8 +219,8 @@
     */
    private boolean shouldFetchStateOnStartup()
    {
-      boolean loaderFetch = cacheLoaderManager != null && cacheLoaderManager.isFetchPersistentState();
-      return !configuration.isInactiveOnStartup() && buddyManager == null && (configuration.isFetchInMemoryState() || loaderFetch);
+      boolean loaderFetch = configuration.getCacheLoaderConfig() != null && configuration.getCacheLoaderConfig().isFetchPersistentState();
+      return !configuration.isInactiveOnStartup() && !isUsingBuddyReplication && (configuration.isFetchInMemoryState() || loaderFetch);
    }
 
    private void initialiseChannelAndRpcDispatcher() throws CacheException
@@ -409,8 +406,8 @@
             throw new TimeoutException("State retrieval timed out waiting for flush unblock.");
       }
       rsps = responseFilter == null
-            ? disp.callRemoteMethods(validMembers, methodCall, modeToUse, timeout, buddyManager != null && buddyManager.isEnabled())
-            : disp.callRemoteMethods(validMembers, methodCall, modeToUse, timeout, buddyManager != null && buddyManager.isEnabled(), false, responseFilter);
+            ? disp.callRemoteMethods(validMembers, methodCall, modeToUse, timeout, isUsingBuddyReplication)
+            : disp.callRemoteMethods(validMembers, methodCall, modeToUse, timeout, isUsingBuddyReplication, false, responseFilter);
 
       // a null response is 99% likely to be due to a marshalling problem - we throw a NSE, this needs to be changed when
       // JGroups supports http://jira.jboss.com/jira/browse/JGRP-193

Modified: core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java	2008-01-18 14:18:18 UTC (rev 5163)
+++ core/trunk/src/main/java/org/jboss/cache/buddyreplication/BuddyManager.java	2008-01-18 14:18:58 UTC (rev 5164)
@@ -32,6 +32,7 @@
 import org.jboss.cache.statetransfer.StateTransferManager;
 import org.jboss.cache.util.ExposedByteArrayOutputStream;
 import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+import org.jboss.cache.util.reflect.ReflectionUtil;
 import org.jboss.util.stream.MarshalledValueInputStream;
 import org.jboss.util.stream.MarshalledValueOutputStream;
 import org.jgroups.Address;
@@ -240,12 +241,28 @@
       }
    }
 
+   // TODO: This needs to be started manually for now, rather than by @Start.  See CacheImpl.internalStart()  
    public void init() throws CacheException
    {
       log.debug("Starting BuddyManager");
       buddyGroup = new BuddyGroup();
       buddyGroup.setDataOwner(cache.getLocalAddress());
-      buddyGroup.setGroupName(getGroupNameFromAddress(cache.getLocalAddress()));
+      Address localAddress = rpcManager.getLocalAddress();
+      if (localAddress == null)
+      {
+         if (configuration.getCacheMode() == Configuration.CacheMode.LOCAL)
+         {
+            log.warn("Buddy replication is enabled but cache mode is LOCAL - not starting BuddyManager!");
+            ReflectionUtil.setValue(config, "accessible", true);
+            config.setEnabled(false);
+            return;
+         }
+         else
+         {
+            throw new CacheException("Unable to initialize BuddyManager - the RPCManager has not connected to the cluster and local Address is null!");
+         }
+      }
+      buddyGroup.setGroupName(getGroupNameFromAddress(localAddress));
 
       if (config.getBuddyPoolName() != null)
       {




More information about the jbosscache-commits mailing list