JBoss Cache SVN: r7616 - in core/branches/flat/src: main/java/org/horizon/lock and 13 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-30 11:48:58 -0500 (Fri, 30 Jan 2009)
New Revision: 7616
Removed:
core/branches/flat/src/main/java/org/horizon/marshall/NodeData.java
core/branches/flat/src/main/java/org/horizon/marshall/NodeDataExceptionMarker.java
core/branches/flat/src/main/java/org/horizon/marshall/NodeDataMarker.java
core/branches/flat/src/main/java/org/horizon/util/concurrent/SelfInitializingConcurrentHashMap.java
Modified:
core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheLoader.java
core/branches/flat/src/main/java/org/horizon/loader/Modification.java
core/branches/flat/src/main/java/org/horizon/loader/SingletonStoreCacheLoader.java
core/branches/flat/src/main/java/org/horizon/lock/LockManager.java
core/branches/flat/src/main/java/org/horizon/marshall/EntryData.java
core/branches/flat/src/main/java/org/horizon/marshall/EntryDataExceptionMarker.java
core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifier.java
core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifierImpl.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryActivated.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryCreated.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryEvicted.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryInvalidated.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryLoaded.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryModified.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryPassivated.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryRemoved.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryVisited.java
core/branches/flat/src/main/java/org/horizon/notifications/annotation/Listener.java
core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryActivatedEvent.java
core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryCreatedEvent.java
core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryEvent.java
core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryEvictedEvent.java
core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryLoadedEvent.java
core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryModifiedEvent.java
core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryPassivatedEvent.java
core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryRemovedEvent.java
core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryVisitedEvent.java
core/branches/flat/src/main/java/org/horizon/notifications/event/Event.java
core/branches/flat/src/main/java/org/horizon/statetransfer/DefaultStateTransferManager.java
core/branches/flat/src/main/java/org/horizon/transaction/GlobalTransaction.java
core/branches/flat/src/main/resources/cache-jdbc.properties
core/branches/flat/src/main/resources/config-samples/all.xml
core/branches/flat/src/test/java/org/horizon/api/mvcc/LockAssert.java
core/branches/flat/src/test/java/org/horizon/api/mvcc/LockTestBase.java
core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java
core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java
core/branches/flat/src/test/java/org/horizon/replication/SyncCacheListenerTest.java
core/branches/flat/src/test/resources/cache-jdbc.properties
Log:
Javadocs, comments, variable names
Modified: core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheLoader.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheLoader.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheLoader.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -77,7 +77,7 @@
}
if (objectFromStream instanceof EntryDataExceptionMarker) {
EntryDataExceptionMarker ndem = (EntryDataExceptionMarker) objectFromStream;
- throw new CacheException("State provider cacheloader at node " + ndem.getCacheNodeIdentity()
+ throw new CacheException("State provider cacheloader at node " + ndem.getKey()
+ " threw exception during loadState (see Caused by)", ndem.getCause());
}
Modified: core/branches/flat/src/main/java/org/horizon/loader/Modification.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/Modification.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/loader/Modification.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -26,11 +26,8 @@
/**
- * Represents a modification in the cache. Contains the nature of the modification (e.g. PUT, REMOVE), the fqn of the
- * node, the new value and the previous value. A list of modifications will be sent to all nodes in a cluster when a
- * transaction has been committed (PREPARE phase). A Modification is also used to roll back changes, e.g. since we know
- * the previous value, we can reconstruct the previous state by applying the changes in a modification listin reverse
- * order.
+ * Represents a modification in the cache. Contains the nature of the modification (e.g. PUT, REMOVE), the entry's key,
+ * the new value and the previous value.
*
* @author <a href="mailto:bela@jboss.org">Bela Ban</a> Apr 12, 2003
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/loader/SingletonStoreCacheLoader.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/SingletonStoreCacheLoader.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/loader/SingletonStoreCacheLoader.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -47,10 +47,10 @@
import java.util.concurrent.TimeoutException;
/**
- * SingletonStoreCacheLoader is a delegating cache loader used for situations when only one node should interact with
- * the underlying store. The coordinator of the cluster will be responsible for the underlying CacheLoader.
- * SingletonStoreCacheLoader is a simply facade to a real CacheLoader implementation. It always delegates reads to the
- * real CacheLoader.
+ * SingletonStoreCacheLoader is a delegating cache loader used for situations when only one cache instance should
+ * interact with the underlying store. The coordinator of the cluster will be responsible for the underlying
+ * CacheLoader. SingletonStoreCacheLoader is a simply facade to a real CacheLoader implementation. It always delegates
+ * reads to the real CacheLoader.
* <p/>
* Writes are forwarded only if this SingletonStoreCacheLoader is currently the cordinator. This avoid having all
* CacheLoaders in a cluster writing the same data to the same underlying store. Although not incorrect (e.g. a DB will
@@ -100,8 +100,8 @@
private Address localAddress;
/**
- * Whether the the current node is the coordinator and therefore SingletonStoreCacheLoader is active. Being active
- * means delegating calls to the underlying cache loader.
+ * Whether the the current cache instance is the coordinator and therefore SingletonStoreCacheLoader is active. Being
+ * active means delegating calls to the underlying cache loader.
*/
private boolean active;
@@ -176,11 +176,11 @@
}
/**
- * Method called when the node either becomes the coordinator or stops being the coordinator. If it becomes the
- * coordinator, it can optionally start the in-memory state transfer to the underlying cache store.
+ * Method called when the cache instance either becomes the coordinator or stops being the coordinator. If it becomes
+ * the coordinator, it can optionally start the in-memory state transfer to the underlying cache store.
*
- * @param newActiveState true if the node just became the coordinator, false if the nodes stopped being the
- * coordinator.
+ * @param newActiveState true if the cache instance just became the coordinator, false if the cache instance stopped
+ * being the coordinator.
*/
protected void activeStatusChanged(boolean newActiveState) throws PushStateException {
active = newActiveState;
@@ -211,33 +211,14 @@
}
/**
- * Pushes the state of a specific node by reading the node's data from the cache and putting in the cache store
+ * Pushes the state of a specific cache entry by reading the entry's data from the cache and putting in the cache store
* via the cache loader. This method is call recursively so that it iterates through the whole cache.
*
- * @param node instance of NodeSPI to push to the cache loader
- * @throws Exception if there's any issues reading the data from the cache or pushing the node's data to the cache
- * loader.
*/
// TODO implement me
-// protected void pushState(NodeSPI node) throws Exception
+// protected void pushState(Object key) throws Exception
// {
-// /* Put the node's data first */
-// Set keys = node.getKeysDirect();
-// Fqn fqn = node.getFqn();
-//
-// for (Object aKey : keys)
-// {
-// Object value = cache.get(fqn, aKey);
-// put(fqn, aKey, value);
-// }
-//
-// /* Navigates to the children */
-// Collection<NodeSPI> children = node.getChildrenDirect();
-// for (NodeSPI aChildren : children)
-// {
-// //Map.Entry entry = (Map.Entry) aChildren;
-// pushState(aChildren);
-// }
+// /* Put the key's data first */
// }
/**
@@ -268,9 +249,9 @@
}
/**
- * Called when the SingletonStoreCacheLoader discovers that the node has become the coordinator and push in memory
- * state has been enabled. It might not actually push the state if there's an ongoing push task running, in which
- * case will wait for the push task to finish.
+ * Called when the SingletonStoreCacheLoader discovers that the cache instance has become the coordinator and push in
+ * memory state has been enabled. It might not actually push the state if there's an ongoing push task running, in
+ * which case will wait for the push task to finish.
*
* @throws PushStateException when the push state task reports an issue.
*/
@@ -318,10 +299,10 @@
}
/**
- * Indicates whether the current nodes is the coordinator of the cluster.
+ * Indicates whether the current cache instances is the coordinator of the cluster.
*
- * @param newView View instance containing the new view of the cluster
- * @return whether the current node is the coordinator or not.
+ * @param members new member list
+ * @return whether the current cache instance is the coordinator or not.
*/
private boolean isCoordinator(List<Address> members) {
if (members != null && localAddress != null) {
@@ -333,7 +314,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
// @Override
public Object put(Fqn name, Object key, Object value) throws Exception {
@@ -345,7 +326,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
// @Override
public void put(Fqn name, Map attributes) throws Exception {
@@ -357,7 +338,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
// @Override
// public void put(List<Modification> modifications) throws Exception
@@ -370,7 +351,7 @@
// }
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
// @Override
public Object remove(Fqn fqn, Object key) throws Exception {
@@ -382,7 +363,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
// @Override
public void remove(Fqn fqn) throws Exception {
@@ -392,7 +373,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
// @Override
public void removeData(Fqn fqn) throws Exception {
@@ -402,7 +383,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
// @Override
// public void prepare(Object tx, List<Modification> modifications, boolean one_phase) throws Exception
@@ -414,7 +395,7 @@
// }
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
@Override
public void commit(Object tx) // throws Exception
@@ -425,7 +406,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
@Override
public void rollback(Object tx) {
@@ -435,7 +416,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
@Override
public void storeEntireState(ObjectInputStream is) //throws Exception
@@ -446,7 +427,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
// @Override
public void storeState(Fqn subtree, ObjectInputStream is) throws Exception {
@@ -456,7 +437,7 @@
}
/**
- * Calls the underlying cache loader's operation if the current node is the coordinator.
+ * Calls the underlying cache loader's operation if the current cache instance is the coordinator.
*/
@Override
public String toString() {
@@ -465,14 +446,14 @@
/**
* Cache listener that reacts to cluster topology changes to find out whether a new coordinator is elected.
- * SingletonStoreCacheLoader reacts to these changes in order to decide which node should interact with the
+ * SingletonStoreCacheLoader reacts to these changes in order to decide which cache instance should interact with the
* underlying cache store.
*/
@Listener
public class SingletonStoreListener {
/**
- * Cache started, check whether the node is the coordinator and set the singleton store cache loader's active
- * status.
+ * Cache started, check whether the cache instance is the coordinator and set the singleton store cache loader's
+ * active status.
*/
@CacheStarted
public void cacheStarted(Event e) {
@@ -487,9 +468,10 @@
}
/**
- * The cluster formation changed, so determine whether the current node stopped being the coordinator or became
- * the coordinator. This method can lead to an optional in memory to cache loader state push, if the current node
- * became the coordinator. This method will report any issues that could potentially arise from this push.
+ * The cluster formation changed, so determine whether the current cache instance stopped being the coordinator or
+ * became the coordinator. This method can lead to an optional in memory to cache loader state push, if the
+ * current cache instance became the coordinator. This method will report any issues that could potentially arise
+ * from this push.
*/
@ViewChanged
public void viewChange(ViewChangedEvent event) {
@@ -500,7 +482,7 @@
activeStatusChanged(tmp);
}
catch (PushStateException e) {
- log.error("exception reported changing nodes active status", e);
+ log.error("exception reported changing cache instance's active status", e);
}
}
Modified: core/branches/flat/src/main/java/org/horizon/lock/LockManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/lock/LockManager.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/lock/LockManager.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -24,7 +24,7 @@
import org.horizon.context.InvocationContext;
/**
- * An interface to deal with all aspects of acquiring and releasing locks for nodes in the cache.
+ * An interface to deal with all aspects of acquiring and releasing locks for cache entries.
*
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 1.0
@@ -41,9 +41,9 @@
Object getLockOwner(InvocationContext ctx);
/**
- * Acquires a lock of type lockType, for a given owner, on a specific Node in the cache, denoted by fqn. This method
- * will try for {@link org.horizon.config.Configuration#getLockAcquisitionTimeout()} milliseconds and give up if it
- * is unable to acquire the required lock.
+ * Acquires a lock of type lockType, for a given owner, on a specific entry in the cache. This method will try for
+ * {@link org.horizon.config.Configuration#getLockAcquisitionTimeout()} milliseconds and give up if it is unable to
+ * acquire the required lock.
*
* @param key key to lock
* @param owner owner to acquire the lock for
@@ -53,8 +53,8 @@
boolean lock(Object key, Object owner) throws InterruptedException;
/**
- * Acquires a lock of type lockType, for a given owner, on a specific Node in the cache, denoted by fqn. This method
- * will try for timeout milliseconds and give up if it is unable to acquire the required lock.
+ * Acquires a lock of type lockType, for a given owner, on a specific entry in the cache. This method will try for
+ * timeout milliseconds and give up if it is unable to acquire the required lock.
*
* @param key key to lock
* @param owner owner to acquire the lock for
@@ -65,13 +65,13 @@
boolean lock(Object key, Object owner, long timeout) throws InterruptedException;
/**
- * Acquires a lock of type lockType, on a specific Node in the cache, denoted by fqn. This method will try for a
- * period of time and give up if it is unable to acquire the required lock. The period of time is specified in
- * {@link org.horizon.config.Option#getLockAcquisitionTimeout()} and, if this is unset, the default timeout set in
- * {@link org.horizon.config.Configuration#getLockAcquisitionTimeout()} is used.
+ * Acquires a lock of type lockType, on a specific entry in the cache. This method will try for a period of time and
+ * give up if it is unable to acquire the required lock. The period of time is specified in {@link
+ * org.horizon.config.Option#getLockAcquisitionTimeout()} and, if this is unset, the default timeout set in {@link
+ * org.horizon.config.Configuration#getLockAcquisitionTimeout()} is used.
* <p/>
* In addition, any locks acquired are added to the context OR transaction entry using {@link
- * InvocationContext#addLock(Object)}.
+ * org.horizon.context.InvocationContext#addKeyLocked(Object)}
* <p/>
* The owner for the lock is determined by passing the invocation context to {@link
* #getLockOwner(InvocationContext)}.
@@ -107,12 +107,12 @@
* Tests whether a given owner owns a lock of lockType on a particular Fqn.
*
* @param owner owner
- * @return true if the owner does own the specified lock type on the specified node, false otherwise.
+ * @return true if the owner does own the specified lock type on the specified cache entry, false otherwise.
*/
boolean ownsLock(Object key, Object owner);
/**
- * Returns true if the node is locked (either for reading or writing) by anyone, and false otherwise.
+ * Returns true if the cache entry is locked (either for reading or writing) by anyone, and false otherwise.
*
* @return true of locked; false if not.
*/
Modified: core/branches/flat/src/main/java/org/horizon/marshall/EntryData.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/EntryData.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/marshall/EntryData.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -28,12 +28,11 @@
import java.util.Map;
/**
- * Serializable representation of the data of a node (FQN and attributes)
+ * Serializable representation of an entry in the cache
*
* @author Bela Ban
* @since 1.0
*/
-// TODO: 3.0.0: remove Externalizable and rely on the CacheMarshaller.
public class EntryData<K, V> implements Externalizable, Map.Entry<K, V> {
private K key;
private V value;
@@ -53,13 +52,13 @@
return value;
}
- // TODO: 3.0.0: Remove and replace with marshallNodeData/unmarshallNodeData methods in the CacheMarshaller so that we can use the same marshalling framework for Fqns.
+ // TODO: Remove and replace with methods in the CacheMarshaller so that we can use the same marshalling framework
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(key);
out.writeObject(value);
}
- // TODO: 3.0.0: Remove in and replace with marshallNodeData/unmarshallNodeData methods in the CacheMarshaller so that we can use the same marshalling framework for Fqns.
+ // TODO: Remove in and replace with methods in the CacheMarshaller so that we can use the same marshalling framework
@SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
key = (K) in.readObject();
Modified: core/branches/flat/src/main/java/org/horizon/marshall/EntryDataExceptionMarker.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/EntryDataExceptionMarker.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/marshall/EntryDataExceptionMarker.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -29,28 +29,28 @@
public class EntryDataExceptionMarker implements Externalizable {
private static final long serialVersionUID = 240199474174502551L;
private Throwable cause;
- private Object cacheNodeIdentity;
+ private Object key;
- public EntryDataExceptionMarker(Throwable t, Object node) {
+ public EntryDataExceptionMarker(Throwable t, Object key) {
cause = t;
- cacheNodeIdentity = node;
+ key = key;
}
public Throwable getCause() {
return cause;
}
- public Object getCacheNodeIdentity() {
- return cacheNodeIdentity;
+ public Object getKey() {
+ return key;
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(cause);
- out.writeObject(cacheNodeIdentity);
+ out.writeObject(key);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
cause = (Throwable) in.readObject();
- cacheNodeIdentity = in.readObject();
+ key = in.readObject();
}
}
\ No newline at end of file
Deleted: core/branches/flat/src/main/java/org/horizon/marshall/NodeData.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/NodeData.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/marshall/NodeData.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -1,127 +0,0 @@
-/*
- * 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.horizon.marshall;
-
-import org.horizon.tree.Fqn;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Serializable representation of the data of a node (FQN and attributes)
- *
- * @author Bela Ban
- * @since 1.0
- */
-// TODO: 3.0.0: remove Externalizable and rely on the CacheMarshaller.
-public class NodeData<K, V> implements Externalizable {
- private Fqn fqn = null;
- private Map<K, V> attrs = null;
-
- static final long serialVersionUID = -7571995794010294485L;
-
- public NodeData() {
- }
-
- public NodeData(Fqn fqn) {
- this.fqn = fqn;
- }
-
- public NodeData(Fqn fqn, Map<K, V> attrs, boolean mapSafe) {
- this.fqn = fqn;
- if (mapSafe || attrs == null)
- this.attrs = attrs;
- else
- this.attrs = new HashMap<K, V>(attrs);
- }
-
- public NodeData(String fqn, Map<K, V> attrs, boolean mapSafe) {
- this(Fqn.fromString(fqn), attrs, mapSafe);
- }
-
- public Map<K, V> getAttributes() {
- return attrs;
- }
-
- public Fqn getFqn() {
- return fqn;
- }
-
- public boolean isMarker() {
- return false;
- }
-
- public boolean isExceptionMarker() {
- return false;
- }
-
- // TODO: 3.0.0: Remove and replace with marshallNodeData/unmarshallNodeData methods in the CacheMarshaller so that we can use the same marshalling framework for Fqns.
- public void writeExternal(ObjectOutput out) throws IOException {
- out.writeObject(fqn);
- if (attrs != null) {
- out.writeBoolean(true);
- out.writeObject(attrs);
- } else {
- out.writeBoolean(false);
- }
- }
-
- // TODO: 3.0.0: Remove in and replace with marshallNodeData/unmarshallNodeData methods in the CacheMarshaller so that we can use the same marshalling framework for Fqns.
- @SuppressWarnings("unchecked")
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- fqn = (Fqn) in.readObject();
- if (in.readBoolean()) {
- attrs = (Map<K, V>) in.readObject();
- }
- }
-
- @Override
- public String toString() {
- return "NodeData {fqn: " + fqn + ", attrs=" + attrs + "}";
- }
-
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- NodeData nodeData = (NodeData) o;
-
- if (attrs != null ? !attrs.equals(nodeData.attrs) : nodeData.attrs != null) return false;
- if (fqn != null ? !fqn.equals(nodeData.fqn) : nodeData.fqn != null) return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result;
- result = (fqn != null ? fqn.hashCode() : 0);
- result = 31 * result + (attrs != null ? attrs.hashCode() : 0);
- return result;
- }
-}
Deleted: core/branches/flat/src/main/java/org/horizon/marshall/NodeDataExceptionMarker.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/NodeDataExceptionMarker.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/marshall/NodeDataExceptionMarker.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -1,74 +0,0 @@
-/*
- * 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.horizon.marshall;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-
-public class NodeDataExceptionMarker extends NodeData {
-
- private static final long serialVersionUID = 240199474174502551L;
- private Throwable cause;
- private Object cacheNodeIdentity;
-
- public NodeDataExceptionMarker() {
- super();
- }
-
- public NodeDataExceptionMarker(Throwable t, Object node) {
- cause = t;
- cacheNodeIdentity = node;
- }
-
- public Throwable getCause() {
- return cause;
- }
-
- public Object getCacheNodeIdentity() {
- return cacheNodeIdentity;
- }
-
- @Override
- public boolean isExceptionMarker() {
- return true;
- }
-
- @Override
- public void writeExternal(ObjectOutput out) throws IOException {
- super.writeExternal(out);
- out.writeObject(cause);
- out.writeObject(cacheNodeIdentity);
- }
-
- @Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- super.readExternal(in);
- cause = (Throwable) in.readObject();
- cacheNodeIdentity = in.readObject();
- }
-
- @Override
- public String toString() {
- return "NodeDataExceptionMarker";
- }
-}
Deleted: core/branches/flat/src/main/java/org/horizon/marshall/NodeDataMarker.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/marshall/NodeDataMarker.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/marshall/NodeDataMarker.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -1,37 +0,0 @@
-/*
- * 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.horizon.marshall;
-
-public class NodeDataMarker extends NodeData {
-
- private static final long serialVersionUID = 4851793846346021014L;
-
- @Override
- public boolean isMarker() {
- return true;
- }
-
- @Override
- public String toString() {
- return "NodeDataMarker";
- }
-}
Modified: core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifier.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifier.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifier.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -33,54 +33,47 @@
*/
public interface CacheNotifier extends Listenable {
/**
- * Notifies all registered listeners of a nodeCreated event.
+ * Notifies all registered listeners of a CacheEntryCreated event.
*/
void notifyCacheEntryCreated(Object key, boolean pre, InvocationContext ctx);
/**
- * Notifies all registered listeners of a nodeModified event.
+ * Notifies all registered listeners of a CacheEntryModified event.
*/
void notifyCacheEntryModified(Object key, boolean pre, InvocationContext ctx);
/**
- * When notifying about node modifications, in many scenarios there is a need of building a new Map object. If no
- * listeners are registered for notification then it is pointless building this object - so guard the notification
- * with this call.
+ * Notifies all registered listeners of a CacheEntryRemoved event.
*/
- boolean shouldNotifyOnNodeModified();
-
- /**
- * Notifies all registered listeners of a nodeRemoved event.
- */
void notifyCacheEntryRemoved(Object key, boolean pre, InvocationContext ctx);
/**
- * Notifies all registered listeners of a nodeVisited event.
+ * Notifies all registered listeners of a CacheEntryVisited event.
*/
void notifyCacheEntryVisited(Object key, boolean pre, InvocationContext ctx);
/**
- * Notifies all registered listeners of a nodeEvicted event.
+ * Notifies all registered listeners of a CacheEntryEvicted event.
*/
void notifyCacheEntryEvicted(Object key, boolean pre, InvocationContext ctx);
/**
- * Notifies all registered listeners of a nodeInvalidated event.
+ * Notifies all registered listeners of a CacheEntryInvalidated event.
*/
void notifyCacheEntryInvalidated(Object key, boolean pre, InvocationContext ctx);
/**
- * Notifies all registered listeners of a nodeLoaded event.
+ * Notifies all registered listeners of a CacheEntryLoaded event.
*/
void notifyCacheEntryLoaded(Object key, boolean pre, InvocationContext ctx);
/**
- * Notifies all registered listeners of a nodeActivated event.
+ * Notifies all registered listeners of a CacheEntryActivated event.
*/
void notifyCacheEntryActivated(Object key, boolean pre, InvocationContext ctx);
/**
- * Notifies all registered listeners of a nodePassivated event.
+ * Notifies all registered listeners of a CacheEntryPassivated event.
*/
void notifyCacheEntryPassivated(Object key, boolean pre, InvocationContext ctx);
Modified: core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifierImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifierImpl.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifierImpl.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -72,35 +72,32 @@
private static final Class[] allowedMethodAnnotations =
{
CacheStarted.class, CacheStopped.class, CacheEntryCreated.class, CacheEntryRemoved.class, CacheEntryVisited.class, CacheEntryModified.class,
- CacheEntryActivated.class, CacheEntryPassivated.class, CacheEntryLoaded.class, CacheEntryEvicted.class, TransactionRegistered.class, TransactionCompleted.class, ViewChanged.class,
+ CacheEntryActivated.class, CacheEntryPassivated.class, CacheEntryLoaded.class, CacheEntryEvicted.class, TransactionRegistered.class, TransactionCompleted.class,
CacheEntryInvalidated.class
};
private static final Class[] parameterTypes =
{
CacheStartedEvent.class, CacheStoppedEvent.class, CacheEntryCreatedEvent.class, CacheEntryRemovedEvent.class, CacheEntryVisitedEvent.class, CacheEntryModifiedEvent.class,
- CacheEntryActivatedEvent.class, CacheEntryPassivatedEvent.class, CacheEntryLoadedEvent.class, CacheEntryEvictedEvent.class, TransactionRegisteredEvent.class, TransactionCompletedEvent.class, ViewChangedEvent.class,
+ CacheEntryActivatedEvent.class, CacheEntryPassivatedEvent.class, CacheEntryLoadedEvent.class, CacheEntryEvictedEvent.class, TransactionRegisteredEvent.class, TransactionCompletedEvent.class,
CacheEntryInvalidatedEvent.class
};
final Map<Class<? extends Annotation>, List<ListenerInvocation>> listenersMap = new HashMap<Class<? extends Annotation>, List<ListenerInvocation>>(16, 0.99f);
final List<ListenerInvocation> cacheStartedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
final List<ListenerInvocation> cacheStoppedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> nodeCreatedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> nodeRemovedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> nodeVisitedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> nodeModifiedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> nodeActivatedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> nodePassivatedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> nodeLoadedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> nodeInvalidatedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> nodeEvictedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheEntryCreatedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheEntryRemovedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheEntryVisitedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheEntryModifiedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheEntryActivatedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheEntryPassivatedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheEntryLoadedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheEntryInvalidatedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheEntryEvictedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
final List<ListenerInvocation> transactionRegisteredListeners = new CopyOnWriteArrayList<ListenerInvocation>();
final List<ListenerInvocation> transactionCompletedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- final List<ListenerInvocation> viewChangedListeners = new CopyOnWriteArrayList<ListenerInvocation>();
- // final Map<Class, List<ListenerInvocation>> listenerInvocations = new ConcurrentHashMap<Class, List<ListenerInvocation>>();
private Cache cache;
- private boolean useMarshalledValueMaps;
private Configuration config;
// two separate executor services, one for sync and one for async listeners
private ExecutorService syncProcessor;
@@ -110,18 +107,17 @@
public CacheNotifierImpl() {
listenersMap.put(CacheStarted.class, cacheStartedListeners);
listenersMap.put(CacheStopped.class, cacheStoppedListeners);
- listenersMap.put(CacheEntryCreated.class, nodeCreatedListeners);
- listenersMap.put(CacheEntryRemoved.class, nodeRemovedListeners);
- listenersMap.put(CacheEntryVisited.class, nodeVisitedListeners);
- listenersMap.put(CacheEntryModified.class, nodeModifiedListeners);
- listenersMap.put(CacheEntryActivated.class, nodeActivatedListeners);
- listenersMap.put(CacheEntryPassivated.class, nodePassivatedListeners);
- listenersMap.put(CacheEntryLoaded.class, nodeLoadedListeners);
- listenersMap.put(CacheEntryEvicted.class, nodeEvictedListeners);
+ listenersMap.put(CacheEntryCreated.class, cacheEntryCreatedListeners);
+ listenersMap.put(CacheEntryRemoved.class, cacheEntryRemovedListeners);
+ listenersMap.put(CacheEntryVisited.class, cacheEntryVisitedListeners);
+ listenersMap.put(CacheEntryModified.class, cacheEntryModifiedListeners);
+ listenersMap.put(CacheEntryActivated.class, cacheEntryActivatedListeners);
+ listenersMap.put(CacheEntryPassivated.class, cacheEntryPassivatedListeners);
+ listenersMap.put(CacheEntryLoaded.class, cacheEntryLoadedListeners);
+ listenersMap.put(CacheEntryEvicted.class, cacheEntryEvictedListeners);
listenersMap.put(TransactionRegistered.class, transactionRegisteredListeners);
listenersMap.put(TransactionCompleted.class, transactionCompletedListeners);
- listenersMap.put(ViewChanged.class, viewChangedListeners);
- listenersMap.put(CacheEntryInvalidated.class, nodeInvalidatedListeners);
+ listenersMap.put(CacheEntryInvalidated.class, cacheEntryInvalidatedListeners);
}
@Inject
@@ -145,7 +141,6 @@
@Start
void start() {
- useMarshalledValueMaps = config.isUseLazyDeserialization();
syncProcessor = new WithinThreadExecutor();
}
@@ -229,17 +224,16 @@
public void removeAllCacheListeners() {
cacheStartedListeners.clear();
cacheStoppedListeners.clear();
- nodeCreatedListeners.clear();
- nodeRemovedListeners.clear();
- nodeVisitedListeners.clear();
- nodeModifiedListeners.clear();
- nodeActivatedListeners.clear();
- nodePassivatedListeners.clear();
- nodeLoadedListeners.clear();
- nodeEvictedListeners.clear();
+ cacheEntryCreatedListeners.clear();
+ cacheEntryRemovedListeners.clear();
+ cacheEntryVisitedListeners.clear();
+ cacheEntryModifiedListeners.clear();
+ cacheEntryActivatedListeners.clear();
+ cacheEntryPassivatedListeners.clear();
+ cacheEntryLoadedListeners.clear();
+ cacheEntryEvictedListeners.clear();
transactionRegisteredListeners.clear();
transactionCompletedListeners.clear();
- viewChangedListeners.clear();
}
public Set<Object> getListeners() {
@@ -251,7 +245,7 @@
}
public void notifyCacheEntryCreated(Object key, boolean pre, InvocationContext ctx) {
- if (!nodeCreatedListeners.isEmpty()) {
+ if (!cacheEntryCreatedListeners.isEmpty()) {
boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
@@ -262,13 +256,13 @@
e.setKey(key);
e.setTransaction(tx);
e.setType(CACHE_ENTRY_CREATED);
- for (ListenerInvocation listener : nodeCreatedListeners) listener.invoke(e);
+ for (ListenerInvocation listener : cacheEntryCreatedListeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
public void notifyCacheEntryModified(Object key, boolean pre, InvocationContext ctx) {
- if (!nodeModifiedListeners.isEmpty()) {
+ if (!cacheEntryModifiedListeners.isEmpty()) {
boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
@@ -279,17 +273,13 @@
e.setKey(key);
e.setTransaction(tx);
e.setType(CACHE_ENTRY_MODIFIED);
- for (ListenerInvocation listener : nodeModifiedListeners) listener.invoke(e);
+ for (ListenerInvocation listener : cacheEntryModifiedListeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
- public boolean shouldNotifyOnNodeModified() {
- return !nodeModifiedListeners.isEmpty();
- }
-
public void notifyCacheEntryRemoved(Object key, boolean pre, InvocationContext ctx) {
- if (!nodeRemovedListeners.isEmpty()) {
+ if (!cacheEntryRemovedListeners.isEmpty()) {
boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
@@ -300,13 +290,13 @@
e.setKey(key);
e.setTransaction(tx);
e.setType(CACHE_ENTRY_REMOVED);
- for (ListenerInvocation listener : nodeRemovedListeners) listener.invoke(e);
+ for (ListenerInvocation listener : cacheEntryRemovedListeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
public void notifyCacheEntryVisited(Object key, boolean pre, InvocationContext ctx) {
- if (!nodeVisitedListeners.isEmpty()) {
+ if (!cacheEntryVisitedListeners.isEmpty()) {
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
@@ -315,13 +305,13 @@
e.setKey(key);
e.setTransaction(tx);
e.setType(CACHE_ENTRY_VISITED);
- for (ListenerInvocation listener : nodeVisitedListeners) listener.invoke(e);
+ for (ListenerInvocation listener : cacheEntryVisitedListeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
public void notifyCacheEntryEvicted(final Object key, final boolean pre, InvocationContext ctx) {
- if (!nodeEvictedListeners.isEmpty()) {
+ if (!cacheEntryEvictedListeners.isEmpty()) {
final boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
@@ -332,13 +322,13 @@
e.setKey(key);
e.setTransaction(tx);
e.setType(CACHE_ENTRY_EVICTED);
- for (ListenerInvocation listener : nodeEvictedListeners) listener.invoke(e);
+ for (ListenerInvocation listener : cacheEntryEvictedListeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
public void notifyCacheEntryInvalidated(final Object key, final boolean pre, InvocationContext ctx) {
- if (!nodeInvalidatedListeners.isEmpty()) {
+ if (!cacheEntryInvalidatedListeners.isEmpty()) {
final boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
@@ -349,13 +339,13 @@
e.setKey(key);
e.setTransaction(tx);
e.setType(CACHE_ENTRY_INVALIDATED);
- for (ListenerInvocation listener : nodeInvalidatedListeners) listener.invoke(e);
+ for (ListenerInvocation listener : cacheEntryInvalidatedListeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
public void notifyCacheEntryLoaded(Object key, boolean pre, InvocationContext ctx) {
- if (!nodeLoadedListeners.isEmpty()) {
+ if (!cacheEntryLoadedListeners.isEmpty()) {
boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
@@ -366,13 +356,13 @@
e.setKey(key);
e.setTransaction(tx);
e.setType(CACHE_ENTRY_LOADED);
- for (ListenerInvocation listener : nodeLoadedListeners) listener.invoke(e);
+ for (ListenerInvocation listener : cacheEntryLoadedListeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
public void notifyCacheEntryActivated(Object key, boolean pre, InvocationContext ctx) {
- if (!nodeActivatedListeners.isEmpty()) {
+ if (!cacheEntryActivatedListeners.isEmpty()) {
boolean originLocal = ctx.isOriginLocal();
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
@@ -383,13 +373,13 @@
e.setKey(key);
e.setTransaction(tx);
e.setType(CACHE_ENTRY_ACTIVATED);
- for (ListenerInvocation listener : nodeActivatedListeners) listener.invoke(e);
+ for (ListenerInvocation listener : cacheEntryActivatedListeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
public void notifyCacheEntryPassivated(Object key, boolean pre, InvocationContext ctx) {
- if (!nodePassivatedListeners.isEmpty()) {
+ if (!cacheEntryPassivatedListeners.isEmpty()) {
Transaction tx = ctx.getTransaction();
InvocationContext backup = resetInvocationContext(ctx);
EventImpl e = new EventImpl();
@@ -398,7 +388,7 @@
e.setKey(key);
e.setTransaction(tx);
e.setType(CACHE_ENTRY_PASSIVATED);
- for (ListenerInvocation listener : nodePassivatedListeners) listener.invoke(e);
+ for (ListenerInvocation listener : cacheEntryPassivatedListeners) listener.invoke(e);
restoreInvocationContext(backup);
}
}
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryActivated.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryActivated.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryActivated.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -27,15 +27,15 @@
import java.lang.annotation.Target;
/**
- * This annotation should be used on methods that need to be notified when a node is activated.
+ * This annotation should be used on methods that need to be notified when a cache entry is activated.
* <p/>
* Methods annotated with this annotation should be public and take in a single parameter, a {@link
- * org.horizon.notifications.event.NodeActivatedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
+ * org.horizon.notifications.event.CacheEntryActivatedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
* will be thrown when registering your cache listener.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @see Listener
- * @see org.horizon.notifications.annotation.NodePassivated
+ * @see CacheEntryPassivated
* @since 1.0
*/
@Retention(RetentionPolicy.RUNTIME)
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryCreated.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryCreated.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryCreated.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -27,10 +27,10 @@
import java.lang.annotation.Target;
/**
- * This annotation should be used on methods that need to be notified when a node is created.
+ * This annotation should be used on methods that need to be notified when a cache entry is created.
* <p/>
* Methods annotated with this annotation should be public and take in a single parameter, a {@link
- * org.horizon.notifications.event.NodeCreatedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
+ * org.horizon.notifications.event.CacheEntryCreatedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
* will be thrown when registering your cache listener.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryEvicted.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryEvicted.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryEvicted.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -27,15 +27,15 @@
import java.lang.annotation.Target;
/**
- * This annotation should be used on methods that need to be notified when a node is evicted.
+ * This annotation should be used on methods that need to be notified when a cache entry is evicted.
* <p/>
* Methods annotated with this annotation should be public and take in a single parameter, a {@link
- * org.horizon.notifications.event.NodeEvictedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
+ * org.horizon.notifications.event.CacheEntryEvictedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
* will be thrown when registering your cache listener.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @see Listener
- * @see org.horizon.notifications.annotation.NodeLoaded
+ * @see CacheEntryLoaded
* @since 1.0
*/
@Retention(RetentionPolicy.RUNTIME)
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryInvalidated.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryInvalidated.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryInvalidated.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -27,11 +27,11 @@
import java.lang.annotation.Target;
/**
- * This annotation should be used on methods that need to be notified when a node is invalidated.
+ * This annotation should be used on methods that need to be notified when a cache entry is invalidated.
* <p/>
* Methods annotated with this annotation should be public and take in a single parameter, a {@link
- * org.horizon.notifications.event.NodeInvalidatedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
- * will be thrown when registering your cache listener.
+ * org.horizon.notifications.event.CacheEntryInvalidatedEvent} otherwise an {@link
+ * org.horizon.notifications.IncorrectCacheListenerException} will be thrown when registering your cache listener.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @see Listener
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryLoaded.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryLoaded.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryLoaded.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -27,11 +27,11 @@
import java.lang.annotation.Target;
/**
- * This annotation should be used on methods that need to be notified when a node is loaded from a {@link
+ * This annotation should be used on methods that need to be notified when a cache entry is loaded from a {@link
* org.horizon.loader.CacheLoader}.
* <p/>
* Methods annotated with this annotation should be public and take in a single parameter, a {@link
- * org.horizon.notifications.event.NodeEvictedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
+ * org.horizon.notifications.event.CacheEntryLoadedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
* will be thrown when registering your cache listener.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryModified.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryModified.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryModified.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -27,10 +27,10 @@
import java.lang.annotation.Target;
/**
- * This annotation should be used on methods that need to be notified when a node has been modified.
+ * This annotation should be used on methods that need to be notified when a cache entry has been modified.
* <p/>
* Methods annotated with this annotation should be public and take in a single parameter, a {@link
- * org.horizon.notifications.event.NodeModifiedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
+ * org.horizon.notifications.event.CacheEntryModifiedEvent} otherwise an {@link org.horizon.notifications.IncorrectCacheListenerException}
* will be thrown when registering your cache listener.
* <p/>
*
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryPassivated.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryPassivated.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryPassivated.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -27,10 +27,10 @@
import java.lang.annotation.Target;
/**
- * This annotation should be used on methods that need to be notified when a node is passivated.
+ * This annotation should be used on methods that need to be notified when a cache entry is passivated.
* <p/>
* Methods annotated with this annotation should accept a single parameter, a {@link
- * org.horizon.notifications.event.NodePassivatedEvent} otherwise a {@link org.horizon.notifications.IncorrectCacheListenerException}
+ * org.horizon.notifications.event.CacheEntryPassivatedEvent} otherwise a {@link org.horizon.notifications.IncorrectCacheListenerException}
* will be thrown when registering your listener.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryRemoved.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryRemoved.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryRemoved.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -27,10 +27,10 @@
import java.lang.annotation.Target;
/**
- * This annotation should be used on methods that need to be notified when a node is removed from the cache.
+ * This annotation should be used on methods that need to be notified when a cache entry is removed from the cache.
* <p/>
* Methods annotated with this annotation should accept a single parameter, a {@link
- * org.horizon.notifications.event.TransactionRegisteredEvent} otherwise a {@link org.horizon.notifications.IncorrectCacheListenerException}
+ * org.horizon.notifications.event.CacheEntryRemovedEvent} otherwise a {@link org.horizon.notifications.IncorrectCacheListenerException}
* will be thrown when registering your listener.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryVisited.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryVisited.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/CacheEntryVisited.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -27,10 +27,10 @@
import java.lang.annotation.Target;
/**
- * This annotation should be used on methods that need to be notified when a node is visited.
+ * This annotation should be used on methods that need to be notified when a cache entry is visited.
* <p/>
* Methods annotated with this annotation should accept a single parameter, a {@link
- * org.horizon.notifications.event.NodeVisitedEvent} otherwise a {@link org.horizon.notifications.IncorrectCacheListenerException}
+ * org.horizon.notifications.event.CacheEntryVisitedEvent} otherwise a {@link org.horizon.notifications.IncorrectCacheListenerException}
* will be thrown when registering your listener.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
Modified: core/branches/flat/src/main/java/org/horizon/notifications/annotation/Listener.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/annotation/Listener.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/annotation/Listener.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -28,33 +28,34 @@
/**
* Class-level annotation used to annotate an object as being a valid cache listener. Used with the {@link
- * org.horizon.Cache_Legacy#addCacheListener(Object)} and related APIs. <p/> Note that even if a class is annotated with
- * this annotation, it still needs method-level annotation (such as {@link org.horizon.notifications.annotation.CacheStarted})
+ * org.horizon.Cache#addListener(Object)} and related APIs. <p/> Note that even if a class is annotated with this
+ * annotation, it still needs method-level annotation (such as {@link org.horizon.notifications.annotation.CacheStarted})
* to actually receive notifications. <p/> Objects annotated with this annotation - listeners - can be attached to a
- * running {@link org.horizon.Cache_Legacy} so users can be notified of {@link org.horizon.Cache_Legacy} events. <p/>
- * <p/> There can be multiple methods that are annotated to receive the same event, and a method may receive multiple
- * events by using a super type. </p> <p/> <h4>Delivery Semantics</h4> <p/> An event is delivered immediately after the
- * respective operation, but before the underlying cache call returns. For this reason it is important to keep listener
- * processing logic short-lived. If a long running task needs to be performed, it's recommended to use another thread.
- * </p> <p/> <h4>Transactional Semantics</h4> <p/> Since the event is delivered during the actual cache call, the
- * transactional outcome is not yet known. For this reason, <i>events are always delivered, even if the changes they
- * represent are discarded by their containing transaction</i>. For applications that must only process events that
- * represent changes in a completed transaction, {@link org.horizon.notifications.event.TransactionalEvent#getTransaction()}
- * can be used, along with {@link org.horizon.notifications.event.TransactionCompletedEvent#isSuccessful()} to record
- * events and later process them once the transaction has been successfully committed. Example 4 demonstrates this. </p>
- * <p/> <h4>Threading Semantics</h4> <p/> A listener implementation must be capable of handling concurrent invocations.
- * Local notifications reuse the calling thread; remote notifications reuse the network thread. </p> <p/> Since
- * notifications reuse the calling or network thread, it is important to realise that if your listener implementation
- * blocks or performs a long-running task, the original caller which triggered the cache event may block until the
- * listener callback completes. It is therefore a good idea to use the listener to be notified of an event but to
- * perform any long running tasks in a separate thread so as not to block the original caller. </p> <p/> In addition,
- * any locks acquired for the operation being performed will still be held for the callback. This needs to be kept in
- * mind as locks may be held longer than necessary or intended to and may cause deadlocking in certain situations. See
- * above paragraph on long-running tasks that should be run in a separate thread. </p> <b>Note</b>: Since 3.0, a new
+ * running {@link org.horizon.Cache} so users can be notified of {@link org.horizon.Cache} events. <p/> <p/> There can
+ * be multiple methods that are annotated to receive the same event, and a method may receive multiple events by using a
+ * super type. </p> <p/> <h4>Delivery Semantics</h4> <p/> An event is delivered immediately after the respective
+ * operation, but before the underlying cache call returns. For this reason it is important to keep listener processing
+ * logic short-lived. If a long running task needs to be performed, it's recommended to use another thread. </p> <p/>
+ * <h4>Transactional Semantics</h4> <p/> Since the event is delivered during the actual cache call, the transactional
+ * outcome is not yet known. For this reason, <i>events are always delivered, even if the changes they represent are
+ * discarded by their containing transaction</i>. For applications that must only process events that represent changes
+ * in a completed transaction, {@link org.horizon.notifications.event.TransactionalEvent#getTransaction()} can be used,
+ * along with {@link org.horizon.notifications.event.TransactionCompletedEvent#isSuccessful()} to record events and
+ * later process them once the transaction has been successfully committed. Example 4 demonstrates this. </p> <p/>
+ * <h4>Threading Semantics</h4> <p/> A listener implementation must be capable of handling concurrent invocations. Local
+ * notifications reuse the calling thread; remote notifications reuse the network thread. </p> <p/> Since notifications
+ * reuse the calling or network thread, it is important to realise that if your listener implementation blocks or
+ * performs a long-running task, the original caller which triggered the cache event may block until the listener
+ * callback completes. It is therefore a good idea to use the listener to be notified of an event but to perform any
+ * long running tasks in a separate thread so as not to block the original caller. </p> <p/> In addition, any locks
+ * acquired for the operation being performed will still be held for the callback. This needs to be kept in mind as
+ * locks may be held longer than necessary or intended to and may cause deadlocking in certain situations. See above
+ * paragraph on long-running tasks that should be run in a separate thread. </p> <b>Note</b>: Since 3.0, a new
* parameter, <tt>sync</tt>, has been introduced on this annotation. This defaults to <tt>true</tt> which provides the
* above semantics. Alternatively, if you set <tt>sync</tt> to <tt>false</tt>, then invocations are made in a
* <i>separate</i> thread, which will not cause any blocking on the caller or network thread. The separate thread is
- * taken from a pool, which can be configured using {@link org.horizon.config.Configuration#setListenerAsyncPoolSize(int)}.
+ * taken from a pool, which can be configured using {@link org.horizon.config.GlobalConfiguration#setAsyncListenerExecutorProperties(java.util.Properties)}
+ * and {@link org.horizon.config.GlobalConfiguration#setAsyncListenerExecutorFactoryClass(String)}.
* <p/>
* <b>Summary of Notification Annotations</b> <table border="1" cellpadding="1" cellspacing="1" summary="Summary of
* notification annotations"> <tr> <th bgcolor="#CCCCFF" align="left">Annotation</th> <th bgcolor="#CCCCFF"
@@ -62,43 +63,34 @@
* CacheStarted}</td> <td valign="top">{@link org.horizon.notifications.event.CacheStartedEvent}</td> <td valign="top">A
* cache was started</td> </tr> <tr> <td valign="top">{@link CacheStopped}</td> <td valign="top">{@link
* org.horizon.notifications.event.CacheStoppedEvent}</td> <td valign="top">A cache was stopped</td> </tr> <tr> <td
- * valign="top">{@link CacheEntryModified}</td> <td valign="top">{@link org.horizon.notifications.event.NodeModifiedEvent}</td>
- * <td valign="top">A node was modified</td> </tr> <tr> <td valign="top">{@link NodeMoved}</td> <td valign="top">{@link
- * org.horizon.notifications.event.NodeMovedEvent}</td> <td valign="top">A node was moved</td> </tr> <tr> <td
- * valign="top">{@link CacheEntryCreated}</td> <td valign="top">{@link org.horizon.notifications.event.NodeCreatedEvent}</td>
- * <td valign="top">A node was created</td> </tr> <tr> <td valign="top">{@link CacheEntryRemoved}</td> <td
- * valign="top">{@link org.horizon.notifications.event.NodeRemovedEvent}</td> <td valign="top">A node was removed</td>
- * </tr> <tr> <td valign="top">{@link CacheEntryVisited}</td> <td valign="top">{@link
- * org.horizon.notifications.event.NodeVisitedEvent}</td> <td valign="top">A node was visited</td> </tr> <tr> <td
- * valign="top">{@link CacheEntryLoaded}</td> <td valign="top">{@link org.horizon.notifications.event.NodeLoadedEvent}</td>
- * <td valign="top">A node was loaded</td> </tr> <tr> <td valign="top">{@link org.horizon.notifications.annotation.NodeEvicted}</td>
- * <td valign="top">{@link org.horizon.notifications.event.NodeEvictedEvent}</td> <td valign="top">A node was
- * evicted</td> </tr> <tr> <td valign="top">{@link org.horizon.notifications.annotation.NodeActivated}</td> <td
- * valign="top">{@link org.horizon.notifications.event.NodeActivatedEvent}</td> <td valign="top">A node was
- * activated</td> </tr> <tr> <td valign="top">{@link org.horizon.notifications.annotation.NodePassivated}</td> <td
- * valign="top">{@link org.horizon.notifications.event.NodePassivatedEvent}</td> <td valign="top">A node was
- * passivated</td> </tr> <tr> <td valign="top">{@link org.horizon.notifications.annotation.ViewChanged}</td> <td
+ * valign="top">{@link CacheEntryModified}</td> <td valign="top">{@link org.horizon.notifications.event.CacheEntryModifiedEvent}</td>
+ * <td valign="top">A cache entry was modified</td> </tr> <tr> <td valign="top">{@link CacheEntryCreated}</td> <td
+ * valign="top">{@link org.horizon.notifications.event.CacheEntryCreatedEvent}</td> <td valign="top">A cache entry was
+ * created</td> </tr> <tr> <td valign="top">{@link CacheEntryRemoved}</td> <td valign="top">{@link
+ * org.horizon.notifications.event.CacheEntryRemovedEvent}</td> <td valign="top">A cache entry was removed</td> </tr>
+ * <tr> <td valign="top">{@link CacheEntryVisited}</td> <td valign="top">{@link org.horizon.notifications.event.CacheEntryVisitedEvent}</td>
+ * <td valign="top">A cache entry was visited</td> </tr> <tr> <td valign="top">{@link CacheEntryLoaded}</td> <td
+ * valign="top">{@link org.horizon.notifications.event.CacheEntryLoadedEvent}</td> <td valign="top">A cache entry was
+ * loaded</td> </tr> <tr> <td valign="top">{@link CacheEntryEvicted}</td> <td valign="top">{@link
+ * org.horizon.notifications.event.CacheEntryEvictedEvent}</td> <td valign="top">A cache entry was evicted</td> </tr>
+ * <tr> <td valign="top">{@link CacheEntryActivated}</td> <td valign="top">{@link org.horizon.notifications.event.CacheEntryActivatedEvent}</td>
+ * <td valign="top">A cache entry was activated</td> </tr> <tr> <td valign="top">{@link CacheEntryPassivated}</td> <td
+ * valign="top">{@link org.horizon.notifications.event.CacheEntryPassivatedEvent}</td> <td valign="top">A cache entry
+ * was passivated</td> </tr> <tr> <td valign="top">{@link org.horizon.notifications.annotation.ViewChanged}</td> <td
* valign="top">{@link org.horizon.notifications.event.ViewChangedEvent}</td> <td valign="top">A view change event was
- * detected</td> </tr> <tr> <td valign="top">{@link org.horizon.notifications.annotation.CacheBlocked}</td> <td
- * valign="top">{@link org.horizon.notifications.event.CacheBlockedEvent}</td> <td valign="top">A cache block event was
- * detected</td> </tr> <tr> <td valign="top">{@link CacheUnblocked}</td> <td valign="top">{@link
- * org.horizon.notifications.event.CacheUnblockedEvent}</td> <td valign="top">A cache unblock event was detected</td>
- * </tr> <tr> <td valign="top">{@link TransactionRegistered}</td> <td valign@="top">{@link
+ * detected</td> </tr> <tr> <td valign="top">{@link TransactionRegistered}</td> <td valign@="top">{@link
* org.horizon.notifications.event.TransactionRegisteredEvent}</td> <td valign="top">The cache has started to
* participate in a transaction</td> </tr> <tr> <td valign="top">{@link TransactionCompleted}</td> <td
* valign=@"top">{@link org.horizon.notifications.event.TransactionCompletedEvent}</td> <td valign="top">The cache has
- * completed its participation in a transaction</td> </tr> <tr> <td valign="top">{@link BuddyGroupChanged}</td> <td
- * valign=@"top">{@link org.horizon.notifications.event.BuddyGroupChangedEvent}</td> <td valign="top">Buddy replication
- * is enabled and one of the buddy groups that the instance is a member of has changed its membership.</td> </tr> <tr>
- * <td valign="top">{@link CacheEntryInvalidated}</td> <td valign=@"top">{@link org.horizon.notifications.event.NodeInvalidatedEvent}</td>
- * <td valign="top">A node was invalidated by a remote cache. Only if cache mode is INVALIDATION_SYNC or
- * INVALIDATION_ASYNC.</td> </tr>
+ * completed its participation in a transaction</td> </tr> <tr> <td valign="top">{@link CacheEntryInvalidated}</td> <td
+ * valign=@"top">{@link org.horizon.notifications.event.CacheEntryInvalidatedEvent}</td> <td valign="top">A cache entry
+ * was invalidated by a remote cache. Only if cache mode is INVALIDATION_SYNC or INVALIDATION_ASYNC.</td> </tr>
* <p/>
* </table>
* <p/>
* <h4>Example 1 - Method receiving a single event</h4>
* <pre>
- * @CacheListener
+ * @Listener
* public class SingleEventListener
* {
* @CacheStarted
@@ -111,7 +103,7 @@
* <p/>
* <h4>Example 2 - Method receiving multiple events</h4>
* <pre>
- * @CacheListener
+ * @Listener
* public class MultipleEventListener
* {
* @CacheStarted
@@ -128,7 +120,7 @@
* <p/>
* <h4>Example 3 - Multiple methods receiving the same event</h4>
* <pre>
- * @CAcheListener
+ * @Listener
* public class SingleEventListener
* {
* @CacheStarted
@@ -153,7 +145,7 @@
* <b>Example 4 - Processing only events with a committed transaction.</b>
* <p/>
* <pre>
- * @CacheListener
+ * @Listener
* public class TxGuaranteedListener
* {
* private class TxEventQueue
@@ -187,10 +179,9 @@
* <p/>
* private TxEventQueue events = new TxEventQueue();
* <p/>
- * @NodeModified
- * @NodeMoved
- * @NodeCreated
- * @NodeRemoved
+ * @CacheEntryModified
+ * @CacheEntryCreated
+ * @CacheEntryRemoved
* public void handle(Event event)
* {
* events.offer(event);
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryActivatedEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryActivatedEvent.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryActivatedEvent.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -22,7 +22,7 @@
package org.horizon.notifications.event;
/**
- * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.NodeActivated}.
+ * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.CacheEntryActivated}.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryCreatedEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryCreatedEvent.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryCreatedEvent.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -22,7 +22,7 @@
package org.horizon.notifications.event;
/**
- * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.NodeCreated}.
+ * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.CacheEntryCreated}.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryEvent.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryEvent.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -22,14 +22,14 @@
package org.horizon.notifications.event;
/**
- * Transactional events that additionally expose an Fqn as such events pertain to a specific node.
+ * Transactional events that additionally expose an Fqn as such events pertain to a specific cache entry.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 1.0
*/
public interface CacheEntryEvent extends TransactionalEvent {
/**
- * @return the Fqn pointing to the node that is affected.
+ * @return the key to the affected cache entry.
*/
Object getKey();
}
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryEvictedEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryEvictedEvent.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryEvictedEvent.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -22,7 +22,7 @@
package org.horizon.notifications.event;
/**
- * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.NodeEvicted}.
+ * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.CacheEntryEvicted}.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryLoadedEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryLoadedEvent.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryLoadedEvent.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -22,7 +22,7 @@
package org.horizon.notifications.event;
/**
- * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.NodeLoaded}.
+ * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.CacheEntryLoaded}.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryModifiedEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryModifiedEvent.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryModifiedEvent.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -22,7 +22,7 @@
package org.horizon.notifications.event;
/**
- * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.NodeModified}
+ * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.CacheEntryModified}
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryPassivatedEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryPassivatedEvent.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryPassivatedEvent.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -22,7 +22,7 @@
package org.horizon.notifications.event;
/**
- * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.NodePassivated}.
+ * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.CacheEntryPassivated}.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryRemovedEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryRemovedEvent.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryRemovedEvent.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -22,7 +22,7 @@
package org.horizon.notifications.event;
/**
- * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.NodeRemoved}.
+ * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.CacheEntryRemoved}.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryVisitedEvent.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryVisitedEvent.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/CacheEntryVisitedEvent.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -22,7 +22,7 @@
package org.horizon.notifications.event;
/**
- * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.NodeVisited}.
+ * This event is passed in to any method annotated with {@link org.horizon.notifications.annotation.CacheEntryVisited}.
*
* @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
* @since 1.0
Modified: core/branches/flat/src/main/java/org/horizon/notifications/event/Event.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/event/Event.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/notifications/event/Event.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -33,7 +33,7 @@
static enum Type {
CACHE_STARTED, CACHE_STOPPED, CACHE_ENTRY_ACTIVATED, CACHE_ENTRY_PASSIVATED, CACHE_ENTRY_VISITED,
CACHE_ENTRY_LOADED, CACHE_ENTRY_EVICTED, CACHE_ENTRY_CREATED, CACHE_ENTRY_REMOVED, CACHE_ENTRY_MODIFIED,
- TRANSACTION_COMPLETED, TRANSACTION_REGISTERED, VIEW_CHANGED, BUDDY_GROUP_CHANGED, CACHE_ENTRY_INVALIDATED
+ TRANSACTION_COMPLETED, TRANSACTION_REGISTERED, CACHE_ENTRY_INVALIDATED, VIEW_CHANGED_EVENT
}
/**
Modified: core/branches/flat/src/main/java/org/horizon/statetransfer/DefaultStateTransferManager.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/statetransfer/DefaultStateTransferManager.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/statetransfer/DefaultStateTransferManager.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -29,8 +29,6 @@
import org.horizon.logging.Log;
import org.horizon.logging.LogFactory;
import org.horizon.marshall.Marshaller;
-import org.horizon.marshall.NodeData;
-import org.horizon.marshall.NodeDataMarker;
import org.horizon.tree.Fqn;
import java.io.ObjectInputStream;
@@ -46,7 +44,7 @@
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 Object STREAMING_DELIMITER_NODE = new Object();
public static final String PARTIAL_STATE_DELIMITER = "_PARTIAL_STATE_DELIMITER";
Modified: core/branches/flat/src/main/java/org/horizon/transaction/GlobalTransaction.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/transaction/GlobalTransaction.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/transaction/GlobalTransaction.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -30,7 +30,7 @@
/**
- * Uniquely identifies a transaction that spans all nodes in a cluster. This is used when replicating all modifications
+ * Uniquely identifies a transaction that spans all JVMs in a cluster. This is used when replicating all modifications
* in a transaction; the PREPARE and COMMIT (or ROLLBACK) messages have to have a unique identifier to associate the
* changes with<br>
*
Deleted: core/branches/flat/src/main/java/org/horizon/util/concurrent/SelfInitializingConcurrentHashMap.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/concurrent/SelfInitializingConcurrentHashMap.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/java/org/horizon/util/concurrent/SelfInitializingConcurrentHashMap.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -1,144 +0,0 @@
-/*
- * 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.horizon.util.concurrent;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * Primarily used to hold child maps for nodes. Underlying CHM is null initially, and once threads start writing to
- * this map, the CHM is initialized.
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 1.0
- */
-public class SelfInitializingConcurrentHashMap<K, V> implements ConcurrentMap<K, V> {
- private volatile ConcurrentMap<K, V> delegate;
-
- // -------------- initialization methods and helpers ----------------------
- private ConcurrentMap<K, V> getDelegate() {
- if (delegate == null) init();
- return delegate;
- }
-
- private synchronized void init() {
- // Reminiscent of DCL but the delegate here is volatile so construction reordering should not affect.
- if (delegate == null) delegate = new ConcurrentHashMap<K, V>(1, 0.75f, 4);
- }
-
- // -------------- Public API methods that will trigger initialization ----------------------
-
- public final V put(K key, V value) {
- return getDelegate().put(key, value);
- }
-
- public final V remove(Object key) {
- return getDelegate().remove(key);
- }
-
- public final void putAll(Map<? extends K, ? extends V> m) {
- getDelegate().putAll(m);
- }
-
- public final V putIfAbsent(K key, V value) {
- return getDelegate().putIfAbsent(key, value);
- }
-
- public final boolean replace(K key, V oldValue, V newValue) {
- return getDelegate().replace(key, oldValue, newValue);
- }
-
- public final V replace(K key, V value) {
- return getDelegate().replace(key, value);
- }
-
- // -------------- Public API methods that won't trigger initialization ----------------------
-
- public final boolean remove(Object key, Object value) {
- return delegate != null && delegate.remove(key, value);
- }
-
- public final int size() {
- return delegate == null ? 0 : delegate.size();
- }
-
- public final boolean isEmpty() {
- return delegate == null || delegate.isEmpty();
- }
-
- public final boolean containsKey(Object key) {
- return delegate != null && delegate.containsKey(key);
- }
-
- public final boolean containsValue(Object value) {
- return delegate != null && delegate.containsValue(value);
- }
-
- public final V get(Object key) {
- return delegate == null ? null : delegate.get(key);
- }
-
- public final void clear() {
- if (delegate != null) delegate.clear();
- }
-
- public final Set<K> keySet() {
- if (delegate == null || delegate.isEmpty()) return Collections.emptySet();
- return delegate.keySet();
- }
-
- public final Collection<V> values() {
- if (delegate == null || delegate.isEmpty()) return Collections.emptySet();
- return delegate.values();
- }
-
- public final Set<Entry<K, V>> entrySet() {
- if (delegate == null || delegate.isEmpty()) return Collections.emptySet();
- return delegate.entrySet();
- }
-
- @Override
- public String toString() {
- return "SelfInitializingConcurrentHashMap{" +
- "delegate=" + delegate +
- '}';
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- SelfInitializingConcurrentHashMap that = (SelfInitializingConcurrentHashMap) o;
- return !(delegate != null ? !delegate.equals(that.delegate) : that.delegate != null);
- }
-
- @Override
- public int hashCode() {
- int result;
- result = (delegate != null ? delegate.hashCode() : 0);
- return result;
- }
-}
Modified: core/branches/flat/src/main/resources/cache-jdbc.properties
===================================================================
--- core/branches/flat/src/main/resources/cache-jdbc.properties 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/resources/cache-jdbc.properties 2009-01-30 16:48:58 UTC (rev 7616)
@@ -3,67 +3,64 @@
# The table name can also be prepended with schema name for the given table.
# Even though there is an Sql92 standard syntax for this: <schema_name>.<table name>
#schema has different meanings accross various DBMS: Oracle - user name; PointBase - database name
-# Microsoft SQL Server & DB2 - schema name corresponds to the catalog owner
-cache.jdbc.table.name=jbosscache
-cache.jdbc.table.create=true
-cache.jdbc.table.drop=false
-cache.jdbc.table.primarykey=jbosscache_pk
-cache.jdbc.fqn.column=fqn
-cache.jdbc.fqn.type=varchar(255)
-cache.jdbc.node.column=node
-cache.jdbc.node.type=blob
-cache.jdbc.parent.column=parent
-# Specify your DBMS's string concatenation function syntax in the following manner: concat(1 , 2) -> '12'.
-# This syntax should work an most popular DBMS like oracle, db2, mssql, mysql, PostgreSQL. Derby - on which
-#the tests are run does not support 'concat', but '1 || 2' . If no value is sepcified then concat(1 , 2) is used by default.
-cache.jdbc.sql-concat=1 || 2
+# Microsoft SQL Server & DB2 - schema name corresponds to the catalog owner
-# JBoss Cache Table properties for Hypersonic, just overrides
-#cache.jdbc.node.type=OBJECT
+horizon.jdbc.table.name=horizon
+horizon.jdbc.table.create=true
+horizon.jdbc.table.drop=false
+horizon.jdbc.table.primarykey=CACHE_KEY
+horizon.jdbc.key.column=CACHE_KEY
+horizon.jdbc.key.type=VARCHAR(255)
+horizon.jdbc.value.column=CACHE_VALUE
##
# DataSource
-#cache.jdbc.datasource=DefaultDS
+# horizon.jdbc.datasource=DefaultDS
##
# JDBC driver specific properties
# Hypersonic
-#cache.jdbc.node.type=OBJECT
+horizon.jdbc.value.type=BINARY
+horizon.jdbc.driver = org.hsqldb.jdbcDriver
+horizon.jdbc.url=jdbc:hsqldb:mem:horizondb
+horizon.jdbc.user=sa
+horizon.jdbc.password=
+
## MySql
-#cache.jdbc.driver=com.mysql.jdbc.Driver
-#cache.jdbc.url=jdbc:mysql://localhost:3306/jbossdb
-#cache.jdbc.user=root
-#cache.jdbc.password=admin
+#horizon.jdbc.driver=com.mysql.jdbc.Driver
+#horizon.jdbc.url=jdbc:mysql://localhost:3306/horizondb
+#horizon.jdbc.user=root
+#horizon.jdbc.password=admin
## Oracle
-#cache.jdbc.driver=oracle.jdbc.OracleDriver
-#cache.jdbc.url=jdbc:oracle:thin:@192.168.0.100:1521:JBOSSDB
-#cache.jdbc.user=jboss
-#cache.jdbc.password=sa
+#horizon.jdbc.driver=oracle.jdbc.OracleDriver
+#horizon.jdbc.url=jdbc:oracle:thin:@192.168.0.100:1521:HORIZONDB
+#horizon.jdbc.user=scott
+#horizon.jdbc.password=tiger
## MS Sql Server
-#cache.jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
-#cache.jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jbossdb;SelectMethod=cursor
-#cache.jdbc.user=sa
-#cache.jdbc.password=
-#cache.jdbc.node.type=image
+#horizon.jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
+#horizon.jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=horizondb;SelectMethod=cursor
+#horizon.jdbc.user=sa
+#horizon.jdbc.password=
+#horizon.jdbc.value.type=image
## Pointbase
-#cache.jdbc.driver=com.pointbase.jdbc.jdbcUniversalDriver
-#cache.jdbc.url=jdbc:pointbase:server://localhost:9092/jboss,new
-#cache.jdbc.user=PBPUBLIC
-#cache.jdbc.password=PBPUBLIC
+#horizon.jdbc.driver=com.pointbase.jdbc.jdbcUniversalDriver
+#horizon.jdbc.url=jdbc:pointbase:server://localhost:9092/horizon,new
+#horizon.jdbc.user=PBPUBLIC
+#horizon.jdbc.password=PBPUBLIC
## PostgreSQL
-#cache.jdbc.driver = org.postgresql.Driver
-#cache.jdbc.url=jdbc:postgresql://192.168.0.100:5432/jbossdb
-#cache.jdbc.user=postgres
-#cache.jdbc.password=admin
+#horizon.jdbc.driver = org.postgresql.Driver
+#horizon.jdbc.url=jdbc:postgresql://192.168.0.100:5432/horizondb
+#horizon.jdbc.user=postgres
+#horizon.jdbc.password=admin
## Derby
-cache.jdbc.driver = org.apache.derby.jdbc.EmbeddedDriver
-cache.jdbc.url=jdbc:derby:jbossdb;create=true
-cache.jdbc.user=user1
-cache.jdbc.password=user1
\ No newline at end of file
+#horizon.jdbc.driver = org.apache.derby.jdbc.EmbeddedDriver
+#horizon.jdbc.url=jdbc:derby:horizondb;create=true
+#horizon.jdbc.user=user1
+#horizon.jdbc.password=user1
\ No newline at end of file
Modified: core/branches/flat/src/main/resources/config-samples/all.xml
===================================================================
--- core/branches/flat/src/main/resources/config-samples/all.xml 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/main/resources/config-samples/all.xml 2009-01-30 16:48:58 UTC (rev 7616)
@@ -116,7 +116,7 @@
the eviction thread will never run. A separate executor is used for eviction in each cache.
-->
<eviction wakeUpInterval="500" algorithmClass="org.horizon.eviction.LRUAlgorithm" eventQueueSize="200000">
- <property name="maxNodes" value="5000"/>
+ <property name="maxEntries" value="5000"/>
<property name="timeToLive" value="1000"/>
</eviction>
Modified: core/branches/flat/src/test/java/org/horizon/api/mvcc/LockAssert.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/mvcc/LockAssert.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/test/java/org/horizon/api/mvcc/LockAssert.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -17,8 +17,7 @@
}
public static void assertNotLocked(Object key, InvocationContextContainer icc) {
- // can't rely on the negative test since other nodes may share the same lock with lock striping.
-// assert !lockManager.isLocked(fqn) : fqn + " is locked!";
+ // can't rely on the negative test since other entries may share the same lock with lock striping.
assert !icc.get().getKeysLocked().contains(key) : key + " lock recorded!";
}
Modified: core/branches/flat/src/test/java/org/horizon/api/mvcc/LockTestBase.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/mvcc/LockTestBase.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/test/java/org/horizon/api/mvcc/LockTestBase.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -123,11 +123,11 @@
assertNoLocks();
}
- public void testLocksOnEvictNode() throws Exception {
+ public void testLocksOnEvict() throws Exception {
LockTestBaseTL tl = threadLocal.get();
Cache<String, String> cache = tl.cache;
TransactionManager tm = tl.tm;
- // init some data on a node
+ // init some data
cache.putAll(Collections.singletonMap("k", "v"));
assert "v".equals(cache.get("k"));
@@ -140,7 +140,7 @@
assertNoLocks();
}
- public void testLocksOnRemoveNonexistentNode() throws Exception {
+ public void testLocksOnRemoveNonexistent() throws Exception {
LockTestBaseTL tl = threadLocal.get();
Cache<String, String> cache = tl.cache;
TransactionManager tm = tl.tm;
@@ -154,7 +154,7 @@
assertNoLocks();
}
- public void testLocksOnEvictNonexistentNode() throws Exception {
+ public void testLocksOnEvictNonexistent() throws Exception {
LockTestBaseTL tl = threadLocal.get();
Cache<String, String> cache = tl.cache;
TransactionManager tm = tl.tm;
@@ -172,7 +172,7 @@
LockTestBaseTL tl = threadLocal.get();
Cache<String, String> cache = tl.cache;
TransactionManager tm = tl.tm;
- // init some data on a node
+ // init some data
cache.put("k", "v");
cache.put("k2", "v2");
@@ -299,7 +299,7 @@
assertNoLocks();
}
- public void testRollbacksOnNullNode() throws Exception {
+ public void testRollbacksOnNullEntry() throws Exception {
LockTestBaseTL tl = threadLocal.get();
Cache<String, String> cache = tl.cache;
TransactionManager tm = tl.tm;
Modified: core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -124,7 +124,6 @@
}
public void testTxSuspension() throws Exception {
- // create parent node first
replListener2.expect(PutKeyValueCommand.class);
cache1.put(key + "0", value);
replListener2.waitForRPC();
@@ -255,7 +254,6 @@
assert tt2.getNumLocalTransactions() == 0 : "Cache 2 should have no stale local TXs";
System.out.println("PutForExternalReadTest.testMemLeakOnSuspendedTransactions");
- //do not expectWithTx a PFER replication, as the node already exists so this is a no-op
replListener2.expectWithTx(PutKeyValueCommand.class);
tm1.begin();
cache1.putForExternalRead(key, value);
@@ -280,7 +278,6 @@
assert tt2.getNumGlobalTransactions() == 0 : "Cache 2 should have no stale global TXs";
assert tt2.getNumLocalTransactions() == 0 : "Cache 2 should have no stale local TXs";
- //do not expectWithTx a PFER replication, as the node already exists so this is a no-op
replListener2.expectWithTx(PutKeyValueCommand.class, PutKeyValueCommand.class);
tm1.begin();
cache1.put(key, value);
Modified: core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/test/java/org/horizon/profiling/ProfileTest.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -103,7 +103,7 @@
for (final Object key : keys) {
exec.execute(new Runnable() {
public void run() {
- // this will create the necessary nodes.
+ // this will create the necessary entries.
cache.put(key, Collections.emptyMap());
}
});
@@ -125,7 +125,6 @@
long duration = System.currentTimeMillis() - startTime;
log.warn("Finished warmup. " + printDuration(duration));
- //cache.removeNode(Fqn.ROOT);
((Cache) cache).stop();
startup();
Modified: core/branches/flat/src/test/java/org/horizon/replication/SyncCacheListenerTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/SyncCacheListenerTest.java 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/test/java/org/horizon/replication/SyncCacheListenerTest.java 2009-01-30 16:48:58 UTC (rev 7616)
@@ -170,16 +170,16 @@
}
@CacheEntryModified
- public void nodeModified(Event ne) {
+ public void modified(Event ne) {
if (!ne.isPre()) {
- log.debug("nodeModified visited with fqn: " + key);
+ log.debug("modified visited with key: " + key);
try {
// test out if we can get the read lock since there is a write lock going as well.
cache1.get(key);
}
catch (CacheException e) {
- e.printStackTrace();//To change body of catch statement use File | Settings | File Templates.
- fail("nodeModified: test failed with exception: " + e);
+ e.printStackTrace();
+ fail("modified: test failed with exception: " + e);
}
}
}
@@ -194,7 +194,7 @@
public void callback(TransactionalEvent e) {
System.out.println("Callback got event " + e);
log.debug("Callback got event " + e);
- assertFalse("node was removed on remote cache so isLocal should be false", e.isOriginLocal());
+ assertFalse("entry was removed on remote cache so isLocal should be false", e.isOriginLocal());
}
}
}
Modified: core/branches/flat/src/test/resources/cache-jdbc.properties
===================================================================
--- core/branches/flat/src/test/resources/cache-jdbc.properties 2009-01-30 14:22:32 UTC (rev 7615)
+++ core/branches/flat/src/test/resources/cache-jdbc.properties 2009-01-30 16:48:58 UTC (rev 7616)
@@ -11,56 +11,56 @@
horizon.jdbc.table.primarykey=CACHE_KEY
horizon.jdbc.key.column=CACHE_KEY
horizon.jdbc.key.type=VARCHAR(255)
-horizon.jdbc.node.column=CACHE_VALUE
+horizon.jdbc.value.column=CACHE_VALUE
##
# DataSource
-#cache.jdbc.datasource=DefaultDS
+# horizon.jdbc.datasource=DefaultDS
##
# JDBC driver specific properties
# Hypersonic
-cache.jdbc.node.type=BINARY
-cache.jdbc.driver = org.hsqldb.jdbcDriver
-cache.jdbc.url=jdbc:hsqldb:mem:horizondb
-cache.jdbc.user=sa
-cache.jdbc.password=
+horizon.jdbc.value.type=BINARY
+horizon.jdbc.driver = org.hsqldb.jdbcDriver
+horizon.jdbc.url=jdbc:hsqldb:mem:horizondb
+horizon.jdbc.user=sa
+horizon.jdbc.password=
## MySql
-#cache.jdbc.driver=com.mysql.jdbc.Driver
-#cache.jdbc.url=jdbc:mysql://localhost:3306/horizondb
-#cache.jdbc.user=root
-#cache.jdbc.password=admin
+#horizon.jdbc.driver=com.mysql.jdbc.Driver
+#horizon.jdbc.url=jdbc:mysql://localhost:3306/horizondb
+#horizon.jdbc.user=root
+#horizon.jdbc.password=admin
## Oracle
-#cache.jdbc.driver=oracle.jdbc.OracleDriver
-#cache.jdbc.url=jdbc:oracle:thin:@192.168.0.100:1521:HORIZONDB
-#cache.jdbc.user=scott
-#cache.jdbc.password=tiger
+#horizon.jdbc.driver=oracle.jdbc.OracleDriver
+#horizon.jdbc.url=jdbc:oracle:thin:@192.168.0.100:1521:HORIZONDB
+#horizon.jdbc.user=scott
+#horizon.jdbc.password=tiger
## MS Sql Server
-#cache.jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
-#cache.jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=horizondb;SelectMethod=cursor
-#cache.jdbc.user=sa
-#cache.jdbc.password=
-#cache.jdbc.node.type=image
+#horizon.jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
+#horizon.jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=horizondb;SelectMethod=cursor
+#horizon.jdbc.user=sa
+#horizon.jdbc.password=
+#horizon.jdbc.value.type=image
## Pointbase
-#cache.jdbc.driver=com.pointbase.jdbc.jdbcUniversalDriver
-#cache.jdbc.url=jdbc:pointbase:server://localhost:9092/horizon,new
-#cache.jdbc.user=PBPUBLIC
-#cache.jdbc.password=PBPUBLIC
+#horizon.jdbc.driver=com.pointbase.jdbc.jdbcUniversalDriver
+#horizon.jdbc.url=jdbc:pointbase:server://localhost:9092/horizon,new
+#horizon.jdbc.user=PBPUBLIC
+#horizon.jdbc.password=PBPUBLIC
## PostgreSQL
-#cache.jdbc.driver = org.postgresql.Driver
-#cache.jdbc.url=jdbc:postgresql://192.168.0.100:5432/horizondb
-#cache.jdbc.user=postgres
-#cache.jdbc.password=admin
+#horizon.jdbc.driver = org.postgresql.Driver
+#horizon.jdbc.url=jdbc:postgresql://192.168.0.100:5432/horizondb
+#horizon.jdbc.user=postgres
+#horizon.jdbc.password=admin
## Derby
-#cache.jdbc.driver = org.apache.derby.jdbc.EmbeddedDriver
-#cache.jdbc.url=jdbc:derby:horizondb;create=true
-#cache.jdbc.user=user1
-#cache.jdbc.password=user1
\ No newline at end of file
+#horizon.jdbc.driver = org.apache.derby.jdbc.EmbeddedDriver
+#horizon.jdbc.url=jdbc:derby:horizondb;create=true
+#horizon.jdbc.user=user1
+#horizon.jdbc.password=user1
\ No newline at end of file
15 years, 11 months
JBoss Cache SVN: r7615 - core/branches/flat/src/test/java/org/horizon.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-30 09:22:32 -0500 (Fri, 30 Jan 2009)
New Revision: 7615
Modified:
core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java
Log:
Javadoc
Modified: core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java 2009-01-30 14:10:03 UTC (rev 7614)
+++ core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java 2009-01-30 14:22:32 UTC (rev 7615)
@@ -22,6 +22,17 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+/**
+ * A base class that <i>all</i> tests that use clustering needs to extend. <tt>CacheManager</tt>s should <i>only</b> be
+ * created using the methods here, since this class takes care of proper cleanup of the clustering stack.
+ * <p/>
+ * This class also offers some cluster-specific helper methods, like {@link #assertClusterSize(String, int)} and {@link
+ * #attachReplicationListener(Cache)}, the latter which allows you to attach listeners to caches and block until RPC
+ * calls are received. While this is most useful on asynchronous tests, it does not break synchronous tests either so
+ * test code could be reused.
+ * <p/>
+ * See {@link org.horizon.BaseClusteredTest.ReplListener} for details.
+ */
public abstract class BaseClusteredTest {
ThreadLocal<List<CacheManager>> cacheManagerThreadLocal = new ThreadLocal<List<CacheManager>>() {
@Override
@@ -91,6 +102,10 @@
cacheManagerThreadLocal.get().clear();
}
+ /**
+ * A listener that listens for replication events on a cache it is watching. Typical usage: <code> ReplListener r =
+ * attachReplicationListener(cache); r.expect(RemoveCommand.class); // ... r.waitForRPC(); </code>
+ */
protected static class ReplListener {
Cache c;
Set<Class<? extends VisitableCommand>> expectedCommands;
@@ -101,10 +116,21 @@
this.c.addInterceptor(new ReplListenerInterceptor(), 0);
}
+ /**
+ * Expects any commands. The moment a single command is detected, the {@link #waitForRPC()} command will be
+ * unblocked.
+ */
public void expectAny() {
expect();
}
+ /**
+ * Expects a specific set of commands, within transactional scope (i.e., as a payload to a PrepareCommand). If
+ * the cache mode is synchronous, a CommitCommand is expected as well.
+ *
+ * @param commands commands to expect (not counting transaction boundary commands like PrepareCommand and
+ * CommitCommand)
+ */
public void expectWithTx(Class<? extends VisitableCommand>... commands) {
expect(PrepareCommand.class);
expect(commands);
@@ -112,12 +138,22 @@
if (c.getConfiguration().getCacheMode().isSynchronous()) expect(CommitCommand.class);
}
+ /**
+ * Expects any commands, within transactional scope (i.e., as a payload to a PrepareCommand). If the cache mode
+ * is synchronous, a CommitCommand is expected as well.
+ */
public void expectAnyWithTx() {
expect(PrepareCommand.class);
//this is because for async replication we have an 1pc transaction
if (c.getConfiguration().getCacheMode().isSynchronous()) expect(CommitCommand.class);
}
+ /**
+ * Expects a specific set of commands. {@link #waitForRPC()} will block until all of these commands are
+ * detected.
+ *
+ * @param expectedCommands commands to expect
+ */
public void expect(Class<? extends VisitableCommand>... expectedCommands) {
if (this.expectedCommands == null) {
this.expectedCommands = new HashSet<Class<? extends VisitableCommand>>();
@@ -125,10 +161,17 @@
this.expectedCommands.addAll(Arrays.asList(expectedCommands));
}
+ /**
+ * Blocks for a predefined amount of time (120 Seconds) until commands defined in any of the expect*() methods
+ * have been detected. If the commands have not been detected by this time, an exception is thrown.
+ */
public void waitForRPC() {
waitForRPC(120, TimeUnit.SECONDS);
}
+ /**
+ * The same as {@link #waitForRPC()} except that you are allowed to specify the max wait time.
+ */
public void waitForRPC(long time, TimeUnit unit) {
assert expectedCommands != null : "there are no replication expectations; please use ReplListener.expect() before calling this method";
try {
15 years, 11 months
JBoss Cache SVN: r7614 - in core/branches/flat/src: main/java/org/horizon/commands/read and 11 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-30 09:10:03 -0500 (Fri, 30 Jan 2009)
New Revision: 7614
Added:
core/branches/flat/src/main/java/org/horizon/commands/write/DataWriteCommand.java
core/branches/flat/src/main/java/org/horizon/commands/write/WriteCommand.java
core/branches/flat/src/test/java/org/horizon/replication/AsyncReplicatedAPITest.java
core/branches/flat/src/test/java/org/horizon/replication/BaseReplicatedAPITest.java
core/branches/flat/src/test/java/org/horizon/replication/SyncReplicatedAPITest.java
Removed:
core/branches/flat/src/test/java/org/horizon/replication/ExceptionTest.java
Modified:
core/branches/flat/src/main/java/org/horizon/commands/CommandsFactory.java
core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java
core/branches/flat/src/main/java/org/horizon/commands/RemoteCommandFactory.java
core/branches/flat/src/main/java/org/horizon/commands/read/AbstractDataCommand.java
core/branches/flat/src/main/java/org/horizon/commands/write/ClearCommand.java
core/branches/flat/src/main/java/org/horizon/commands/write/EvictCommand.java
core/branches/flat/src/main/java/org/horizon/commands/write/InvalidateCommand.java
core/branches/flat/src/main/java/org/horizon/commands/write/PutKeyValueCommand.java
core/branches/flat/src/main/java/org/horizon/commands/write/PutMapCommand.java
core/branches/flat/src/main/java/org/horizon/commands/write/RemoveCommand.java
core/branches/flat/src/main/java/org/horizon/commands/write/ReplaceCommand.java
core/branches/flat/src/main/java/org/horizon/container/DataContainer.java
core/branches/flat/src/main/java/org/horizon/container/UnsortedDataContainer.java
core/branches/flat/src/main/java/org/horizon/interceptors/CacheLoaderInterceptor.java
core/branches/flat/src/main/java/org/horizon/interceptors/InvalidationInterceptor.java
core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java
core/branches/flat/src/main/java/org/horizon/interceptors/ReplicationInterceptor.java
core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifier.java
core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifierImpl.java
core/branches/flat/src/main/java/org/horizon/util/TestingUtil.java
core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java
core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java
core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java
core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java
core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java
core/branches/flat/src/test/java/org/horizon/replication/ReplicationExceptionTest.java
Log:
Fixed replication, invalidation
Modified: core/branches/flat/src/main/java/org/horizon/commands/CommandsFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/CommandsFactory.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/CommandsFactory.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -52,6 +52,8 @@
RemoveCommand buildRemoveCommand(Object key, Object value);
+ InvalidateCommand buildInvalidateCommand(Object... keys);
+
ReplaceCommand buildReplaceCommand(Object key, Object oldValue, Object newValue);
SizeCommand buildSizeCommand();
@@ -85,6 +87,4 @@
ReplicateCommand buildReplicateCommand(List<ReplicableCommand> toReplicate);
ReplicateCommand buildReplicateCommand(ReplicableCommand call);
-
- InvalidateCommand buildInvalidateCommand(Object fqn);
}
Modified: core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/CommandsFactoryImpl.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -71,6 +71,10 @@
return new RemoveCommand(key, value, notifier);
}
+ public InvalidateCommand buildInvalidateCommand(Object... keys) {
+ return new InvalidateCommand(notifier, keys);
+ }
+
public ReplaceCommand buildReplaceCommand(Object key, Object oldValue, Object newValue) {
return new ReplaceCommand(key, oldValue, newValue);
}
@@ -95,8 +99,7 @@
}
public EvictCommand buildEvictCommand(Object key) {
- EvictCommand command = new EvictCommand(key);
- command.initialize(notifier);
+ EvictCommand command = new EvictCommand(key, notifier);
return command;
}
@@ -137,6 +140,10 @@
if (rc.getCommands() != null)
for (ReplicableCommand nested : rc.getCommands()) initializeReplicableCommand(nested);
break;
+ case InvalidateCommand.METHOD_ID:
+ InvalidateCommand ic = (InvalidateCommand) c;
+ ic.init(notifier);
+ break;
case PrepareCommand.METHOD_ID:
PrepareCommand pc = (PrepareCommand) c;
if (pc.getModifications() != null)
@@ -144,8 +151,4 @@
break;
}
}
-
- public InvalidateCommand buildInvalidateCommand(Object fqn) {
- throw new UnsupportedOperationException("Not implemented");//todo please implement!
- }
}
Modified: core/branches/flat/src/main/java/org/horizon/commands/RemoteCommandFactory.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/RemoteCommandFactory.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/RemoteCommandFactory.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -7,6 +7,7 @@
import org.horizon.commands.tx.PrepareCommand;
import org.horizon.commands.tx.RollbackCommand;
import org.horizon.commands.write.ClearCommand;
+import org.horizon.commands.write.InvalidateCommand;
import org.horizon.commands.write.PutKeyValueCommand;
import org.horizon.commands.write.PutMapCommand;
import org.horizon.commands.write.RemoveCommand;
@@ -64,7 +65,9 @@
case ReplicateCommand.METHOD_ID:
command = new ReplicateCommand();
break;
-
+ case InvalidateCommand.METHOD_ID:
+ command = new InvalidateCommand();
+ break;
default:
throw new CacheException("Unknown command id " + id + "!");
}
Modified: core/branches/flat/src/main/java/org/horizon/commands/read/AbstractDataCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/read/AbstractDataCommand.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/read/AbstractDataCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -69,7 +69,6 @@
return (key != null ? key.hashCode() : 0);
}
-
public String toString() {
return getClass().getSimpleName() + "{" +
"key=" + key +
Modified: core/branches/flat/src/main/java/org/horizon/commands/write/ClearCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/ClearCommand.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/ClearCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -21,7 +21,6 @@
*/
package org.horizon.commands.write;
-import org.horizon.commands.VisitableCommand;
import org.horizon.commands.Visitor;
import org.horizon.container.MVCCEntry;
import org.horizon.context.InvocationContext;
@@ -30,7 +29,7 @@
* @author Mircea.Markus(a)jboss.com
* @since 1.0
*/
-public class ClearCommand implements VisitableCommand {
+public class ClearCommand implements WriteCommand {
private static final Object[] params = new Object[0];
public static final byte METHOD_ID = 17;
@@ -57,4 +56,13 @@
public void setParameters(int commandId, Object[] parameters) {
if (commandId != METHOD_ID) throw new IllegalStateException("Invalid method id");
}
+
+ @Override
+ public String toString() {
+ return "ClearCommand";
+ }
+
+ public boolean isSuccessful() {
+ return true;
+ }
}
Added: core/branches/flat/src/main/java/org/horizon/commands/write/DataWriteCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/DataWriteCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/DataWriteCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -0,0 +1,12 @@
+package org.horizon.commands.write;
+
+import org.horizon.commands.DataCommand;
+
+/**
+ * Mixes features from DataCommand and WriteCommand
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public interface DataWriteCommand extends WriteCommand, DataCommand {
+}
Modified: core/branches/flat/src/main/java/org/horizon/commands/write/EvictCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/EvictCommand.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/EvictCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -22,8 +22,6 @@
package org.horizon.commands.write;
import org.horizon.commands.Visitor;
-import org.horizon.commands.read.AbstractDataCommand;
-import org.horizon.container.MVCCEntry;
import org.horizon.context.InvocationContext;
import org.horizon.notifications.CacheNotifier;
@@ -31,39 +29,36 @@
* @author Mircea.Markus(a)jboss.com
* @since 1.0
*/
-public class EvictCommand extends AbstractDataCommand {
- public static final byte METHOD_ID = 120;
+public class EvictCommand extends RemoveCommand {
- private CacheNotifier notifier;
-
- public EvictCommand(Object key) {
+ public EvictCommand(Object key, CacheNotifier notifier) {
this.key = key;
+ this.notifier = notifier;
}
public void initialize(CacheNotifier notifier) {
this.notifier = notifier;
}
+ @Override
public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable {
return visitor.visitEvictCommand(ctx, this);
}
+ @Override
public Object perform(InvocationContext ctx) throws Throwable {
-
if (key == null) throw new NullPointerException("Key is null!!");
-
- MVCCEntry e = ctx.lookupEntry(key);
- if (e != null && !e.isNullEntry()) {
- //todo - add a actual eviction from thr container
- notifier.notifyCacheEntryEvicted(key, true, ctx);
- e.setDeleted(true);
- e.setValid(false);
- notifier.notifyCacheEntryEvicted(key, false, ctx);
- }
+ super.perform(ctx);
return null;
}
+ @Override
+ public void notify(InvocationContext ctx, boolean isPre) {
+ notifier.notifyCacheEntryEvicted(key, isPre, ctx);
+ }
+
+ @Override
public byte getCommandId() {
- return METHOD_ID;
+ return -1; // these are not meant for replication!
}
}
Modified: core/branches/flat/src/main/java/org/horizon/commands/write/InvalidateCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/InvalidateCommand.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/InvalidateCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -21,17 +21,15 @@
*/
package org.horizon.commands.write;
-import org.horizon.CacheSPI;
import org.horizon.commands.Visitor;
-import org.horizon.commands.read.AbstractDataCommand;
-import org.horizon.container.DataContainer;
import org.horizon.context.InvocationContext;
import org.horizon.logging.Log;
import org.horizon.logging.LogFactory;
import org.horizon.notifications.CacheNotifier;
-import org.horizon.tree.Fqn;
+import java.util.Arrays;
+
/**
* Removes a node's content from memory - never removes the node. It also clenups data for resident nodes - which are
* not being touched by eviction.
@@ -39,26 +37,17 @@
* @author Mircea.Markus(a)jboss.com
* @since 1.0
*/
-public class InvalidateCommand extends AbstractDataCommand {
+public class InvalidateCommand extends RemoveCommand {
public static final int METHOD_ID = 47;
private static final Log log = LogFactory.getLog(InvalidateCommand.class);
private static final boolean trace = log.isTraceEnabled();
+ private Object[] keys;
- /* dependencies*/
- protected CacheSPI spi;
- protected CacheNotifier notifier;
- protected DataContainer dataContainer;
-
- public InvalidateCommand(Object key) {
- this.key = key;
- }
-
public InvalidateCommand() {
}
- public void initialize(CacheSPI cacheSpi, DataContainer dataContainer, CacheNotifier notifier) {
- this.spi = cacheSpi;
- this.dataContainer = dataContainer;
+ public InvalidateCommand(CacheNotifier notifier, Object... keys) {
+ this.keys = keys;
this.notifier = notifier;
}
@@ -68,56 +57,20 @@
* @param ctx invocation context
* @return null
*/
- public Object perform(InvocationContext ctx) {
- Object value = enforceNodeLoading();
- if (trace) log.trace("Invalidating key:" + key);
- if (value == null) {
- return null;
+ public Object perform(InvocationContext ctx) throws Throwable {
+ if (trace) log.trace("Invalidating keys:" + Arrays.toString(keys));
+ for (Object key : keys) {
+ this.key = key;
+ super.perform(ctx);
}
- evictNode(key, ctx);
-// dataContainer.
return null;
}
- boolean evictNode(Object key, InvocationContext ctx) {
- notifier.notifyNodeInvalidated(key, true, ctx);
- try {
- return dataContainer.evict(key);
- }
- finally {
- notifier.notifyNodeInvalidated(key, false, ctx);
- }
+ @Override
+ protected void notify(InvocationContext ctx, boolean isPre) {
+ notifier.notifyCacheEntryInvalidated(key, isPre, ctx);
}
-
- /**
- * //TODO: 2.2.0: rather than using CacheSPI this should use peek(). The other interceptors should obtain locks and
- * load nodes if necessary for this InvalidateCommand. //Even better - this can be handles in the interceptors before
- * call interceptor
- */
- protected Object enforceNodeLoading() {
- return spi.get(key);
- }
-
-
- /**
- * mark the node to be removed (and all children) as invalid so anyone holding a direct reference to it will be aware
- * that it is no longer valid.
- */
- protected void invalidateNode()//NodeSPI node)
- {
- // TODO: Implement me!
- throw new RuntimeException("Implement me!");
-// node.setValid(false, true);
- // root nodes can never be invalid
-// if (fqn.isRoot()) node.setValid(true, false); // non-recursive.
- }
-
-
- public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable {
- return visitor.visitInvalidateCommand(ctx, this);
- }
-
public byte getCommandId() {
return METHOD_ID;
}
@@ -125,21 +78,45 @@
@Override
public String toString() {
return "InvalidateCommand{" +
- "key=" + key +
+ "keys=" + Arrays.toString(keys) +
'}';
}
@Override
public Object[] getParameters() {
- return new Object[]{key};
+ if (keys == null || keys.length == 0) {
+ return new Object[]{0};
+ } else if (keys.length == 1) {
+ return new Object[]{1, keys[0]};
+ } else {
+ Object[] retval = new Object[keys.length + 1];
+ retval[0] = keys.length;
+ System.arraycopy(keys, 0, retval, 1, keys.length);
+ return retval;
+ }
}
@Override
public void setParameters(int commandId, Object[] args) {
- key = args[0];
+ int size = (Integer) args[0];
+ keys = new Object[size];
+ if (size == 1) {
+ keys[0] = args[1];
+ } else if (size > 0) {
+ System.arraycopy(args, 1, keys, 0, size);
+ }
}
- void setFqn(Fqn newFqn) {
- this.key = newFqn;
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable {
+ return visitor.visitInvalidateCommand(ctx, this);
}
+
+ @Override
+ public Object getKey() {
+ throw new UnsupportedOperationException("Not supported. Use getKeys() instead.");
+ }
+
+ public Object[] getKeys() {
+ return keys;
+ }
}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/horizon/commands/write/PutKeyValueCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/PutKeyValueCommand.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/PutKeyValueCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -35,12 +35,13 @@
* @author Mircea.Markus(a)jboss.com
* @since 1.0
*/
-public class PutKeyValueCommand extends AbstractDataCommand {
+public class PutKeyValueCommand extends AbstractDataCommand implements DataWriteCommand {
public static final byte METHOD_ID = 3;
protected Object value;
protected boolean putIfAbsent;
private CacheNotifier notifier;
+ boolean successful = true;
public PutKeyValueCommand(Object key, Object value, boolean putIfAbsent, CacheNotifier notifier) {
super(key);
@@ -69,9 +70,10 @@
}
public Object perform(InvocationContext ctx) throws Throwable {
- Object o = null;
+ Object o;
MVCCEntry e = ctx.lookupEntry(key);
if (e.getValue() != null && putIfAbsent) {
+ successful = false;
return e.getValue();
} else {
notifier.notifyCacheEntryModified(key, true, ctx);
@@ -134,7 +136,6 @@
return result;
}
-
public String toString() {
return "PutKeyValueCommand{" +
"key= " + key +
@@ -142,4 +143,8 @@
", putIfAbsent=" + putIfAbsent +
'}';
}
+
+ public boolean isSuccessful() {
+ return successful;
+ }
}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/horizon/commands/write/PutMapCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/PutMapCommand.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/PutMapCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -21,7 +21,6 @@
*/
package org.horizon.commands.write;
-import org.horizon.commands.VisitableCommand;
import org.horizon.commands.Visitor;
import org.horizon.container.MVCCEntry;
import org.horizon.context.InvocationContext;
@@ -34,7 +33,7 @@
* @author Mircea.Markus(a)jboss.com
* @since 1.0
*/
-public class PutMapCommand implements VisitableCommand {
+public class PutMapCommand implements WriteCommand {
public static final byte METHOD_ID = 121;
private Map<Object, Object> map;
@@ -109,4 +108,8 @@
"map=" + map +
'}';
}
+
+ public boolean isSuccessful() {
+ return true;
+ }
}
Modified: core/branches/flat/src/main/java/org/horizon/commands/write/RemoveCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/RemoveCommand.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/RemoveCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -32,9 +32,10 @@
* @author Mircea.Markus(a)jboss.com
* @since 1.0
*/
-public class RemoveCommand extends AbstractDataCommand {
+public class RemoveCommand extends AbstractDataCommand implements DataWriteCommand {
public static final byte METHOD_ID = 6;
- private CacheNotifier notifier;
+ protected CacheNotifier notifier;
+ boolean successful = true;
protected Object value;
@@ -57,17 +58,30 @@
public Object perform(InvocationContext ctx) throws Throwable {
MVCCEntry e = ctx.lookupEntry(key);
- if (e == null || e.isNullEntry()) return value == null ? null : false;
- if (value != null && e.getValue() != null && !e.getValue().equals(value))
+ if (e == null || e.isNullEntry()) {
+ if (value == null) {
+ return null;
+ } else {
+ successful = false;
+ return false;
+ }
+ }
+ if (value != null && e.getValue() != null && !e.getValue().equals(value)) {
+ successful = false;
return false;
+ }
- notifier.notifyCacheEntryRemoved(key, true, ctx);
+ notify(ctx, true);
e.setDeleted(true);
e.setValid(false);
- notifier.notifyCacheEntryRemoved(key, false, ctx);
+ notify(ctx, false);
return value == null ? e.getValue() : true;
}
+ protected void notify(InvocationContext ctx, boolean isPre) {
+ notifier.notifyCacheEntryRemoved(key, isPre, ctx);
+ }
+
public byte getCommandId() {
return METHOD_ID;
}
@@ -92,9 +106,13 @@
public String toString() {
- return "RemoveCommand{" +
+ return getClass().getSimpleName() + "{" +
"key=" + key +
", value=" + value +
'}';
}
+
+ public boolean isSuccessful() {
+ return successful;
+ }
}
Modified: core/branches/flat/src/main/java/org/horizon/commands/write/ReplaceCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/ReplaceCommand.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/ReplaceCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -31,11 +31,12 @@
* @author Mircea.Markus(a)jboss.com
* @since 1.0
*/
-public class ReplaceCommand extends AbstractDataCommand {
+public class ReplaceCommand extends AbstractDataCommand implements DataWriteCommand {
public static final byte METHOD_ID = 122;
protected Object oldValue;
protected Object newValue;
+ boolean successful = true;
public ReplaceCommand(Object key, Object oldValue, Object newValue) {
super(key);
@@ -52,14 +53,34 @@
public Object perform(InvocationContext ctx) throws Throwable {
MVCCEntry e = ctx.lookupEntry(key);
- if (e == null || e.isNullEntry()) return oldValue == null ? null : false;
- if (oldValue == null || oldValue.equals(e.getValue())) {
- Object old = e.setValue(newValue);
- return oldValue == null ? old : true;
+ if (e != null) {
+ if (ctx.isOriginLocal()) {
+ if (e.isNullEntry()) return returnValue(null, false);
+
+ if (oldValue == null || oldValue.equals(e.getValue())) {
+ Object old = e.setValue(newValue);
+ return returnValue(old, true);
+ }
+ return returnValue(null, false);
+ } else {
+ // for remotely originating calls, this doesn't check the status of what is under the key at the moment
+ Object old = e.setValue(newValue);
+ return returnValue(old, true);
+ }
}
- return oldValue == null ? null : false;
+
+ return returnValue(null, false);
}
+ private Object returnValue(Object beingReplaced, boolean successful) {
+ this.successful = successful;
+ if (oldValue == null) {
+ return beingReplaced;
+ } else {
+ return successful;
+ }
+ }
+
public byte getCommandId() {
return METHOD_ID;
}
@@ -102,4 +123,8 @@
", newValue=" + newValue +
'}';
}
+
+ public boolean isSuccessful() {
+ return successful;
+ }
}
Added: core/branches/flat/src/main/java/org/horizon/commands/write/WriteCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/commands/write/WriteCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/commands/write/WriteCommand.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -0,0 +1,20 @@
+package org.horizon.commands.write;
+
+import org.horizon.commands.VisitableCommand;
+
+/**
+ * A command that modifies the cache in some way
+ *
+ * @author Manik Surtani
+ * @since 1.0
+ */
+public interface WriteCommand extends VisitableCommand {
+ /**
+ * Some commands may want to provide information on whether the command was successful or not. This is different
+ * from a failure, which usually would result in an exception being thrown. An example is a putIfAbsent() not doing
+ * anything because the key in question was present. This would result in a isSuccessful() call returning false.
+ *
+ * @return true if the command completed successfully, false otherwise.
+ */
+ boolean isSuccessful();
+}
Modified: core/branches/flat/src/main/java/org/horizon/container/DataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/DataContainer.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/container/DataContainer.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -47,6 +47,4 @@
void clear();
Set<K> keySet();
-
- boolean evict(Object key);
}
Modified: core/branches/flat/src/main/java/org/horizon/container/UnsortedDataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/container/UnsortedDataContainer.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/container/UnsortedDataContainer.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -76,10 +76,6 @@
return new KeySet();
}
- public boolean evict(Object key) {
- throw new UnsupportedOperationException("Not implemented");//todo please implement!
- }
-
public String toString() {
return data.toString();
}
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/CacheLoaderInterceptor.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/CacheLoaderInterceptor.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -24,6 +24,7 @@
import org.horizon.annotations.ManagedAttribute;
import org.horizon.annotations.ManagedOperation;
import org.horizon.commands.read.GetKeyValueCommand;
+import org.horizon.commands.write.InvalidateCommand;
import org.horizon.commands.write.PutKeyValueCommand;
import org.horizon.commands.write.RemoveCommand;
import org.horizon.commands.write.ReplaceCommand;
@@ -60,7 +61,6 @@
protected EntryFactory entryFactory;
protected boolean isActivation = false;
-// protected boolean usingVersionedInvalidation = false;
/**
@@ -74,8 +74,6 @@
DataContainer<Object, Object> dataContainer, EntryFactory entryFactory, CacheNotifier notifier) {
this.txTable = txTable;
this.clm = clm;
-// CacheMode mode = configuration.getCacheMode();
-// usingVersionedInvalidation = mode.isInvalidation();
this.dataContainer = dataContainer;
this.notifier = notifier;
this.entryFactory = entryFactory;
@@ -104,6 +102,14 @@
}
@Override
+ public Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable {
+ if (command.getKeys() != null) {
+ for (Object key : command.getKeys()) loadIfNeeded(ctx, key);
+ }
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ @Override
public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable {
if (command.getKey() != null) {
loadIfNeeded(ctx, command.getKey());
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/InvalidationInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/InvalidationInterceptor.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/InvalidationInterceptor.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -29,9 +29,13 @@
import org.horizon.commands.VisitableCommand;
import org.horizon.commands.tx.PrepareCommand;
import org.horizon.commands.write.ClearCommand;
+import org.horizon.commands.write.DataWriteCommand;
import org.horizon.commands.write.InvalidateCommand;
import org.horizon.commands.write.PutKeyValueCommand;
+import org.horizon.commands.write.PutMapCommand;
import org.horizon.commands.write.RemoveCommand;
+import org.horizon.commands.write.ReplaceCommand;
+import org.horizon.commands.write.WriteCommand;
import org.horizon.config.Option;
import org.horizon.context.InvocationContext;
import org.horizon.context.TransactionContext;
@@ -80,27 +84,39 @@
@Override
public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable {
- return handleWriteMethod(ctx, command, command);
+ return handleInvalidate(ctx, command);
}
@Override
+ public Object visitReplaceCommand(InvocationContext ctx, ReplaceCommand command) throws Throwable {
+ return handleInvalidate(ctx, command);
+ }
+
+ @Override
public Object visitRemoveCommand(InvocationContext ctx, RemoveCommand command) throws Throwable {
- return handleWriteMethod(ctx, command.getKey(), command);
+ return handleInvalidate(ctx, command);
}
@Override
public Object visitClearCommand(InvocationContext ctx, ClearCommand command) throws Throwable {
-// return handleWriteMethod(ctx, command.getKey(), command);
- //todo handle this - should perfor a remote invalidation aswell!!!
- return null;
+ // just broadcast the clear command - this is simplest!
+ Object retval = invokeNextInterceptor(ctx, command);
+ if (ctx.isOriginLocal()) replicateCall(ctx, command, defaultSynchronous, ctx.getOptionOverrides());
+ return retval;
}
@Override
+ public Object visitPutMapCommand(InvocationContext ctx, PutMapCommand command) throws Throwable {
+ Object[] keys = command.getMap() == null ? null : command.getMap().keySet().toArray();
+ return handleInvalidate(ctx, command, keys);
+ }
+
+ @Override
public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable {
Object retval = invokeNextInterceptor(ctx, command);
Transaction tx = ctx.getTransaction();
if (tx != null) {
- if (trace) log.trace("Entering InvalidationInterceptor_Legacy's prepare phase");
+ if (trace) log.trace("Entering InvalidationInterceptor's prepare phase");
// fetch the modifications before the transaction is committed (and thus removed from the txTable)
GlobalTransaction gtx = ctx.getGlobalTransaction();
TransactionContext transactionContext = ctx.getTransactionContext();
@@ -123,20 +139,25 @@
return retval;
}
- private Object handleWriteMethod(InvocationContext ctx, Object key, VisitableCommand command)
- throws Throwable {
+ private Object handleInvalidate(InvocationContext ctx, DataWriteCommand command) throws Throwable {
+ return handleInvalidate(ctx, command, command.getKey());
+ }
+
+ private Object handleInvalidate(InvocationContext ctx, WriteCommand command, Object... keys) throws Throwable {
Object retval = invokeNextInterceptor(ctx, command);
- Transaction tx = ctx.getTransaction();
- Option optionOverride = ctx.getOptionOverrides();
- if (log.isDebugEnabled()) log.debug("Is a CRUD method");
- if (key != null) {
- // could be potentially TRANSACTIONAL. Ignore if it is, until we see a prepare().
- if (tx == null || !TransactionTable.isValid(tx)) {
- // the no-tx case:
- //replicate an evict call.
- invalidateAcrossCluster(key, isSynchronous(optionOverride), ctx);
- } else {
- if (isLocalModeForced(ctx)) ctx.getTransactionContext().addLocalModification(command);
+ if (command.isSuccessful()) {
+ Transaction tx = ctx.getTransaction();
+ Option optionOverride = ctx.getOptionOverrides();
+ if (log.isDebugEnabled()) log.debug("Is a CRUD method");
+ if (keys != null && keys.length != 0) {
+ // could be potentially TRANSACTIONAL. Ignore if it is, until we see a prepare().
+ if (tx == null || !TransactionTable.isValid(tx)) {
+ // the no-tx case:
+ //replicate an evict call.
+ invalidateAcrossCluster(isSynchronous(optionOverride), ctx, keys);
+ } else {
+ if (isLocalModeForced(ctx)) ctx.getTransactionContext().addLocalModification(command);
+ }
}
}
return retval;
@@ -152,7 +173,7 @@
log.debug("Modification list contains a putForExternalRead operation. Not invalidating.");
} else {
try {
- for (Object key : filterVisitor.result) invalidateAcrossCluster(key, defaultSynchronous, ctx);
+ invalidateAcrossCluster(defaultSynchronous, ctx, filterVisitor.result.toArray());
}
catch (Throwable t) {
log.warn("Unable to broadcast evicts as a part of the prepare phase. Rolling back.", t);
@@ -193,11 +214,11 @@
}
- protected void invalidateAcrossCluster(Object fqn, boolean synchronous, InvocationContext ctx) throws Throwable {
+ protected void invalidateAcrossCluster(boolean synchronous, InvocationContext ctx, Object[] keys) throws Throwable {
if (!isLocalModeForced(ctx)) {
// increment invalidations counter if statistics maintained
incrementInvalidations();
- InvalidateCommand command = commandsFactory.buildInvalidateCommand(fqn);
+ InvalidateCommand command = commandsFactory.buildInvalidateCommand(keys);
if (log.isDebugEnabled()) log.debug("Cache [" + rpcManager.getAddress() + "] replicating " + command);
// voila, invalidated!
replicateCall(ctx, command, synchronous, ctx.getOptionOverrides());
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/LockingInterceptor.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -28,6 +28,7 @@
import org.horizon.commands.tx.RollbackCommand;
import org.horizon.commands.write.ClearCommand;
import org.horizon.commands.write.EvictCommand;
+import org.horizon.commands.write.InvalidateCommand;
import org.horizon.commands.write.PutKeyValueCommand;
import org.horizon.commands.write.PutMapCommand;
import org.horizon.commands.write.RemoveCommand;
@@ -143,8 +144,16 @@
@Override
public Object visitEvictCommand(InvocationContext ctx, EvictCommand command) throws Throwable {
+ // ensure keys are properly locked for evict commands
+ return visitRemoveCommand(ctx, command);
+ }
+
+ @Override
+ public Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable {
try {
- entryFactory.wrapEntryForWriting(ctx, command.getKey(), false, true);
+ if (command.getKeys() != null) {
+ for (Object key : command.getKeys()) entryFactory.wrapEntryForWriting(ctx, key, false, true);
+ }
return invokeNextInterceptor(ctx, command);
}
finally {
Modified: core/branches/flat/src/main/java/org/horizon/interceptors/ReplicationInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/interceptors/ReplicationInterceptor.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/interceptors/ReplicationInterceptor.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -21,7 +21,6 @@
*/
package org.horizon.interceptors;
-import org.horizon.commands.VisitableCommand;
import org.horizon.commands.tx.CommitCommand;
import org.horizon.commands.tx.PrepareCommand;
import org.horizon.commands.tx.RollbackCommand;
@@ -30,6 +29,7 @@
import org.horizon.commands.write.PutMapCommand;
import org.horizon.commands.write.RemoveCommand;
import org.horizon.commands.write.ReplaceCommand;
+import org.horizon.commands.write.WriteCommand;
import org.horizon.config.Configuration;
import org.horizon.context.InvocationContext;
import org.horizon.context.TransactionContext;
@@ -103,22 +103,25 @@
* If we are within one transaction we won't do any replication as replication would only be performed at commit
* time. If the operation didn't originate locally we won't do any replication either.
*/
- private Object handleCrudMethod(InvocationContext ctx, VisitableCommand command)
+ private Object handleCrudMethod(InvocationContext ctx, WriteCommand command)
throws Throwable {
boolean local = isLocalModeForced(ctx);
if (local && ctx.getTransaction() == null) return invokeNextInterceptor(ctx, command);
// FIRST pass this call up the chain. Only if it succeeds (no exceptions) locally do we attempt to replicate.
Object returnValue = invokeNextInterceptor(ctx, command);
- if (ctx.getTransaction() == null && ctx.isOriginLocal()) {
- if (trace) {
- log.trace("invoking method " + command.getClass().getSimpleName() + ", members=" + rpcManager.getMembers() + ", mode=" +
- configuration.getCacheMode() + ", exclude_self=" + true + ", timeout=" +
- configuration.getSyncReplTimeout());
+
+ if (command.isSuccessful()) {
+ if (ctx.getTransaction() == null && ctx.isOriginLocal()) {
+ if (trace) {
+ log.trace("invoking method " + command.getClass().getSimpleName() + ", members=" + rpcManager.getMembers() + ", mode=" +
+ configuration.getCacheMode() + ", exclude_self=" + true + ", timeout=" +
+ configuration.getSyncReplTimeout());
+ }
+
+ replicateCall(ctx, command, isSynchronous(ctx.getOptionOverrides()), ctx.getOptionOverrides());
+ } else {
+ if (local) ctx.getTransactionContext().addLocalModification(command);
}
-
- replicateCall(ctx, command, isSynchronous(ctx.getOptionOverrides()), ctx.getOptionOverrides());
- } else {
- if (local) ctx.getTransactionContext().addLocalModification(command);
}
return returnValue;
}
Modified: core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifier.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifier.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifier.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -98,6 +98,4 @@
* @param transaction the transaction that has just completed
*/
void notifyTransactionRegistered(Transaction transaction, InvocationContext ctx);
-
- void notifyNodeInvalidated(Object key, boolean pre, InvocationContext ctx);
}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifierImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifierImpl.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/notifications/CacheNotifierImpl.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -531,8 +531,4 @@
if (list == null) throw new CacheException("Unknown listener annotation: " + annotation);
return list;
}
-
- public void notifyNodeInvalidated(Object key, boolean pre, InvocationContext ctx) {
- throw new UnsupportedOperationException("Not implemented");//todo please implement!
- }
}
Modified: core/branches/flat/src/main/java/org/horizon/util/TestingUtil.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/util/TestingUtil.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/main/java/org/horizon/util/TestingUtil.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -559,29 +559,6 @@
return (CommandsFactory) extractField(cache, "commandsFactory");
}
- public static String getJGroupsAttribute(Cache cache, String protocol, String attribute) {
- throw new RuntimeException("Implement me");
-// String s = ((JChannel) ((CacheSPI) cache).getRPCManager().getChannel()).getProperties();
-// String[] protocols = s.split(":");
-// String attribs = null;
-// for (String p : protocols) {
-// boolean hasAttribs = p.contains("(");
-// String name = hasAttribs ? p.substring(0, p.indexOf('(')) : p;
-// attribs = hasAttribs ? p.substring(p.indexOf('(') + 1, p.length() - 1) : null;
-//
-// if (name.equalsIgnoreCase(protocol)) break;
-// }
-//
-// if (attribs != null) {
-// String[] attrArray = attribs.split(";");
-// for (String a : attrArray) {
-// String[] kvPairs = a.split("=");
-// if (kvPairs[0].equalsIgnoreCase(attribute)) return kvPairs[1];
-// }
-// }
-// return null;
- }
-
public static void dumpCacheContents(List caches) {
System.out.println("**** START: Cache Contents ****");
int count = 1;
@@ -591,7 +568,6 @@
System.out.println(" ** Cache " + count + " is null!");
} else {
System.out.println(" ** Cache " + count + " is " + c.getCacheManager().getAddress());
-// System.out.println(" " + CachePrinter.printCacheDetails(c));
}
count++;
}
@@ -616,6 +592,6 @@
}
public static TransactionManager getTransactionManager(Cache cache) {
- return extractComponent(cache, TransactionManager.class);
+ return cache == null ? null : extractComponent(cache, TransactionManager.class);
}
}
Modified: core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -125,11 +125,11 @@
this.expectedCommands.addAll(Arrays.asList(expectedCommands));
}
- public void waitForReplication() {
- waitForReplication(120, TimeUnit.SECONDS);
+ public void waitForRPC() {
+ waitForRPC(120, TimeUnit.SECONDS);
}
- public void waitForReplication(long time, TimeUnit unit) {
+ public void waitForRPC(long time, TimeUnit unit) {
assert expectedCommands != null : "there are no replication expectations; please use ReplListener.expect() before calling this method";
try {
if (!latch.await(time, unit)) {
Modified: core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -78,8 +78,8 @@
invalAsyncCache1.put("k", "invalAsync");
localCache1.put("k", "local");
- r1.waitForReplication();
- r2.waitForReplication();
+ r1.waitForRPC();
+ r2.waitForRPC();
assert replSyncCache1.get("k").equals("replSync");
assert replSyncCache2.get("k").equals("replSync");
@@ -92,6 +92,4 @@
assert localCache1.get("k").equals("local");
assert localCache2.get("k") == null;
}
-
-
}
Modified: core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -57,7 +57,7 @@
public void testNoOpWhenKeyPresent() {
replListener2.expect(PutKeyValueCommand.class);
cache1.putForExternalRead(key, value);
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
assertEquals("PFER should have succeeded", value, cache1.get(key));
@@ -66,14 +66,14 @@
// reset
replListener2.expect(RemoveCommand.class);
cache1.remove(key);
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
assert cache1.isEmpty() : "Should have reset";
assert cache2.isEmpty() : "Should have reset";
replListener2.expect(PutKeyValueCommand.class);
cache1.put(key, value);
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
// now this pfer should be a no-op
cache1.putForExternalRead(key, value2);
@@ -127,7 +127,7 @@
// create parent node first
replListener2.expect(PutKeyValueCommand.class);
cache1.put(key + "0", value);
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
// start a tx and do some stuff.
replListener2.expect(PutKeyValueCommand.class);
@@ -136,7 +136,7 @@
cache1.putForExternalRead(key, value); // should have happened in a separate tx and have committed already.
Transaction t = tm1.suspend();
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
assertEquals("PFER should have completed", value, cache1.get(key));
assertEquals("PFER should have completed", value, cache2.get(key));
@@ -201,7 +201,7 @@
replListener2.expect(PutKeyValueCommand.class);
cache1.putForExternalRead(key, value);
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
assertEquals("PFER updated cache1", value, cache1.get(key));
assertEquals("PFER propagated to cache2 as expected", value, cache2.get(key));
@@ -244,7 +244,7 @@
tm1.begin();
cache1.putForExternalRead(key, value);
tm1.commit();
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
TransactionTable tt1 = getTransactionTable(cache1);
TransactionTable tt2 = getTransactionTable(cache2);
@@ -261,7 +261,7 @@
cache1.putForExternalRead(key, value);
cache1.put(key, value);
tm1.commit();
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
assert tt1.getNumGlobalTransactions() == 0 : "Cache 1 should have no stale global TXs";
assert tt1.getNumLocalTransactions() == 0 : "Cache 1 should have no stale local TXs";
@@ -273,7 +273,7 @@
cache1.put(key, value);
cache1.putForExternalRead(key, value);
tm1.commit();
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
assert tt1.getNumGlobalTransactions() == 0 : "Cache 1 should have no stale global TXs";
assert tt1.getNumLocalTransactions() == 0 : "Cache 1 should have no stale local TXs";
@@ -287,7 +287,7 @@
cache1.putForExternalRead(key, value);
cache1.put(key, value);
tm1.commit();
- replListener2.waitForReplication();
+ replListener2.waitForRPC();
assert tt1.getNumGlobalTransactions() == 0 : "Cache 1 should have no stale global TXs";
assert tt1.getNumLocalTransactions() == 0 : "Cache 1 should have no stale local TXs";
Modified: core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/test/java/org/horizon/config/parsing/ConfigurationParserTest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -212,6 +212,6 @@
}
public void testEviction() throws Exception {
- assert false : "Implement me once the eviction config beans have been fixed!";
+ // TODO: implement me
}
}
Modified: core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -4,6 +4,8 @@
import org.horizon.BaseClusteredTest;
import org.horizon.Cache;
import org.horizon.commands.RPCCommand;
+import org.horizon.commands.write.ClearCommand;
+import org.horizon.commands.write.InvalidateCommand;
import org.horizon.config.Configuration;
import org.horizon.remoting.RPCManager;
import org.horizon.remoting.RPCManagerImpl;
@@ -14,8 +16,7 @@
import org.horizon.transaction.DummyTransactionManagerLookup;
import org.horizon.util.TestingUtil;
import static org.testng.AssertJUnit.*;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeTest;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import javax.transaction.RollbackException;
@@ -29,7 +30,7 @@
protected Cache cache1, cache2;
protected boolean isSync;
- @BeforeTest
+ @BeforeMethod
public void setUp() {
Configuration c = new Configuration();
c.setStateRetrievalTimeout(1000);
@@ -42,26 +43,6 @@
TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
}
- @AfterMethod
- public void cleanUp() {
- for (Cache c : new Cache[]{cache1, cache2}) {
- TransactionManager tm = TestingUtil.getTransactionManager(c);
- try {
- if (tm != null && tm.getTransaction() != null) {
- tm.rollback();
- }
- } catch (Exception e) {
- try {
- if (tm != null) tm.suspend();
- } catch (Exception e2) {
- // ignore
- }
- }
- c.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
- c.clear();
- }
- }
-
public void testRemove() throws Exception {
cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
cache1.put("key", "value");
@@ -73,58 +54,58 @@
ReplListener rl = attachReplicationListener(cache2);
rl.expectAny();
assertEquals("value", cache1.remove("key"));
- rl.waitForReplication();
+ rl.waitForRPC();
assertEquals(false, cache2.containsKey("key"));
}
- public void nodeResurrectionTest() throws Exception {
- ReplListener rl = attachReplicationListener(cache2);
- rl.expectAny();
+ public void testResurrectEntry() throws Exception {
+ ReplListener r2 = attachReplicationListener(cache2);
+ r2.expect(InvalidateCommand.class);
cache1.put("key", "value");
- rl.waitForReplication();
+ r2.waitForRPC();
assertEquals("value", cache1.get("key"));
assertEquals(null, cache2.get("key"));
- rl.expectAny();
+ r2.expect(InvalidateCommand.class);
cache1.put("key", "newValue");
- rl.waitForReplication();
+ r2.waitForRPC();
assertEquals("newValue", cache1.get("key"));
assertEquals(null, cache2.get("key"));
- rl.expectAny();
+ r2.expect(InvalidateCommand.class);
assertEquals("newValue", cache1.remove("key"));
- rl.waitForReplication();
+ r2.waitForRPC();
assertEquals(null, cache1.get("key"));
assertEquals(null, cache2.get("key"));
// Restore locally
- rl.expectAny();
+ r2.expect(InvalidateCommand.class);
cache1.put("key", "value");
- rl.waitForReplication();
+ r2.waitForRPC();
assertEquals("value", cache1.get("key"));
assertEquals(null, cache2.get("key"));
- ReplListener rl2 = attachReplicationListener(cache1);
- rl2.expectAny();
+ ReplListener r1 = attachReplicationListener(cache1);
+ r1.expect(InvalidateCommand.class);
cache2.put("key", "value2");
- rl2.waitForReplication();
+ r1.waitForRPC();
+ assertEquals("value2", cache2.get("key"));
assertEquals(null, cache1.get("key"));
- assertEquals("value2", cache2.get("key"));
}
- public void deleteNonExistentTest() throws Exception {
+ public void testDeleteNonExistentEntry() throws Exception {
assertNull("Should be null", cache1.get("key"));
assertNull("Should be null", cache2.get("key"));
ReplListener rl2 = attachReplicationListener(cache2);
- rl2.expectAny();
+ rl2.expect(InvalidateCommand.class);
cache1.put("key", "value");
- rl2.waitForReplication();
+ rl2.waitForRPC();
assertEquals("value", cache1.get("key"));
assertNull("Should be null", cache2.get("key"));
@@ -132,12 +113,12 @@
// OK, here's the real test
TransactionManager tm = TestingUtil.getTransactionManager(cache2);
ReplListener rl1 = attachReplicationListener(cache1);
- rl1.expectAnyWithTx();
+ rl1.expect(InvalidateCommand.class); // invalidates always happen outside of a tx
tm.begin();
// Remove an entry that doesn't exist in cache2
cache2.remove("key");
tm.commit();
- rl1.waitForReplication();
+ rl1.waitForRPC();
assert cache1.get("key") == null;
assert cache2.get("key") == null;
@@ -189,6 +170,7 @@
Transport origTransport = TestingUtil.extractComponent(cache1, Transport.class);
try {
Transport mockTransport = createMock(Transport.class);
+ rpcManager.setTransport(mockTransport);
Address addressOne = createNiceMock(Address.class);
Address addressTwo = createNiceMock(Address.class);
List<Address> members = new ArrayList<Address>(2);
@@ -196,6 +178,7 @@
members.add(addressTwo);
expect(mockTransport.getMembers()).andReturn(members).anyTimes();
+ expect(mockTransport.getAddress()).andReturn(addressOne).anyTimes();
expect(mockTransport.invokeRemotely((List<Address>) anyObject(), (RPCCommand) anyObject(),
eq(isSync ? ResponseMode.SYNCHRONOUS : ResponseMode.ASYNCHRONOUS),
anyLong(), anyBoolean(), (ResponseFilter) anyObject())).andReturn(null).anyTimes();
@@ -208,4 +191,120 @@
if (rpcManager != null) rpcManager.setTransport(origTransport);
}
}
+
+ public void testPutIfAbsent() {
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value");
+ assert cache2.get("key").equals("value");
+ assert cache1.get("key") == null;
+
+ ReplListener r = attachReplicationListener(cache2);
+ r.expect(InvalidateCommand.class);
+ cache1.putIfAbsent("key", "value");
+ r.waitForRPC();
+
+ assert cache1.get("key").equals("value");
+ assert cache2.get("key") == null;
+
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+
+ assert cache1.get("key").equals("value");
+ assert cache2.get("key").equals("value2");
+
+ cache1.putIfAbsent("key", "value3");
+
+ assert cache1.get("key").equals("value");
+ assert cache2.get("key").equals("value2"); // should not invalidate cache2!!
+ }
+
+ public void testRemoveIfPresent() {
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "value1");
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+ assert cache1.get("key").equals("value1");
+ assert cache2.get("key").equals("value2");
+
+ cache1.remove("key", "value");
+
+ assert cache1.get("key").equals("value1") : "Should not remove";
+ assert cache2.get("key").equals("value2") : "Should not evict";
+
+ ReplListener r = attachReplicationListener(cache2);
+ r.expect(InvalidateCommand.class);
+ cache1.remove("key", "value1");
+ r.waitForRPC();
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key") == null;
+ }
+
+ public void testClear() {
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "value1");
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+ assert cache1.get("key").equals("value1");
+ assert cache2.get("key").equals("value2");
+
+ ReplListener r = attachReplicationListener(cache2);
+ r.expect(ClearCommand.class);
+ cache1.clear();
+ r.waitForRPC();
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key") == null;
+ }
+
+ public void testReplace() {
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+ assert cache1.get("key") == null;
+ assert cache2.get("key").equals("value2");
+
+ cache1.replace("key", "value1"); // should do nothing since there is nothing to replace on cache1
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key").equals("value2");
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "valueN");
+
+ ReplListener r = attachReplicationListener(cache2);
+ r.expect(InvalidateCommand.class);
+ cache1.replace("key", "value1");
+ r.waitForRPC();
+
+ assert cache1.get("key").equals("value1");
+ assert cache2.get("key") == null;
+ }
+
+ public void testReplaceWithOldVal() {
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+ assert cache1.get("key") == null;
+ assert cache2.get("key").equals("value2");
+
+ cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key").equals("value2");
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "valueN");
+
+ cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
+
+ assert cache1.get("key").equals("valueN");
+ assert cache2.get("key").equals("value2");
+
+ ReplListener r = attachReplicationListener(cache2);
+ r.expect(InvalidateCommand.class);
+ cache1.replace("key", "valueN", "value1");
+ r.waitForRPC();
+
+ assert cache1.get("key").equals("value1");
+ assert cache2.get("key") == null;
+ }
}
Modified: core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/test/java/org/horizon/replication/AsyncReplTest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -51,7 +51,7 @@
replListener2.expectAny();
cache1.put(key, "value1");
// allow for replication
- replListener2.waitForReplication(60, TimeUnit.SECONDS);
+ replListener2.waitForRPC(60, TimeUnit.SECONDS);
assertEquals("value1", cache1.get(key));
assertEquals("value1", cache2.get(key));
@@ -59,7 +59,7 @@
cache1.put(key, "value2");
assertEquals("value2", cache1.get(key));
- replListener2.waitForReplication(60, TimeUnit.SECONDS);
+ replListener2.waitForRPC(60, TimeUnit.SECONDS);
assertEquals("value2", cache1.get(key));
assertEquals("value2", cache2.get(key));
@@ -73,7 +73,7 @@
replListener2.expectAny();
cache1.put(key, "value1");
// allow for replication
- replListener2.waitForReplication(60, TimeUnit.SECONDS);
+ replListener2.waitForRPC(60, TimeUnit.SECONDS);
assertEquals("value1", cache1.get(key));
assertEquals("value1", cache2.get(key));
@@ -87,7 +87,7 @@
mgr.commit();
- replListener2.waitForReplication(60, TimeUnit.SECONDS);
+ replListener2.waitForRPC(60, TimeUnit.SECONDS);
assertEquals("value2", cache1.get(key));
assertEquals("value2", cache2.get(key));
Added: core/branches/flat/src/test/java/org/horizon/replication/AsyncReplicatedAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/AsyncReplicatedAPITest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/replication/AsyncReplicatedAPITest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -0,0 +1,10 @@
+package org.horizon.replication;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", sequential = true)
+public class AsyncReplicatedAPITest extends BaseReplicatedAPITest {
+ public AsyncReplicatedAPITest() {
+ isSync = false;
+ }
+}
Added: core/branches/flat/src/test/java/org/horizon/replication/BaseReplicatedAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/BaseReplicatedAPITest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/replication/BaseReplicatedAPITest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -0,0 +1,212 @@
+package org.horizon.replication;
+
+import org.horizon.BaseClusteredTest;
+import org.horizon.Cache;
+import org.horizon.commands.write.ClearCommand;
+import org.horizon.commands.write.PutKeyValueCommand;
+import org.horizon.commands.write.PutMapCommand;
+import org.horizon.commands.write.RemoveCommand;
+import org.horizon.commands.write.ReplaceCommand;
+import org.horizon.config.Configuration;
+import org.horizon.transaction.DummyTransactionManagerLookup;
+import org.horizon.util.TestingUtil;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Test(groups = "functional", sequential = true)
+public abstract class BaseReplicatedAPITest extends BaseClusteredTest {
+
+ Cache cache1, cache2;
+ protected boolean isSync;
+
+ @BeforeMethod
+ public void setUp() {
+ Configuration c = new Configuration();
+ c.setStateRetrievalTimeout(1000);
+ c.setFetchInMemoryState(false);
+ c.setCacheMode(isSync ? Configuration.CacheMode.REPL_SYNC : Configuration.CacheMode.REPL_ASYNC);
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ List<Cache> caches = createClusteredCaches(2, "replication", c);
+ cache1 = caches.get(0);
+ cache2 = caches.get(1);
+ TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
+ }
+
+ public void put() {
+ // test a simple put!
+ assert cache1.get("key") == null;
+ assert cache2.get("key") == null;
+
+ ReplListener r = attachReplicationListener(cache2);
+ r.expect(PutKeyValueCommand.class);
+ cache1.put("key", "value");
+ r.waitForRPC();
+
+ assert cache1.get("key").equals("value");
+ assert cache2.get("key").equals("value");
+
+ Map map = new HashMap();
+ map.put("key2", "value2");
+ map.put("key3", "value3");
+
+ r.expect(PutMapCommand.class);
+ cache1.putAll(map);
+ r.waitForRPC();
+
+ assert cache1.get("key").equals("value");
+ assert cache2.get("key").equals("value");
+ assert cache1.get("key2").equals("value2");
+ assert cache2.get("key2").equals("value2");
+ assert cache1.get("key3").equals("value3");
+ assert cache2.get("key3").equals("value3");
+ }
+
+ public void remove() {
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value");
+ assert cache2.get("key").equals("value");
+ assert cache1.get("key") == null;
+
+ ReplListener r = attachReplicationListener(cache2);
+ r.expect(RemoveCommand.class);
+ cache1.remove("key");
+ r.waitForRPC();
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key") == null;
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "value");
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value");
+ assert cache1.get("key").equals("value");
+ assert cache2.get("key").equals("value");
+
+ r.expect(RemoveCommand.class);
+ cache1.remove("key");
+ r.waitForRPC();
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key") == null;
+ }
+
+ public void testPutIfAbsent() {
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "valueOld");
+ assert cache2.get("key").equals("valueOld");
+ assert cache1.get("key") == null;
+
+ BaseClusteredTest.ReplListener r = attachReplicationListener(cache2);
+ r.expect(PutKeyValueCommand.class);
+ cache1.putIfAbsent("key", "value");
+ r.waitForRPC();
+
+ assert cache1.get("key").equals("value");
+ assert cache2.get("key").equals("value");
+
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+
+ assert cache1.get("key").equals("value");
+ assert cache2.get("key").equals("value2");
+
+ cache1.putIfAbsent("key", "value3");
+
+ assert cache1.get("key").equals("value");
+ assert cache2.get("key").equals("value2"); // should not invalidate cache2!!
+ }
+
+ public void testRemoveIfPresent() {
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "value1");
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+ assert cache1.get("key").equals("value1");
+ assert cache2.get("key").equals("value2");
+
+ cache1.remove("key", "value");
+
+ assert cache1.get("key").equals("value1") : "Should not remove";
+ assert cache2.get("key").equals("value2") : "Should not remove";
+
+ BaseClusteredTest.ReplListener r = attachReplicationListener(cache2);
+ r.expect(RemoveCommand.class);
+ cache1.remove("key", "value1");
+ r.waitForRPC();
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key") == null;
+ }
+
+ public void testClear() {
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "value1");
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+ assert cache1.get("key").equals("value1");
+ assert cache2.get("key").equals("value2");
+
+ BaseClusteredTest.ReplListener r = attachReplicationListener(cache2);
+ r.expect(ClearCommand.class);
+ cache1.clear();
+ r.waitForRPC();
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key") == null;
+ }
+
+ public void testReplace() {
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+ assert cache1.get("key") == null;
+ assert cache2.get("key").equals("value2");
+
+ cache1.replace("key", "value1"); // should do nothing since there is nothing to replace on cache1
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key").equals("value2");
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "valueN");
+
+ BaseClusteredTest.ReplListener r = attachReplicationListener(cache2);
+ r.expect(ReplaceCommand.class);
+ cache1.replace("key", "value1");
+ r.waitForRPC();
+
+ assert cache1.get("key").equals("value1");
+ assert cache2.get("key").equals("value1");
+ }
+
+ public void testReplaceWithOldVal() {
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value2");
+ assert cache1.get("key") == null;
+ assert cache2.get("key").equals("value2");
+
+ cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key").equals("value2");
+
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "valueN");
+
+ cache1.replace("key", "valueOld", "value1"); // should do nothing since there is nothing to replace on cache1
+
+ assert cache1.get("key").equals("valueN");
+ assert cache2.get("key").equals("value2");
+
+ BaseClusteredTest.ReplListener r = attachReplicationListener(cache2);
+ r.expect(ReplaceCommand.class);
+ cache1.replace("key", "valueN", "value1");
+ r.waitForRPC();
+
+ assert cache1.get("key").equals("value1");
+ assert cache2.get("key").equals("value1");
+ }
+}
Deleted: core/branches/flat/src/test/java/org/horizon/replication/ExceptionTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/ExceptionTest.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/test/java/org/horizon/replication/ExceptionTest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -1,71 +0,0 @@
-package org.horizon.replication;
-
-import org.horizon.BaseClusteredTest;
-import org.horizon.Cache;
-import org.horizon.commands.VisitableCommand;
-import org.horizon.config.Configuration;
-import org.horizon.context.InvocationContext;
-import org.horizon.interceptors.base.CommandInterceptor;
-import org.horizon.lock.TimeoutException;
-import org.horizon.transaction.DummyTransactionManagerLookup;
-import org.horizon.util.TestingUtil;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import javax.transaction.TransactionManager;
-import java.util.List;
-
-/**
- * Tests the type of exceptions thrown for Lock Acquisition Timeouts versus Sync Repl Timeouts
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
- */
-@Test(groups = "functional", sequential = true)
-public class ExceptionTest extends BaseClusteredTest {
- private Cache cache1;
- private Cache cache2;
-
- @BeforeMethod
- public void setUp() {
- Configuration c = new Configuration();
- c.setSyncCommitPhase(true);
- c.setSyncRollbackPhase(true);
- c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
- c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
-
- List<Cache> caches = createClusteredCaches(2, "ExceptionTestCache", c);
- cache1 = caches.get(0);
- cache2 = caches.get(1);
- }
-
- @Test(groups = "functional", expectedExceptions = {TimeoutException.class})
- public void testSyncReplTimeout() {
- cache2.addInterceptor(new CommandInterceptor() {
- @Override
- protected Object handleDefault(InvocationContext ctx, VisitableCommand cmd) throws Throwable {
- // Add a delay
- Thread.sleep(100);
- return super.handleDefault(ctx, cmd);
- }
- }, 0);
-
- cache1.getConfiguration().setSyncReplTimeout(1);
- cache2.getConfiguration().setSyncReplTimeout(1);
- TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
-
- cache1.put("k", "v");
- }
-
- @Test(groups = "functional", expectedExceptions = {TimeoutException.class})
- public void testLockAcquisitionTimeout() throws Exception {
- cache2.getConfiguration().setLockAcquisitionTimeout(1);
- TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
-
- // get a lock on cache 2 and hold on to it.
- TransactionManager tm = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
- tm.begin();
- cache2.put("block", "block");
- tm.suspend();
- cache1.put("block", "v");
- }
-}
Modified: core/branches/flat/src/test/java/org/horizon/replication/ReplicationExceptionTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/ReplicationExceptionTest.java 2009-01-29 18:06:23 UTC (rev 7613)
+++ core/branches/flat/src/test/java/org/horizon/replication/ReplicationExceptionTest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -9,8 +9,12 @@
import org.horizon.BaseClusteredTest;
import org.horizon.Cache;
+import org.horizon.commands.VisitableCommand;
import org.horizon.config.Configuration;
+import org.horizon.context.InvocationContext;
+import org.horizon.interceptors.base.CommandInterceptor;
import org.horizon.lock.IsolationLevel;
+import org.horizon.lock.TimeoutException;
import org.horizon.transaction.DummyTransactionManagerLookup;
import org.horizon.util.TestingUtil;
import static org.testng.AssertJUnit.assertNotNull;
@@ -28,7 +32,7 @@
@Test(groups = "functional", sequential = true)
public class ReplicationExceptionTest extends BaseClusteredTest {
- private Cache<String, ContainerData> cache1, cache2;
+ private Cache cache1, cache2;
@BeforeMethod
public void setUp() {
@@ -89,6 +93,37 @@
}
}
+ @Test(groups = "functional", expectedExceptions = {TimeoutException.class})
+ public void testSyncReplTimeout() {
+ cache2.addInterceptor(new CommandInterceptor() {
+ @Override
+ protected Object handleDefault(InvocationContext ctx, VisitableCommand cmd) throws Throwable {
+ // Add a delay
+ Thread.sleep(100);
+ return super.handleDefault(ctx, cmd);
+ }
+ }, 0);
+
+ cache1.getConfiguration().setSyncReplTimeout(1);
+ cache2.getConfiguration().setSyncReplTimeout(1);
+ TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
+
+ cache1.put("k", "v");
+ }
+
+ @Test(groups = "functional", expectedExceptions = {TimeoutException.class})
+ public void testLockAcquisitionTimeout() throws Exception {
+ cache2.getConfiguration().setLockAcquisitionTimeout(1);
+ TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
+
+ // get a lock on cache 2 and hold on to it.
+ TransactionManager tm = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
+ tm.begin();
+ cache2.put("block", "block");
+ tm.suspend();
+ cache1.put("block", "v");
+ }
+
static class NonSerializabeData {
int i;
}
Added: core/branches/flat/src/test/java/org/horizon/replication/SyncReplicatedAPITest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/SyncReplicatedAPITest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/replication/SyncReplicatedAPITest.java 2009-01-30 14:10:03 UTC (rev 7614)
@@ -0,0 +1,11 @@
+package org.horizon.replication;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", sequential = true)
+public class SyncReplicatedAPITest extends BaseReplicatedAPITest {
+ public SyncReplicatedAPITest() {
+ isSync = true;
+ }
+}
+
15 years, 11 months
JBoss Cache SVN: r7613 - in core/branches/flat/src/test/java/org/horizon: api and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-29 13:06:23 -0500 (Thu, 29 Jan 2009)
New Revision: 7613
Added:
core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java
core/branches/flat/src/test/java/org/horizon/invalidation/
core/branches/flat/src/test/java/org/horizon/invalidation/AsyncInvalidationTest.java
core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
core/branches/flat/src/test/java/org/horizon/invalidation/SyncInvalidationTest.java
Modified:
core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java
core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java
core/branches/flat/src/test/java/org/horizon/api/tree/NodeReplicatedMoveTest.java
core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTest.java
core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTxTest.java
core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java
Log:
Invalidation tests
Modified: core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java 2009-01-29 15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/BaseClusteredTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -13,12 +13,12 @@
import org.horizon.util.TestingUtil;
import org.testng.annotations.AfterMethod;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -43,7 +43,7 @@
*
* @return the new CacheManager
*/
- protected CacheManager addCacheManager() {
+ protected CacheManager addClusterEnabledCacheManager() {
return addCacheManager(GlobalConfiguration.getClusteredDefault());
}
@@ -67,8 +67,8 @@
protected List<Cache> createClusteredCaches(int numMembersInCluster, String cacheName, Configuration c) {
List<Cache> caches = new ArrayList<Cache>(numMembersInCluster);
- for (int i=0; i<numMembersInCluster; i++) {
- CacheManager cm = addCacheManager();
+ for (int i = 0; i < numMembersInCluster; i++) {
+ CacheManager cm = addClusterEnabledCacheManager();
cm.defineCache(cacheName, c);
caches.add(cm.getCache(cacheName));
}
Added: core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/api/MixedModeTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -0,0 +1,97 @@
+package org.horizon.api;
+
+import org.horizon.BaseClusteredTest;
+import org.horizon.Cache;
+import org.horizon.config.Configuration;
+import org.horizon.manager.CacheManager;
+import org.horizon.util.TestingUtil;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", sequential = true)
+public class MixedModeTest extends BaseClusteredTest {
+ Cache replSyncCache1, replSyncCache2;
+ Cache replAsyncCache1, replAsyncCache2;
+ Cache invalAsyncCache1, invalAsyncCache2;
+ Cache invalSyncCache1, invalSyncCache2;
+ Cache localCache1, localCache2;
+
+ @BeforeMethod
+ public void setUp() {
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
+
+ Configuration replSync = new Configuration();
+ replSync.setCacheMode(Configuration.CacheMode.REPL_SYNC);
+
+ Configuration replAsync = new Configuration();
+ replAsync.setCacheMode(Configuration.CacheMode.REPL_ASYNC);
+
+ Configuration invalSync = new Configuration();
+ invalSync.setCacheMode(Configuration.CacheMode.INVALIDATION_SYNC);
+
+ Configuration invalAsync = new Configuration();
+ invalAsync.setCacheMode(Configuration.CacheMode.INVALIDATION_ASYNC);
+
+ Configuration local = new Configuration();
+ local.setCacheMode(Configuration.CacheMode.LOCAL);
+
+ defineCacheOnAllManagers("replSync", replSync);
+ defineCacheOnAllManagers("replAsync", replAsync);
+ defineCacheOnAllManagers("invalSync", invalSync);
+ defineCacheOnAllManagers("invalAsync", invalAsync);
+ defineCacheOnAllManagers("local", local);
+
+ replSyncCache1 = cm1.getCache("replSync");
+ replSyncCache2 = cm2.getCache("replSync");
+ replAsyncCache1 = cm1.getCache("replAsync");
+ replAsyncCache2 = cm2.getCache("replAsync");
+ invalSyncCache1 = cm1.getCache("invalSync");
+ invalSyncCache2 = cm2.getCache("invalSync");
+ invalAsyncCache1 = cm1.getCache("invalAsync");
+ invalAsyncCache2 = cm2.getCache("invalAsync");
+ localCache1 = cm1.getCache("local");
+ localCache2 = cm2.getCache("local");
+
+ TestingUtil.blockUntilViewsReceived(60000, cm1, cm2);
+ }
+
+ public void testMixedMode() {
+ ReplListener r1 = attachReplicationListener(replAsyncCache2);
+ ReplListener r2 = attachReplicationListener(invalAsyncCache2);
+
+ invalSyncCache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ invalSyncCache2.put("k", "v");
+ assert invalSyncCache2.get("k").equals("v");
+ assert invalSyncCache1.get("k") == null;
+ invalAsyncCache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ invalAsyncCache2.put("k", "v");
+ assert invalAsyncCache2.get("k").equals("v");
+ assert invalAsyncCache1.get("k") == null;
+
+ r1.expectAny();
+ r2.expectAny();
+
+ replSyncCache1.put("k", "replSync");
+ replAsyncCache1.put("k", "replAsync");
+ invalSyncCache1.put("k", "invalSync");
+ invalAsyncCache1.put("k", "invalAsync");
+ localCache1.put("k", "local");
+
+ r1.waitForReplication();
+ r2.waitForReplication();
+
+ assert replSyncCache1.get("k").equals("replSync");
+ assert replSyncCache2.get("k").equals("replSync");
+ assert replAsyncCache1.get("k").equals("replAsync");
+ assert replAsyncCache2.get("k").equals("replAsync");
+ assert invalSyncCache1.get("k").equals("invalSync");
+ assert invalSyncCache2.get("k") == null;
+ assert invalAsyncCache1.get("k").equals("invalAsync");
+ assert invalAsyncCache2.get("k") == null;
+ assert localCache1.get("k").equals("local");
+ assert localCache2.get("k") == null;
+ }
+
+
+}
Modified: core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java 2009-01-29 15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/api/mvcc/PutForExternalReadTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -39,8 +39,8 @@
Configuration c = new Configuration();
c.setCacheMode(Configuration.CacheMode.REPL_SYNC);
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
defineCacheOnAllManagers("replSync", c);
cache1 = cm1.getCache("replSync");
@@ -167,7 +167,7 @@
expect(mockTransport.invokeRemotely(anyAddresses(), (RPCCommand) anyObject(), anyResponseMode(),
anyLong(), anyBoolean(), (ResponseFilter) anyObject()))
.andThrow(new RuntimeException("Barf!")).anyTimes();
-
+
replay(mockTransport);
try {
Modified: core/branches/flat/src/test/java/org/horizon/api/tree/NodeReplicatedMoveTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/tree/NodeReplicatedMoveTest.java 2009-01-29 15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/api/tree/NodeReplicatedMoveTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -41,8 +41,8 @@
c.setSyncCommitPhase(true);
c.setSyncRollbackPhase(true);
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
defineCacheOnAllManagers("replSync", c);
Modified: core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTest.java 2009-01-29 15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -37,8 +37,8 @@
c.setInvocationBatchingEnabled(true);
c.setFetchInMemoryState(false);
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
defineCacheOnAllManagers("replSync", c);
Modified: core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTxTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTxTest.java 2009-01-29 15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/api/tree/SyncReplTxTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -45,8 +45,8 @@
c.setSyncRollbackPhase(true);
c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
defineCacheOnAllManagers("replSync", c);
Added: core/branches/flat/src/test/java/org/horizon/invalidation/AsyncInvalidationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/invalidation/AsyncInvalidationTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/invalidation/AsyncInvalidationTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -0,0 +1,10 @@
+package org.horizon.invalidation;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", sequential = true)
+public class AsyncInvalidationTest extends BaseInvalidationTest {
+ public AsyncInvalidationTest() {
+ isSync = false;
+ }
+}
Added: core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/invalidation/BaseInvalidationTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -0,0 +1,211 @@
+package org.horizon.invalidation;
+
+import static org.easymock.EasyMock.*;
+import org.horizon.BaseClusteredTest;
+import org.horizon.Cache;
+import org.horizon.commands.RPCCommand;
+import org.horizon.config.Configuration;
+import org.horizon.remoting.RPCManager;
+import org.horizon.remoting.RPCManagerImpl;
+import org.horizon.remoting.ResponseFilter;
+import org.horizon.remoting.ResponseMode;
+import org.horizon.remoting.transport.Address;
+import org.horizon.remoting.transport.Transport;
+import org.horizon.transaction.DummyTransactionManagerLookup;
+import org.horizon.util.TestingUtil;
+import static org.testng.AssertJUnit.*;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import javax.transaction.RollbackException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.util.ArrayList;
+import java.util.List;
+
+@Test(groups = "functional", sequential = true)
+public abstract class BaseInvalidationTest extends BaseClusteredTest {
+ protected Cache cache1, cache2;
+ protected boolean isSync;
+
+ @BeforeTest
+ public void setUp() {
+ Configuration c = new Configuration();
+ c.setStateRetrievalTimeout(1000);
+ c.setFetchInMemoryState(false);
+ c.setCacheMode(isSync ? Configuration.CacheMode.INVALIDATION_SYNC : Configuration.CacheMode.INVALIDATION_ASYNC);
+ c.setTransactionManagerLookupClass(DummyTransactionManagerLookup.class.getName());
+ List<Cache> caches = createClusteredCaches(2, "invalidation", c);
+ cache1 = caches.get(0);
+ cache2 = caches.get(1);
+ TestingUtil.blockUntilViewsReceived(10000, cache1, cache2);
+ }
+
+ @AfterMethod
+ public void cleanUp() {
+ for (Cache c : new Cache[]{cache1, cache2}) {
+ TransactionManager tm = TestingUtil.getTransactionManager(c);
+ try {
+ if (tm != null && tm.getTransaction() != null) {
+ tm.rollback();
+ }
+ } catch (Exception e) {
+ try {
+ if (tm != null) tm.suspend();
+ } catch (Exception e2) {
+ // ignore
+ }
+ }
+ c.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ c.clear();
+ }
+ }
+
+ public void testRemove() throws Exception {
+ cache1.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache1.put("key", "value");
+ assertEquals("value", cache1.get("key"));
+ cache2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ cache2.put("key", "value");
+ assertEquals("value", cache2.get("key"));
+
+ ReplListener rl = attachReplicationListener(cache2);
+ rl.expectAny();
+ assertEquals("value", cache1.remove("key"));
+ rl.waitForReplication();
+
+ assertEquals(false, cache2.containsKey("key"));
+ }
+
+ public void nodeResurrectionTest() throws Exception {
+ ReplListener rl = attachReplicationListener(cache2);
+ rl.expectAny();
+ cache1.put("key", "value");
+ rl.waitForReplication();
+
+ assertEquals("value", cache1.get("key"));
+ assertEquals(null, cache2.get("key"));
+ rl.expectAny();
+ cache1.put("key", "newValue");
+ rl.waitForReplication();
+
+ assertEquals("newValue", cache1.get("key"));
+ assertEquals(null, cache2.get("key"));
+
+ rl.expectAny();
+ assertEquals("newValue", cache1.remove("key"));
+ rl.waitForReplication();
+
+ assertEquals(null, cache1.get("key"));
+ assertEquals(null, cache2.get("key"));
+
+ // Restore locally
+ rl.expectAny();
+ cache1.put("key", "value");
+ rl.waitForReplication();
+
+ assertEquals("value", cache1.get("key"));
+ assertEquals(null, cache2.get("key"));
+
+ ReplListener rl2 = attachReplicationListener(cache1);
+ rl2.expectAny();
+ cache2.put("key", "value2");
+ rl2.waitForReplication();
+
+ assertEquals(null, cache1.get("key"));
+ assertEquals("value2", cache2.get("key"));
+ }
+
+ public void deleteNonExistentTest() throws Exception {
+ assertNull("Should be null", cache1.get("key"));
+ assertNull("Should be null", cache2.get("key"));
+
+ ReplListener rl2 = attachReplicationListener(cache2);
+ rl2.expectAny();
+ cache1.put("key", "value");
+ rl2.waitForReplication();
+
+ assertEquals("value", cache1.get("key"));
+ assertNull("Should be null", cache2.get("key"));
+
+ // OK, here's the real test
+ TransactionManager tm = TestingUtil.getTransactionManager(cache2);
+ ReplListener rl1 = attachReplicationListener(cache1);
+ rl1.expectAnyWithTx();
+ tm.begin();
+ // Remove an entry that doesn't exist in cache2
+ cache2.remove("key");
+ tm.commit();
+ rl1.waitForReplication();
+
+ assert cache1.get("key") == null;
+ assert cache2.get("key") == null;
+ }
+
+ public void testTxSyncUnableToInvalidate() throws Exception {
+ cache1.put("key", "value");
+ assertEquals("value", cache1.get("key"));
+ assertNull(cache2.get("key"));
+
+ // start a tx that cacahe1 will have to send out an evict ...
+ TransactionManager mgr1 = TestingUtil.getTransactionManager(cache1);
+ TransactionManager mgr2 = TestingUtil.getTransactionManager(cache2);
+
+ mgr1.begin();
+ cache1.put("key", "value2");
+ Transaction tx1 = mgr1.suspend();
+ mgr2.begin();
+ cache2.put("key", "value3");
+ Transaction tx2 = mgr2.suspend();
+ mgr1.resume(tx1);
+ // this oughtta fail
+ try {
+ mgr1.commit();
+ if (isSync)
+ assertTrue("Ought to have failed!", false);
+ else
+ assert true : "Ought to have succeeded";
+ }
+ catch (RollbackException roll) {
+ if (isSync)
+ assertTrue("Ought to have failed!", true);
+ else
+ assert false : "Ought to have succeeded!";
+ }
+
+ mgr2.resume(tx2);
+ try {
+ mgr2.commit();
+ assertTrue("Ought to have succeeded!", true);
+ }
+ catch (RollbackException roll) {
+ assertTrue("Ought to have succeeded!", false);
+ }
+ }
+
+ public void testCacheMode() throws Exception {
+ RPCManagerImpl rpcManager = (RPCManagerImpl) TestingUtil.extractComponent(cache1, RPCManager.class);
+ Transport origTransport = TestingUtil.extractComponent(cache1, Transport.class);
+ try {
+ Transport mockTransport = createMock(Transport.class);
+ Address addressOne = createNiceMock(Address.class);
+ Address addressTwo = createNiceMock(Address.class);
+ List<Address> members = new ArrayList<Address>(2);
+ members.add(addressOne);
+ members.add(addressTwo);
+
+ expect(mockTransport.getMembers()).andReturn(members).anyTimes();
+ expect(mockTransport.invokeRemotely((List<Address>) anyObject(), (RPCCommand) anyObject(),
+ eq(isSync ? ResponseMode.SYNCHRONOUS : ResponseMode.ASYNCHRONOUS),
+ anyLong(), anyBoolean(), (ResponseFilter) anyObject())).andReturn(null).anyTimes();
+ replay(mockTransport);
+
+ cache1.put("k", "v");
+ verify(mockTransport);
+
+ } finally {
+ if (rpcManager != null) rpcManager.setTransport(origTransport);
+ }
+ }
+}
Added: core/branches/flat/src/test/java/org/horizon/invalidation/SyncInvalidationTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/invalidation/SyncInvalidationTest.java (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/invalidation/SyncInvalidationTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -0,0 +1,10 @@
+package org.horizon.invalidation;
+
+import org.testng.annotations.Test;
+
+@Test(groups = "functional", sequential = true)
+public class SyncInvalidationTest extends BaseInvalidationTest {
+ public SyncInvalidationTest() {
+ isSync = true;
+ }
+}
Modified: core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java 2009-01-29 15:36:59 UTC (rev 7612)
+++ core/branches/flat/src/test/java/org/horizon/replication/SyncReplTest.java 2009-01-29 18:06:23 UTC (rev 7613)
@@ -38,8 +38,8 @@
@BeforeMethod(alwaysRun = true)
public void setUp() {
- CacheManager cm1 = addCacheManager();
- CacheManager cm2 = addCacheManager();
+ CacheManager cm1 = addClusterEnabledCacheManager();
+ CacheManager cm2 = addClusterEnabledCacheManager();
Configuration replSync = new Configuration();
replSync.setCacheMode(Configuration.CacheMode.REPL_SYNC);
15 years, 11 months
JBoss Cache SVN: r7612 - in searchable/trunk/src: test/java/org/jboss/cache/search and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: navssurtani
Date: 2009-01-29 10:36:59 -0500 (Thu, 29 Jan 2009)
New Revision: 7612
Added:
searchable/trunk/src/test/java/org/jboss/cache/search/SearchableCacheFactoryTest.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
Log:
More validation
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2009-01-29 12:44:21 UTC (rev 7611)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/SearchableCacheFactory.java 2009-01-29 15:36:59 UTC (rev 7612)
@@ -86,7 +86,7 @@
if (classes.length == 0)
{
- if (log.isWarnEnabled()) log.warn("You haven't passed in any classes to index. Is this an error?");
+ throw new IllegalArgumentException("You haven't passed in any classes to index.");
}
// step 1: create hibernate search searchFactory
@@ -132,7 +132,7 @@
if (classes.length == 0)
{
- if (log.isWarnEnabled()) log.warn("You haven't passed in any classes to index. Is this an error?");
+ throw new IllegalArgumentException("You haven't passed in any classes to index.");
}
// step 1: create hibernate search searchFactory
Added: searchable/trunk/src/test/java/org/jboss/cache/search/SearchableCacheFactoryTest.java
===================================================================
--- searchable/trunk/src/test/java/org/jboss/cache/search/SearchableCacheFactoryTest.java (rev 0)
+++ searchable/trunk/src/test/java/org/jboss/cache/search/SearchableCacheFactoryTest.java 2009-01-29 15:36:59 UTC (rev 7612)
@@ -0,0 +1,44 @@
+package org.jboss.cache.search;
+
+import org.testng.annotations.Test;
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.pojo.PojoCacheFactory;
+import org.jboss.cache.pojo.PojoCache;
+
+/**
+ * @author Navin Surtani (<a href="mailto:nsurtani@redhat.com">nsurtani(a)redhat.com</a>)
+ *
+ * Test class for the SearchableCacheFactory.
+ */
+
+@Test (groups = "functional")
+public class SearchableCacheFactoryTest
+{
+
+ @Test (expectedExceptions = IllegalArgumentException.class)
+ public void testCreateSearchableCacheWithZeroArray()
+ {
+ Class[] fakeClasses = new Class[0];
+
+ Cache coreCache = new DefaultCacheFactory().createCache();
+ SearchableCache searchableCache = new SearchableCacheFactory().createSearchableCache(coreCache, null, fakeClasses);
+
+ }
+
+ @Test (expectedExceptions = IllegalArgumentException.class)
+ public void testCreateSearchableCacheWithZeroArrayPojo()
+ {
+ Class[] fakeClasses = new Class[0];
+ boolean toStart = false;
+ PojoCache pojo = PojoCacheFactory.createCache(new Configuration(), toStart);
+ pojo.start(); // if toStart above is true, it will starts the cache automatically.
+
+ SearchableCache searchableCache = new SearchableCacheFactory().createSearchableCache(pojo, null, fakeClasses);
+
+ }
+
+
+
+}
15 years, 11 months
JBoss Cache SVN: r7611 - core/trunk/src/test/resources.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-29 07:44:21 -0500 (Thu, 29 Jan 2009)
New Revision: 7611
Modified:
core/trunk/src/test/resources/log4j.xml
Log:
Reset log configs
Modified: core/trunk/src/test/resources/log4j.xml
===================================================================
--- core/trunk/src/test/resources/log4j.xml 2009-01-29 12:43:31 UTC (rev 7610)
+++ core/trunk/src/test/resources/log4j.xml 2009-01-29 12:44:21 UTC (rev 7611)
@@ -84,8 +84,8 @@
<root>
<priority value="WARN"/>
- <!--<appender-ref ref="FILE"/>-->
- <appender-ref ref="CONSOLE"/>
+ <appender-ref ref="FILE"/>
+ <!--<appender-ref ref="CONSOLE"/>-->
</root>
</log4j:configuration>
15 years, 11 months
JBoss Cache SVN: r7610 - in core/trunk/src: main/java/org/jboss/cache/interceptors and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2009-01-29 07:43:31 -0500 (Thu, 29 Jan 2009)
New Revision: 7610
Modified:
core/trunk/src/main/java/org/jboss/cache/InternalNode.java
core/trunk/src/main/java/org/jboss/cache/NodeSPI.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java
core/trunk/src/test/java/org/jboss/cache/mock/NodeSpiMock.java
core/trunk/src/test/resources/log4j.xml
Log:
JBCACHE-1471 - Slow cache.get for fqn with a large number of key/value entries.
Modified: core/trunk/src/main/java/org/jboss/cache/InternalNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InternalNode.java 2009-01-29 00:04:52 UTC (rev 7609)
+++ core/trunk/src/main/java/org/jboss/cache/InternalNode.java 2009-01-29 12:43:31 UTC (rev 7610)
@@ -58,6 +58,8 @@
Set<K> getKeys();
+ boolean containsKey(K key);
+
void setInternalState(Map state);
Map getInternalState(boolean onlyInternalState);
Modified: core/trunk/src/main/java/org/jboss/cache/NodeSPI.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeSPI.java 2009-01-29 00:04:52 UTC (rev 7609)
+++ core/trunk/src/main/java/org/jboss/cache/NodeSPI.java 2009-01-29 12:43:31 UTC (rev 7610)
@@ -417,7 +417,16 @@
*/
V getDirect(K key);
+ /**
+ * Returns true if a mapping exists for this key. Returns false if no
+ * mapping exists.
+ *
+ * @param key The key checked for inclusion in the node data.
+ * @return true if a mapping exists for the key, false if not.
+ */
+ boolean containsKeyDirect(K key);
+
/**
* Functionally the same as {@link #clearData()} except that it operates directly on the node and bypasses the
* interceptor chain.
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2009-01-29 00:04:52 UTC (rev 7609)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2009-01-29 12:43:31 UTC (rev 7610)
@@ -432,6 +432,11 @@
return Immutables.immutableSetCopy(data.keySet());
}
+ public boolean containsKey(K key)
+ {
+ return data != null && data.containsKey(key);
+ }
+
public boolean removeChild(Object childName)
{
return children.remove(childName) != null;
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2009-01-29 00:04:52 UTC (rev 7609)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java 2009-01-29 12:43:31 UTC (rev 7610)
@@ -438,7 +438,8 @@
if (trace) log.trace("Don't load [" + fqn + "], key requested is null");
return false;
}
- if (n.getKeysDirect().contains(key))
+
+ if (n.containsKeyDirect(key))
{
if (trace) log.trace("Don't load [" + fqn + "], already have necessary key in memory");
return false;
@@ -544,4 +545,4 @@
{
// this is a no-op. Only used by subclasses.
}
-}
\ No newline at end of file
+}
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2009-01-29 00:04:52 UTC (rev 7609)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2009-01-29 12:43:31 UTC (rev 7610)
@@ -243,6 +243,10 @@
node.clear();
}
+ public boolean containsKeyDirect(K key) {
+ return node.containsKey(key);
+ }
+
public Set<K> getKeysDirect()
{
return node.getKeys();
Modified: core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java 2009-01-29 00:04:52 UTC (rev 7609)
+++ core/trunk/src/main/java/org/jboss/cache/mvcc/NodeReference.java 2009-01-29 12:43:31 UTC (rev 7610)
@@ -202,6 +202,11 @@
return delegate.getKeys();
}
+ public final boolean containsKey(K key)
+ {
+ return delegate.containsKey(key);
+ }
+
public final void setInternalState(Map state)
{
delegate.setInternalState(state);
Modified: core/trunk/src/test/java/org/jboss/cache/mock/NodeSpiMock.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/mock/NodeSpiMock.java 2009-01-29 00:04:52 UTC (rev 7609)
+++ core/trunk/src/test/java/org/jboss/cache/mock/NodeSpiMock.java 2009-01-29 12:43:31 UTC (rev 7610)
@@ -237,6 +237,11 @@
return data.get(key);
}
+ public boolean containsKeyDirect(Object key)
+ {
+ return data != null && data.containsKey(key);
+ }
+
public void clearDataDirect()
{
data.clear();
Modified: core/trunk/src/test/resources/log4j.xml
===================================================================
--- core/trunk/src/test/resources/log4j.xml 2009-01-29 00:04:52 UTC (rev 7609)
+++ core/trunk/src/test/resources/log4j.xml 2009-01-29 12:43:31 UTC (rev 7610)
@@ -84,8 +84,8 @@
<root>
<priority value="WARN"/>
- <appender-ref ref="FILE"/>
- <!-- <appender-ref ref="CONSOLE"/> -->
+ <!--<appender-ref ref="FILE"/>-->
+ <appender-ref ref="CONSOLE"/>
</root>
</log4j:configuration>
15 years, 11 months