[jbosscache-commits] JBoss Cache SVN: r6874 - in core/branches/flat/src/main/java/org/jboss/starobrno: notifier and 1 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Wed Oct 8 10:00:30 EDT 2008
Author: mircea.markus
Date: 2008-10-08 10:00:29 -0400 (Wed, 08 Oct 2008)
New Revision: 6874
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/notifier/
core/branches/flat/src/main/java/org/jboss/starobrno/notifier/Notifier.java
core/branches/flat/src/main/java/org/jboss/starobrno/notifier/event/
core/branches/flat/src/main/java/org/jboss/starobrno/notifier/event/NodeModifiedEvent.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
Log:
_____ ____ ____
\/__/\ \ \ \L\ \\ \ \/\_\
_\ \ \ \ _ <'\ \ \/_/_
/\ \_\ \ \ \L\ \\ \ \L\ \
\ \____/\ \____/ \ \____/
\/___/ \/___/ \/___/
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-08 13:59:44 UTC (rev 6873)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-08 14:00:29 UTC (rev 6874)
@@ -21,9 +21,16 @@
*/
package org.jboss.starobrno;
-import org.jboss.cache.config.Configuration;
import org.jboss.starobrno.context.InvocationContext;
import org.jboss.starobrno.invocation.InvocationContextContainer;
+import org.jboss.starobrno.commands.CommandsFactory;
+import org.jboss.starobrno.commands.read.SizeCommand;
+import org.jboss.starobrno.commands.read.GetKeyValueCommand;
+import org.jboss.starobrno.commands.write.*;
+import org.jboss.starobrno.interceptors.InterceptorChain;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.notifier.Notifier;
+import org.jboss.util.NotImplementedException;
import java.util.Collection;
import java.util.Map;
@@ -35,49 +42,53 @@
public class CacheDelegate implements Cache
{
protected InvocationContextContainer invocationContextContainer;
+ protected CommandsFactory commandsFactory;
+ protected InterceptorChain invoker;
+ protected Configuration config;
+ protected Notifier notifier;
public Object putIfAbsent(Object key, Object value)
{
- // PutKeyValueCommand
- InvocationContext ctx = invocationContextContainer.get();
-
- return null;
+ PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value);
+ command.setPutIfAbsent(true);
+ return invoker.invoke(buildCtx(), command);
}
public boolean remove(Object key, Object value)
{
- // RemoveCommand
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ RemoveCommand command = commandsFactory.buildRemoveCommand(key, value);
+ return (Boolean)invoker.invoke(buildCtx(), command);
}
public boolean replace(Object key, Object oldValue, Object newValue)
{
- // ReplaceCommand
- return false;
+ ReplaceCommand command = commandsFactory.buildReplaceCommand(key, oldValue, newValue);
+ return (Boolean)invoker.invoke(buildCtx(), command);
}
public Object replace(Object key, Object value)
{
- // ReplaceCommand
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ ReplaceCommand command = commandsFactory.buildReplaceCommand(key, value, null);
+ return invoker.invoke(buildCtx(), command);
}
public int size()
{
- // SizeCommand
- return 0; //To change body of implemented methods use File | Settings | File Templates.
+ SizeCommand command = commandsFactory.buildSizeCommand();
+ return (Integer) invoker.invoke(buildCtx(), command);
}
public boolean isEmpty()
{
- // SizeCommand
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ SizeCommand command = commandsFactory.buildSizeCommand();
+ int size = (Integer) invoker.invoke(buildCtx(), command);
+ return size == 0;
}
public boolean containsKey(Object key)
{
- // GetKeyValueCommand
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key);
+ return (Boolean) invoker.invoke(buildCtx(), command);
}
public boolean containsValue(Object value)
@@ -87,32 +98,32 @@
public Object get(Object key)
{
- // GetKeyValueCommand
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key);
+ return invoker.invoke(buildCtx(), command);
}
public Object put(Object key, Object value)
{
- // PutKeyValueCommand
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ PutKeyValueCommand command = commandsFactory.buildPutKeyValueCommand(key, value);
+ return invoker.invoke(buildCtx(), command);
}
public Object remove(Object key)
{
- // RemoveCommand
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ RemoveCommand command = commandsFactory.buildRemoveCommand(key, null);
+ return invoker.invoke(buildCtx(), command);
}
public void putAll(Map t)
{
- // PutMapCommand
- //To change body of implemented methods use File | Settings | File Templates.
+ PutMapCommand command = commandsFactory.buildPutMapCommand(t);
+ invoker.invoke(buildCtx(), command);
}
public void clear()
{
- // ClearCommand
- //To change body of implemented methods use File | Settings | File Templates.
+ ClearCommand command = commandsFactory.buildClearCommand();
+ invoker.invoke(buildCtx(), command);
}
public Set keySet()
@@ -130,44 +141,41 @@
throw new UnsupportedOperationException("Go away");
}
- protected void cacheStatusCheck(org.jboss.cache.InvocationContext ctx)
- {
- if (invocationContextContainer == null) throw new IllegalStateException("The cache has been destroyed!");
- }
-
public void evict(Object key)
{
- // EvictCommand
+ EvictCommand command = commandsFactory.buildEvictCommand(key);
+ invoker.invoke(buildCtx(), command);
}
public Configuration getConfiguration()
{
- return null; //TODO: Autogenerated. Implement me properly
+ return config;
}
public void addCacheListener(Object listener)
{
- //TODO: Autogenerated. Implement me properly
+ notifier.addCacheListener(listener);
}
public void removeCacheListener(Object listener)
{
- //TODO: Autogenerated. Implement me properly
+ notifier.removeCacheListener(listener);
}
public Set getCacheListeners()
{
- return null; //TODO: Autogenerated. Implement me properly
+ return notifier.getCacheListeners();
}
- public org.jboss.cache.InvocationContext getInvocationContext()
+ public InvocationContext getInvocationContext()
{
- return null; //TODO: Autogenerated. Implement me properly
+ return invocationContextContainer.get();
}
- public void setInvocationContext(org.jboss.cache.InvocationContext ctx)
+ public void setInvocationContext(InvocationContext ctx)
{
- //TODO: Autogenerated. Implement me properly
+ if (ctx == null) invocationContextContainer.remove();
+ else invocationContextContainer.set(ctx);
}
public void start()
@@ -179,4 +187,9 @@
{
//TODO: Autogenerated. Implement me properly
}
+
+ private InvocationContext buildCtx()
+ {
+ return invocationContextContainer.get();
+ }
}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/notifier/Notifier.java (from rev 6858, core/branches/flat/src/main/java/org/jboss/cache/notifications/Notifier.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/notifier/Notifier.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/notifier/Notifier.java 2008-10-08 14:00:29 UTC (rev 6874)
@@ -0,0 +1,145 @@
+/*
+ * 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.jboss.starobrno.notifier;
+
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.notifier.event.NodeModifiedEvent;
+import org.jboss.cache.buddyreplication.BuddyGroup;
+import org.jgroups.View;
+
+import javax.transaction.Transaction;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Public interface with all allowed notifications.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 2.2
+ */
+public interface Notifier
+{
+ /**
+ * Notifies all registered listeners of a nodeCreated event.
+ */
+ void notifyNodeCreated(Object key, boolean pre, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeModified event.
+ */
+ void notifyNodeModified(Object key, boolean pre, NodeModifiedEvent.ModificationType modificationType, Map data, 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.
+ */
+ public boolean shouldNotifyOnNodeModified();
+
+ /**
+ * Notifies all registered listeners of a nodeRemoved event.
+ */
+ void notifyNodeRemoved(Object key, boolean pre, Map data, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeVisited event.
+ */
+ void notifyNodeVisited(Object key, boolean pre, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeEvicted event.
+ */
+ void notifyNodeEvicted(Object key, boolean pre, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeInvalidated event.
+ */
+ void notifyNodeInvalidated(Object key, boolean pre, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeLoaded event.
+ */
+ void notifyNodeLoaded(Object key, boolean pre, Map data, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodeActivated event.
+ */
+ void notifyNodeActivated(Object key, boolean pre, Map data, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a nodePassivated event.
+ */
+ void notifyNodePassivated(Object key, boolean pre, Map data, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a viewChange event. Note that viewChange notifications are ALWAYS sent
+ * immediately.
+ */
+ void notifyViewChange(View view, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a buddy group change event. Note that buddy group change notifications are ALWAYS sent
+ * immediately.
+ *
+ * @param buddyGroup buddy group to set
+ * @param pre if true, this has occured before the buddy group message is broadcast to the cluster
+ */
+ void notifyBuddyGroupChange(BuddyGroup buddyGroup, boolean pre);
+
+ /**
+ * Notifies all registered listeners of a transaction completion event.
+ *
+ * @param transaction the transaction that has just completed
+ * @param successful if true, the transaction committed. If false, this is a rollback event
+ */
+ void notifyTransactionCompleted(Transaction transaction, boolean successful, InvocationContext ctx);
+
+ /**
+ * Notifies all registered listeners of a transaction registration event.
+ *
+ * @param transaction the transaction that has just completed
+ */
+ void notifyTransactionRegistered(Transaction transaction, InvocationContext ctx);
+
+ void notifyCacheBlocked(boolean pre);
+
+ void notifyCacheUnblocked(boolean pre);
+
+ /**
+ * Adds a cache listener to the list of cache listeners registered.
+ *
+ * @param listener
+ */
+ void addCacheListener(Object listener);
+
+ /**
+ * Removes a cache listener from the list of cache listeners registered.
+ *
+ * @param listener
+ */
+ void removeCacheListener(Object listener);
+
+ /**
+ * @return Retrieves an (unmodifiable) set of cache listeners registered.
+ */
+ Set<Object> getCacheListeners();
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/notifier/event/NodeModifiedEvent.java (from rev 6858, core/branches/flat/src/main/java/org/jboss/cache/notifications/event/NodeModifiedEvent.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/notifier/event/NodeModifiedEvent.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/notifier/event/NodeModifiedEvent.java 2008-10-08 14:00:29 UTC (rev 6874)
@@ -0,0 +1,69 @@
+/*
+ * 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.jboss.starobrno.notifier.event;
+
+import org.jboss.cache.notifications.event.NodeEvent;
+
+import java.util.Map;
+
+/**
+ * This event is passed in to any method annotated with {@link org.jboss.cache.notifications.annotation.NodeModified}
+ *
+ * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
+ * @since 2.0.0
+ */
+public interface NodeModifiedEvent extends NodeEvent
+{
+ /**
+ * Different cache modification types.
+ */
+ static enum ModificationType
+ {
+ PUT_DATA, REMOVE_DATA, PUT_MAP
+ }
+
+ /**
+ * @return an instance of the {@link org.jboss.cache.notifications.event.NodeModifiedEvent.ModificationType} enumeration.
+ */
+ ModificationType getModificationType();
+
+ /**
+ * When called with <tt>isPre() == true</tt>, this is the initial state of the {@link org.jboss.cache.Node}
+ * before modification.
+ * <p/>
+ * When called with <tt>isPre() == false</tt>, this depends on the value of <tt>getModificationType()</tt>:
+ * <ul>
+ * <li><b>{@link ModificationType#PUT_DATA}</b>: Map contains the single key/value pair that was added or modified.</li>
+ * <li><b>{@link ModificationType#REMOVE_DATA}</b>: Map contains the key/value pairs that were removed.</li>
+ * <li><b>{@link ModificationType#PUT_MAP}</b>: Map contains the new state of the {@link org.jboss.cache.Node} following modification. This map includes modified key/value
+ * pairs as well as any that were not affected.</li>
+ * </ul>
+ * <p/>
+ * Implementations interested in seeing the difference in the node data in the {@link ModificationType#PUT_MAP} case
+ * can cache the value of <tt>getData()</tt> map passed when <tt>isPre() == true</tt>, and then when the
+ * <tt>isPre() == false</tt> callback is received, pass the cached map and the new result of <tt>getData()</tt> to
+ * {@link org.jboss.cache.util.Util#diffNodeData(java.util.Map,java.util.Map)}
+ *
+ * @return Unmodifiable {@link java.util.Map}; will not be <code>null</code>. See description above.
+ */
+ Map getData();
+}
\ No newline at end of file
More information about the jbosscache-commits
mailing list