Author: manik.surtani(a)jboss.com
Date: 2008-08-01 07:03:23 -0400 (Fri, 01 Aug 2008)
New Revision: 6479
Added:
core/trunk/src/main/java/org/jboss/cache/notifications/annotation/NodeInvalidated.java
core/trunk/src/main/java/org/jboss/cache/notifications/event/NodeInvalidatedEvent.java
core/trunk/src/test/java/org/jboss/cache/notifications/NotifyNodeInvalidatedTest.java
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/VersionedInvalidateCommand.java
core/trunk/src/main/java/org/jboss/cache/commands/write/InvalidateCommand.java
core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
core/trunk/src/main/java/org/jboss/cache/notifications/annotation/CacheListener.java
core/trunk/src/main/java/org/jboss/cache/notifications/event/Event.java
core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java
core/trunk/src/test/java/org/jboss/cache/notifications/EventLog.java
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java
core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
Log:
JBCACHE-86 - a NodeInvalidated callback to listeners
Modified:
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/VersionedInvalidateCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/VersionedInvalidateCommand.java 2008-08-01
09:04:40 UTC (rev 6478)
+++
core/trunk/src/main/java/org/jboss/cache/commands/legacy/write/VersionedInvalidateCommand.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -129,10 +129,10 @@
protected void removeData(NodeSPI n, InvocationContext ctx) throws CacheException
{
- notifier.notifyNodeEvicted(fqn, true, ctx);
+ notifier.notifyNodeInvalidated(fqn, true, ctx);
n.clearDataDirect();
n.setDataLoaded(false);
- notifier.notifyNodeEvicted(fqn, false, ctx);
+ notifier.notifyNodeInvalidated(fqn, false, ctx);
}
public DataVersion getDataVersion()
Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/InvalidateCommand.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/commands/write/InvalidateCommand.java 2008-08-01
09:04:40 UTC (rev 6478)
+++
core/trunk/src/main/java/org/jboss/cache/commands/write/InvalidateCommand.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -65,14 +65,14 @@
boolean evictNode(Fqn fqn, InvocationContext ctx)
{
- notifier.notifyNodeEvicted(fqn, true, ctx);
+ notifier.notifyNodeInvalidated(fqn, true, ctx);
try
{
return dataContainer.evict(fqn);
}
finally
{
- notifier.notifyNodeEvicted(fqn, false, ctx);
+ notifier.notifyNodeInvalidated(fqn, false, ctx);
}
}
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java 2008-08-01
09:04:40 UTC (rev 6478)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/Notifier.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -56,6 +56,11 @@
void notifyNodeEvicted(Fqn fqn, boolean pre, InvocationContext ctx);
/**
+ * Notifies all registered listeners of a nodeInvalidated event.
+ */
+ void notifyNodeInvalidated(Fqn fqn, boolean pre, InvocationContext ctx);
+
+ /**
* Notifies all registered listeners of a nodeLoaded event.
*/
void notifyNodeLoaded(Fqn fqn, boolean pre, Map data, InvocationContext ctx);
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2008-08-01
09:04:40 UTC (rev 6478)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/NotifierImpl.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -28,11 +28,12 @@
import org.jgroups.View;
import javax.transaction.Transaction;
+import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -55,31 +56,35 @@
private static final Class[] allowedMethodAnnotations =
{
CacheStarted.class, CacheStopped.class, CacheBlocked.class,
CacheUnblocked.class, NodeCreated.class, NodeRemoved.class, NodeVisited.class,
NodeModified.class, NodeMoved.class,
- NodeActivated.class, NodePassivated.class, NodeLoaded.class,
NodeEvicted.class, TransactionRegistered.class, TransactionCompleted.class,
ViewChanged.class, BuddyGroupChanged.class
+ NodeActivated.class, NodePassivated.class, NodeLoaded.class,
NodeEvicted.class, TransactionRegistered.class, TransactionCompleted.class,
ViewChanged.class, BuddyGroupChanged.class,
+ NodeInvalidated.class
};
private static final Class[] parameterTypes =
{
CacheStartedEvent.class, CacheStoppedEvent.class, CacheBlockedEvent.class,
CacheUnblockedEvent.class, NodeCreatedEvent.class, NodeRemovedEvent.class,
NodeVisitedEvent.class, NodeModifiedEvent.class, NodeMovedEvent.class,
- NodeActivatedEvent.class, NodePassivatedEvent.class,
NodeLoadedEvent.class, NodeEvictedEvent.class, TransactionRegisteredEvent.class,
TransactionCompletedEvent.class, ViewChangedEvent.class, BuddyGroupChangedEvent.class
+ NodeActivatedEvent.class, NodePassivatedEvent.class,
NodeLoadedEvent.class, NodeEvictedEvent.class, TransactionRegisteredEvent.class,
TransactionCompletedEvent.class, ViewChangedEvent.class, BuddyGroupChangedEvent.class,
+ NodeInvalidatedEvent.class
};
- private final List<ListenerInvocation> cacheStartedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> cacheStoppedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> cacheBlockedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> cacheUnblockedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> nodeCreatedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> nodeRemovedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> nodeVisitedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> nodeModifiedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> nodeMovedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> nodeActivatedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> nodePassivatedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> nodeLoadedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> nodeEvictedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> transactionRegisteredListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> transactionCompletedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> viewChangedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
- private final List<ListenerInvocation> buddyGroupChangedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
+ final Map<Class<? extends Annotation>, List<ListenerInvocation>>
listenersMap = new HashMap<Class<? extends Annotation>,
List<ListenerInvocation>>(32);
+ final List<ListenerInvocation> cacheStartedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheStoppedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheBlockedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> cacheUnblockedListeners = 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> nodeMovedListeners = 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> transactionRegisteredListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> transactionCompletedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> viewChangedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
+ final List<ListenerInvocation> buddyGroupChangedListeners = new
CopyOnWriteArrayList<ListenerInvocation>();
// final Map<Class, List<ListenerInvocation>> listenerInvocations = new
ConcurrentHashMap<Class, List<ListenerInvocation>>();
private Cache cache;
@@ -88,10 +93,29 @@
public NotifierImpl()
{
+ listenersMap.put(CacheStarted.class, cacheStartedListeners);
+ listenersMap.put(CacheStopped.class, cacheStoppedListeners);
+ listenersMap.put(CacheBlocked.class, cacheBlockedListeners);
+ listenersMap.put(CacheUnblocked.class, cacheUnblockedListeners);
+ listenersMap.put(NodeCreated.class, nodeCreatedListeners);
+ listenersMap.put(NodeRemoved.class, nodeRemovedListeners);
+ listenersMap.put(NodeVisited.class, nodeVisitedListeners);
+ listenersMap.put(NodeModified.class, nodeModifiedListeners);
+ listenersMap.put(NodeMoved.class, nodeMovedListeners);
+ listenersMap.put(NodeActivated.class, nodeActivatedListeners);
+ listenersMap.put(NodePassivated.class, nodePassivatedListeners);
+ listenersMap.put(NodeLoaded.class, nodeLoadedListeners);
+ listenersMap.put(NodeEvicted.class, nodeEvictedListeners);
+ listenersMap.put(TransactionRegistered.class, transactionRegisteredListeners);
+ listenersMap.put(TransactionCompleted.class, transactionCompletedListeners);
+ listenersMap.put(ViewChanged.class, viewChangedListeners);
+ listenersMap.put(BuddyGroupChanged.class, buddyGroupChangedListeners);
+ listenersMap.put(NodeInvalidated.class, nodeInvalidatedListeners);
}
public NotifierImpl(Cache cache)
{
+ this();
this.cache = cache;
}
@@ -120,6 +144,7 @@
*
* @param listener object to be considered as a listener.
*/
+ @SuppressWarnings("unchecked")
private void validateAndAddListenerInvocation(Object listener)
{
testListenerClassValidity(listener.getClass());
@@ -162,7 +187,7 @@
private void addListenerInvocation(Class annotation, ListenerInvocation li)
{
- List<ListenerInvocation> result = getListenersForAnnotation(annotation);
+ List<ListenerInvocation> result =
getListenerCollectionForAnnotation(annotation);
result.add(li);
}
@@ -179,7 +204,7 @@
private void removeListenerInvocation(Class annotation, Object listener)
{
if (listener == null) return;
- List<ListenerInvocation> l = getListenersForAnnotation(annotation);
+ List<ListenerInvocation> l = getListenerCollectionForAnnotation(annotation);
Set<Object> markedForRemoval = new HashSet<Object>();
for (ListenerInvocation li : l)
{
@@ -216,23 +241,10 @@
public Set<Object> getCacheListeners()
{
Set<Object> result = new HashSet<Object>();
- result.addAll(getListeningObjects(cacheStartedListeners));
- result.addAll(getListeningObjects(cacheStoppedListeners));
- result.addAll(getListeningObjects(cacheBlockedListeners));
- result.addAll(getListeningObjects(cacheUnblockedListeners));
- result.addAll(getListeningObjects(nodeCreatedListeners));
- result.addAll(getListeningObjects(nodeRemovedListeners));
- result.addAll(getListeningObjects(nodeVisitedListeners));
- result.addAll(getListeningObjects(nodeModifiedListeners));
- result.addAll(getListeningObjects(nodeMovedListeners));
- result.addAll(getListeningObjects(nodeActivatedListeners));
- result.addAll(getListeningObjects(nodePassivatedListeners));
- result.addAll(getListeningObjects(nodeLoadedListeners));
- result.addAll(getListeningObjects(nodeEvictedListeners));
- result.addAll(getListeningObjects(transactionRegisteredListeners));
- result.addAll(getListeningObjects(transactionCompletedListeners));
- result.addAll(getListeningObjects(viewChangedListeners));
- result.addAll(getListeningObjects(buddyGroupChangedListeners));
+ for (List<ListenerInvocation> list : listenersMap.values())
+ {
+ for (ListenerInvocation li : list) result.add(li.target);
+ }
return Collections.unmodifiableSet(result);
}
@@ -359,6 +371,25 @@
}
}
+ public void notifyNodeInvalidated(final Fqn fqn, final boolean pre, InvocationContext
ctx)
+ {
+ if (!nodeInvalidatedListeners.isEmpty())
+ {
+ final boolean originLocal = ctx.isOriginLocal();
+ Transaction tx = ctx.getTransaction();
+ InvocationContext backup = resetInvocationContext(ctx);
+ EventImpl e = new EventImpl();
+ e.setCache(cache);
+ e.setOriginLocal(originLocal);
+ e.setPre(pre);
+ e.setFqn(fqn);
+ e.setTransaction(tx);
+ e.setType(NODE_INVALIDATED);
+ for (ListenerInvocation listener : nodeInvalidatedListeners)
listener.invoke(e);
+ restoreInvocationContext(backup);
+ }
+ }
+
public void notifyNodeLoaded(Fqn fqn, boolean pre, Map data, InvocationContext ctx)
{
if (!nodeLoadedListeners.isEmpty())
@@ -619,174 +650,10 @@
}
- private List<ListenerInvocation> getListenersForAnnotation(Class annotation)
+ private List<ListenerInvocation> getListenerCollectionForAnnotation(Class<?
extends Annotation> annotation)
{
- if (annotation == CacheStarted.class)
- {
- return cacheStartedListeners;
- }
- else if (annotation == CacheStopped.class)
- {
- return cacheStoppedListeners;
- }
- else if (annotation == CacheBlocked.class)
- {
- return cacheBlockedListeners;
- }
- else if (annotation == CacheUnblocked.class)
- {
- return cacheUnblockedListeners;
- }
- else if (annotation == NodeCreated.class)
- {
- return nodeCreatedListeners;
- }
- else if (annotation == NodeRemoved.class)
- {
- return nodeRemovedListeners;
- }
- else if (annotation == NodeVisited.class)
- {
- return nodeVisitedListeners;
- }
- else if (annotation == NodeModified.class)
- {
- return nodeModifiedListeners;
- }
- else if (annotation == NodeMoved.class)
- {
- return nodeMovedListeners;
- }
- else if (annotation == NodeActivated.class)
- {
- return nodeActivatedListeners;
- }
- else if (annotation == NodePassivated.class)
- {
- return nodePassivatedListeners;
- }
- else if (annotation == NodeLoaded.class)
- {
- return nodeLoadedListeners;
- }
- else if (annotation == NodeEvicted.class)
- {
- return nodeEvictedListeners;
- }
- else if (annotation == TransactionRegistered.class)
- {
- return transactionRegisteredListeners;
- }
- else if (annotation == TransactionCompleted.class)
- {
- return transactionCompletedListeners;
- }
- else if (annotation == ViewChanged.class)
- {
- return viewChangedListeners;
- }
- else if (annotation == BuddyGroupChanged.class)
- {
- return buddyGroupChangedListeners;
- }
- else
- {
- throw new RuntimeException("Unknown listener class: " + annotation);
- }
+ List<ListenerInvocation> list = listenersMap.get(annotation);
+ if (list == null) throw new CacheException("Unknown listener annotation:
" + annotation);
+ return list;
}
-
- private Collection getListeningObjects(List<ListenerInvocation>
cacheStartedListeners)
- {
- Set result = new HashSet();
- for (ListenerInvocation li : cacheStartedListeners)
- {
- result.add(li.target);
- }
- return result;
- }
-
- public List<ListenerInvocation> getCacheStartedListeners()
- {
- return cacheStartedListeners;
- }
-
- public List<ListenerInvocation> getCacheStoppedListeners()
- {
- return cacheStoppedListeners;
- }
-
- public List<ListenerInvocation> getCacheBlockedListeners()
- {
- return cacheBlockedListeners;
- }
-
- public List<ListenerInvocation> getCacheUnblockedListeners()
- {
- return cacheUnblockedListeners;
- }
-
- public List<ListenerInvocation> getNodeCreatedListeners()
- {
- return nodeCreatedListeners;
- }
-
- public List<ListenerInvocation> getNodeRemovedListeners()
- {
- return nodeRemovedListeners;
- }
-
- public List<ListenerInvocation> getNodeVisitedListeners()
- {
- return nodeVisitedListeners;
- }
-
- public List<ListenerInvocation> getNodeModifiedListeners()
- {
- return nodeModifiedListeners;
- }
-
- public List<ListenerInvocation> getNodeMovedListeners()
- {
- return nodeMovedListeners;
- }
-
- public List<ListenerInvocation> getNodeActivatedListeners()
- {
- return nodeActivatedListeners;
- }
-
- public List<ListenerInvocation> getNodePassivatedListeners()
- {
- return nodePassivatedListeners;
- }
-
- public List<ListenerInvocation> getNodeLoadedListeners()
- {
- return nodeLoadedListeners;
- }
-
- public List<ListenerInvocation> getNodeEvictedListeners()
- {
- return nodeEvictedListeners;
- }
-
- public List<ListenerInvocation> getTransactionRegisteredListeners()
- {
- return transactionRegisteredListeners;
- }
-
- public List<ListenerInvocation> getTransactionCompletedListeners()
- {
- return transactionCompletedListeners;
- }
-
- public List<ListenerInvocation> getViewChangedListeners()
- {
- return viewChangedListeners;
- }
-
- public List<ListenerInvocation> getBuddyGroupChangedListeners()
- {
- return buddyGroupChangedListeners;
- }
}
Modified:
core/trunk/src/main/java/org/jboss/cache/notifications/annotation/CacheListener.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/notifications/annotation/CacheListener.java 2008-08-01
09:04:40 UTC (rev 6478)
+++
core/trunk/src/main/java/org/jboss/cache/notifications/annotation/CacheListener.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -152,6 +152,11 @@
* <td valign=@"top">{@link
org.jboss.cache.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 it's membership.</td>
* </tr>
+ * <tr>
+ * <td valign="top">{@link NodeInvalidated}</td>
+ * <td valign=@"top">{@link
org.jboss.cache.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>
* <p/>
* </table>
* <p/>
@@ -283,12 +288,10 @@
* @see TransactionCompleted
* @see TransactionRegistered
* @see BuddyGroupChanged
+ * @see NodeInvalidated
* @see org.jboss.cache.Cache#addCacheListener(Object)
- * @see org.jboss.cache.Cache#addCacheListener(org.jboss.cache.Fqn,Object)
* @see org.jboss.cache.Cache#removeCacheListener(Object)
- * @see org.jboss.cache.Cache#removeCacheListener(org.jboss.cache.Fqn,Object)
* @see org.jboss.cache.Cache#getCacheListeners()
- * @see org.jboss.cache.Cache#getCacheListeners(org.jboss.cache.Fqn)
* @since 2.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
Copied:
core/trunk/src/main/java/org/jboss/cache/notifications/annotation/NodeInvalidated.java
(from rev 6476,
core/trunk/src/main/java/org/jboss/cache/notifications/annotation/NodeEvicted.java)
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/notifications/annotation/NodeInvalidated.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/notifications/annotation/NodeInvalidated.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -0,0 +1,23 @@
+package org.jboss.cache.notifications.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation should be used on methods that need to be notified when a node is
invalidated.
+ * <p/>
+ * Methods annotated with this annotation should be public and take in a single
parameter, a {@link org.jboss.cache.notifications.event.NodeInvalidatedEvent}
+ * otherwise an {@link org.jboss.cache.notifications.IncorrectCacheListenerException}
will be thrown when registering
+ * your cache listener.
+ *
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ * @see org.jboss.cache.notifications.annotation.CacheListener
+ * @since 3.0
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.METHOD)
+public @interface NodeInvalidated
+{
+}
\ No newline at end of file
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/event/Event.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/event/Event.java 2008-08-01
09:04:40 UTC (rev 6478)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/event/Event.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -14,7 +14,7 @@
{
CACHE_STARTED, CACHE_STOPPED, CACHE_BLOCKED, CACHE_UNBLOCKED, NODE_ACTIVATED,
NODE_PASSIVATED,
NODE_LOADED, NODE_EVICTED, NODE_CREATED, NODE_REMOVED, NODE_MODIFIED, NODE_MOVED,
NODE_VISITED,
- TRANSACTION_COMPLETED, TRANSACTION_REGISTERED, VIEW_CHANGED, BUDDY_GROUP_CHANGED
+ TRANSACTION_COMPLETED, TRANSACTION_REGISTERED, VIEW_CHANGED, BUDDY_GROUP_CHANGED,
NODE_INVALIDATED
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java 2008-08-01
09:04:40 UTC (rev 6478)
+++ core/trunk/src/main/java/org/jboss/cache/notifications/event/EventImpl.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -17,7 +17,7 @@
public class EventImpl implements CacheBlockedEvent, CacheUnblockedEvent,
CacheStartedEvent, CacheStoppedEvent,
NodeActivatedEvent, NodeCreatedEvent, NodeEvictedEvent, NodeLoadedEvent,
NodeModifiedEvent, NodeMovedEvent,
NodePassivatedEvent, NodeRemovedEvent, NodeVisitedEvent, TransactionCompletedEvent,
TransactionRegisteredEvent,
- ViewChangedEvent, BuddyGroupChangedEvent
+ ViewChangedEvent, BuddyGroupChangedEvent, NodeInvalidatedEvent
{
private boolean pre = false; // by default events are after the fact
private Cache cache;
Added:
core/trunk/src/main/java/org/jboss/cache/notifications/event/NodeInvalidatedEvent.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/notifications/event/NodeInvalidatedEvent.java
(rev 0)
+++
core/trunk/src/main/java/org/jboss/cache/notifications/event/NodeInvalidatedEvent.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -0,0 +1,11 @@
+package org.jboss.cache.notifications.event;
+
+/**
+ * Notifies a listener of an invalidation event
+ *
+ * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
+ * @since 3.0
+ */
+public interface NodeInvalidatedEvent extends NodeEvent
+{
+}
Modified: core/trunk/src/test/java/org/jboss/cache/notifications/EventLog.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/EventLog.java 2008-08-01
09:04:40 UTC (rev 6478)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/EventLog.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -1,6 +1,17 @@
package org.jboss.cache.notifications;
-import org.jboss.cache.notifications.annotation.*;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeActivated;
+import org.jboss.cache.notifications.annotation.NodeCreated;
+import org.jboss.cache.notifications.annotation.NodeEvicted;
+import org.jboss.cache.notifications.annotation.NodeInvalidated;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.annotation.NodeMoved;
+import org.jboss.cache.notifications.annotation.NodePassivated;
+import org.jboss.cache.notifications.annotation.NodeRemoved;
+import org.jboss.cache.notifications.annotation.NodeVisited;
+import org.jboss.cache.notifications.annotation.TransactionCompleted;
+import org.jboss.cache.notifications.annotation.TransactionRegistered;
import org.jboss.cache.notifications.event.Event;
import org.jboss.cache.notifications.event.EventImpl;
@@ -22,6 +33,7 @@
@NodeEvicted
@NodePassivated
@NodeActivated
+ @NodeInvalidated
public void callback(Event e)
{
events.add(e);
Modified:
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java 2008-08-01
09:04:40 UTC (rev 6478)
+++
core/trunk/src/test/java/org/jboss/cache/notifications/NotifierAnnotationsTest.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -180,9 +180,9 @@
{
Object l = new TestMultipleMethodsListener();
n.addCacheListener(l);
- List invocations = n.getCacheStartedListeners();
+ List invocations = n.cacheStartedListeners;
assertEquals(1, invocations.size());
- invocations = n.getCacheStoppedListeners();
+ invocations = n.cacheStoppedListeners;
assertEquals(1, invocations.size());
assertEquals(1, n.getCacheListeners().size());
}
@@ -191,9 +191,9 @@
{
Object l = new TestMultipleAnnotationsOneMethodListener();
n.addCacheListener(l);
- List invocations = n.getCacheStartedListeners();
+ List invocations = n.cacheStartedListeners;
assertEquals(1, invocations.size());
- invocations = n.getCacheStoppedListeners();
+ invocations = n.cacheStoppedListeners;
assertEquals(1, invocations.size());
assertEquals(1, n.getCacheListeners().size());
}
@@ -202,7 +202,7 @@
{
Object l = new TestMultipleMethodsOneAnnotationListener();
n.addCacheListener(l);
- List invocations = n.getCacheStartedListeners();
+ List invocations = n.cacheStartedListeners;
assertEquals(2, invocations.size());
assertEquals(1, n.getCacheListeners().size());
}
Modified: core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java 2008-08-01
09:04:40 UTC (rev 6478)
+++ core/trunk/src/test/java/org/jboss/cache/notifications/NotifierTest.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -63,7 +63,6 @@
Map expected = new HashMap();
expected.put("k", "v");
notifier.notifyNodeModified(fqn, true, NodeModifiedEvent.ModificationType.PUT_DATA,
expected, ctx);
- assert notifier.getNodeModifiedListeners().size() == 1;
assert allEventsListener.nodeModifiedEvent != null;
assert allEventsListener.nodeModifiedEvent.getData().equals(expected);
assert allEventsListener.nodeModifiedEvent.getModificationType() ==
NodeModifiedEvent.ModificationType.PUT_DATA;
Added:
core/trunk/src/test/java/org/jboss/cache/notifications/NotifyNodeInvalidatedTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/notifications/NotifyNodeInvalidatedTest.java
(rev 0)
+++
core/trunk/src/test/java/org/jboss/cache/notifications/NotifyNodeInvalidatedTest.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -0,0 +1,49 @@
+package org.jboss.cache.notifications;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.config.Configuration.NodeLockingScheme;
+import org.jboss.cache.factories.UnitTestCacheConfigurationFactory;
+import org.jboss.cache.notifications.event.Event;
+import static org.jboss.cache.notifications.event.Event.Type.NODE_INVALIDATED;
+import org.jboss.cache.notifications.event.EventImpl;
+import org.jboss.cache.util.TestingUtil;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Test(groups = "functional")
+public class NotifyNodeInvalidatedTest
+{
+ public void testInvalidatedCallback() throws CloneNotSupportedException
+ {
+ Cache<String, String> c1 = null, c2 = null;
+ try
+ {
+ Configuration cfg =
UnitTestCacheConfigurationFactory.createConfiguration(CacheMode.INVALIDATION_SYNC,
false);
+ cfg.setNodeLockingScheme(NodeLockingScheme.MVCC);
+ c1 = new DefaultCacheFactory<String, String>().createCache(cfg.clone());
+ c2 = new DefaultCacheFactory<String, String>().createCache(cfg.clone());
+ EventLog eventLog = new EventLog();
+ c2.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
+ c2.put("/a/b/c", "x", "y");
+ c2.addCacheListener(eventLog);
+ c1.put("/a/b/c", "k", "v");
+
+ List<Event> expected = new ArrayList<Event>();
+ expected.add(new EventImpl(true, c2, null, null,
Fqn.fromString("/a/b/c"), null, false, null, false, null, NODE_INVALIDATED));
+ expected.add(new EventImpl(false, c2, null, null,
Fqn.fromString("/a/b/c"), null, false, null, false, null, NODE_INVALIDATED));
+
+ assert expected.equals(eventLog.events) : "Expected " + expected +
" but got " + eventLog.events;
+ assert c2.getNode("/a/b/c") == null;
+ }
+ finally
+ {
+ TestingUtil.killCaches(c1, c2);
+ }
+ }
+}
Modified:
core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java 2008-08-01
09:04:40 UTC (rev 6478)
+++
core/trunk/src/test/java/org/jboss/cache/notifications/RemoteCacheListenerTest.java 2008-08-01
11:03:23 UTC (rev 6479)
@@ -63,7 +63,7 @@
private Cache<String, String> cache1, cache2;
@SuppressWarnings("unused")
- private TransactionManager tm1, tm2;
+ private TransactionManager tm1;
private EventLog eventLog1 = new EventLog(), eventLog2 = new EventLog();
private Fqn fqn = Fqn.fromString("/test");
@@ -95,7 +95,6 @@
cache2.addCacheListener(eventLog2);
tm1 = cache1.getConfiguration().getRuntimeConfig().getTransactionManager();
- tm2 = cache2.getConfiguration().getRuntimeConfig().getTransactionManager();
}
@AfterMethod(alwaysRun = true)