[jboss-cvs] JBossCache/src/org/jboss/cache ...
Elias Ross
genman at noderunner.net
Tue Apr 17 02:09:13 EDT 2007
User: genman
Date: 07/04/17 02:09:13
Modified: src/org/jboss/cache CacheImpl.java
Log:
JBCACHE-1005 - Clean up warnings generated from genericising of interface
Use Collections.singletonMap() for cases only a single key/value is used
Revision Changes Path
1.58 +120 -122 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.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- CacheImpl.java 28 Mar 2007 16:12:11 -0000 1.57
+++ CacheImpl.java 17 Apr 2007 06:09:13 -0000 1.58
@@ -79,7 +79,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
@@ -227,7 +226,7 @@
/**
* Cache notifier handler class.
*/
- private Notifier notifier;
+ private Notifier<K, V> notifier;
/**
* MBean interface for this cache.
@@ -254,7 +253,7 @@
*/
protected CacheImpl() throws Exception
{
- notifier = new Notifier(this);
+ notifier = new Notifier<K, V>(this);
regionManager = new RegionManager(this);
}
@@ -298,7 +297,7 @@
/**
* Returns the root node.
*/
- public NodeSPI getRoot()
+ public NodeSPI<K, V> getRoot()
{
return root;
}
@@ -567,13 +566,14 @@
}
if (notifier == null)
- notifier = new Notifier(this);
+ notifier = new Notifier<K, V>(this);
// create a new root temporarily.
- NodeSPI tempRoot = nf.createRootDataNode();
+ NodeSPI<K, V> tempRoot = nf.createRootDataNode();
// if we don't already have a root or the new (temp) root is of a different class (optimistic vs pessimistic) to
// the current root, then we use the new one. Helps preserve data between cache restarts.
- if (root == null || !root.getClass().equals(tempRoot.getClass())) root = tempRoot;
+ if (root == null || !root.getClass().equals(tempRoot.getClass()))
+ root = tempRoot;
setUseReplQueue(configuration.isUseReplQueue());
setIsolationLevel(configuration.getIsolationLevel());
@@ -668,7 +668,7 @@
|| configuration.getMultiplexerStack() != null
|| configuration.getRuntimeConfig().getMuxChannelFactory() != null)
{
- throw new CacheException("Unable to start multiplexed Channel and property ClusterConfig not set");
+ throw new RuntimeException("Unable to start multiplexed Channel and property ClusterConfig not set");
}
configuration.setClusterConfig(getDefaultProperties());
log.debug("setting cluster properties to default value");
@@ -1010,8 +1010,8 @@
*/
protected Node createSubtreeRootNode(Fqn subtree) throws CacheException
{
- NodeSPI parent = root;
- NodeSPI child = null;
+ NodeSPI<K, V> parent = root;
+ NodeSPI<K, V> child = null;
Object owner = getOwnerForLock();
Object name;
NodeFactory factory = configuration.getRuntimeConfig().getNodeFactory();
@@ -1108,7 +1108,7 @@
private void removeLocksForDeadMembers(NodeSPI<K, V> node, List deadMembers)
{
- Set deadOwners = new HashSet();
+ Set<Object> deadOwners = new HashSet<Object>();
NodeLock lock = node.getLock();
Object owner = lock.getWriterOwner();
@@ -1212,16 +1212,16 @@
*
* @param fqn name of the DataNode to retreive
*/
- public Node get(Fqn fqn) throws CacheException
+ public Node<K, V> get(Fqn fqn) throws CacheException
{
MethodCall m = MethodCallFactory.create(MethodDeclarations.getNodeMethodLocal, fqn);
- return (Node) invokeMethod(m);
+ return (Node<K, V>) invokeMethod(m);
}
/**
* Returns the raw data of the node; called externally internally.
*/
- public Node _get(Fqn fqn) throws CacheException
+ public Node<K, V> _get(Fqn fqn) throws CacheException
{
return findNode(fqn);
}
@@ -1298,7 +1298,7 @@
return get(fqn, key, true);
}
- public Object _get(Fqn fqn, Object key, boolean sendNodeEvent) throws CacheException
+ public V _get(Fqn fqn, K key, boolean sendNodeEvent) throws CacheException
{
if (log.isTraceEnabled())
{
@@ -1306,7 +1306,7 @@
append(sendNodeEvent).append("\")"));
}
if (sendNodeEvent) notifier.notifyNodeVisited(fqn, true, true);
- NodeSPI n = findNode(fqn);
+ NodeSPI<K, V> n = findNode(fqn);
if (n == null)
{
log.trace("node not found");
@@ -1805,7 +1805,7 @@
{
num++;
}
- for (NodeSPI cn : n.getChildrenDirect(true))
+ for (NodeSPI<K, V> cn : n.getChildrenDirect(true))
{
num += numLocks(cn);
}
@@ -1826,7 +1826,7 @@
private int numNodes(NodeSPI<K, V> n)
{
int count = 1;// for n
- for (NodeSPI child : n.getChildrenDirect())
+ for (NodeSPI<K, V> child : n.getChildrenDirect())
{
count += numNodes(child);
}
@@ -1852,14 +1852,13 @@
*/
public int getNumberOfAttributes(Fqn fqn)
{
- NodeSPI n = findNode(fqn);
- return numAttributes(n);
+ return numAttributes(findNode(fqn));
}
private int numAttributes(NodeSPI<K, V> n)
{
int count = 0;
- for (NodeSPI child : n.getChildrenDirect())
+ for (NodeSPI<K, V> child : n.getChildrenDirect())
{
count += numAttributes(child);
}
@@ -1879,7 +1878,7 @@
* @throws Exception
* @deprecated Note this is due to be moved to an interceptor.
*/
- public List callRemoteMethods(List mbrs, MethodCall method_call,
+ public List callRemoteMethods(List<Address> mbrs, MethodCall method_call,
boolean synchronous, boolean exclude_self, long timeout)
throws Exception
{
@@ -1899,20 +1898,20 @@
* @throws Exception
* @deprecated Note this is due to be moved to an interceptor.
*/
- public List callRemoteMethods(List mbrs, MethodCall method_call, int mode, boolean exclude_self, long timeout)
+ public List callRemoteMethods(List<Address> mbrs, MethodCall method_call, int mode, boolean exclude_self, long timeout)
throws Exception
{
RspList rsps;
Rsp rsp;
List retval;
- Vector validMembers;
+ Vector<Address> validMembers;
if (disp == null)
{
return null;
}
- validMembers = mbrs != null ? new Vector(mbrs) : new Vector(this.members);
+ validMembers = mbrs != null ? new Vector<Address>(mbrs) : new Vector<Address>(this.members);
if (exclude_self && validMembers.size() > 0)
{
Object local_addr = getLocalAddress();
@@ -1990,7 +1989,7 @@
* @throws Exception
* @deprecated Note this is due to be moved to an interceptor.
*/
- public List callRemoteMethods(List members, Method method, Object[] args,
+ public List callRemoteMethods(List<Address> members, Method method, Object[] args,
boolean synchronous, boolean exclude_self, long timeout)
throws Exception
{
@@ -2009,7 +2008,7 @@
* @throws Exception
* @deprecated Note this is due to be moved to an interceptor.
*/
- public List callRemoteMethods(Vector members, String method_name,
+ public List callRemoteMethods(Vector<Address> members, String method_name,
Class[] types, Object[] args,
boolean synchronous, boolean exclude_self, long timeout)
throws Exception
@@ -2024,22 +2023,22 @@
/* ----- These are VERSIONED callbacks to facilitate JBCACHE-843. Also see docs/design/DataVersion.txt --- */
- public void _putForExternalRead(GlobalTransaction gtx, Fqn fqn, Object key, Object value, DataVersion dv) throws CacheException
+ public void _putForExternalRead(GlobalTransaction gtx, Fqn fqn, K key, V value, DataVersion dv) throws CacheException
{
_putForExternalRead(gtx, fqn, key, value);
}
- public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops, DataVersion dv) throws CacheException
+ public void _put(GlobalTransaction tx, Fqn fqn, Map<K, V> data, boolean create_undo_ops, DataVersion dv) throws CacheException
{
_put(tx, fqn, data, create_undo_ops, false, dv);
}
- public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops, boolean erase_contents, DataVersion dv) throws CacheException
+ public void _put(GlobalTransaction tx, Fqn fqn, Map<K, V> data, boolean create_undo_ops, boolean erase_contents, DataVersion dv) throws CacheException
{
_put(tx, fqn, data, create_undo_ops, erase_contents);
}
- public Object _put(GlobalTransaction tx, Fqn fqn, Object key, Object value, boolean create_undo_ops, DataVersion dv) throws CacheException
+ public Object _put(GlobalTransaction tx, Fqn fqn, K key, V value, boolean create_undo_ops, DataVersion dv) throws CacheException
{
return _put(tx, fqn, key, value, create_undo_ops);
}
@@ -2049,7 +2048,7 @@
return _remove(tx, fqn, create_undo_ops, true);
}
- public Object _remove(GlobalTransaction tx, Fqn fqn, Object key, boolean create_undo_ops, DataVersion dv) throws CacheException
+ public Object _remove(GlobalTransaction tx, Fqn fqn, K key, boolean create_undo_ops, DataVersion dv) throws CacheException
{
return _remove(tx, fqn, key, create_undo_ops);
}
@@ -2077,7 +2076,7 @@
* @param create_undo_ops If true, undo operations will be created (default is true).
* Otherwise they will not be created (used by rollback()).
*/
- public void _put(GlobalTransaction tx, String fqn, Map data, boolean create_undo_ops)
+ public void _put(GlobalTransaction tx, String fqn, Map<K, V> data, boolean create_undo_ops)
throws CacheException
{
_put(tx, Fqn.fromString(fqn), data, create_undo_ops);
@@ -2099,7 +2098,7 @@
* @param create_undo_ops If true, undo operations will be created (default is true).
* Otherwise they will not be created (used by rollback()).
*/
- public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops)
+ public void _put(GlobalTransaction tx, Fqn fqn, Map<K, V> data, boolean create_undo_ops)
throws CacheException
{
_put(tx, fqn, data, create_undo_ops, false);
@@ -2121,7 +2120,7 @@
* @param erase_contents Clear the existing hashmap before putting the new data into it
* Otherwise they will not be created (used by rollback()).
*/
- public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops, boolean erase_contents)
+ public void _put(GlobalTransaction tx, Fqn fqn, Map<K, V> data, boolean create_undo_ops, boolean erase_contents)
throws CacheException
{
if (log.isTraceEnabled())
@@ -2129,8 +2128,8 @@
log.trace("_put(" + tx + ", \"" + fqn + "\", " + data + " undo=" + create_undo_ops + " erase=" + erase_contents + ")");
}
- NodeSPI n = findNodeCheck(tx, fqn);
- Map rawData = n.getDataDirect();
+ NodeSPI<K, V> n = findNodeCheck(tx, fqn);
+ Map<K, V> rawData = n.getDataDirect();
notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.PUT_MAP, rawData, true);
// create a compensating method call (reverting the effect of
@@ -2142,7 +2141,8 @@
tx_table.addUndoOperation(tx, undo_op);
}
- if (erase_contents) n.clearDataDirect();
+ if (erase_contents)
+ n.clearDataDirect();
n.putAllDirect(data);
notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.PUT_MAP, n.getDataDirect(), true);
@@ -2154,7 +2154,7 @@
*
* @return Previous value (if any)
*/
- public Object _put(GlobalTransaction tx, String fqn, Object key, Object value, boolean create_undo_ops)
+ public Object _put(GlobalTransaction tx, String fqn, K key, V value, boolean create_undo_ops)
throws CacheException
{
return _put(tx, Fqn.fromString(fqn), key, value, create_undo_ops);
@@ -2166,7 +2166,7 @@
*
* @return Previous value (if any)
*/
- public Object _put(GlobalTransaction tx, Fqn fqn, Object key, Object value, boolean create_undo_ops)
+ public Object _put(GlobalTransaction tx, Fqn fqn, K key, V value, boolean create_undo_ops)
throws CacheException
{
if (log.isTraceEnabled())
@@ -2180,11 +2180,11 @@
log.warn("using a map as a key in a map, did you mean to do that?");
}
- NodeSPI n = findNodeCheck(tx, fqn);
- Map rawData = n.getDataDirect();
+ NodeSPI<K, V> n = findNodeCheck(tx, fqn);
+ Map<K, V> rawData = n.getDataDirect();
notifier.notifyNodeModified(fqn, true, CacheListener.ModificationType.PUT_DATA, rawData, true);
- Object old_value = n.putDirect(key, value);
+ V old_value = n.putDirect(key, value);
// create a compensating method call (reverting the effect of
// this modification) and put it into the TX's undo list.
@@ -2203,8 +2203,7 @@
tx_table.addUndoOperation(tx, undo_op);
}
- Map newData = new HashMap();
- newData.put(key, value);
+ Map<K, V> newData = Collections.singletonMap(key, value);
notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.PUT_DATA, newData, true);
return old_value;
}
@@ -2263,8 +2262,8 @@
throws CacheException
{
- NodeSPI n;
- NodeSPI parent_node;
+ NodeSPI<K, V> n;
+ NodeSPI<K, V> parent_node;
MethodCall undo_op = null;
if (log.isTraceEnabled())
@@ -2363,7 +2362,7 @@
* @param key
* @return Object
*/
- public Object _remove(GlobalTransaction tx, String fqn, Object key, boolean create_undo_ops)
+ public V _remove(GlobalTransaction tx, String fqn, K key, boolean create_undo_ops)
throws CacheException
{
return _remove(tx, Fqn.fromString(fqn), key, create_undo_ops);
@@ -2376,11 +2375,11 @@
* @param key
* @return Object
*/
- public Object _remove(GlobalTransaction tx, Fqn fqn, Object key, boolean create_undo_ops)
+ public V _remove(GlobalTransaction tx, Fqn fqn, K key, boolean create_undo_ops)
throws CacheException
{
MethodCall undo_op = null;
- Object old_value = null;
+ V old_value = null;
if (log.isTraceEnabled())
{
@@ -2389,7 +2388,7 @@
// Find the node. This will lock it (if <tt>locking</tt> is true) and
// add the temporarily created parent nodes to the TX's node list if tx != null)
- NodeSPI n = findNode(fqn);
+ NodeSPI<K, V> n = findNode(fqn);
if (n == null)
{
log.warn("node " + fqn + " not found");
@@ -2409,8 +2408,7 @@
tx_table.addUndoOperation(tx, undo_op);
}
- Map removedData = new HashMap();
- removedData.put(key, old_value);
+ Map<K, V> removedData = Collections.singletonMap(key, old_value);
notifier.notifyNodeModified(fqn, false, CacheListener.ModificationType.REMOVE_DATA, removedData, true);
return old_value;
@@ -2474,7 +2472,7 @@
return;
}
- Map data = n.getDataDirect();
+ Map<K, V> data = n.getDataDirect();
// create a compensating method call (reverting the effect of
// this modification) and put it into the TX's undo list.
@@ -2724,7 +2722,7 @@
log.warn("Problems processing clusteredGet call", e);
}
- List results = new ArrayList(2);
+ List<Object> results = new ArrayList<Object>(2);
if (callResults != null)
{
results.add(true);
@@ -2758,7 +2756,7 @@
{
getInvocationContext().setOriginLocal(false);
- NodeSPI actualNode = findNode(fqn);
+ NodeSPI<K, V> actualNode = findNode(fqn);
Fqn backupNodeFqn = null;
if (actualNode == null && searchSubtrees)
{
@@ -2803,7 +2801,7 @@
{
NodeData data = new NodeData(BuddyManager.getActualFqn(node.getFqn()), node.getDataDirect());
list.add(data);
- for (NodeSPI childNode : node.getChildrenDirect())
+ for (NodeSPI<K, V> childNode : node.getChildrenDirect())
{
getNodeData(list, childNode);
}
@@ -2927,7 +2925,7 @@
*/
public void _releaseAllLocks(Fqn fqn)
{
- NodeSPI n;
+ NodeSPI<K, V> n;
try
{
@@ -2947,7 +2945,7 @@
private void releaseAll(NodeSPI<K, V> n)
{
- for (NodeSPI child : n.getChildrenDirect())
+ for (NodeSPI<K, V> child : n.getChildrenDirect())
{
releaseAll(child);
}
@@ -3049,7 +3047,7 @@
/**
* @return an instance of {@link Notifier} which has been configured with this instance of CacheImpl.
*/
- public Notifier getNotifier()
+ public Notifier<K, V> getNotifier()
{
return notifier;
}
@@ -3099,14 +3097,14 @@
public void _move(Fqn nodeToMoveFqn, Fqn newParentFqn)
{
// the actual move algorithm.
- NodeSPI newParent = findNode(newParentFqn);
+ NodeSPI<K, V> newParent = findNode(newParentFqn);
if (newParent == null)
{
throw new NodeNotExistsException("New parent node " + newParentFqn + " does not exist when attempting to move node!!");
}
- NodeSPI node = findNode(nodeToMoveFqn);
+ NodeSPI<K, V> node = findNode(nodeToMoveFqn);
if (node == null)
{
@@ -3798,9 +3796,9 @@
}
}
- private NodeSPI findNodeCheck(GlobalTransaction tx, Fqn fqn)
+ private NodeSPI<K, V> findNodeCheck(GlobalTransaction tx, Fqn fqn)
{
- NodeSPI n = findNode(fqn);
+ NodeSPI<K, V> n = findNode(fqn);
if (n == null)
{
String errStr = "node " + fqn + " not found (gtx=" + tx + ", caller=" + Thread.currentThread() + ")";
@@ -4117,10 +4115,10 @@
{
if (recursive)
{
- Node n = get(fqn);
+ Node<K, V> n = get(fqn);
if (n != null)
{
- evictChildren((NodeSPI) n);
+ evictChildren((NodeSPI<K, V>) n);
}
}
else
@@ -4129,10 +4127,9 @@
}
}
- private void evictChildren(NodeSPI n)
+ private void evictChildren(NodeSPI<K, V> n)
{
- Set<NodeSPI> children = n.getChildrenDirect();
- for (NodeSPI child : children)
+ for (NodeSPI<K, V> child : n.getChildrenDirect())
{
evictChildren(child);
}
@@ -4157,7 +4154,7 @@
public void putForExternalRead(Fqn fqn, K key, V value)
{
// if the node exists then this should be a no-op.
- if (peek(fqn, false) == null)
+ if (exists(fqn) == false)
{
getInvocationContext().getOptionOverrides().setFailSilently(true);
GlobalTransaction tx = getCurrentTransaction();
@@ -4166,11 +4163,12 @@
}
else
{
+ if (log.isDebugEnabled())
log.debug("putForExternalRead() called with Fqn " + fqn + " and this node already exists. This method is hence a no op.");
}
}
- public void _putForExternalRead(GlobalTransaction gtx, Fqn fqn, Object key, Object value)
+ public void _putForExternalRead(GlobalTransaction gtx, Fqn fqn, K key, V value)
{
_put(gtx, fqn, key, value, true);
}
More information about the jboss-cvs-commits
mailing list