[jboss-cvs] JBossCache/src/org/jboss/cache ...
Elias Ross
genman at noderunner.net
Tue Jan 16 20:31:07 EST 2007
User: genman
Date: 07/01/16 20:31:07
Modified: src/org/jboss/cache CacheImpl.java RPCManager.java
RegionImpl.java RegionManager.java
TreeCacheView2.java
Log:
Restrict visibility in CacheImpl of methods and members
Revision Changes Path
1.30 +172 -196 JBossCache/src/org/jboss/cache/CacheImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheImpl.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- CacheImpl.java 15 Jan 2007 18:10:55 -0000 1.29
+++ CacheImpl.java 17 Jan 2007 01:31:06 -0000 1.30
@@ -13,7 +13,6 @@
import org.jboss.cache.buddyreplication.BuddyNotInitException;
import org.jboss.cache.buddyreplication.GravitateResult;
import org.jboss.cache.config.BuddyReplicationConfig;
-import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.RuntimeConfig;
import org.jboss.cache.factories.InterceptorChainFactory;
@@ -51,7 +50,6 @@
import org.jgroups.ExtendedMessageListener;
import org.jgroups.JChannel;
import org.jgroups.Message;
-import org.jgroups.MessageListener;
import org.jgroups.View;
import org.jgroups.blocks.GroupRequest;
import org.jgroups.blocks.RpcDispatcher;
@@ -97,17 +95,30 @@
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
* @author Brian Stansberry
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Id: CacheImpl.java,v 1.29 2007/01/15 18:10:55 msurtani Exp $
+ * @version $Id: CacheImpl.java,v 1.30 2007/01/17 01:31:06 genman Exp $
* <p/>
* @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
*/
-public class CacheImpl implements Cloneable, ExtendedMembershipListener, CacheSPI
+public class CacheImpl implements CacheSPI
{
+
+ /**
+ * CacheImpl log.
+ */
+ private final static Log log = LogFactory.getLog(CacheImpl.class);
+
private static final String CREATE_MUX_CHANNEL = "createMultiplexerChannel";
+
private static final String[] MUX_TYPES = {"java.lang.String", "java.lang.String"};
- protected NodeSPI root;
+ /**
+ * Root node.
+ */
+ private NodeSPI root;
+ /**
+ * Cache's region manager.
+ */
private RegionManager regionManager = null;
/**
@@ -118,27 +129,22 @@
/**
* True if this CacheImpl is the coordinator.
*/
- protected boolean coordinator = false;
-
- /**
- * CacheImpl log.
- */
- protected final static Log log = LogFactory.getLog(CacheImpl.class);
+ private boolean coordinator = false;
/**
* List of cluster group members.
*/
- protected final Vector<Address> members = new Vector<Address>();
+ private final Vector<Address> members = new Vector<Address>();
/**
* JGroups RpcDispatcher in use.
*/
- protected RpcDispatcher disp = null;
+ private RpcDispatcher disp = null;
/**
* JGroups message listener.
*/
- protected MessageListenerAdaptor ml = new MessageListenerAdaptor();
+ private MessageListenerAdaptor ml = new MessageListenerAdaptor();
/**
* Maintains mapping of transactions (keys) and Modifications/Undo-Operations
@@ -148,72 +154,102 @@
/**
* HashMap<Thread, List<Lock>, maintains locks acquired by threads (used when no TXs are used)
*/
- private final Map<Thread, List<NodeLock>> lock_table = new ConcurrentHashMap<Thread, List<NodeLock>>();
+ private Map<Thread, List<NodeLock>> lock_table;
/**
* Set<Fqn> of Fqns of the topmost node of internal regions that should
* not included in standard state transfers.
*/
- protected Set<Fqn> internalFqns = new CopyOnWriteArraySet<Fqn>();
+ private Set<Fqn> internalFqns = new CopyOnWriteArraySet<Fqn>();
/**
* True if state was initialized during start-up.
*/
- protected volatile boolean isStateSet = false;
+ private volatile boolean isStateSet = false;
- protected String evictionInterceptorClass = "org.jboss.cache.interceptors.EvictionInterceptor";
+ /**
+ * Class name used to handle evictions.
+ */
+ private String evictionInterceptorClass = "org.jboss.cache.interceptors.EvictionInterceptor";
/**
* Marshaller if register to handle marshalling
*/
- protected Marshaller marshaller_ = null;
+ private Marshaller marshaller_ = null;
/**
* {@link #invokeMethod(MethodCall)} will dispatch to this chain of interceptors.
* In the future, this will be replaced with JBossAop. This is a first step towards refactoring JBossCache.
*/
- protected Interceptor interceptor_chain = null;
+ private Interceptor interceptor_chain = null;
/**
* Method to acquire a TransactionManager. By default we use JBossTransactionManagerLookup. Has
* to be set before calling {@link #start()}
*/
- protected TransactionManagerLookup tm_lookup = null;
+ private TransactionManagerLookup tm_lookup = null;
/**
* Used to get the Transaction associated with the current thread
*/
- protected TransactionManager tm = null;
-
- protected CacheLoaderManager cacheLoaderManager;
+ private TransactionManager tm = null;
/**
- * for legacy use *
+ * Cache loader manager.
*/
- protected CacheLoaderConfig cloaderConfig;
+ private CacheLoaderManager cacheLoaderManager;
/**
* Queue used to replicate updates when mode is repl-async
*/
- protected ReplicationQueue repl_queue = null;
+ private ReplicationQueue repl_queue = null;
/**
- * create was called.
+ * True if create() was called.
*/
- protected boolean useCreateService = false;
+ private boolean createCalled = false;
/**
* Buddy Manager
*/
- protected BuddyManager buddyManager;
+ private BuddyManager buddyManager;
/**
* State transfer manager. Do not access this field directly -- use the getter
*/
private StateTransferManager stateTransferManager;
+
+ /**
+ * Cache notifier handler class.
+ */
private Notifier notifier;
+
+ /**
+ * MBean interface for this cache.
+ */
private CacheJmxWrapperMBean cacheMBean;
+ private boolean started;
+
+ private ThreadLocal<InvocationContext> invocationContextContainer = new ThreadLocal<InvocationContext>() {
+ @Override
+ protected InvocationContext initialValue() {
+ return new InvocationContext();
+ }
+ };
+
+ private Configuration configuration = new Configuration(this);
+
+ private RPCManager rpcManager;
+
+ /**
+ * Constructs an uninitialized CacheImpl.
+ */
+ protected CacheImpl() throws Exception
+ {
+ notifier = new Notifier(this);
+ regionManager = new RegionManager(this);
+ }
public StateTransferManager getStateTransferManager()
{
@@ -229,21 +265,11 @@
this.stateTransferManager = manager;
}
- private long stateFetchTimeout;
-
- private ThreadLocal<InvocationContext> invocationContextContainer = new ThreadLocal<InvocationContext>();
-
- public boolean started;
-
public Configuration getConfiguration()
{
return configuration;
}
- private Configuration configuration = new Configuration(this);
-
- private RPCManager rpcManager;
-
public RPCManager getRpcManager()
{
return rpcManager;
@@ -255,15 +281,6 @@
}
/**
- * Constructs an uninitialized CacheImpl.
- */
- protected CacheImpl() throws Exception
- {
- notifier = new Notifier(this);
- regionManager = new RegionManager(this);
- }
-
- /**
* Returns the CacheImpl implementation version.
*/
public String getVersion()
@@ -272,8 +289,7 @@
}
/**
- * Used internally by interceptors.
- * Don't use as client, this method will go away.
+ * Returns the root node.
*/
public NodeSPI getRoot()
{
@@ -289,9 +305,10 @@
}
/**
- * Returns the members as a Vector.
+ * Returns the members as a List.
+ * This list may be concurrently modified.
*/
- public Vector<Address> getMembers()
+ public List<Address> getMembers()
{
return members;
}
@@ -317,6 +334,10 @@
*/
public Map<Thread, List<NodeLock>> getLockTable()
{
+ if (lock_table == null)
+ {
+ lock_table = new ConcurrentHashMap<Thread, List<NodeLock>>();
+ }
return lock_table;
}
@@ -329,26 +350,6 @@
}
/**
- * Returns false.
- *
- * @deprecated
- */
- public boolean getDeadlockDetection()
- {
- return false;
- }
-
- /**
- * Does nothing.
- *
- * @deprecated
- */
- public void setDeadlockDetection(boolean dt)
- {
- log.warn("Using deprecated configuration element 'DeadlockDetection'. Will be ignored.");
- }
-
- /**
* Used for testing only - sets the interceptor chain.
*/
public void setInterceptorChain(Interceptor i)
@@ -369,32 +370,9 @@
*/
public CacheLoader getCacheLoader()
{
- if (cacheLoaderManager == null) return null;
- return cacheLoaderManager.getCacheLoader();
- }
-
- /**
- * Used for PojoCache. No-op here.
- *
- * @param config
- * @throws CacheException
- */
- public void setPojoCacheConfig(Element config) throws CacheException
- {
- log.warn("setPojoCacheConfig(): You have a PojoCache config that is not used in CacheImpl.");
- }
-
- public Element getPojoCacheConfig()
- {
+ if (cacheLoaderManager == null)
return null;
- }
-
- /**
- * Returns the MessageListener in use.
- */
- public MessageListener getMessageListener()
- {
- return ml;
+ return cacheLoaderManager.getCacheLoader();
}
public String getEvictionInterceptorClass()
@@ -429,13 +407,13 @@
/**
* Returns the replication queue.
*/
- public ReplicationQueue getReplQueue()
+ public ReplicationQueue getReplicationQueue()
{
return repl_queue;
}
/**
- * @param level
+ * Sets the cache locking isolation level.
*/
private void setIsolationLevel(IsolationLevel level)
{
@@ -444,8 +422,6 @@
/**
* Sets the TransactionManagerLookup object
- *
- * @param l
*/
public void setTransactionManagerLookup(TransactionManagerLookup l)
{
@@ -453,6 +429,7 @@
}
/**
+ * Returns the transaction manager in use.
*/
public TransactionManager getTransactionManager()
{
@@ -490,7 +467,7 @@
{
if (subtree == null)
{
- throw new IllegalArgumentException("Cannot fetch partial state. Invalid subtree " + subtree);
+ throw new IllegalArgumentException("Cannot fetch partial state. Null subtree.");
}
fetchPartialState(sources, subtree.toString());
}
@@ -510,7 +487,7 @@
return;
}
- ArrayList targets = new ArrayList(Arrays.asList(sources));
+ List<Address> targets = new LinkedList(Arrays.asList(sources));
//skip *this* node as a target
targets.remove(getLocalAddress());
@@ -530,7 +507,7 @@
Address target = (Address) iter.next();
log.debug("Node " + getLocalAddress() + " fetching partial state " + stateId + " from member " + target);
isStateSet = false;
- successfulTransfer = channel.getState(target, stateId, stateFetchTimeout);
+ successfulTransfer = channel.getState(target, stateId, getStateFetchTimeout());
if (successfulTransfer)
{
try
@@ -552,6 +529,14 @@
}
/**
+ * Returns the state fetch timeout, 5 seconds past lock acquisition timeout.
+ */
+ private long getStateFetchTimeout()
+ {
+ return configuration.getLockAcquisitionTimeout() + 5000;
+ }
+
+ /**
* Lifecycle method. This is like initialize.
*
* @throws Exception
@@ -571,8 +556,8 @@
nf.init();
}
- if (notifier == null) notifier = new Notifier(this);
- stateFetchTimeout = configuration.getLockAcquisitionTimeout() + 5000;
+ if (notifier == null)
+ notifier = new Notifier(this);
// create a new root temporarily.
NodeSPI tempRoot = nf.createRootDataNode();
@@ -613,7 +598,7 @@
}
// create cache loader
- if ((configuration.getCacheLoaderConfig() != null || cloaderConfig != null) && cacheLoaderManager == null)
+ if (configuration.getCacheLoaderConfig() != null && cacheLoaderManager == null)
{
initialiseCacheLoaderManager();
}
@@ -685,7 +670,7 @@
// always use the InactiveRegionAwareRpcDispatcher - exceptions due to regions not being active should not propagate to remote
// nodes as errors. - Manik
- disp = new InactiveRegionAwareRpcDispatcher(channel, ml, this, this);
+ disp = new InactiveRegionAwareRpcDispatcher(channel, ml, new MembershipListenerAdaptor(), this);
// disp = new RpcDispatcher(channel, ml, this, this);
disp.setRequestMarshaller(getMarshaller());
@@ -702,7 +687,7 @@
getRegionManager().setDefaultInactive(configuration.isInactiveOnStartup());
- useCreateService = true;
+ createCalled = true;
}
protected boolean shouldFetchStateOnStartup()
@@ -720,7 +705,7 @@
{
// Get around the problem of standalone user forgets to call create.
- if (!useCreateService)
+ if (!createCalled)
{
create();
}
@@ -797,16 +782,15 @@
}
/**
- * No-op.
+ * Lifecycle method.
*/
public void destroy()
{
- useCreateService = false;
+ createCalled = false;
regionManager = null;
notifier = null;
}
-
/**
* Lifecycle method.
*/
@@ -824,7 +808,7 @@
disp.stop();
disp = null;
}
- if (members != null && members.size() > 0)
+ if (members != null)
{
members.clear();
}
@@ -848,7 +832,7 @@
notifier.setEvictionPolicyListener(null);
}
- useCreateService = false;
+ createCalled = false;
started = false;
}
@@ -932,7 +916,7 @@
}
}
- protected void determineCoordinator()
+ private void determineCoordinator()
{
// Synchronize on members to make the answer atomic for the current view
synchronized (members)
@@ -945,6 +929,7 @@
/**
* Returns the address of the coordinator or null if there is no
* coordinator.
+ * Waits until the membership view is updated.
*/
public Address getCoordinator()
{
@@ -1151,7 +1136,7 @@
}
private void removeLocksForDeadMembers(NodeSPI node,
- Vector deadMembers)
+ List deadMembers)
{
Set deadOwners = new HashSet();
NodeLock lock = node.getLock();
@@ -1192,7 +1177,7 @@
}
}
- private boolean isLockOwnerDead(Object owner, Vector deadMembers)
+ private boolean isLockOwnerDead(Object owner, List deadMembers)
{
boolean result = false;
if (owner != null && owner instanceof GlobalTransaction)
@@ -1208,7 +1193,7 @@
long start, stop;
isStateSet = false;
start = System.currentTimeMillis();
- boolean rc = channel.getState(null, stateFetchTimeout);
+ boolean rc = channel.getState(null, getStateFetchTimeout());
if (rc)
{
ml.waitForState();
@@ -1855,10 +1840,6 @@
private int numNodes(NodeSPI n)
{
- if (n == null)
- {
- return 0;
- }
int count = 1;// for n
for (NodeSPI child : n.getChildrenDirect())
{
@@ -1978,7 +1959,6 @@
// return null;
throw new NotSerializableException("RpcDispatcher returned a null. This is most often caused by args for " + method_call + " not being serializable.");
}
-
if (mode == GroupRequest.GET_NONE)
{
return new ArrayList();// async case
@@ -2032,13 +2012,6 @@
return callRemoteMethods(members, MethodCallFactory.create(method, args), synchronous, exclude_self, timeout);
}
- public List callRemoteMethods(Vector members, Method method, Object[] args,
- boolean synchronous, boolean exclude_self, long timeout)
- throws Exception
- {
- return callRemoteMethods(members, MethodCallFactory.create(method, args), synchronous, exclude_self, timeout);
- }
-
/**
* @param members
* @param method_name
@@ -3049,13 +3022,7 @@
public InvocationContext getInvocationContext()
{
- InvocationContext ctx = invocationContextContainer.get();
- if (ctx == null)
- {
- ctx = new InvocationContext();
- invocationContextContainer.set(ctx);
- }
- return ctx;
+ return invocationContextContainer.get();
}
public void setInvocationContext(InvocationContext ctx)
@@ -3487,6 +3454,8 @@
/*----------------------- MembershipListener ------------------------*/
+ protected class MembershipListenerAdaptor implements ExtendedMembershipListener {
+
public void viewAccepted(View new_view)
{
Vector new_mbrs = new_view.getMembers();
@@ -3520,7 +3489,6 @@
}
}
-
/**
* Called when a member is suspected.
*/
@@ -3562,6 +3530,8 @@
}
}
+ }
+
/*------------------- End of MembershipListener ----------------------*/
/* ------------------------------ Private methods --------------------------- */
@@ -4107,4 +4077,10 @@
{
return started;
}
+
+ protected void setMessageListener(MessageListenerAdaptor ml)
+ {
+ this.ml = ml;
+ }
+
}
1.7 +1 -1 JBossCache/src/org/jboss/cache/RPCManager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RPCManager.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/RPCManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- RPCManager.java 2 Jan 2007 17:15:29 -0000 1.6
+++ RPCManager.java 17 Jan 2007 01:31:06 -0000 1.7
@@ -70,6 +70,6 @@
*/
public ReplicationQueue getReplicationQueue()
{
- return c.getReplQueue();
+ return c.getReplicationQueue();
}
}
1.18 +17 -17 JBossCache/src/org/jboss/cache/RegionImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RegionImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/RegionImpl.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- RegionImpl.java 4 Jan 2007 16:46:45 -0000 1.17
+++ RegionImpl.java 17 Jan 2007 01:31:06 -0000 1.18
@@ -6,6 +6,10 @@
*/
package org.jboss.cache;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.config.EvictionRegionConfig;
@@ -15,10 +19,6 @@
import org.jboss.cache.eviction.NodeEventType;
import org.jboss.cache.util.Util;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
/**
* Default implementation of a {@link Region}
*
@@ -228,7 +228,7 @@
{
if (log.isTraceEnabled()) log.trace("Instantiating " + className);
EvictionPolicy ep = (EvictionPolicy) Util.loadClass(className).newInstance();
- ep.configure(regionManager.cache);
+ ep.configure(regionManager.getCache());
return ep;
}
catch (Exception e)
1.23 +10 -4 JBossCache/src/org/jboss/cache/RegionManager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RegionManager.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/RegionManager.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- RegionManager.java 15 Jan 2007 18:10:55 -0000 1.22
+++ RegionManager.java 17 Jan 2007 01:31:06 -0000 1.23
@@ -39,10 +39,10 @@
/**
* A registry of regions that have been defined.
*/
- Map<Fqn, Region> regionsRegistry = new ConcurrentHashMap<Fqn, Region>();
- boolean defaultInactive;
+ private Map<Fqn, Region> regionsRegistry = new ConcurrentHashMap<Fqn, Region>();
+ private boolean defaultInactive;
private Log log = LogFactory.getLog(RegionManager.class);
- CacheImpl cache;
+ private CacheImpl cache;
private boolean usingEvictions;
private EvictionConfig evictionConfig;
private EvictionTimerTask evictionTimerTask = new EvictionTimerTask();
@@ -377,7 +377,7 @@
}
Address[] groupMembers = null;
- Vector<Address> members = cache.getMembers();
+ List<Address> members = cache.getMembers();
synchronized (members)
{
groupMembers = members.toArray(new Address[members.size()]);
@@ -799,4 +799,10 @@
{
return "RegionManager " + dumpRegions();
}
+
+ public CacheImpl getCache()
+ {
+ return this.cache;
+ }
+
}
1.22 +10 -9 JBossCache/src/org/jboss/cache/TreeCacheView2.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheView2.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheView2.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- TreeCacheView2.java 11 Jan 2007 13:49:07 -0000 1.21
+++ TreeCacheView2.java 17 Jan 2007 01:31:06 -0000 1.22
@@ -36,12 +36,13 @@
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
-import java.util.Vector;
+import java.util.List;
/**
@@ -52,7 +53,7 @@
* The view itself caches only the nodes, but doesn't cache any of the data (HashMap) associated with it. When
* data needs to be displayed, the underlying cache will be accessed directly.
*
- * @version $Revision: 1.21 $
+ * @version $Revision: 1.22 $
*/
public class TreeCacheView2
{
@@ -544,11 +545,11 @@
{
public void run()
{
- Vector mbrship;
+ List mbrship;
if (new_view != null && (mbrship = new_view.getMembers()) != null)
{
_put(SEP, "members", mbrship);
- _put(SEP, "coordinator", mbrship.firstElement());
+ _put(SEP, "coordinator", mbrship.get(0));
}
}
}.start();
@@ -570,14 +571,14 @@
*/
void init()
{
- Vector mbrship = null;
+ List mbrship = null;
// addGuiNode(SEP);
- mbrship = getMembers() != null ? (Vector) getMembers().clone() : null;
+ mbrship = getMembers();
if (mbrship != null && mbrship.size() > 0)
{
_put(SEP, "members", mbrship);
- _put(SEP, "coordinator", mbrship.firstElement());
+ _put(SEP, "coordinator", mbrship.get(0));
}
}
@@ -895,11 +896,11 @@
}
}
- Vector getMembers()
+ List getMembers()
{
try
{
- return cache_.getMembers();
+ return new ArrayList(cache_.getMembers());
}
catch (Throwable t)
{
More information about the jboss-cvs-commits
mailing list