JBoss Cache SVN: r6862 - core/branches/flat/src/main/java/org/jboss/starobrno/commands/read.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-10-08 06:46:56 -0400 (Wed, 08 Oct 2008)
New Revision: 6862
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java
Removed:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbtractDataCommand.java
Log:
_____ ____ ____
\/__/\ \ \ \L\ \\ \ \/\_\
_\ \ \ \ _ <'\ \ \/_/_
/\ \_\ \ \ \L\ \\ \ \L\ \
\ \____/\ \____/ \ \____/
\/___/ \/___/ \/___/
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java (from rev 6861, core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbtractDataCommand.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java 2008-10-08 10:46:56 UTC (rev 6862)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.commands.read;
+
+import org.jboss.starobrno.commands.DataCommand;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public abstract class AbstractDataCommand implements DataCommand
+{
+ protected Object key;
+
+ public Object getKey()
+ {
+ return key;
+ }
+
+ public void setKey(Object key)
+ {
+ this.key = key;
+ }
+
+ protected AbstractDataCommand(Object key)
+ {
+ this.key = key;
+ }
+
+ protected AbstractDataCommand()
+ {
+ }
+}
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbtractDataCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbtractDataCommand.java 2008-10-08 10:45:26 UTC (rev 6861)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbtractDataCommand.java 2008-10-08 10:46:56 UTC (rev 6862)
@@ -1,51 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt 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.commands.read;
-
-import org.jboss.starobrno.commands.DataCommand;
-
-/**
- * @author Mircea.Markus(a)jboss.com
- */
-public abstract class AbtractDataCommand implements DataCommand
-{
- protected Object key;
-
- public Object getKey()
- {
- return key;
- }
-
- public void setKey(Object key)
- {
- this.key = key;
- }
-
- protected AbtractDataCommand(Object key)
- {
- this.key = key;
- }
-
- protected AbtractDataCommand()
- {
- }
-}
16 years, 2 months
JBoss Cache SVN: r6861 - core/branches/flat/src/main/java/org/jboss/starobrno/commands/read.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-10-08 06:45:26 -0400 (Wed, 08 Oct 2008)
New Revision: 6861
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbtractDataCommand.java
Removed:
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java
Log:
_____ ____ ____
\/__/\ \ \ \L\ \\ \ \/\_\
_\ \ \ \ _ <'\ \ \/_/_
/\ \_\ \ \ \L\ \\ \ \L\ \
\ \____/\ \____/ \ \____/
\/___/ \/___/ \/___/
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java 2008-10-08 10:42:17 UTC (rev 6860)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java 2008-10-08 10:45:26 UTC (rev 6861)
@@ -1,87 +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.jboss.starobrno.commands.read;
-
-import org.jboss.starobrno.commands.DataCommand;
-import org.jboss.starobrno.DataContainer;
-
-/**
- * An abstract class providing basic functionality of all {@link org.jboss.cache.commands.DataCommand}s.
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 2.2.0
- */
-public abstract class AbstractDataCommand implements DataCommand
-{
- protected DataContainer dataContainer;
-
- public void initialize(DataContainer dataContainer)
- {
- this.dataContainer = dataContainer;
- }
-
- private Object key;
-
- /**
- * Basic versions of these methods
- */
- public Object[] getParameters()
- {
- return new Object[]{key};
- }
-
- /**
- * Basic versions of these methods
- */
- public void setParameters(int commandId, Object[] args)
- {
- key = args[0];
- }
-
- public boolean equals(Object o)
- {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- AbstractDataCommand that = (AbstractDataCommand) o;
-
- if (key != null ? !key.equals(that.key) : that.key != null) return false;
-
- return true;
- }
-
- public int hashCode()
- {
- int result;
- result = (dataContainer != null ? dataContainer.hashCode() : 0);
- result = 31 * result + (key != null ? key.hashCode() : 0);
- return result;
- }
-
-
- public String toString()
- {
- return "AbstractDataCommand{" +
- "key=" + key +
- '}';
- }
-}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbtractDataCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbtractDataCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbtractDataCommand.java 2008-10-08 10:45:26 UTC (rev 6861)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.commands.read;
+
+import org.jboss.starobrno.commands.DataCommand;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public abstract class AbtractDataCommand implements DataCommand
+{
+ protected Object key;
+
+ public Object getKey()
+ {
+ return key;
+ }
+
+ public void setKey(Object key)
+ {
+ this.key = key;
+ }
+
+ protected AbtractDataCommand(Object key)
+ {
+ this.key = key;
+ }
+
+ protected AbtractDataCommand()
+ {
+ }
+}
16 years, 2 months
JBoss Cache SVN: r6860 - in core/branches/flat/src/main/java/org/jboss/starobrno: lifecycle and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 06:42:17 -0400 (Wed, 08 Oct 2008)
New Revision: 6860
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/lifecycle/
core/branches/flat/src/main/java/org/jboss/starobrno/lifecycle/Lifecycle.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
Log:
Updated interfaces
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-10-08 09:34:41 UTC (rev 6859)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-10-08 10:42:17 UTC (rev 6860)
@@ -21,11 +21,29 @@
*/
package org.jboss.starobrno;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.config.Configuration;
+import org.jboss.starobrno.lifecycle.Lifecycle;
+
+import java.util.Set;
import java.util.concurrent.ConcurrentMap;
/**
* @author Mircea.Markus(a)jboss.com
*/
-public interface Cache extends ConcurrentMap
+public interface Cache<K, V> extends ConcurrentMap<K, V>, Lifecycle
{
+ void evict(K key);
+
+ Configuration getConfiguration();
+
+ void addCacheListener(Object listener);
+
+ void removeCacheListener(Object listener);
+
+ Set<Object> getCacheListeners();
+
+ InvocationContext getInvocationContext();
+
+ void setInvocationContext(InvocationContext ctx);
}
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 09:34:41 UTC (rev 6859)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-08 10:42:17 UTC (rev 6860)
@@ -21,104 +21,161 @@
*/
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.context.InvocationContext;
+import java.util.Collection;
import java.util.Map;
import java.util.Set;
-import java.util.Collection;
/**
* @author Mircea.Markus(a)jboss.com
*/
public class CacheDelegate implements Cache
{
-
protected InvocationContextContainer invocationContextContainer;
public Object putIfAbsent(Object key, Object value)
{
+ // PutKeyValueCommand
InvocationContext ctx = invocationContextContainer.get();
return null;
}
public boolean remove(Object key, Object value)
{
+ // RemoveCommand
return false; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean replace(Object key, Object oldValue, Object newValue)
{
+ // ReplaceCommand
return false;
}
public Object replace(Object key, Object value)
{
+ // ReplaceCommand
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public int size()
{
+ // SizeCommand
return 0; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean isEmpty()
{
+ // SizeCommand
return false; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean containsKey(Object key)
{
+ // GetKeyValueCommand
return false; //To change body of implemented methods use File | Settings | File Templates.
}
public boolean containsValue(Object value)
{
- return false; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException("Go away");
}
public Object get(Object key)
{
+ // GetKeyValueCommand
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Object put(Object key, Object value)
{
+ // PutKeyValueCommand
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Object remove(Object key)
{
+ // RemoveCommand
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void putAll(Map t)
{
+ // PutMapCommand
//To change body of implemented methods use File | Settings | File Templates.
}
public void clear()
{
+ // ClearCommand
//To change body of implemented methods use File | Settings | File Templates.
}
public Set keySet()
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException("Go away");
}
public Collection values()
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException("Go away");
}
public Set entrySet()
{
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ 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
+ }
+
+ public Configuration getConfiguration()
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ public void addCacheListener(Object listener)
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ public void removeCacheListener(Object listener)
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ public Set getCacheListeners()
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ public org.jboss.cache.InvocationContext getInvocationContext()
+ {
+ return null; //TODO: Autogenerated. Implement me properly
+ }
+
+ public void setInvocationContext(org.jboss.cache.InvocationContext ctx)
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ public void start()
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
+
+ public void stop()
+ {
+ //TODO: Autogenerated. Implement me properly
+ }
}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/lifecycle/Lifecycle.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/lifecycle/Lifecycle.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/lifecycle/Lifecycle.java 2008-10-08 10:42:17 UTC (rev 6860)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.lifecycle;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface Lifecycle
+{
+ void start();
+
+ void stop();
+}
16 years, 2 months
JBoss Cache SVN: r6859 - in core/branches/flat/src/main/java/org/jboss/starobrno: commands and 11 other directories.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-10-08 05:34:41 -0400 (Wed, 08 Oct 2008)
New Revision: 6859
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheException.java
core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/
core/branches/flat/src/main/java/org/jboss/starobrno/commands/AbstractVisitor.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/DataCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/ReplicableCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/VisitableCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/WriteCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/
core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/
core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/
core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/
core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/DefaultFactoryFor.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Destroy.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Inject.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/NonVolatile.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Start.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Stop.java
core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/
core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/PrePostProcessingCommandInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/SkipCheckChainedInterceptor.java
core/branches/flat/src/main/java/org/jboss/starobrno/invocation/
core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/transaction/
core/branches/flat/src/main/java/org/jboss/starobrno/transaction/GlobalTransaction.java
core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionContext.java
Removed:
core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
core/branches/flat/src/main/java/org/jboss/starobrno/test/
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/CacheManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
Log:
Deleted: core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-10-08 09:30:07 UTC (rev 6858)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -1,145 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt 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;
-
-import org.jboss.util.NotImplementedException;
-import org.jboss.starobrno.config.CacheConfig;
-
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.Collection;
-import java.util.HashSet;
-
-/**
- * @author Mircea.Markus(a)jboss.com
- */
-public class Cache implements ConcurrentMap
-{
- private ConcurrentHashMap data = new ConcurrentHashMap();
- private Map<String, AtomicGroup> atomicGroups = new ConcurrentHashMap<String, AtomicGroup>();
- private CacheConfig cacheConfig;
-
-
- public Cache(CacheConfig cacheConfig)
- {
- this.cacheConfig = cacheConfig;
- }
-
- public Object putIfAbsent(Object key, Object value)
- {
- return data.putIfAbsent(key, value);
- }
-
- public boolean remove(Object key, Object value)
- {
- return data.remove(key, value);
- }
-
- public boolean replace(Object key, Object oldValue, Object newValue)
- {
- return data.replace(key, oldValue, newValue);
- }
-
- public Object replace(Object key, Object value)
- {
- return data.replace(key, value);
- }
-
- public int size()
- {
- throw new NotImplementedException("not impl!");
- }
-
- public boolean isEmpty()
- {
- throw new NotImplementedException("not impl!");
- }
-
- public boolean containsKey(Object key)
- {
- return false;
- }
-
- public boolean containsValue(Object value)
- {
- return data.contains(value);
- }
-
- public Object get(Object key)
- {
- return data.get(key);
- }
-
- public Object put(Object key, Object value)
- {
- return data.put(key, value);
- }
-
- public Object remove(Object key)
- {
- return data.remove(key);
- }
-
- public void putAll(Map t)
- {
- data.putAll(t);
- }
-
- public void clear()
- {
- data.clear();
- }
-
- public Set keySet()
- {
- throw new NotImplementedException("not impl!");
- }
-
- public Collection values()
- {
- throw new NotImplementedException("not impl!");
- }
-
- public Set entrySet()
- {
- throw new NotImplementedException("not impl!");
- }
-
- public boolean equals(Object o)
- {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- Cache cache = (Cache) o;
-
- if (data != null ? !data.equals(cache.data) : cache.data != null) return false;
-
- return true;
- }
-
- public int hashCode()
- {
- return (data != null ? data.hashCode() : 0);
- }
-}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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;
+
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public interface Cache extends ConcurrentMap
+{
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheDelegate.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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;
+
+import org.jboss.starobrno.invocation.InvocationContextContainer;
+import org.jboss.starobrno.context.InvocationContext;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Collection;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class CacheDelegate implements Cache
+{
+
+ protected InvocationContextContainer invocationContextContainer;
+
+ public Object putIfAbsent(Object key, Object value)
+ {
+ InvocationContext ctx = invocationContextContainer.get();
+ return null;
+ }
+
+ public boolean remove(Object key, Object value)
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean replace(Object key, Object oldValue, Object newValue)
+ {
+ return false;
+ }
+
+ public Object replace(Object key, Object value)
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int size()
+ {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isEmpty()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean containsValue(Object value)
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object get(Object key)
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object put(Object key, Object value)
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object remove(Object key)
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void putAll(Map t)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void clear()
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Set keySet()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Collection values()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Set entrySet()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ protected void cacheStatusCheck(org.jboss.cache.InvocationContext ctx)
+ {
+ if (invocationContextContainer == null) throw new IllegalStateException("The cache has been destroyed!");
+ }
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/CacheException.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/CacheException.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheException.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheException.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+/**
+ * Thrown when operations on {@link org.jboss.cache.Cache} or {@link org.jboss.cache.Node} fail unexpectedly.
+ * <p/>
+ * Specific subclasses such as {@link org.jboss.cache.lock.TimeoutException}, {@link org.jboss.cache.config.ConfigurationException} and {@link org.jboss.cache.lock.LockingException}
+ * have more specific uses.
+ *
+ * @author <a href="mailto:bela@jboss.org">Bela Ban</a>
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
+ */
+public class CacheException extends RuntimeException
+{
+
+ private static final long serialVersionUID = -4386393072593859164L;
+
+ public CacheException()
+ {
+ super();
+ }
+
+ public CacheException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public CacheException(String msg)
+ {
+ super(msg);
+ }
+
+ public CacheException(String msg, Throwable cause)
+ {
+ super(msg, cause);
+ }
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java (from rev 6852, core/branches/flat/src/main/java/org/jboss/starobrno/Cache.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheImpl.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,144 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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;
+
+import org.jboss.util.NotImplementedException;
+import org.jboss.starobrno.config.CacheConfig;
+
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Collection;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class CacheImpl implements Cache
+{
+ private ConcurrentHashMap data = new ConcurrentHashMap();
+ private Map<String, AtomicGroup> atomicGroups = new ConcurrentHashMap<String, AtomicGroup>();
+ private CacheConfig cacheConfig;
+
+
+ public CacheImpl(CacheConfig cacheConfig)
+ {
+ this.cacheConfig = cacheConfig;
+ }
+
+ public Object putIfAbsent(Object key, Object value)
+ {
+ return data.putIfAbsent(key, value);
+ }
+
+ public boolean remove(Object key, Object value)
+ {
+ return data.remove(key, value);
+ }
+
+ public boolean replace(Object key, Object oldValue, Object newValue)
+ {
+ return data.replace(key, oldValue, newValue);
+ }
+
+ public Object replace(Object key, Object value)
+ {
+ return data.replace(key, value);
+ }
+
+ public int size()
+ {
+ throw new NotImplementedException("not impl!");
+ }
+
+ public boolean isEmpty()
+ {
+ throw new NotImplementedException("not impl!");
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return false;
+ }
+
+ public boolean containsValue(Object value)
+ {
+ return data.contains(value);
+ }
+
+ public Object get(Object key)
+ {
+ return data.get(key);
+ }
+
+ public Object put(Object key, Object value)
+ {
+ return data.put(key, value);
+ }
+
+ public Object remove(Object key)
+ {
+ return data.remove(key);
+ }
+
+ public void putAll(Map t)
+ {
+ data.putAll(t);
+ }
+
+ public void clear()
+ {
+ data.clear();
+ }
+
+ public Set keySet()
+ {
+ throw new NotImplementedException("not impl!");
+ }
+
+ public Collection values()
+ {
+ throw new NotImplementedException("not impl!");
+ }
+
+ public Set entrySet()
+ {
+ throw new NotImplementedException("not impl!");
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ CacheImpl cache = (CacheImpl) o;
+
+ if (data != null ? !data.equals(cache.data) : cache.data != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ return (data != null ? data.hashCode() : 0);
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/CacheManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/CacheManager.java 2008-10-08 09:30:07 UTC (rev 6858)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/CacheManager.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -33,19 +33,19 @@
public class CacheManager
{
private Configuration config;
- private Map<String, Cache> caches = new HashMap<String, Cache>();
+ private Map<String, CacheImpl> caches = new HashMap<String, CacheImpl>();
public CacheManager(Configuration config)
{
this.config = config;
}
- public Cache getCache(String confName)
+ public CacheImpl getCache(String confName)
{
if (caches.containsKey(confName)) return caches.get(confName);
CacheConfig config = this.config.getCacheConfig(confName);
if (config == null) throw new IllegalArgumentException("No such cache config: " + confName);
- Cache result = new Cache(config);
+ CacheImpl result = new CacheImpl(config);
caches.put(confName, result);
return result;
}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/commands/AbstractVisitor.java (from rev 6854, core/branches/flat/src/main/java/org/jboss/cache/commands/AbstractVisitor.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/AbstractVisitor.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/AbstractVisitor.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,72 @@
+/*
+ * 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.commands;
+
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+
+import java.util.Collection;
+
+/**
+ * An abstract implementation of a Visitor that delegates all visit calls to a default handler which can be overridden.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @author Manik Surtani
+ * @since 2.2.0
+ */
+public abstract class AbstractVisitor implements Visitor
+{
+ public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+
+ /**
+ * A default handler for all commands visited. This is called for any visit method called, unless a visit command is
+ * appropriately overridden.
+ *
+ * @param ctx invocation context
+ * @param command command to handle
+ * @return return value
+ * @throws Throwable in the case of a problem
+ */
+ protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable
+ {
+ return null;
+ }
+
+ /**
+ * Helper method to visit a collection of VisitableCommands.
+ *
+ * @param ctx Invocation context
+ * @param toVisit collection of commands to visit
+ * @throws Throwable in the event of problems
+ */
+ public void visitCollection(InvocationContext ctx, Collection<? extends VisitableCommand> toVisit) throws Throwable
+ {
+ for (VisitableCommand command : toVisit)
+ {
+ command.acceptVisitor(ctx, this);
+ }
+ }
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/commands/DataCommand.java (from rev 6854, core/branches/flat/src/main/java/org/jboss/cache/commands/DataCommand.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/DataCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/DataCommand.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,35 @@
+/*
+ * 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.commands;
+
+
+/**
+ * Commands of this type manipulate data in the cache.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.2.0
+ */
+public interface DataCommand extends VisitableCommand
+{
+ Object getKey();
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/commands/ReplicableCommand.java (from rev 6854, core/branches/flat/src/main/java/org/jboss/cache/commands/ReplicableCommand.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/ReplicableCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/ReplicableCommand.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -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.commands;
+
+import org.jboss.starobrno.context.InvocationContext;
+
+/**
+ * The core of the command-based cache framework. Commands correspond to specific areas of functionality in the cache,
+ * and can be replicated using the {@link org.jboss.cache.marshall.Marshaller} framework.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @author Manik Surtani
+ * @since 2.2.0
+ */
+public interface ReplicableCommand
+{
+ /**
+ * Performs the primary function of the command. Please see specific implementation classes for details on what is
+ * performed as well as return types.
+ * <b>Important</b>: this method will be invoked at the end of interceptors chain. It should never be called directly from
+ * a custom interceptor.
+ *
+ * @param ctx invocation context
+ * @return arbitrary return value generated by performing this command
+ * @throws Throwable in the event of problems.
+ */
+ Object perform(InvocationContext ctx) throws Throwable;
+
+ /**
+ * Used by marshallers to convert this command into an id for streaming.
+ *
+ * @return the method id of this command. This is compatible with pre-2.2.0 MethodCall ids.
+ */
+ int getCommandId();
+
+ /**
+ * Used by marshallers to stream this command across a network
+ *
+ * @return an object array of arguments, compatible with pre-2.2.0 MethodCall args.
+ */
+ Object[] getParameters();
+
+ /**
+ * Used by the {@link org.jboss.cache.commands.CommandsFactory} to create a command from raw data read off a stream.
+ *
+ * @param commandId command id to set. This is usually unused but *could* be used in the event of a command having multiple IDs, such as {@link org.jboss.cache.commands.write.PutKeyValueCommand}.
+ * @param parameters object array of args
+ */
+ void setParameters(int commandId, Object[] parameters);
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/commands/VisitableCommand.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/commands/VisitableCommand.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/VisitableCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/VisitableCommand.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,44 @@
+/*
+ * 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.commands;
+
+import org.jboss.starobrno.context.InvocationContext;
+
+
+/**
+ * A type of command that can accept {@link org.jboss.cache.commands.Visitor}s, such as {@link org.jboss.cache.interceptors.base.CommandInterceptor}s.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.2.0
+ */
+public interface VisitableCommand extends ReplicableCommand
+{
+ /**
+ * Accept a visitor, and return the result of accepting this visitor.
+ *
+ * @param ctx invocation context
+ * @param visitor visitor to accept
+ * @return arbitrary return value
+ * @throws Throwable in the event of problems
+ */
+ Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable;
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java (from rev 6854, core/branches/flat/src/main/java/org/jboss/cache/commands/Visitor.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/Visitor.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,48 @@
+/*
+ * 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.commands;
+
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.commands.write.PutKeyValueCommand;
+
+/**
+ * This interface is the core of JBoss Cache, where each {@link org.jboss.cache.commands.VisitableCommand} can be visited by a Visitor implementation.
+ * Visitors which are accepted by the {@link org.jboss.cache.commands.VisitableCommand} are able to modify the command
+ * based on any logic encapsulated by the visitor.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @author Manik Surtani
+ * @since 2.2.0
+ */
+public interface Visitor
+{
+
+ /**
+ * Visits a PutKeyValueCommand.
+ *
+ * @param ctx invocation context
+ * @param command command to visit
+ * @return response from the visit
+ * @throws Throwable in the event of problems.
+ */
+ Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable;
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/commands/WriteCommand.java (from rev 6854, core/branches/flat/src/main/java/org/jboss/cache/commands/WriteCommand.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/WriteCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/WriteCommand.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,48 @@
+/*
+ * 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.commands;
+
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.commands.*;
+import org.jboss.cache.commands.DataCommand;
+
+/**
+ * A write command that has a reference to a {@link org.jboss.cache.transaction.GlobalTransaction}.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.2.0
+ */
+public interface WriteCommand extends DataCommand
+{
+ /**
+ * @return a GlobalTransaction associated with this command.
+ */
+ GlobalTransaction getGlobalTransaction();
+
+ /**
+ * Sets a GlobalTransaction on this command.
+ *
+ * @param gtx global transaction to set
+ */
+ void setGlobalTransaction(GlobalTransaction gtx);
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java (from rev 6854, core/branches/flat/src/main/java/org/jboss/cache/commands/read/AbstractDataCommand.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/read/AbstractDataCommand.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,87 @@
+/*
+ * 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.commands.read;
+
+import org.jboss.starobrno.commands.DataCommand;
+import org.jboss.starobrno.DataContainer;
+
+/**
+ * An abstract class providing basic functionality of all {@link org.jboss.cache.commands.DataCommand}s.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.2.0
+ */
+public abstract class AbstractDataCommand implements DataCommand
+{
+ protected DataContainer dataContainer;
+
+ public void initialize(DataContainer dataContainer)
+ {
+ this.dataContainer = dataContainer;
+ }
+
+ private Object key;
+
+ /**
+ * Basic versions of these methods
+ */
+ public Object[] getParameters()
+ {
+ return new Object[]{key};
+ }
+
+ /**
+ * Basic versions of these methods
+ */
+ public void setParameters(int commandId, Object[] args)
+ {
+ key = args[0];
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ AbstractDataCommand that = (AbstractDataCommand) o;
+
+ if (key != null ? !key.equals(that.key) : that.key != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (dataContainer != null ? dataContainer.hashCode() : 0);
+ result = 31 * result + (key != null ? key.hashCode() : 0);
+ return result;
+ }
+
+
+ public String toString()
+ {
+ return "AbstractDataCommand{" +
+ "key=" + key +
+ '}';
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/commands/write/PutKeyValueCommand.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,142 @@
+/*
+ * 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.commands.write;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.NodeNotExistsException;
+import org.jboss.cache.NodeSPI;
+
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.commands.read.AbstractDataCommand;
+import org.jboss.starobrno.commands.Visitor;
+
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * Implements functionality defined by {@link org.jboss.cache.Cache#put(org.jboss.cache.Fqn, Object, Object)}.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public class PutKeyValueCommand extends AbstractDataCommand
+{
+ public static final int METHOD_ID = 3;
+ public static final int VERSIONED_METHOD_ID = 39;
+
+ private static final Log log = LogFactory.getLog(org.jboss.cache.commands.write.PutKeyValueCommand.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ /* parametres */
+ protected Object key;
+ protected Object value;
+
+ public PutKeyValueCommand(GlobalTransaction gtx, Object key, Object value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+
+ public PutKeyValueCommand()
+ {
+ }
+
+ /**
+ * Puts the specified key and value into the data map in the node referenced by the specified Fqn.
+ *
+ * @param ctx invocation context
+ * @return the value being overwritten, if any, otherwise a null.
+ */
+ public Object perform(InvocationContext ctx)
+ {
+ if (trace) log.trace("Perform(, k='" + key + "', v='" + value + "')");
+ return null;
+ }
+
+ public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable
+ {
+ return visitor.visitPutKeyValueCommand(ctx, this);
+ }
+
+ public Object getKey()
+ {
+ return key;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+
+ public void setKey(Object key)
+ {
+ this.key = key;
+ }
+
+ public void setValue(Object value)
+ {
+ this.value = value;
+ }
+
+ public int getCommandId()
+ {
+ return METHOD_ID;
+ }
+
+ @Override
+ public Object[] getParameters()
+ {
+ return new Object[]{key, value, false};
+ }
+
+ @Override
+ public void setParameters(int commandId, Object[] args)
+ {
+ key = args[0];
+ value = args[1];
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ if (!super.equals(o)) return false;
+
+ PutKeyValueCommand that = (PutKeyValueCommand) o;
+
+ if (key != null ? !key.equals(that.key) : that.key != null) return false;
+ if (value != null ? !value.equals(that.value) : that.value != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (key != null ? key.hashCode() : 0);
+ result = 31 * result + (value != null ? value.hashCode() : 0);
+ return result;
+ }
+}
\ No newline at end of file
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-10-08 09:30:07 UTC (rev 6858)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/config/Configuration.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -1,55 +1,55 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt 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.config;
-
-import org.jboss.util.NotImplementedException;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author Mircea.Markus(a)jboss.com
- */
-public class Configuration
-{
- public Map<String, CacheConfig> cacheConfigs = new HashMap<String, CacheConfig>();
-
- //todo - to be implemented, do the parsing here
- public Configuration(String configFile)
- {
- throw new NotImplementedException("not impl!");
- }
-
- public Configuration()
- {
- }
-
- public CacheConfig getCacheConfig(String name)
- {
- return cacheConfigs.get(name);
- }
-
- public void addCacheConfig(String name, CacheConfig config)
- {
- cacheConfigs.put(name, config);
- }
-}
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.config;
+
+import org.jboss.util.NotImplementedException;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Mircea.Markus(a)jboss.com
+ */
+public class Configuration
+{
+ public Map<String, CacheConfig> cacheConfigs = new HashMap<String, CacheConfig>();
+
+ //todo - to be implemented, do the parsing here
+ public Configuration(String configFile)
+ {
+ throw new NotImplementedException("not impl!");
+ }
+
+ public Configuration()
+ {
+ }
+
+ public CacheConfig getCacheConfig(String name)
+ {
+ return cacheConfigs.get(name);
+ }
+
+ public void addCacheConfig(String name, CacheConfig config)
+ {
+ cacheConfigs.put(name, config);
+ }
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java 2008-10-08 09:30:07 UTC (rev 6858)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -21,9 +21,9 @@
*/
package org.jboss.starobrno.context;
-import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.config.Option;
-import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.transaction.GlobalTransaction;
import javax.transaction.Transaction;
import java.util.List;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java 2008-10-08 09:30:07 UTC (rev 6858)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -23,15 +23,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.commands.VisitableCommand;
+import org.jboss.starobrno.mvcc.MVCCEntry;
+import org.jboss.starobrno.transaction.GlobalTransaction;
+import org.jboss.starobrno.commands.VisitableCommand;
import org.jboss.cache.config.Option;
-import org.jboss.cache.marshall.MethodCall;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.TransactionTable;
import org.jboss.cache.util.Immutables;
-import org.jboss.starobrno.mvcc.MVCCEntry;
+import org.jboss.cache.transaction.TransactionTable;
import javax.transaction.Transaction;
import java.util.Collections;
@@ -60,8 +57,6 @@
private boolean originLocal = true;
private boolean localRollbackOnly;
@Deprecated
- private MethodCall methodCall;
- @Deprecated
private VisitableCommand command;
/**
@@ -456,7 +451,6 @@
optionOverrides = null;
originLocal = true;
invocationLocks = null;
- methodCall = null;
command = null;
if (lookedUpEntries != null)
{
@@ -485,42 +479,6 @@
}
/**
- * @return the method call associated with this invocation
- */
- @Deprecated
- @SuppressWarnings("deprecation")
- public MethodCall getMethodCall()
- {
- if (methodCall == null)
- {
- methodCall = createMethodCall();
- }
- return methodCall;
- }
-
- @SuppressWarnings("deprecation")
- private MethodCall createMethodCall()
- {
- if (command == null) return null;
- MethodCall call = new MethodCall();
- call.setMethodId(command.getCommandId());
- call.setArgs(command.getParameters());
- return call;
- }
-
- /**
- * Sets the method call associated with this invocation.
- *
- * @param methodCall methodcall to set
- * @deprecated not used anymore. Interceptors will get a {@link org.jboss.cache.commands.ReplicableCommand} instance passed in along with an InvocationContext.
- */
- @Deprecated
- public void setMethodCall(MethodCall methodCall)
- {
- this.methodCall = methodCall;
- }
-
- /**
* If the lock acquisition timeout is overridden for current call using an option, then return that one.
* If not overridden, return default value.
*
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/DefaultFactoryFor.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/factories/annotations/DefaultFactoryFor.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/DefaultFactoryFor.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/DefaultFactoryFor.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,46 @@
+/*
+ * 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.factories.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation that is used internally, for defining a DEFAULT factory to be used when constructing components. This
+ * annotation allows you to define which components can be constructed by the annotated factory.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@Target(TYPE)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface DefaultFactoryFor
+{
+ /**
+ * Components that may be constructed by a factory annotated with this annotation.
+ *
+ * @return classes that can be constructed by this factory
+ */
+ public abstract Class[] classes();
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Destroy.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/factories/annotations/Destroy.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Destroy.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Destroy.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,49 @@
+/*
+ * 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.factories.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Method level annotation that indicates a (no-param) method to be called on a component registered in the ComponentRegistry
+ * when the cache is destroyed.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@Target(METHOD)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Destroy
+{
+ /**
+ * Optional parameter which defines the order in which this method will be called when the ComponentRegistry moves
+ * to the STARTED state. Defaults to 10.
+ *
+ * @return execution priority
+ * @since 2.2.0
+ */
+ public abstract int priority() default 10;
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Inject.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/factories/annotations/Inject.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Inject.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Inject.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,73 @@
+/*
+ * 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.factories.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Used to annotate a method as one that is used to inject a registered component into another component. The component
+ * to be constructed must be built using the {@link org.jboss.cache.factories.ComponentFactory#construct(Class)} method, or if your object that needs
+ * components injected into it already exists, it can be built using the {@link org.jboss.cache.factories.ComponentRegistry#wireDependencies(Object)}
+ * method.
+ * <p/>
+ * Usage example:
+ * <pre>
+ * public class MyClass
+ * {
+ * private TransactionManager tm;
+ * private BuddyManager bm;
+ * private Notifier n;
+ * <p/>
+ * &Inject
+ * public void setTransactionManager(TransactionManager tm)
+ * {
+ * this.tm = tm;
+ * }
+ * <p/>
+ * &Inject
+ * public void injectMoreStuff(BuddyManager bm, Notifier n)
+ * {
+ * this.bm = bm;
+ * this.n = n;
+ * }
+ * }
+ * <p/>
+ * </pre>
+ * and an instance of this class can be constructed and wired using
+ * <pre>
+ * MyClass myClass = componentFactory.construct(MyClass.class); // instance will have dependencies injected.
+ * </pre>
+ *
+ * @author Manik Surtani
+ * @since 2.1.0
+ */
+// ensure this annotation is available at runtime.
+(a)Retention(RetentionPolicy.RUNTIME)
+
+// only applies to fields.
+(a)Target(ElementType.METHOD)
+public @interface Inject
+{
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/NonVolatile.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/factories/annotations/NonVolatile.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/NonVolatile.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/NonVolatile.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,46 @@
+/*
+ * 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.factories.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation is used for components that will be registered in the {@link org.jboss.cache.factories.ComponentRegistry},
+ * that are resilient to changes in configuration. Examples are the {@link org.jboss.cache.CacheSPI} implementation used, which does
+ * not change regardless of the configuration. Components such as the {@link org.jboss.cache.lock.LockManager}, though, should
+ * <b>never</b> be marked as <tt>@NonVolatile</tt> since based on the configuration, different lock manager implementations
+ * may be selected. LockManager is, hence, <b>not</b> resilient to changes in the configuration.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.2.0
+ */
+// ensure this annotation is available at runtime.
+(a)Retention(RetentionPolicy.RUNTIME)
+
+// only applies to classes.
+(a)Target(ElementType.TYPE)
+public @interface NonVolatile
+{
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Start.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/factories/annotations/Start.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Start.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Start.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,49 @@
+/*
+ * 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.factories.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Method level annotation that indicates a (no-param) method to be called on a component registered in the ComponentRegistry
+ * when the cache starts.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@Target(METHOD)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Start
+{
+ /**
+ * Optional parameter which defines the order in which this method will be called when the ComponentRegistry moves
+ * to the STARTED state. Defaults to 10.
+ *
+ * @return execution priority
+ * @since 2.2.0
+ */
+ public abstract int priority() default 10;
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Stop.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/factories/annotations/Stop.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Stop.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/annotations/Stop.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,49 @@
+/*
+ * 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.factories.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Method level annotation that indicates a (no-param) method to be called on a component registered in the ComponentRegistry
+ * when the cache stops.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@Target(METHOD)
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Stop
+{
+ /**
+ * Optional parameter which defines the order in which this method will be called when the ComponentRegistry moves
+ * to the STARTED state. Defaults to 10.
+ *
+ * @return execution priority
+ * @since 2.2.0
+ */
+ public abstract int priority() default 10;
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/factories/context/ContextFactory.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/factories/context/ContextFactory.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,54 @@
+/*
+ * 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.factories.context;
+
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.cache.transaction.TransactionContext;
+
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+
+/**
+ * This is the factory responsible for creating {@link org.jboss.cache.InvocationContext}s and {@link org.jboss.cache.transaction.TransactionContext}s
+ * for requests, based on the configuration used.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface ContextFactory
+{
+ /**
+ * @return a new invocation context
+ */
+ InvocationContext createInvocationContext();
+
+ /**
+ * @param tx JTA transaction to associate the new context with
+ * @return a new transaction context
+ * @throws javax.transaction.RollbackException
+ * in the event of an invalid transaaction
+ * @throws javax.transaction.SystemException
+ * in the event of an invalid transaction
+ */
+ TransactionContext createTransactionContext(Transaction tx) throws SystemException, RollbackException;
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/InterceptorChain.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,386 @@
+/*
+ * 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.interceptors;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.CacheException;
+import org.jboss.starobrno.context.InvocationContext;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.annotations.Start;
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.interceptors.base.CommandInterceptor;
+import org.jboss.starobrno.invocation.InvocationContextContainer;
+import org.jboss.cache.util.CachePrinter;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Knows how to build and manage an chain of interceptors. Also in charge with invoking methods on the chain.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ * todo - if you add the same interceptor instance twice, things get really dirty.
+ * -- this should be treated as an missuse and an exception should be thrown
+ */
+public class InterceptorChain
+{
+ /**
+ * reference to the first interceptor in the chain
+ */
+ private CommandInterceptor firstInChain;
+
+ /**
+ * used for invoking commands on the chain
+ */
+ private InvocationContextContainer invocationContextContainer;
+ private static final Log log = LogFactory.getLog(InterceptorChain.class);
+
+ /**
+ * Constructs an interceptor chain having the supplied interceptor as first.
+ */
+ public InterceptorChain(CommandInterceptor first)
+ {
+ this.firstInChain = first;
+ }
+
+ @Inject
+ public void initialize(InvocationContextContainer invocationContextContainer)
+ {
+ this.invocationContextContainer = invocationContextContainer;
+ }
+
+ @Start
+ private void printChainInfo()
+ {
+ if (log.isDebugEnabled()) log.debug("Interceptor chain is: " + toString());
+ }
+
+ /**
+ * Inserts the given interceptor at the specified position in the chain (o based indexing).
+ *
+ * @throws IllegalArgumentException if the position is invalid (e.g. 5 and there are only 2 interceptors in the chain)
+ */
+ public synchronized void addInterceptor(CommandInterceptor interceptor, int position)
+ {
+ if (position == 0)
+ {
+ interceptor.setNext(firstInChain);
+ firstInChain = interceptor;
+ return;
+ }
+ if (firstInChain == null) return;
+ CommandInterceptor it = firstInChain;
+ int index = 0;
+ while (it != null)
+ {
+ if (++index == position)
+ {
+ interceptor.setNext(it.getNext());
+ it.setNext(interceptor);
+ return;
+ }
+ it = it.getNext();
+ }
+ throw new IllegalArgumentException("Invalid index: " + index + " !");
+ }
+
+ /**
+ * Removes the interceptor at the given postion.
+ *
+ * @throws IllegalArgumentException if the position is invalid (e.g. 5 and there are only 2 interceptors in the chain)
+ */
+ public synchronized void removeInterceptor(int position)
+ {
+ if (firstInChain == null) return;
+ if (position == 0)
+ {
+ firstInChain = firstInChain.getNext();
+ return;
+ }
+ CommandInterceptor it = firstInChain;
+ int index = 0;
+ while (it != null)
+ {
+ if (++index == position)
+ {
+ if (it.getNext() == null) return; //nothing to remove
+ it.setNext(it.getNext().getNext());
+ return;
+ }
+ it = it.getNext();
+ }
+ throw new IllegalArgumentException("Invalid position: " + position + " !");
+ }
+
+ /**
+ * Returns the number of interceptors in the chain.
+ */
+ public int size()
+ {
+ int size = 0;
+ CommandInterceptor it = firstInChain;
+ while (it != null)
+ {
+ size++;
+ it = it.getNext();
+ }
+ return size;
+
+ }
+
+ /**
+ * Returns an unmofiable list with all the interceptors in sequence.
+ * If first in chain is null an empty list is returned.
+ */
+ public List<CommandInterceptor> asList()
+ {
+ if (firstInChain == null) return Collections.emptyList();
+
+ List<CommandInterceptor> retval = new LinkedList<CommandInterceptor>();
+ CommandInterceptor tmp = firstInChain;
+ do
+ {
+ retval.add(tmp);
+ tmp = tmp.getNext();
+ }
+ while (tmp != null);
+ return Collections.unmodifiableList(retval);
+ }
+
+
+ /**
+ * Removes all the occurences of supplied interceptor type from the chain.
+ */
+ public synchronized void removeInterceptor(Class<? extends CommandInterceptor> clazz)
+ {
+ if (firstInChain.getClass() == clazz)
+ {
+ firstInChain = firstInChain.getNext();
+ }
+ CommandInterceptor it = firstInChain.getNext();
+ CommandInterceptor prevIt = firstInChain;
+ while (it != null)
+ {
+ if (it.getClass() == clazz)
+ {
+ prevIt.setNext(it.getNext());
+ }
+ prevIt = it;
+ it = it.getNext();
+ }
+ }
+
+ /**
+ * Adds a new interceptor in list after an interceptor of a given type.
+ *
+ * @return true if the interceptor was added; i.e. the afterInterceptor exists
+ */
+ public synchronized boolean addAfterInterceptor(CommandInterceptor toAdd, Class<? extends CommandInterceptor> afterInterceptor)
+ {
+ CommandInterceptor it = firstInChain;
+ while (it != null)
+ {
+ if (it.getClass().equals(afterInterceptor))
+ {
+ toAdd.setNext(it.getNext());
+ it.setNext(toAdd);
+ return true;
+ }
+ it = it.getNext();
+ }
+ return false;
+ }
+
+ /**
+ * Adds a new interceptor in list after an interceptor of a given type.
+ *
+ * @return true if the interceptor was added; i.e. the afterInterceptor exists
+ */
+ public synchronized boolean addBeforeInterceptor(CommandInterceptor toAdd, Class<? extends CommandInterceptor> beforeInterceptor)
+ {
+ if (firstInChain.getClass().equals(beforeInterceptor))
+ {
+ toAdd.setNext(firstInChain);
+ firstInChain = toAdd;
+ return true;
+ }
+ CommandInterceptor it = firstInChain;
+ while (it.getNext() != null)
+ {
+ if (it.getNext().getClass().equals(beforeInterceptor))
+ {
+ toAdd.setNext(it.getNext());
+ it.setNext(toAdd);
+ return true;
+ }
+ it = it.getNext();
+ }
+ return false;
+ }
+
+ /**
+ * Appends at the end.
+ */
+ public void appendIntereceptor(CommandInterceptor ci)
+ {
+ CommandInterceptor it = firstInChain;
+ while (it.hasNext()) it = it.getNext();
+ it.setNext(ci);
+ // make sure we nullify the "next" pointer in the last interceptors.
+ ci.setNext(null);
+ }
+
+ /**
+ * Walks the command through the interceptor chain. The received ctx is being passed in.
+ */
+ @SuppressWarnings("deprecation")
+ public Object invoke(InvocationContext ctx, VisitableCommand command)
+ {
+ ctx.setCommand(command);
+ try
+ {
+ return command.acceptVisitor(ctx, firstInChain);
+ }
+ catch (CacheException e)
+ {
+ throw e;
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw new CacheException(t);
+ }
+ }
+
+ /**
+ * Similar to {@link #invoke(org.jboss.cache.starbrnoInvocationContext , org.jboss.cache.starbrnocommands.VisitableCommand)}, but
+ * constructs a invocation context on the fly, using {@link org.jboss.cache.starbrnoinvocation.InvocationContextContainer#get()}
+ */
+ public Object invokeRemote(VisitableCommand cacheCommand) throws Throwable
+ {
+ InvocationContext ctxt = invocationContextContainer.get();
+ ctxt.setOriginLocal(false);
+ return cacheCommand.acceptVisitor(ctxt, firstInChain);
+ }
+
+ /**
+ * Similar to {@link #invoke(org.jboss.cache.starbrnoInvocationContext , org.jboss.cache.starbrnocommands.VisitableCommand)}, but
+ * constructs a invocation context on the fly, using {@link org.jboss.cache.starbrnoinvocation.InvocationContextContainer#get()} and setting the origin local flag to its default value.
+ */
+ public Object invoke(VisitableCommand cacheCommand) throws Throwable
+ {
+ InvocationContext ctxt = invocationContextContainer.get();
+ return cacheCommand.acceptVisitor(ctxt, firstInChain);
+ }
+
+ /**
+ * @return the first interceptor in the chain.
+ */
+ public CommandInterceptor getFirstInChain()
+ {
+ return firstInChain;
+ }
+
+ /**
+ * Mainly used by unit tests to replace the interceptor chain with the starting point passed in.
+ *
+ * @param interceptor interceptor to be used as the first interceptor in the chain.
+ */
+ public void setFirstInChain(CommandInterceptor interceptor)
+ {
+ this.firstInChain = interceptor;
+ }
+
+ public InvocationContext getInvocationContext()
+ {
+ return invocationContextContainer.get();
+ }
+
+ /**
+ * Returns all interceptors which extend the given command interceptor.
+ */
+ public List<CommandInterceptor> getInterceptorsWhichExtend(Class<? extends CommandInterceptor> interceptorClass)
+ {
+ List<CommandInterceptor> result = new ArrayList<CommandInterceptor>();
+ for (CommandInterceptor interceptor : asList())
+ {
+ boolean isSubclass = interceptorClass.isAssignableFrom(interceptor.getClass());
+ if (isSubclass)
+ {
+ result.add(interceptor);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns all the interceptors that have the fully qualified name of their class equal with the supplied class name.
+ */
+ public List<CommandInterceptor> getInterceptorsWithClassName(String fqName)
+ {
+ CommandInterceptor iterator = firstInChain;
+ List<CommandInterceptor> result = new ArrayList<CommandInterceptor>(2);
+ while (iterator != null)
+ {
+ if (iterator.getClass().getName().equals(fqName)) result.add(iterator);
+ iterator = iterator.getNext();
+ }
+ return result;
+ }
+
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ CommandInterceptor i = firstInChain;
+ if (i != null)
+ {
+ if (i.getNext() != null)
+ {
+ sb.append(i.getNext()).append("\n");
+ }
+ sb.append("\t>> ");
+ sb.append(i.getClass().getName());
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Checks whether the chain contains the supplied interceptor instance.
+ */
+ public boolean containsInstance(CommandInterceptor interceptor)
+ {
+ CommandInterceptor it = firstInChain;
+ while (it != null)
+ {
+ if (it == interceptor) return true;
+ it = it.getNext();
+ }
+ return false;
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/CommandInterceptor.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,133 @@
+/*
+ * 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.interceptors.base;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.starobrno.commands.AbstractVisitor;
+import org.jboss.starobrno.commands.VisitableCommand;
+import org.jboss.starobrno.config.Configuration;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.context.InvocationContext;
+
+/**
+ * This is the base class for all interceptors to extend, and implements the {@link org.jboss.cache.commands.Visitor} interface
+ * allowing it to intercept invocations on {@link org.jboss.cache.commands.VisitableCommand}s.
+ * <p/>
+ * Commands are created either by the {@link org.jboss.cache.invocation.CacheInvocationDelegate} (for invocations on the {@link org.jboss.cache.Cache}
+ * public interface), the {@link org.jboss.cache.invocation.NodeInvocationDelegate} for invocations on the {@link org.jboss.cache.Node}
+ * public interface, or by the {@link org.jboss.cache.marshall.CommandAwareRpcDispatcher} for remotely originating invocations, and
+ * are passed up the interceptor chain by using the {@link org.jboss.cache.interceptors.InterceptorChain} helper class.
+ * <p/>
+ * When writing interceptors, authors can either override a specific visitXXX() method (such as {@link #visitGetKeyValueCommand(org.jboss.cache.InvocationContext , org.jboss.cache.commands.read.GetKeyValueCommand)})
+ * or the more generic {@link #handleDefault(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand)} which is the default behaviour of
+ * any visit method, as defined in {@link org.jboss.cache.commands.AbstractVisitor#handleDefault(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand)}.
+ * <p/>
+ * The preferred approach is to override the specific visitXXX() methods that are of interest rather than to override {@link #handleDefault(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand)}
+ * and then write a series of if statements or a switch block, if command-specific behaviour is needed.
+ * <p/>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @see org.jboss.cache.commands.VisitableCommand
+ * @see org.jboss.cache.commands.Visitor
+ * @see org.jboss.cache.interceptors.InterceptorChain
+ * @since 2.2
+ */
+public class CommandInterceptor extends AbstractVisitor
+{
+ private CommandInterceptor next;
+
+ protected Log log;
+ protected boolean trace;
+
+ protected Configuration configuration;
+
+ public CommandInterceptor()
+ {
+ log = LogFactory.getLog(getClass());
+ trace = log.isTraceEnabled();
+ }
+
+ @Inject
+ private void injectConfiguration(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ /**
+ * Retrieves the next interceptor in the chain.
+ *
+ * @return the next interceptor in the chain.
+ */
+ public CommandInterceptor getNext()
+ {
+ return next;
+ }
+
+ /**
+ * @return true if there is another interceptor in the chain after this; false otherwise.
+ */
+ public boolean hasNext()
+ {
+ return getNext() != null;
+ }
+
+ /**
+ * Sets the next interceptor in the chain to the interceptor passed in.
+ *
+ * @param next next interceptor in the chain.
+ */
+ public void setNext(CommandInterceptor next)
+ {
+ this.next = next;
+ }
+
+ /**
+ * Invokes the next interceptor in the chain. This is how interceptor implementations should pass a call up the chain
+ * to the next interceptor. In previous (pre-2.2.0) implementations of JBoss Cache, this was done by calling
+ * <pre>super.invoke()</pre>.
+ *
+ * @param ctx invocation context
+ * @param command command to pass up the chain.
+ * @return return value of the invocation
+ * @throws Throwable in the event of problems
+ */
+ public Object invokeNextInterceptor(InvocationContext ctx, VisitableCommand command) throws Throwable
+ {
+ return command.acceptVisitor(ctx, next);
+ }
+
+ /**
+ * The default behaviour of the visitXXX methods, which is to ignore the call and pass the call up to the next
+ * interceptor in the chain.
+ *
+ * @param ctx invocation context
+ * @param command command to invoke
+ * @return return value
+ * @throws Throwable in the event of problems
+ */
+ @Override
+ protected Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/PrePostProcessingCommandInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/PrePostProcessingCommandInterceptor.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/PrePostProcessingCommandInterceptor.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,463 @@
+/*
+ * 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.interceptors.base;
+
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.interceptors.base.CommandInterceptor;
+import org.jboss.cache.commands.VisitableCommand;
+import org.jboss.cache.commands.legacy.write.CreateNodeCommand;
+import org.jboss.cache.commands.read.ExistsCommand;
+import org.jboss.cache.commands.read.GetChildrenNamesCommand;
+import org.jboss.cache.commands.read.GetDataMapCommand;
+import org.jboss.cache.commands.read.GetKeyValueCommand;
+import org.jboss.cache.commands.read.GetKeysCommand;
+import org.jboss.cache.commands.read.GetNodeCommand;
+import org.jboss.cache.commands.read.GravitateDataCommand;
+import org.jboss.cache.commands.tx.CommitCommand;
+import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
+import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.commands.tx.RollbackCommand;
+import org.jboss.cache.commands.write.ClearDataCommand;
+import org.jboss.cache.commands.write.EvictCommand;
+import org.jboss.cache.commands.write.InvalidateCommand;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
+
+/**
+ * This interceptor adds pre and post processing to each <tt>visitXXX()</tt> method.
+ * <p/>
+ * For each <tt>visitXXX()</tt> method invoked, it will first call {@link #doBeforeCall(org.jboss.cache.InvocationContext, org.jboss.cache.commands.VisitableCommand)}
+ * and if this method returns true, it will proceed to invoking a <tt>handleXXX()</tt> method and lastly, {@link #doAfterCall(org.jboss.cache.InvocationContext, org.jboss.cache.commands.VisitableCommand)}
+ * in a <tt>finally</tt> block. Note that the <tt>doAfterCall()</tt> method is still invoked even if <tt>doBeforeCall()</tt> returns <tt>false</tt>.
+ * <p/>
+ * Instead of overriding <tt>visitXXX()</tt> methods, implementations should override their <tt>handleXXX()</tt> counterparts defined in this class
+ * instead, as well as the {@link #doAfterCall(org.jboss.cache.InvocationContext ,org.jboss.cache.commands.VisitableCommand)} method and
+ * optionally {@link #doBeforeCall(org.jboss.cache.InvocationContext, org.jboss.cache.commands.VisitableCommand)}.
+ * <p/>
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public abstract class PrePostProcessingCommandInterceptor extends CommandInterceptor
+{
+ @Override
+ public final Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handlePutDataMapCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handlePutKeyValueCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ @Override
+ public final Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handlePutForExternalReadCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+
+ protected Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ protected Object handlePutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+
+ @Override
+ public final Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleRemoveNodeCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitCreateNodeCommand(InvocationContext ctx, CreateNodeCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleCreateNodeCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ /**
+ * @deprecated in 3.0. Will be removed when Optimistic and Pessimistic locking is removed.
+ */
+ @Deprecated
+ protected Object handleCreateNodeCommand(InvocationContext ctx, CreateNodeCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+
+ @Override
+ public final Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleClearDataCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleEvictFqnCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleInvalidateCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleRemoveKeyCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleGetDataMapCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleExistsNodeCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleGetKeyValueCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleGetNodeCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleGetKeysCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleGetChildrenNamesCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleMoveCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleGravitateDataCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handlePrepareCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleRollbackCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleCommitCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ @Override
+ public final Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
+ {
+ try
+ {
+ return doBeforeCall(ctx, command) ? handleOptimisticPrepareCommand(ctx, command) : null;
+ }
+ finally
+ {
+ doAfterCall(ctx, command);
+ }
+ }
+
+ protected Object handleOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
+ {
+ return handleDefault(ctx, command);
+ }
+
+ /**
+ * Callback that is invoked after every handleXXX() method defined above.
+ *
+ * @param ctx invocation context
+ * @param command command which was invoked
+ */
+ protected abstract void doAfterCall(InvocationContext ctx, VisitableCommand command);
+
+ protected boolean doBeforeCall(InvocationContext ctx, VisitableCommand command)
+ {
+ return true;
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/SkipCheckChainedInterceptor.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/SkipCheckChainedInterceptor.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/interceptors/base/SkipCheckChainedInterceptor.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,395 @@
+/*
+ * 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.interceptors.base;
+
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.interceptors.base.CommandInterceptor;
+import org.jboss.cache.commands.VisitableCommand;
+import org.jboss.cache.commands.read.ExistsCommand;
+import org.jboss.cache.commands.read.GetChildrenNamesCommand;
+import org.jboss.cache.commands.read.GetDataMapCommand;
+import org.jboss.cache.commands.read.GetKeyValueCommand;
+import org.jboss.cache.commands.read.GetKeysCommand;
+import org.jboss.cache.commands.read.GetNodeCommand;
+import org.jboss.cache.commands.read.GravitateDataCommand;
+import org.jboss.cache.commands.tx.CommitCommand;
+import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
+import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.commands.tx.RollbackCommand;
+import org.jboss.cache.commands.write.ClearDataCommand;
+import org.jboss.cache.commands.write.EvictCommand;
+import org.jboss.cache.commands.write.InvalidateCommand;
+import org.jboss.cache.commands.write.MoveCommand;
+import org.jboss.cache.commands.write.PutDataMapCommand;
+import org.jboss.cache.commands.write.PutForExternalReadCommand;
+import org.jboss.cache.commands.write.PutKeyValueCommand;
+import org.jboss.cache.commands.write.RemoveKeyCommand;
+import org.jboss.cache.commands.write.RemoveNodeCommand;
+
+/**
+ * This interceptor will call {@link #skipInterception(org.jboss.cache.InvocationContext ,org.jboss.cache.commands.VisitableCommand)} before invoking each visit method
+ * (and the {@link #handleDefault(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand)} method). If
+ * {@link #skipInterception(org.jboss.cache.InvocationContext ,org.jboss.cache.commands.VisitableCommand)} returns <tt>false</tt>, the invocation will be skipped
+ * and passed up the interceptor chain instead.
+ * <p/>
+ * Instead of overriding visitXXX() methods, implementations should override their handleXXX() counterparts defined in this class
+ * instead, as well as the {@link #skipInterception(org.jboss.cache.InvocationContext ,org.jboss.cache.commands.VisitableCommand)} method.
+ * Also, instead of overriding {@link #handleDefault(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand)}, implementors
+ * should override {@link #handleAll(org.jboss.cache.InvocationContext , org.jboss.cache.commands.VisitableCommand)}.
+ *
+ * @author Mircea.Markus(a)jboss.com
+ * @since 2.2
+ */
+public abstract class SkipCheckChainedInterceptor extends CommandInterceptor
+{
+ @Override
+ public final Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handlePutDataMapCommand(ctx, command);
+ }
+
+ protected Object handlePutDataMapCommand(InvocationContext ctx, PutDataMapCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handlePutKeyValueCommand(ctx, command);
+ }
+
+ @Override
+ public final Object visitPutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handlePutForExternalReadCommand(ctx, command);
+ }
+
+ protected Object handlePutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ protected Object handlePutForExternalReadCommand(InvocationContext ctx, PutForExternalReadCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleRemoveNodeCommand(ctx, command);
+ }
+
+ protected Object handleRemoveNodeCommand(InvocationContext ctx, RemoveNodeCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitClearDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleRemoveDataCommand(ctx, command);
+ }
+
+ protected Object handleRemoveDataCommand(InvocationContext ctx, ClearDataCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleEvictFqnCommand(ctx, command);
+ }
+
+ protected Object handleEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleInvalidateCommand(ctx, command);
+ }
+
+ protected Object handleInvalidateCommand(InvocationContext ctx, InvalidateCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleRemoveKeyCommand(ctx, command);
+ }
+
+ protected Object handleRemoveKeyCommand(InvocationContext ctx, RemoveKeyCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleGetDataMapCommand(ctx, command);
+ }
+
+ protected Object handleGetDataMapCommand(InvocationContext ctx, GetDataMapCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleExistsNodeCommand(ctx, command);
+ }
+
+ protected Object handleExistsNodeCommand(InvocationContext ctx, ExistsCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleGetKeyValueCommand(ctx, command);
+ }
+
+ protected Object handleGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleGetNodeCommand(ctx, command);
+ }
+
+ protected Object handleGetNodeCommand(InvocationContext ctx, GetNodeCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleGetKeysCommand(ctx, command);
+ }
+
+ protected Object handleGetKeysCommand(InvocationContext ctx, GetKeysCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleGetChildrenNamesCommand(ctx, command);
+ }
+
+ protected Object handleGetChildrenNamesCommand(InvocationContext ctx, GetChildrenNamesCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleMoveCommand(ctx, command);
+ }
+
+ protected Object handleMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleGravitateDataCommand(ctx, command);
+ }
+
+ protected Object handleGravitateDataCommand(InvocationContext ctx, GravitateDataCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handlePrepareCommand(ctx, command);
+ }
+
+ protected Object handlePrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleRollbackCommand(ctx, command);
+ }
+
+ protected Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleCommitCommand(ctx, command);
+ }
+
+ protected Object handleCommitCommand(InvocationContext ctx, CommitCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object visitOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleOptimisticPrepareCommand(ctx, command);
+ }
+
+ protected Object handleOptimisticPrepareCommand(InvocationContext ctx, OptimisticPrepareCommand command) throws Throwable
+ {
+ return handleAll(ctx, command);
+ }
+
+ @Override
+ public final Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable
+ {
+ if (skipInterception(ctx, command))
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+ return handleAll(ctx, command);
+ }
+
+ /**
+ * Default implementation, which just passes the call up the interceptor chain
+ *
+ * @param ctx invocation context
+ * @param command command
+ * @return return value
+ * @throws Throwable in the event of problems
+ */
+ protected Object handleAll(InvocationContext ctx, VisitableCommand command) throws Throwable
+ {
+ return invokeNextInterceptor(ctx, command);
+ }
+
+ /**
+ * Tests whether the command should be intercepted or not. This is invoked before any of the handleXXX() methods.
+ *
+ * @param ctx invocation context
+ * @param command command
+ * @return true if the invocation should skip the current interceptor and move on to the next in the chain, false otherwise.
+ */
+ protected abstract boolean skipInterception(InvocationContext ctx, VisitableCommand command);
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/invocation/InvocationContextContainer.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/invocation/InvocationContextContainer.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,53 @@
+/*
+ * 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.invocation;
+
+import org.jboss.starobrno.factories.annotations.NonVolatile;
+import org.jboss.starobrno.factories.annotations.Inject;
+import org.jboss.starobrno.factories.context.ContextFactory;
+import org.jboss.starobrno.context.InvocationContext;
+
+
+/**
+ * Container and factory for thread locals
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.1.0
+ */
+@NonVolatile
+public class InvocationContextContainer extends ThreadLocal<InvocationContext>
+{
+ ContextFactory contextFactory;
+
+ @Inject
+ public void injectContextFactory(ContextFactory contextFactory)
+ {
+ this.contextFactory = contextFactory;
+ }
+
+ @Override
+ protected InvocationContext initialValue()
+ {
+ // create if this is initially unset
+ return contextFactory.createInvocationContext();
+ }
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/transaction/GlobalTransaction.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/transaction/GlobalTransaction.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/transaction/GlobalTransaction.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/transaction/GlobalTransaction.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,160 @@
+/*
+ * 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.transaction;
+
+
+import org.jgroups.Address;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+
+/**
+ * Uniquely identifies a transaction that spans all nodes 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>
+ *
+ * @author <a href="mailto:bela@jboss.org">Bela Ban</a> Apr 12, 2003
+ * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
+ * @version $Revision$
+ */
+public class GlobalTransaction implements Externalizable
+{
+
+ private static final long serialVersionUID = 8011434781266976149L;
+
+ private static long sid = 0;
+
+ private Address addr = null;
+ private long id = -1;
+ private transient boolean remote = false;
+
+ // cache the hashcode
+ private transient int hash_code = -1; // in the worst case, hashCode() returns 0, then increases, so we're safe here
+
+ /**
+ * empty ctor used by externalization
+ */
+ public GlobalTransaction()
+ {
+ }
+
+ private GlobalTransaction(Address addr)
+ {
+ this.addr = addr;
+ id = newId();
+ }
+
+ private static synchronized long newId()
+ {
+ return ++sid;
+ }
+
+ public static GlobalTransaction create(Address addr)
+ {
+ return new GlobalTransaction(addr);
+ }
+
+ public Object getAddress()
+ {
+ return addr;
+ }
+
+ public void setAddress(Address address)
+ {
+ addr = address;
+ }
+
+ public long getId()
+ {
+ return id;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ if (hash_code == -1)
+ {
+ hash_code = (addr != null ? addr.hashCode() : 0) + (int) id;
+ }
+ return hash_code;
+ }
+
+ @Override
+ public boolean equals(Object other)
+ {
+ if (this == other)
+ return true;
+ if (!(other instanceof GlobalTransaction))
+ return false;
+
+ GlobalTransaction otherGtx = (GlobalTransaction) other;
+ boolean aeq = (addr == null) ? (otherGtx.addr == null) : addr.equals(otherGtx.addr);
+ return aeq && (id == otherGtx.id);
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("GlobalTransaction:<").append(addr).append(">:").append(id);
+ return sb.toString();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeObject(addr);
+ out.writeLong(id);
+ // out.writeInt(hash_code);
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ addr = (Address) in.readObject();
+ id = in.readLong();
+ hash_code = -1;
+ }
+
+ /**
+ * @return Returns the remote.
+ */
+ public boolean isRemote()
+ {
+ return remote;
+ }
+
+ /**
+ * @param remote The remote to set.
+ */
+ public void setRemote(boolean remote)
+ {
+ this.remote = remote;
+ }
+
+
+ public void setId(long id)
+ {
+ this.id = id;
+ }
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionContext.java (from rev 6850, core/branches/flat/src/main/java/org/jboss/cache/transaction/TransactionContext.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionContext.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/transaction/TransactionContext.java 2008-10-08 09:34:41 UTC (rev 6859)
@@ -0,0 +1,283 @@
+/*
+ * 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.transaction;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.WriteCommand;
+import org.jboss.cache.config.Option;
+import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
+
+import javax.transaction.Transaction;
+import java.util.List;
+
+/**
+ * Captures information pertaining to a specific JTA transaction.
+ * <p/>
+ * This was a concrete class called TransactionEntry prior to 3.0.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @see org.jboss.cache.InvocationContext
+ */
+public interface TransactionContext
+{
+ /**
+ * Adds a modification to the modification list.
+ *
+ * @param command modification
+ */
+ void addModification(WriteCommand command);
+
+ /**
+ * Returns all modifications. If there are no modifications in this transaction this method will return an empty list.
+ *
+ * @return list of modifications.
+ */
+ List<WriteCommand> getModifications();
+
+ /**
+ * Adds a modification to the local modification list.
+ *
+ * @param command command to add to list. Should not be null.
+ * @throws NullPointerException if the command to be added is null.
+ */
+ void addLocalModification(WriteCommand command);
+
+ /**
+ * Returns all modifications that have been invoked with the LOCAL cache mode option. These will also be in the standard modification list.
+ *
+ * @return list of LOCAL modifications, or an empty list.
+ */
+ List<WriteCommand> getLocalModifications();
+
+ /**
+ * Adds the node that has been removed in the scope of the current transaction.
+ *
+ * @param fqn fqn that has been removed.
+ * @throws NullPointerException if the Fqn is null.
+ */
+ void addRemovedNode(Fqn fqn);
+
+ /**
+ * Gets the list of removed nodes.
+ *
+ * @return list of nodes removed in the current transaction scope. Note that this method will return an empty list if nothing has been removed. The list returned is defensively copied.
+ */
+ List<Fqn> getRemovedNodes();
+
+ /**
+ * Sets the local transaction to be associated with this transaction context.
+ *
+ * @param tx JTA transaction to associate with.
+ */
+ void setTransaction(Transaction tx);
+
+ /**
+ * Returns a local transaction associated with this context.
+ *
+ * @return a JTA transaction
+ */
+ Transaction getTransaction();
+
+ /**
+ * Adds a lock to the currently maintained collection of locks acquired.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#addLock(Object)} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link org.jboss.cache.Fqn}s as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link org.jboss.cache.Fqn}.
+ *
+ * @param lock lock to add
+ * @see org.jboss.cache.InvocationContext#addLock(Object)
+ */
+ @SuppressWarnings("unchecked")
+ void addLock(Object lock);
+
+ /**
+ * Removes a lock from the currently maintained collection of locks acquired.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#removeLock(Object)} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link org.jboss.cache.Fqn}s as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link org.jboss.cache.Fqn}.
+ *
+ * @param lock lock to remove
+ * @see org.jboss.cache.InvocationContext#removeLock(Object)
+ */
+ @SuppressWarnings("unchecked")
+ void removeLock(Object lock);
+
+ /**
+ * Clears all locks from the currently maintained collection of locks acquired.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#clearLocks()} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link org.jboss.cache.Fqn}s as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link org.jboss.cache.Fqn}.
+ *
+ * @see org.jboss.cache.InvocationContext#clearLocks()
+ */
+ void clearLocks();
+
+ /**
+ * Adds a List of locks to the currently maintained collection of locks acquired.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#addAllLocks(java.util.List)} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept <tt>List<Fqn></tt>.
+ *
+ * @param newLocks locks to add
+ * @see org.jboss.cache.InvocationContext#addAllLocks(java.util.List)
+ */
+ @SuppressWarnings("unchecked")
+ void addAllLocks(List newLocks);
+
+ /**
+ * Returns an immutable, defensive copy of the List of locks currently maintained for the transaction.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#getLocks()} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to return <tt>List<Fqn></tt>.
+ *
+ * @return locks held in current scope.
+ * @see org.jboss.cache.InvocationContext#getLocks()
+ */
+ @SuppressWarnings("unchecked")
+ List getLocks();
+
+ /**
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#hasLock(Object)} ()} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ *
+ * @param lock lock to test
+ * @return true if the lock being tested is already held in the current scope, false otherwise.
+ */
+ boolean hasLock(Object lock);
+
+ /**
+ * Gets the value of the forceAsyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
+ * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
+ * a transactional context.
+ *
+ * @return true if the forceAsyncReplication flag is set to true.
+ */
+ boolean isForceAsyncReplication();
+
+ /**
+ * Sets the value of the forceAsyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
+ * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
+ * a transactional context. Also used by OptimisticReplicationInterceptor when dealing
+ * with {@link org.jboss.cache.config.Option#setForceAsynchronous(boolean)} in a
+ * non-transactional context (i.e. with an implicit transaction).
+ *
+ * @param forceAsyncReplication value of forceAsyncReplication
+ */
+ void setForceAsyncReplication(boolean forceAsyncReplication);
+
+ /**
+ * Gets the value of the forceSyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
+ * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
+ * a transactional context.
+ *
+ * @return true if the forceAsyncReplication flag is set to true.
+ */
+ boolean isForceSyncReplication();
+
+ /**
+ * Sets the value of the forceSyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
+ * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
+ * a transactional context.
+ *
+ * @param forceSyncReplication value of forceSyncReplication
+ */
+ void setForceSyncReplication(boolean forceSyncReplication);
+
+ /**
+ * Adds an Fqn to the list of uninitialized nodes created by the cache loader.
+ *
+ * @param fqn fqn to add. Must not be null.
+ */
+ void addDummyNodeCreatedByCacheLoader(Fqn fqn);
+
+ /**
+ * @return a list of uninitialized nodes created by the cache loader, or an empty list.
+ */
+ List<Fqn> getDummyNodesCreatedByCacheLoader();
+
+ /**
+ * Sets a transaction-scope option override
+ *
+ * @param o option to set
+ */
+ void setOption(Option o);
+
+ /**
+ * Retrieves a transaction scope option override
+ *
+ * @return option
+ */
+ Option getOption();
+
+ /**
+ * @return the ordered sync handler associated with this transaction
+ */
+ OrderedSynchronizationHandler getOrderedSynchronizationHandler();
+
+ /**
+ * Associates an ordered sync handler with this transaction.
+ *
+ * @param orderedSynchronizationHandler to set
+ */
+ void setOrderedSynchronizationHandler(OrderedSynchronizationHandler orderedSynchronizationHandler);
+
+ /**
+ * @return true if modifications were registered.
+ */
+ boolean hasModifications();
+
+ /**
+ * @return true if any modifications have been invoked with cache mode being LOCAL.
+ */
+ boolean hasLocalModifications();
+
+ /**
+ * @return true if either there are modifications or local modifications that are not for replicating.
+ */
+ boolean hasAnyModifications();
+
+ /**
+ * Cleans up internal state, freeing up references.
+ */
+ void reset();
+}
\ No newline at end of file
16 years, 2 months
JBoss Cache SVN: r6858 - in core/branches/flat/src/main/java/org/jboss/starobrno: lock and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 05:30:07 -0400 (Wed, 08 Oct 2008)
New Revision: 6858
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/lock/
core/branches/flat/src/main/java/org/jboss/starobrno/lock/LockManager.java
core/branches/flat/src/main/java/org/jboss/starobrno/lock/StripedLockManager.java
Log:
Updated lock manager
Added: core/branches/flat/src/main/java/org/jboss/starobrno/lock/LockManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/lock/LockManager.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/lock/LockManager.java 2008-10-08 09:30:07 UTC (rev 6858)
@@ -0,0 +1,136 @@
+/*
+ * 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.lock;
+
+import org.jboss.starobrno.context.InvocationContext;
+
+/**
+ * An interface to deal with all aspects of acquiring and releasing locks for nodes in the cache.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 2.2.0
+ */
+public interface LockManager
+{
+ /**
+ * Determines the owner to be used when obtaining locks, given an invocation context. This is typically a {@link org.jboss.cache.transaction.GlobalTransaction} if one
+ * is present in the context, or {@link Thread#currentThread()} if one is not present.
+ *
+ * @param ctx invocation context
+ * @return owner to be used for acquiring locks.
+ */
+ 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.jboss.cache.config.Configuration#getLockAcquisitionTimeout()} milliseconds and give up if it is unable to acquire the required lock.
+ *
+ * @param fqn Fqn to lock
+ * @param lockType type of lock to acquire
+ * @param owner owner to acquire the lock for
+ * @return true if the lock was acquired, false otherwise.
+ */
+ 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.
+ *
+ * @param fqn Fqn to lock
+ * @param lockType type of lock to acquire
+ * @param owner owner to acquire the lock for
+ * @param timeout maximum length of time to wait for (in millis)
+ * @return true if the lock was acquired, false otherwise.
+ */
+ 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.jboss.cache.config.Option#getLockAcquisitionTimeout()} and, if this is unset, the default timeout
+ * set in {@link org.jboss.cache.config.Configuration#getLockAcquisitionTimeout()} is used.
+ * <p/>
+ * In addition, any locks acquired are added to the context OR transaction entry using {@link org.jboss.cache.InvocationContext#addLock(Object)}.
+ * <p/>
+ * The owner for the lock is determined by passing the invocation context to {@link #getLockOwner(org.jboss.cache.InvocationContext)}.
+ * <p/>
+ *
+ * @param fqn Fqn to lock
+ * @param lockType type of lock to acquire
+ * @param ctx invocation context associated with this invocation
+ * @return true if the lock was acquired, false otherwise.
+ */
+ boolean lockAndRecord(Object key, InvocationContext ctx) throws InterruptedException;
+
+ /**
+ * Releases the lock passed in, held by the specified owner
+ *
+ * @param fqn Fqn of the node to unlock
+ * @param owner lock owner
+ */
+ void unlock(Object key, Object owner);
+
+ /**
+ * Releases locks present in an invocation context and transaction entry, if one is available.
+ * <p/>
+ * Locks are released in reverse order of which they are acquired and registered.
+ * <p/>
+ * Lock owner is determined by passing the invocation context to {@link #getLockOwner(org.jboss.cache.InvocationContext)}
+ * <p/>
+ *
+ * @param ctx invocation context to inspect
+ */
+ void unlock(InvocationContext ctx);
+
+ /**
+ * Tests whether a given owner owns a lock of lockType on a particular Fqn.
+ *
+ * @param fqn fqn to test
+ * @param lockType type of lock to test for
+ * @param owner owner
+ * @return true if the owner does own the specified lock type on the specified node, 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.
+ *
+ * @param n node to inspect
+ * @return true of locked; false if not.
+ */
+ boolean isLocked(Object key);
+
+ /**
+ * Retrieves the write lock owner, if any, for the current Fqn.
+ *
+ * @param f Fqn to inspect
+ * @return the owner of the lock, or null if not locked.
+ */
+ Object getOwner(Object key);
+
+ /**
+ * Prints lock information for all locks.
+ *
+ * @return lock information
+ */
+ String printLockInfo();
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/lock/StripedLockManager.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/lock/StripedLockManager.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/lock/StripedLockManager.java 2008-10-08 09:30:07 UTC (rev 6858)
@@ -0,0 +1,164 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.lock;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.annotations.Inject;
+import org.jboss.cache.factories.annotations.Start;
+import org.jboss.cache.invocation.InvocationContextContainer;
+import org.jboss.cache.lock.MVCCLockManager;
+import org.jboss.cache.util.concurrent.locks.LockContainer;
+import org.jboss.cache.util.concurrent.locks.OwnableReentrantLock;
+import org.jboss.cache.util.concurrent.locks.OwnableReentrantLockContainer;
+import org.jboss.cache.util.concurrent.locks.ReentrantLockContainer;
+import org.jboss.starobrno.context.InvocationContext;
+
+import javax.transaction.TransactionManager;
+import java.util.List;
+import java.util.ListIterator;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import java.util.concurrent.locks.Lock;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class StripedLockManager implements LockManager
+{
+ protected Configuration configuration;
+ protected long lockAcquisitionTimeout;
+ LockContainer<Object> lockContainer;
+ private TransactionManager transactionManager;
+ private InvocationContextContainer invocationContextContainer;
+ private static final Log log = LogFactory.getLog(MVCCLockManager.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ @Inject
+ public void injectDependencies(Configuration configuration, TransactionManager transactionManager, InvocationContextContainer invocationContextContainer)
+ {
+ this.configuration = configuration;
+ this.transactionManager = transactionManager;
+ this.invocationContextContainer = invocationContextContainer;
+ }
+
+ @Start
+ public void startLockManager()
+ {
+ this.lockAcquisitionTimeout = configuration.getLockAcquisitionTimeout();
+ lockContainer = transactionManager == null ? new ReentrantLockContainer<Object>(configuration.getConcurrencyLevel()) : new OwnableReentrantLockContainer<Object>(configuration.getConcurrencyLevel(), invocationContextContainer);
+ }
+
+ public Object getLockOwner(InvocationContext ctx)
+ {
+ return ctx.getGlobalTransaction() != null ? ctx.getGlobalTransaction() : Thread.currentThread();
+ }
+
+ public boolean lock(Object key, Object owner) throws InterruptedException
+ {
+ if (trace) log.trace("Attempting to lock " + key);
+ Lock lock = lockContainer.getLock(key);
+ return lock.tryLock(lockAcquisitionTimeout, MILLISECONDS);
+ }
+
+ public boolean lock(Object key, Object owner, long timeoutMillis) throws InterruptedException
+ {
+ if (trace) log.trace("Attempting to lock " + key);
+ Lock lock = lockContainer.getLock(key);
+ return lock.tryLock(timeoutMillis, MILLISECONDS);
+ }
+
+ public boolean lockAndRecord(Object key, InvocationContext ctx) throws InterruptedException
+ {
+ if (trace) log.trace("Attempting to lock " + key);
+ Lock lock = lockContainer.getLock(key);
+ if (lock.tryLock(ctx.getLockAcquisitionTimeout(lockAcquisitionTimeout), MILLISECONDS))
+ {
+ ctx.addKeyLocked(key);
+ return true;
+ }
+
+ // couldn't acquire lock!
+ return false;
+ }
+
+ public void unlock(Object key, Object owner)
+ {
+ if (trace) log.trace("Attempting to unlock " + key);
+ Lock lock = lockContainer.getLock(key);
+ lock.unlock();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void unlock(InvocationContext ctx)
+ {
+ List<Object> locks = ctx.getKeysLocked();
+ if (!locks.isEmpty())
+ {
+ // unlocking needs to be done in reverse order.
+ ListIterator<Object> it = locks.listIterator(locks.size());
+ while (it.hasPrevious())
+ {
+ Object k = it.previous();
+ if (trace) log.trace("Attempting to unlock " + k);
+ lockContainer.getLock(k).unlock();
+ }
+ }
+ }
+
+ public boolean ownsLock(Object key, Object owner)
+ {
+ return lockContainer.ownsLock(key, owner);
+ }
+
+ public boolean isLocked(Object key)
+ {
+ return lockContainer.isLocked(key);
+ }
+
+ public Object getOwner(Object key)
+ {
+ if (lockContainer.isLocked(key))
+ {
+ Lock l = lockContainer.getLock(key);
+
+ if (l instanceof OwnableReentrantLock)
+ {
+ return ((OwnableReentrantLock) l).getOwner();
+ }
+ else
+ {
+ // cannot determine owner.
+ return null;
+ }
+ }
+ else return null;
+ }
+
+ public String printLockInfo()
+ {
+ return lockContainer.toString();
+ }
+}
16 years, 2 months
JBoss Cache SVN: r6857 - core/branches/flat/src/main/java/org/jboss/starobrno/mvcc.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 05:17:21 -0400 (Wed, 08 Oct 2008)
New Revision: 6857
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/ReadCommittedEntry.java
Log:
Updated entries
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntry.java 2008-10-08 08:46:07 UTC (rev 6856)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntry.java 2008-10-08 09:17:21 UTC (rev 6857)
@@ -21,8 +21,8 @@
*/
package org.jboss.starobrno.mvcc;
-import org.jboss.cache.InvocationContext;
import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.context.InvocationContext;
import java.util.Map.Entry;
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/ReadCommittedEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/ReadCommittedEntry.java 2008-10-08 08:46:07 UTC (rev 6856)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/ReadCommittedEntry.java 2008-10-08 09:17:21 UTC (rev 6857)
@@ -23,9 +23,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.mvcc.ReadCommittedNode;
import org.jboss.starobrno.DataContainer;
+import org.jboss.starobrno.context.InvocationContext;
import static org.jboss.starobrno.mvcc.ReadCommittedEntry.Flags.*;
import java.util.Map.Entry;
@@ -38,7 +37,7 @@
*/
public class ReadCommittedEntry implements MVCCEntry
{
- private static final Log log = LogFactory.getLog(ReadCommittedNode.class);
+ private static final Log log = LogFactory.getLog(ReadCommittedEntry.class);
private static final boolean trace = log.isTraceEnabled();
protected volatile Entry entry, backup;
16 years, 2 months
JBoss Cache SVN: r6856 - core/branches/flat/src/main/java/org/jboss/starobrno/context.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 04:46:07 -0400 (Wed, 08 Oct 2008)
New Revision: 6856
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/context/EntryLookup.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java
Modified:
core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
Log:
Contexts
Added: core/branches/flat/src/main/java/org/jboss/starobrno/context/EntryLookup.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/EntryLookup.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/EntryLookup.java 2008-10-08 08:46:07 UTC (rev 6856)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.context;
+
+import org.jboss.starobrno.mvcc.MVCCEntry;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface EntryLookup
+{
+ MVCCEntry lookupEntry(Object key);
+
+ Map<Object, MVCCEntry> getLookedUpEntries();
+
+ void putLookedUpEntry(MVCCEntry e);
+
+ void putLookedUpEntries(Set<MVCCEntry> lookedUpEntries);
+
+ void clearLookedUpEntries();
+}
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java 2008-10-08 08:22:02 UTC (rev 6855)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java 2008-10-08 08:46:07 UTC (rev 6856)
@@ -24,13 +24,9 @@
import org.jboss.cache.commands.VisitableCommand;
import org.jboss.cache.config.Option;
import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.TransactionContext;
-import org.jboss.starobrno.mvcc.MVCCEntry;
import javax.transaction.Transaction;
import java.util.List;
-import java.util.Map;
-import java.util.Set;
/**
* // TODO: MANIK: Document this
@@ -38,18 +34,8 @@
* @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
* @since 3.0
*/
-public interface InvocationContext
+public interface InvocationContext extends EntryLookup
{
- MVCCEntry lookupEntry(Object key);
-
- Map<Object, MVCCEntry> getLookedUpEntries();
-
- void putLookedUpEntry(MVCCEntry e);
-
- void putLookedUpEntries(Set<MVCCEntry> lookedUpEntries);
-
- void clearLookedUpEntries();
-
void setLocalRollbackOnly(boolean localRollbackOnly);
Transaction getTransaction();
Modified: core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java 2008-10-08 08:22:02 UTC (rev 6855)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java 2008-10-08 08:46:07 UTC (rev 6856)
@@ -29,7 +29,6 @@
import org.jboss.cache.config.Option;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.transaction.GlobalTransaction;
-import org.jboss.cache.transaction.TransactionContext;
import org.jboss.cache.transaction.TransactionTable;
import org.jboss.cache.util.Immutables;
import org.jboss.starobrno.mvcc.MVCCEntry;
@@ -86,10 +85,8 @@
*/
public MVCCEntry lookupEntry(Object k)
{
- // TODO: Fix this after we have a Transaction context that works.
-// if (transactionContext != null) return transactionContext.lookupEntry(k);
-// return lookedUpEntries == null ? null : lookedUpEntries.get(k);
- return null;
+ if (transactionContext != null) return transactionContext.lookupEntry(k);
+ return lookedUpEntries == null ? null : lookedUpEntries.get(k);
}
/**
@@ -103,29 +100,26 @@
*/
public void putLookedUpEntry(MVCCEntry e)
{
- // TODO: Fix this after we have a Transaction context that works.
-
-// if (transactionContext != null)
-// transactionContext.putLookedUpEntry(e);
-// else
-// {
-// if (lookedUpEntries == null) lookedUpEntries = new HashMap<Object, MVCCEntry>(4);
-// lookedUpEntries.put(e.getKey(), e);
-// }
+ if (transactionContext != null)
+ transactionContext.putLookedUpEntry(e);
+ else
+ {
+ if (lookedUpEntries == null) lookedUpEntries = new HashMap<Object, MVCCEntry>(4);
+ lookedUpEntries.put(e.getKey(), e);
+ }
}
public void putLookedUpEntries(Set<MVCCEntry> lookedUpEntries)
{
- // TODO: Fix this after we have a Transaction context that works.
-// if (transactionContext != null)
-// transactionContext.putLookedUpEntries(lookedUpEntries);
-// else
-// {
-// if (this.lookedUpEntries == null)
-// this.lookedUpEntries = new HashMap<Object, MVCCEntry>();
-//
-// for (MVCCEntry e: lookedUpEntries) this.lookedUpEntries.put(e.getKey(), e);
-// }
+ if (transactionContext != null)
+ transactionContext.putLookedUpEntries(lookedUpEntries);
+ else
+ {
+ if (this.lookedUpEntries == null)
+ this.lookedUpEntries = new HashMap<Object, MVCCEntry>();
+
+ for (MVCCEntry e : lookedUpEntries) this.lookedUpEntries.put(e.getKey(), e);
+ }
}
/**
@@ -135,12 +129,9 @@
*/
public void clearLookedUpEntries()
{
- // TODO: see if we can reinstate common behaviour once we have the ICI calling ctx.reset() instead of ctx.clearLookedUpNodes()
-// if (transactionContext != null)
-// transactionContext.clearLookedUpNodes();
-// else
-
- if (lookedUpEntries != null) lookedUpEntries.clear();
+ if (transactionContext != null)
+ transactionContext.clearLookedUpEntries();
+ else if (lookedUpEntries != null) lookedUpEntries.clear();
}
/**
@@ -154,10 +145,8 @@
@SuppressWarnings("unchecked")
public Map<Object, MVCCEntry> getLookedUpEntries()
{
- // TODO: Fix this after we have a Transaction context that works.
-// if (transactionContext != null) return transactionContext.getLookedUpNodes();
-// return (Map<Fqn, NodeSPI>) (lookedUpEntries == null ? Collections.emptyMap() : lookedUpEntries);
- return null;
+ if (transactionContext != null) return transactionContext.getLookedUpEntries();
+ return (Map<Object, MVCCEntry>) (lookedUpEntries == null ? Collections.emptyMap() : lookedUpEntries);
}
@SuppressWarnings("unchecked")
@@ -299,7 +288,7 @@
public List getKeysLocked()
{
// first check transactional scope
- if (transactionContext != null) return transactionContext.getLocks();
+ if (transactionContext != null) return transactionContext.getKeysLocked();
return invocationLocks == null || invocationLocks.isEmpty() ? Collections.emptyList() : Immutables.immutableListConvert(invocationLocks);
}
@@ -316,12 +305,12 @@
* @param locks locks to add
*/
@SuppressWarnings("unchecked")
- public void addAllKeysLocked(List locks)
+ public void addAllKeysLocked(List<Object> locks)
{
// first check transactional scope
if (transactionContext != null)
{
- transactionContext.addAllLocks(locks);
+ transactionContext.addAllKeysLocked(locks);
}
else
{
@@ -349,7 +338,7 @@
// first check transactional scope
if (transactionContext != null)
{
- transactionContext.addLock(lock);
+ transactionContext.addKeyLocked(lock);
}
else
{
@@ -377,7 +366,7 @@
// first check transactional scope
if (transactionContext != null)
{
- transactionContext.removeLock(lock);
+ transactionContext.removeKeyLocked(lock);
}
else
{
@@ -401,7 +390,7 @@
// first check transactional scope
if (transactionContext != null)
{
- transactionContext.clearLocks();
+ transactionContext.clearKeysLocked();
}
else
{
@@ -422,7 +411,7 @@
// first check transactional scope
if (transactionContext != null)
{
- return transactionContext.hasLock(lock);
+ return transactionContext.hasLockedKey(lock);
}
else
{
Added: core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContext.java 2008-10-08 08:46:07 UTC (rev 6856)
@@ -0,0 +1,283 @@
+/*
+ * 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.context;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.WriteCommand;
+import org.jboss.cache.config.Option;
+import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
+
+import javax.transaction.Transaction;
+import java.util.List;
+
+/**
+ * Captures information pertaining to a specific JTA transaction.
+ * <p/>
+ * This was a concrete class called TransactionEntry prior to 3.0.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @see org.jboss.cache.InvocationContext
+ */
+public interface TransactionContext extends EntryLookup
+{
+ /**
+ * Adds a modification to the modification list.
+ *
+ * @param command modification
+ */
+ void addModification(WriteCommand command);
+
+ /**
+ * Returns all modifications. If there are no modifications in this transaction this method will return an empty list.
+ *
+ * @return list of modifications.
+ */
+ List<WriteCommand> getModifications();
+
+ /**
+ * Adds a modification to the local modification list.
+ *
+ * @param command command to add to list. Should not be null.
+ * @throws NullPointerException if the command to be added is null.
+ */
+ void addLocalModification(WriteCommand command);
+
+ /**
+ * Returns all modifications that have been invoked with the LOCAL cache mode option. These will also be in the standard modification list.
+ *
+ * @return list of LOCAL modifications, or an empty list.
+ */
+ List<WriteCommand> getLocalModifications();
+
+ /**
+ * Adds the node that has been removed in the scope of the current transaction.
+ *
+ * @param fqn fqn that has been removed.
+ * @throws NullPointerException if the Fqn is null.
+ */
+ void addRemovedNode(Fqn fqn);
+
+ /**
+ * Gets the list of removed nodes.
+ *
+ * @return list of nodes removed in the current transaction scope. Note that this method will return an empty list if nothing has been removed. The list returned is defensively copied.
+ */
+ List<Fqn> getRemovedNodes();
+
+ /**
+ * Sets the local transaction to be associated with this transaction context.
+ *
+ * @param tx JTA transaction to associate with.
+ */
+ void setTransaction(Transaction tx);
+
+ /**
+ * Returns a local transaction associated with this context.
+ *
+ * @return a JTA transaction
+ */
+ Transaction getTransaction();
+
+ /**
+ * Adds a lock to the currently maintained collection of locks acquired.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#addLock(Object)} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link org.jboss.cache.Fqn}s as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link org.jboss.cache.Fqn}.
+ *
+ * @param lock lock to add
+ * @see org.jboss.cache.InvocationContext#addLock(Object)
+ */
+ @SuppressWarnings("unchecked")
+ void addKeyLocked(Object lock);
+
+ /**
+ * Removes a lock from the currently maintained collection of locks acquired.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#removeLock(Object)} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link org.jboss.cache.Fqn}s as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link org.jboss.cache.Fqn}.
+ *
+ * @param lock lock to remove
+ * @see org.jboss.cache.InvocationContext#removeLock(Object)
+ */
+ @SuppressWarnings("unchecked")
+ void removeKeyLocked(Object lock);
+
+ /**
+ * Clears all locks from the currently maintained collection of locks acquired.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#clearLocks()} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link org.jboss.cache.Fqn}s as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link org.jboss.cache.Fqn}.
+ *
+ * @see org.jboss.cache.InvocationContext#clearLocks()
+ */
+ void clearKeysLocked();
+
+ /**
+ * Adds a List of locks to the currently maintained collection of locks acquired.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#addAllLocks(java.util.List)} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept <tt>List<Fqn></tt>.
+ *
+ * @param newLocks locks to add
+ * @see org.jboss.cache.InvocationContext#addAllLocks(java.util.List)
+ */
+ @SuppressWarnings("unchecked")
+ void addAllKeysLocked(List<Object> newLocks);
+
+ /**
+ * Returns an immutable, defensive copy of the List of locks currently maintained for the transaction.
+ * <p/>
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#getLocks()} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ * <p/>
+ * Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to return <tt>List<Fqn></tt>.
+ *
+ * @return locks held in current scope.
+ * @see org.jboss.cache.InvocationContext#getLocks()
+ */
+ @SuppressWarnings("unchecked")
+ List<Object> getKeysLocked();
+
+ /**
+ * Most code could not use this method directly, but use {@link org.jboss.cache.InvocationContext#hasLock(Object)} ()} instead,
+ * which would delegate to this method if a transaction is in scope or otherwise use invocation-specific locks.
+ *
+ * @param lock lock to test
+ * @return true if the lock being tested is already held in the current scope, false otherwise.
+ */
+ boolean hasLockedKey(Object lock);
+
+ /**
+ * Gets the value of the forceAsyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
+ * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
+ * a transactional context.
+ *
+ * @return true if the forceAsyncReplication flag is set to true.
+ */
+ boolean isForceAsyncReplication();
+
+ /**
+ * Sets the value of the forceAsyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
+ * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
+ * a transactional context. Also used by OptimisticReplicationInterceptor when dealing
+ * with {@link org.jboss.cache.config.Option#setForceAsynchronous(boolean)} in a
+ * non-transactional context (i.e. with an implicit transaction).
+ *
+ * @param forceAsyncReplication value of forceAsyncReplication
+ */
+ void setForceAsyncReplication(boolean forceAsyncReplication);
+
+ /**
+ * Gets the value of the forceSyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
+ * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
+ * a transactional context.
+ *
+ * @return true if the forceAsyncReplication flag is set to true.
+ */
+ boolean isForceSyncReplication();
+
+ /**
+ * Sets the value of the forceSyncReplication flag. Used by ReplicationInterceptor and OptimisticReplicationInterceptor
+ * when dealing with {@link org.jboss.cache.Cache#putForExternalRead(org.jboss.cache.Fqn,Object,Object)} within
+ * a transactional context.
+ *
+ * @param forceSyncReplication value of forceSyncReplication
+ */
+ void setForceSyncReplication(boolean forceSyncReplication);
+
+ /**
+ * Adds an Fqn to the list of uninitialized nodes created by the cache loader.
+ *
+ * @param fqn fqn to add. Must not be null.
+ */
+ void addDummyNodeCreatedByCacheLoader(Fqn fqn);
+
+ /**
+ * @return a list of uninitialized nodes created by the cache loader, or an empty list.
+ */
+ List<Fqn> getDummyNodesCreatedByCacheLoader();
+
+ /**
+ * Sets a transaction-scope option override
+ *
+ * @param o option to set
+ */
+ void setOption(Option o);
+
+ /**
+ * Retrieves a transaction scope option override
+ *
+ * @return option
+ */
+ Option getOption();
+
+ /**
+ * @return the ordered sync handler associated with this transaction
+ */
+ OrderedSynchronizationHandler getOrderedSynchronizationHandler();
+
+ /**
+ * Associates an ordered sync handler with this transaction.
+ *
+ * @param orderedSynchronizationHandler to set
+ */
+ void setOrderedSynchronizationHandler(OrderedSynchronizationHandler orderedSynchronizationHandler);
+
+ /**
+ * @return true if modifications were registered.
+ */
+ boolean hasModifications();
+
+ /**
+ * @return true if any modifications have been invoked with cache mode being LOCAL.
+ */
+ boolean hasLocalModifications();
+
+ /**
+ * @return true if either there are modifications or local modifications that are not for replicating.
+ */
+ boolean hasAnyModifications();
+
+ /**
+ * Cleans up internal state, freeing up references.
+ */
+ void reset();
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/TransactionContextImpl.java 2008-10-08 08:46:07 UTC (rev 6856)
@@ -0,0 +1,346 @@
+/*
+ * 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.context;
+
+import org.jboss.cache.Fqn;
+import org.jboss.cache.commands.WriteCommand;
+import org.jboss.cache.config.Option;
+import org.jboss.cache.interceptors.OrderedSynchronizationHandler;
+import org.jboss.cache.util.Immutables;
+import org.jboss.starobrno.mvcc.MVCCEntry;
+
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A transaction context specially geared to dealing with MVCC.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class TransactionContextImpl implements TransactionContext
+{
+ /**
+ * Local transaction
+ */
+ private Transaction ltx = null;
+ private Option option;
+ private OrderedSynchronizationHandler orderedSynchronizationHandler;
+
+ private boolean forceAsyncReplication = false;
+ private boolean forceSyncReplication = false;
+
+ /**
+ * List<ReversibleCommand> of modifications ({@link org.jboss.cache.commands.WriteCommand}). They will be replicated on TX commit
+ */
+ private List<WriteCommand> modificationList;
+ /**
+ * A list of modifications that have been encountered with a LOCAL mode option. These will be removed from the modification list during replication.
+ */
+ private List<WriteCommand> localModifications;
+
+ /**
+ * LinkedHashSet of locks acquired by the transaction. We use a LinkedHashSet because we need efficient Set semantics
+ * but also need guaranteed ordering for use by lock release code (see JBCCACHE-874).
+ * <p/>
+ * This needs to be unchecked since we support both MVCC (Fqns held here) or legacy Opt/Pess locking (NodeLocks held here).
+ * once we drop support for opt/pess locks we can genericise this to contain Fqns. - Manik Surtani, June 2008
+ */
+ private LinkedHashSet<Object> transactionLocks;
+
+ /**
+ * A list of dummy uninitialised nodes created by the cache loader interceptor to load data for a
+ * given node in this tx.
+ */
+ private List<Fqn> dummyNodesCreatedByCacheLoader;
+
+ /**
+ * List<Fqn> of nodes that have been removed by the transaction
+ */
+ private List<Fqn> removedNodes = null;
+
+ private final Map<Object, MVCCEntry> lookedUpEntries = new HashMap<Object, MVCCEntry>(8);
+
+ public TransactionContextImpl(Transaction tx) throws SystemException, RollbackException
+ {
+ ltx = tx;
+ orderedSynchronizationHandler = new OrderedSynchronizationHandler(tx);
+ }
+
+ /**
+ * Retrieves a node from the registry of looked up nodes in the current scope.
+ * <p/>
+ * This is not normally called directly since {@link org.jboss.cache.InvocationContext#lookUpNode(org.jboss.cache.Fqn)}
+ * would delegate to this method if a transaction is in scope.
+ * <p/>
+ *
+ * @param fqn fqn to look up
+ * @return a node, or null if it cannot be found.
+ */
+ public MVCCEntry lookupEntry(Object key)
+ {
+ return lookedUpEntries.get(key);
+ }
+
+ /**
+ * Puts an entry in the registry of looked up nodes in the current scope.
+ * <p/>
+ * This is not normally called directly since {@link org.jboss.cache.InvocationContext#putLookedUpNode(org.jboss.cache.Fqn, org.jboss.cache.NodeSPI)}
+ * would delegate to this method if a transaction is in scope.
+ * <p/>
+ *
+ * @param f fqn to add
+ * @param n node to add
+ */
+ public void putLookedUpEntry(MVCCEntry entry)
+ {
+ lookedUpEntries.put(entry.getKey(), entry);
+ }
+
+ /**
+ * Clears the registry of looked up nodes.
+ * <p/>
+ * This is not normally called directly since {@link org.jboss.cache.InvocationContext#clearLookedUpNodes()}
+ * would delegate to this method if a transaction is in scope.
+ * <p/>
+ */
+ public void clearLookedUpEntries()
+ {
+ lookedUpEntries.clear();
+ }
+
+ /**
+ * Retrieves a map of nodes looked up within the current invocation's scope.
+ * <p/>
+ * This is not normally called directly since {@link org.jboss.cache.InvocationContext#getLookedUpNodes()}
+ * would delegate to this method if a transaction is in scope.
+ * <p/>
+ *
+ * @return a map of looked up nodes.
+ */
+ public Map<Object, MVCCEntry> getLookedUpEntries()
+ {
+ return lookedUpEntries;
+ }
+
+ public void reset()
+ {
+ orderedSynchronizationHandler = null;
+ modificationList = null;
+ localModifications = null;
+ option = null;
+ if (transactionLocks != null) transactionLocks.clear();
+ if (dummyNodesCreatedByCacheLoader != null) dummyNodesCreatedByCacheLoader.clear();
+ if (removedNodes != null) removedNodes.clear();
+ lookedUpEntries.clear();
+ }
+
+ public void putLookedUpEntries(Set<MVCCEntry> entries)
+ {
+ for (MVCCEntry e : entries) lookedUpEntries.put(e.getKey(), e);
+ }
+
+ public void addModification(WriteCommand command)
+ {
+ if (command == null) return;
+ if (modificationList == null) modificationList = new LinkedList<WriteCommand>();
+ modificationList.add(command);
+ }
+
+ public List<WriteCommand> getModifications()
+ {
+ if (modificationList == null) return Collections.emptyList();
+ return modificationList;
+ }
+
+ public void addLocalModification(WriteCommand command)
+ {
+ if (command == null) throw new NullPointerException("Command is null!");
+ if (localModifications == null) localModifications = new LinkedList<WriteCommand>();
+ localModifications.add(command);
+ }
+
+ public List<WriteCommand> getLocalModifications()
+ {
+ if (localModifications == null) return Collections.emptyList();
+ return localModifications;
+ }
+
+
+ public void addRemovedNode(Fqn fqn)
+ {
+ if (fqn == null) throw new NullPointerException("Fqn is null!");
+ if (removedNodes == null) removedNodes = new LinkedList<Fqn>();
+ removedNodes.add(fqn);
+ }
+
+ public List<Fqn> getRemovedNodes()
+ {
+ if (removedNodes == null) return Collections.emptyList();
+ return new ArrayList<Fqn>(removedNodes);
+ }
+
+ public void setTransaction(Transaction tx)
+ {
+ ltx = tx;
+ }
+
+ public Transaction getTransaction()
+ {
+ return ltx;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void addKeyLocked(Object lock)
+ {
+ // no need to worry about concurrency here - a context is only valid for a single thread.
+ if (transactionLocks == null) transactionLocks = new LinkedHashSet(5);
+ transactionLocks.add(lock);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void removeKeyLocked(Object lock)
+ {
+ // no need to worry about concurrency here - a context is only valid for a single thread.
+ if (transactionLocks != null) transactionLocks.remove(lock);
+ }
+
+ public void clearKeysLocked()
+ {
+ if (transactionLocks != null) transactionLocks.clear();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void addAllKeysLocked(List<Object> newLocks)
+ {
+ // no need to worry about concurrency here - a context is only valid for a single thread.
+ if (transactionLocks == null) transactionLocks = new LinkedHashSet(5);
+ transactionLocks.addAll(newLocks);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Object> getKeysLocked()
+ {
+ return transactionLocks == null || transactionLocks.isEmpty() ? Collections.emptyList() : Immutables.immutableListConvert(transactionLocks);
+ }
+
+ public boolean hasLockedKey(Object lock)
+ {
+ return transactionLocks != null && transactionLocks.contains(lock);
+ }
+
+ public boolean isForceAsyncReplication()
+ {
+ return forceAsyncReplication;
+ }
+
+ public void setForceAsyncReplication(boolean forceAsyncReplication)
+ {
+ this.forceAsyncReplication = forceAsyncReplication;
+ if (forceAsyncReplication)
+ {
+ forceSyncReplication = false;
+ }
+ }
+
+ public boolean isForceSyncReplication()
+ {
+ return forceSyncReplication;
+ }
+
+ public void setForceSyncReplication(boolean forceSyncReplication)
+ {
+ this.forceSyncReplication = forceSyncReplication;
+ if (forceSyncReplication)
+ {
+ forceAsyncReplication = false;
+ }
+ }
+
+ /**
+ * Returns debug information about this transaction.
+ */
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("TransactionEntry\nmodificationList: ").append(modificationList);
+ return sb.toString();
+ }
+
+ public void addDummyNodeCreatedByCacheLoader(Fqn fqn)
+ {
+ if (dummyNodesCreatedByCacheLoader == null)
+ dummyNodesCreatedByCacheLoader = new LinkedList<Fqn>();
+ dummyNodesCreatedByCacheLoader.add(fqn);
+ }
+
+ public List<Fqn> getDummyNodesCreatedByCacheLoader()
+ {
+ if (dummyNodesCreatedByCacheLoader == null) return Collections.emptyList();
+ return dummyNodesCreatedByCacheLoader;
+ }
+
+ public void setOption(Option o)
+ {
+ this.option = o;
+ }
+
+ public Option getOption()
+ {
+ return this.option;
+ }
+
+ public OrderedSynchronizationHandler getOrderedSynchronizationHandler()
+ {
+ return orderedSynchronizationHandler;
+ }
+
+ public void setOrderedSynchronizationHandler(OrderedSynchronizationHandler orderedSynchronizationHandler)
+ {
+ this.orderedSynchronizationHandler = orderedSynchronizationHandler;
+ }
+
+ public boolean hasModifications()
+ {
+ return modificationList != null && !modificationList.isEmpty();
+ }
+
+ public boolean hasLocalModifications()
+ {
+ return localModifications != null && !localModifications.isEmpty();
+ }
+
+ public boolean hasAnyModifications()
+ {
+ return hasModifications() || hasLocalModifications();
+ }
+}
16 years, 2 months
JBoss Cache SVN: r6855 - core/branches/flat/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-08 04:22:02 -0400 (Wed, 08 Oct 2008)
New Revision: 6855
Modified:
core/branches/flat/src/main/java/org/jboss/cache/Version.java
Log:
Updated version info
Modified: core/branches/flat/src/main/java/org/jboss/cache/Version.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/Version.java 2008-10-07 16:22:07 UTC (rev 6854)
+++ core/branches/flat/src/main/java/org/jboss/cache/Version.java 2008-10-08 08:22:02 UTC (rev 6855)
@@ -32,11 +32,28 @@
@Immutable
public class Version
{
- public static final String version = "3.0.0-SNAPSHOT";
- public static final String codename = "Naga";
+ public static final String version = "1.0-SNAPSHOT";
+ public static final String codename = "Starobrno";
//public static final String cvs = "$Id: Version.java 4592 2007-10-10 16:44:36Z manik.surtani(a)jboss.com $";
- static final byte[] version_id = {'0', '3', '0', '0', 'S'};
-
+ static final byte[] version_id = {'0', '1', '0', '0', 'S'};
+ static final String art = " ____ __ \n" +
+ "/\\ _`\\ __ /\\ \\__ \n" +
+ "\\ \\ \\L\\ \\_ __ ___ /\\_\\ __ ___\\ \\ ,_\\ \n" +
+ " \\ \\ ,__/\\`'__\\/ __`\\\\/\\ \\ /'__`\\ /'___\\ \\ \\/ \n" +
+ " \\ \\ \\/\\ \\ \\//\\ \\L\\ \\\\ \\ \\/\\ __//\\ \\__/\\ \\ \\_ \n" +
+ " \\ \\_\\ \\ \\_\\\\ \\____/_\\ \\ \\ \\____\\ \\____\\\\ \\__\\\n" +
+ " \\/_/ \\/_/ \\/___//\\ \\_\\ \\/____/\\/____/ \\/__/\n" +
+ " \\ \\____/ \n" +
+ " \\/___/ \n" +
+ " ____ __ __ \n" +
+ "/\\ _`\\ /\\ \\__ /\\ \\ \n" +
+ "\\ \\,\\L\\_\\ \\ ,_\\ __ _ __ ___\\ \\ \\____ _ __ ___ ___ \n" +
+ " \\/_\\__ \\\\ \\ \\/ /'__`\\ /\\`'__\\/ __`\\ \\ '__`\\/\\`'__\\/' _ `\\ / __`\\ \n" +
+ " /\\ \\L\\ \\ \\ \\_/\\ \\L\\.\\_\\ \\ \\//\\ \\L\\ \\ \\ \\L\\ \\ \\ \\/ /\\ \\/\\ \\/\\ \\L\\ \\\n" +
+ " \\ `\\____\\ \\__\\ \\__/.\\_\\\\ \\_\\\\ \\____/\\ \\_,__/\\ \\_\\ \\ \\_\\ \\_\\ \\____/\n" +
+ " \\/_____/\\/__/\\/__/\\/_/ \\/_/ \\/___/ \\/___/ \\/_/ \\/_/\\/_/\\/___/ \n" +
+ " \n" +
+ " ";
private static final int MAJOR_SHIFT = 11;
private static final int MINOR_SHIFT = 6;
private static final int MAJOR_MASK = 0x00f800;
@@ -51,6 +68,8 @@
*/
public static void main(String[] args)
{
+ System.out.println(art);
+ System.out.println();
System.out.println("\nVersion: \t" + version);
System.out.println("Codename: \t" + codename);
//System.out.println("CVS: \t" + cvs);
16 years, 2 months
JBoss Cache SVN: r6854 - in core/branches/flat/src/main/java/org/jboss/starobrno: context and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-07 12:22:07 -0400 (Tue, 07 Oct 2008)
New Revision: 6854
Added:
core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/
core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java
core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryImpl.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryReference.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/NullMarkerEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/ReadCommittedEntry.java
core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/RepeatableReadEntry.java
Log:
Another pint of Starobrno
Added: core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/DataContainer.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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;
+
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface DataContainer<K, V>
+{
+ Set<Entry<K, V>> getEntries();
+
+ Entry<K, V> getEntry(K k);
+
+ void putEntry(Entry<K, V> entry);
+
+ boolean exists(Entry<K, V> entry);
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/UnsortedDataContainer.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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;
+
+import java.util.LinkedHashSet;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * // TODO: crappy and inefficient - but just a placeholder for now.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class UnsortedDataContainer<K, V> implements DataContainer<K, V>
+{
+ Set<Entry<K, V>> entries = new LinkedHashSet<Entry<K, V>>();
+
+ public Set<Entry<K, V>> getEntries()
+ {
+ return entries;
+ }
+
+ public Entry<K, V> getEntry(K k)
+ {
+ if (k == null) throw new NullPointerException("I don't like nulls!");
+ for (Entry<K, V> e : entries)
+ {
+ if (k.equals(e.getKey())) return e;
+ }
+ return null;
+ }
+
+ public void putEntry(Entry<K, V> kvEntry)
+ {
+ entries.add(kvEntry);
+ }
+
+ public boolean exists(Entry<K, V> kvEntry)
+ {
+ return getEntry(kvEntry.getKey()) != null;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContext.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.context;
+
+import org.jboss.cache.commands.VisitableCommand;
+import org.jboss.cache.config.Option;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.transaction.TransactionContext;
+import org.jboss.starobrno.mvcc.MVCCEntry;
+
+import javax.transaction.Transaction;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface InvocationContext
+{
+ MVCCEntry lookupEntry(Object key);
+
+ Map<Object, MVCCEntry> getLookedUpEntries();
+
+ void putLookedUpEntry(MVCCEntry e);
+
+ void putLookedUpEntries(Set<MVCCEntry> lookedUpEntries);
+
+ void clearLookedUpEntries();
+
+ void setLocalRollbackOnly(boolean localRollbackOnly);
+
+ Transaction getTransaction();
+
+ void setTransaction(Transaction transaction);
+
+ TransactionContext getTransactionContext();
+
+ void setTransactionContext(TransactionContext transactionContext);
+
+ GlobalTransaction getGlobalTransaction();
+
+ void setGlobalTransaction(GlobalTransaction globalTransaction);
+
+ Option getOptionOverrides();
+
+ boolean isOptionsUninitialised();
+
+ void setOptionOverrides(Option optionOverrides);
+
+ boolean isOriginLocal();
+
+ List<Object> getKeysLocked();
+
+ void addAllKeysLocked(List<Object> keysLocked);
+
+ void addKeyLocked(Object keyLocked);
+
+ void removeKeyLocked(Object keyLocked);
+
+ void clearKeysLocked();
+
+ boolean hasLockedKey(Object key);
+
+ boolean isLockingSuppressed();
+
+ void setOriginLocal(boolean originLocal);
+
+ boolean isLocalRollbackOnly();
+
+ void reset();
+
+ InvocationContext copy();
+
+ void setState(InvocationContext template);
+
+ long getLockAcquisitionTimeout(long timeout);
+
+ void setCommand(VisitableCommand cacheCommand);
+
+ VisitableCommand getCommand();
+
+ boolean isValidTransaction();
+
+ void throwIfNeeded(Throwable e) throws Throwable;
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/context/InvocationContextImpl.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,619 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.context;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.commands.VisitableCommand;
+import org.jboss.cache.config.Option;
+import org.jboss.cache.marshall.MethodCall;
+import org.jboss.cache.transaction.GlobalTransaction;
+import org.jboss.cache.transaction.TransactionContext;
+import org.jboss.cache.transaction.TransactionTable;
+import org.jboss.cache.util.Immutables;
+import org.jboss.starobrno.mvcc.MVCCEntry;
+
+import javax.transaction.Transaction;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class InvocationContextImpl implements InvocationContext
+{
+ private static final Log log = LogFactory.getLog(InvocationContext.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ private Transaction transaction;
+ private GlobalTransaction globalTransaction;
+ protected TransactionContext transactionContext;
+ private Option optionOverrides;
+ // defaults to true.
+ private boolean originLocal = true;
+ private boolean localRollbackOnly;
+ @Deprecated
+ private MethodCall methodCall;
+ @Deprecated
+ private VisitableCommand command;
+
+ /**
+ * LinkedHashSet of locks acquired by the invocation. We use a LinkedHashSet because we need efficient Set semantics
+ * but also need guaranteed ordering for use by lock release code (see JBCCACHE-874).
+ * <p/>
+ * This needs to be unchecked since we support both MVCC (Fqns held here) or legacy Opt/Pess locking (NodeLocks held here).
+ * once we drop support for opt/pess locks we can genericise this to contain Fqns. - Manik Surtani, June 2008
+ */
+ protected LinkedHashSet<Object> invocationLocks;
+ private HashMap<Object, MVCCEntry> lookedUpEntries = null;
+
+ /**
+ * Retrieves a node from the registry of looked up nodes in the current scope.
+ * <p/>
+ * If a transaction is in progress, implementations should delegate to {@link org.jboss.cache.transaction.MVCCTransactionContext#lookUpNode(Fqn)}
+ * <p/>
+ *
+ * @param fqn fqn to look up
+ * @return a node, or null if it cannot be found.
+ */
+ public MVCCEntry lookupEntry(Object k)
+ {
+ // TODO: Fix this after we have a Transaction context that works.
+// if (transactionContext != null) return transactionContext.lookupEntry(k);
+// return lookedUpEntries == null ? null : lookedUpEntries.get(k);
+ return null;
+ }
+
+ /**
+ * Puts an entry in the registry of looked up nodes in the current scope.
+ * <p/>
+ * If a transaction is in progress, implementations should delegate to {@link org.jboss.cache.transaction.MVCCTransactionContext#putLookedUpNode(Fqn, NodeSPI)}
+ * <p/>
+ *
+ * @param f fqn to add
+ * @param n node to add
+ */
+ public void putLookedUpEntry(MVCCEntry e)
+ {
+ // TODO: Fix this after we have a Transaction context that works.
+
+// if (transactionContext != null)
+// transactionContext.putLookedUpEntry(e);
+// else
+// {
+// if (lookedUpEntries == null) lookedUpEntries = new HashMap<Object, MVCCEntry>(4);
+// lookedUpEntries.put(e.getKey(), e);
+// }
+ }
+
+ public void putLookedUpEntries(Set<MVCCEntry> lookedUpEntries)
+ {
+ // TODO: Fix this after we have a Transaction context that works.
+// if (transactionContext != null)
+// transactionContext.putLookedUpEntries(lookedUpEntries);
+// else
+// {
+// if (this.lookedUpEntries == null)
+// this.lookedUpEntries = new HashMap<Object, MVCCEntry>();
+//
+// for (MVCCEntry e: lookedUpEntries) this.lookedUpEntries.put(e.getKey(), e);
+// }
+ }
+
+ /**
+ * Clears the registry of looked up nodes.
+ * <p/>
+ * If a transaction is in progress, implementations should delegate to {@link org.jboss.cache.transaction.MVCCTransactionContext#clearLookedUpNodes()}.
+ */
+ public void clearLookedUpEntries()
+ {
+ // TODO: see if we can reinstate common behaviour once we have the ICI calling ctx.reset() instead of ctx.clearLookedUpNodes()
+// if (transactionContext != null)
+// transactionContext.clearLookedUpNodes();
+// else
+
+ if (lookedUpEntries != null) lookedUpEntries.clear();
+ }
+
+ /**
+ * Retrieves a map of nodes looked up within the current invocation's scope.
+ * <p/>
+ * If a transaction is in progress, implementations should delegate to {@link org.jboss.cache.transaction.MVCCTransactionContext#getLookedUpNodes()}.
+ * <p/>
+ *
+ * @return a map of looked up nodes.
+ */
+ @SuppressWarnings("unchecked")
+ public Map<Object, MVCCEntry> getLookedUpEntries()
+ {
+ // TODO: Fix this after we have a Transaction context that works.
+// if (transactionContext != null) return transactionContext.getLookedUpNodes();
+// return (Map<Fqn, NodeSPI>) (lookedUpEntries == null ? Collections.emptyMap() : lookedUpEntries);
+ return null;
+ }
+
+ @SuppressWarnings("unchecked")
+ public InvocationContext copy()
+ {
+ InvocationContextImpl copy = new InvocationContextImpl();
+ doCopy(copy);
+ if (lookedUpEntries != null) copy.lookedUpEntries = (HashMap<Object, MVCCEntry>) lookedUpEntries.clone();
+ return copy;
+ }
+
+
+ /**
+ * Marks teh context as only rolling back.
+ *
+ * @param localRollbackOnly if true, the context is only rolling back.
+ */
+ public void setLocalRollbackOnly(boolean localRollbackOnly)
+ {
+ this.localRollbackOnly = localRollbackOnly;
+ }
+
+ /**
+ * Retrieves the transaction associated with this invocation
+ *
+ * @return The transaction associated with this invocation
+ */
+ public Transaction getTransaction()
+ {
+ return transaction;
+ }
+
+ /**
+ * Sets a transaction object on the invocation context.
+ *
+ * @param transaction transaction to set
+ */
+ public void setTransaction(Transaction transaction)
+ {
+ this.transaction = transaction;
+ }
+
+ /**
+ * @return the transaction entry associated with the current transaction, or null if the current thread is not associated with a transaction.
+ * @since 2.2.0
+ */
+ public TransactionContext getTransactionContext()
+ {
+ return transactionContext;
+ }
+
+ /**
+ * Sets the transaction context to be associated with the current thread.
+ *
+ * @param transactionContext transaction context to set
+ * @since 2.2.0
+ */
+ public void setTransactionContext(TransactionContext transactionContext)
+ {
+ this.transactionContext = transactionContext;
+ }
+
+ /**
+ * Retrieves the global transaction associated with this invocation
+ *
+ * @return the global transaction associated with this invocation
+ */
+ public GlobalTransaction getGlobalTransaction()
+ {
+ return globalTransaction;
+ }
+
+ /**
+ * Sets the global transaction associated with this invocation
+ *
+ * @param globalTransaction global transaction to set
+ */
+ public void setGlobalTransaction(GlobalTransaction globalTransaction)
+ {
+ this.globalTransaction = globalTransaction;
+ }
+
+
+ /**
+ * Retrieves the option overrides associated with this invocation
+ *
+ * @return the option overrides associated with this invocation
+ */
+ public Option getOptionOverrides()
+ {
+ if (optionOverrides == null)
+ {
+ optionOverrides = new Option();
+ }
+ return optionOverrides;
+ }
+
+ /**
+ * @return true of no options have been set on this context, false otherwise.
+ */
+ public boolean isOptionsUninitialised()
+ {
+ return optionOverrides == null;
+ }
+
+ /**
+ * Sets the option overrides to be associated with this invocation
+ *
+ * @param optionOverrides options to set
+ */
+ public void setOptionOverrides(Option optionOverrides)
+ {
+ this.optionOverrides = optionOverrides;
+ }
+
+ /**
+ * Tests if this invocation originated locally or from a remote cache.
+ *
+ * @return true if the invocation originated locally.
+ */
+ public boolean isOriginLocal()
+ {
+ return originLocal;
+ }
+
+ /**
+ * Returns an immutable, defensive copy of the List of locks currently maintained for the current scope.
+ * <p/>
+ * Note that if a transaction is in scope, implementations should retrieve these locks from the {@link org.jboss.cache.transaction.TransactionContext}.
+ * Retrieving locks from this method should always ensure they are retrieved from the appropriate scope.
+ * <p/>
+ * Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to return <tt>List<Fqn></tt>.
+ *
+ * @return locks held in current scope.
+ */
+ @SuppressWarnings("unchecked")
+ public List getKeysLocked()
+ {
+ // first check transactional scope
+ if (transactionContext != null) return transactionContext.getLocks();
+ return invocationLocks == null || invocationLocks.isEmpty() ? Collections.emptyList() : Immutables.immutableListConvert(invocationLocks);
+ }
+
+ /**
+ * Adds a List of locks to the currently maintained collection of locks acquired.
+ * <p/>
+ * Note that if a transaction is in scope, implementations should record locks on the {@link org.jboss.cache.transaction.TransactionContext}.
+ * Adding locks using this method should always ensure they are applied to the appropriate scope.
+ * <p/>
+ * Note that currently (as of 3.0.0) this list is unchecked. This is to allow support for both MVCC (which uses Fqns as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept <tt>List<Fqn></tt>.
+ *
+ * @param locks locks to add
+ */
+ @SuppressWarnings("unchecked")
+ public void addAllKeysLocked(List locks)
+ {
+ // first check transactional scope
+ if (transactionContext != null)
+ {
+ transactionContext.addAllLocks(locks);
+ }
+ else
+ {
+ // no need to worry about concurrency here - a context is only valid for a single thread.
+ if (invocationLocks == null) invocationLocks = new LinkedHashSet(4);
+ invocationLocks.addAll(locks);
+ }
+ }
+
+ /**
+ * Adds a lock to the currently maintained collection of locks acquired.
+ * <p/>
+ * Note that if a transaction is in scope, implementations should record this lock on the {@link org.jboss.cache.transaction.TransactionContext}.
+ * Using this method should always ensure that the appropriate scope is used.
+ * <p/>
+ * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link Fqn}s as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link Fqn}.
+ *
+ * @param lock lock to add
+ */
+ @SuppressWarnings("unchecked")
+ public void addKeyLocked(Object lock)
+ {
+ // first check transactional scope
+ if (transactionContext != null)
+ {
+ transactionContext.addLock(lock);
+ }
+ else
+ {
+ // no need to worry about concurrency here - a context is only valid for a single thread.
+ if (invocationLocks == null) invocationLocks = new LinkedHashSet(4);
+ invocationLocks.add(lock);
+ }
+ }
+
+ /**
+ * Removes a lock from the currently maintained collection of locks acquired.
+ * <p/>
+ * Note that if a transaction is in scope, implementations should remove this lock from the {@link org.jboss.cache.transaction.TransactionContext}.
+ * Using this method should always ensure that the lock is removed from the appropriate scope.
+ * <p/>
+ * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link Fqn}s as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link Fqn}.
+ *
+ * @param lock lock to remove
+ */
+ @SuppressWarnings("unchecked")
+ public void removeKeyLocked(Object lock)
+ {
+ // first check transactional scope
+ if (transactionContext != null)
+ {
+ transactionContext.removeLock(lock);
+ }
+ else
+ {
+ // no need to worry about concurrency here - a context is only valid for a single thread.
+ if (invocationLocks != null) invocationLocks.remove(lock);
+ }
+ }
+
+ /**
+ * Clears all locks from the currently maintained collection of locks acquired.
+ * <p/>
+ * Note that if a transaction is in scope, implementations should clear locks from the {@link org.jboss.cache.transaction.TransactionContext}.
+ * Using this method should always ensure locks are cleared in the appropriate scope.
+ * <p/>
+ * Note that currently (as of 3.0.0) this lock is weakly typed. This is to allow support for both MVCC (which uses {@link Fqn}s as locks)
+ * as well as legacy Optimistic and Pessimistic Locking schemes (which use {@link org.jboss.cache.lock.NodeLock} as locks). Once support for
+ * legacy node locking schemes are dropped, this method will be more strongly typed to accept {@link Fqn}.
+ */
+ public void clearKeysLocked()
+ {
+ // first check transactional scope
+ if (transactionContext != null)
+ {
+ transactionContext.clearLocks();
+ }
+ else
+ {
+ // no need to worry about concurrency here - a context is only valid for a single thread.
+ if (invocationLocks != null) invocationLocks.clear();
+ }
+ }
+
+ /**
+ * Note that if a transaction is in scope, implementations should test this lock from on {@link org.jboss.cache.transaction.TransactionContext}.
+ * Using this method should always ensure locks checked in the appropriate scope.
+ *
+ * @param lock lock to test
+ * @return true if the lock being tested is already held in the current scope, false otherwise.
+ */
+ public boolean hasLockedKey(Object lock)
+ {
+ // first check transactional scope
+ if (transactionContext != null)
+ {
+ return transactionContext.hasLock(lock);
+ }
+ else
+ {
+ return invocationLocks != null && invocationLocks.contains(lock);
+ }
+ }
+
+ /**
+ * @return true if options exist to suppress locking - false otherwise. Note that this is only used by the {@link org.jboss.cache.interceptors.PessimisticLockInterceptor}.
+ */
+ public boolean isLockingSuppressed()
+ {
+ return getOptionOverrides() != null && getOptionOverrides().isSuppressLocking();
+ }
+
+ /**
+ * If set to true, the invocation is assumed to have originated locally. If set to false,
+ * assumed to have originated from a remote cache.
+ *
+ * @param originLocal flag to set
+ */
+ public void setOriginLocal(boolean originLocal)
+ {
+ this.originLocal = originLocal;
+ }
+
+ /**
+ * @return true if the current transaction is set to rollback only.
+ */
+ public boolean isLocalRollbackOnly()
+ {
+ return localRollbackOnly;
+ }
+
+ /**
+ * Resets the context, freeing up any references.
+ */
+ public void reset()
+ {
+ transaction = null;
+ globalTransaction = null;
+ optionOverrides = null;
+ originLocal = true;
+ invocationLocks = null;
+ methodCall = null;
+ command = null;
+ if (lookedUpEntries != null)
+ {
+ lookedUpEntries.clear();
+ lookedUpEntries = null;
+ }
+ }
+
+ /**
+ * Sets the state of the InvocationContext based on the template context passed in
+ *
+ * @param template template to copy from
+ */
+ public void setState(InvocationContext template)
+ {
+ if (template == null)
+ {
+ throw new NullPointerException("Template InvocationContext passed in to InvocationContext.setState() passed in is null");
+ }
+
+ this.setGlobalTransaction(template.getGlobalTransaction());
+ this.setLocalRollbackOnly(template.isLocalRollbackOnly());
+ this.setOptionOverrides(template.getOptionOverrides());
+ this.setOriginLocal(template.isOriginLocal());
+ this.setTransaction(template.getTransaction());
+ }
+
+ /**
+ * @return the method call associated with this invocation
+ */
+ @Deprecated
+ @SuppressWarnings("deprecation")
+ public MethodCall getMethodCall()
+ {
+ if (methodCall == null)
+ {
+ methodCall = createMethodCall();
+ }
+ return methodCall;
+ }
+
+ @SuppressWarnings("deprecation")
+ private MethodCall createMethodCall()
+ {
+ if (command == null) return null;
+ MethodCall call = new MethodCall();
+ call.setMethodId(command.getCommandId());
+ call.setArgs(command.getParameters());
+ return call;
+ }
+
+ /**
+ * Sets the method call associated with this invocation.
+ *
+ * @param methodCall methodcall to set
+ * @deprecated not used anymore. Interceptors will get a {@link org.jboss.cache.commands.ReplicableCommand} instance passed in along with an InvocationContext.
+ */
+ @Deprecated
+ public void setMethodCall(MethodCall methodCall)
+ {
+ this.methodCall = methodCall;
+ }
+
+ /**
+ * If the lock acquisition timeout is overridden for current call using an option, then return that one.
+ * If not overridden, return default value.
+ *
+ * @param timeout timeout to fall back to
+ * @return timeout to use
+ */
+ public long getLockAcquisitionTimeout(long timeout)
+ {
+ // TODO: this stuff really doesn't belong here. Put it somewhere else.
+ if (getOptionOverrides() != null
+ && getOptionOverrides().getLockAcquisitionTimeout() >= 0)
+ {
+ timeout = getOptionOverrides().getLockAcquisitionTimeout();
+ }
+ return timeout;
+ }
+
+ /**
+ * This is only used for backward compatibility with old interceptors implementation and should <b>NOT</b> be
+ * use by any new custom interceptors. The commands is now passed in as the second param in each implementing
+ * handlers (handler = method in ChainedInterceptor class)
+ *
+ * @param cacheCommand command to set
+ */
+ @Deprecated
+ @SuppressWarnings("deprecation")
+ public void setCommand(VisitableCommand cacheCommand)
+ {
+ this.command = cacheCommand;
+ }
+
+ /**
+ * @return command that is in scope
+ * @see #setCommand(org.jboss.cache.commands.VisitableCommand)
+ */
+ @Deprecated
+ @SuppressWarnings("deprecation")
+ public VisitableCommand getCommand()
+ {
+ return command;
+ }
+
+ /**
+ * @return true if there is current transaction associated with the invocation, and this transaction is in a valid state.
+ */
+ public boolean isValidTransaction()
+ {
+ // ought to move to the transaction context
+ return transaction != null && TransactionTable.isValid(transaction);
+ }
+
+ /**
+ * Throws the given throwable provided no options suppress or prevent this from happening.
+ *
+ * @param e throwable to throw
+ * @throws Throwable if allowed to throw one.
+ */
+ public void throwIfNeeded(Throwable e) throws Throwable
+ {
+ // TODO: this stuff really doesn't belong here. Put it somewhere else.
+ Option optionOverride = getOptionOverrides();
+ boolean shouldRethtrow = optionOverride == null || !optionOverride.isFailSilently();
+ if (!shouldRethtrow)
+ {
+ if (trace)
+ log.trace("There was a problem handling this request, but failSilently was set, so suppressing exception", e);
+ return;
+ }
+ throw e;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void doCopy(InvocationContext c)
+ {
+ InvocationContextImpl copy = (InvocationContextImpl) c;
+ copy.command = command;
+ copy.globalTransaction = globalTransaction;
+ copy.invocationLocks = invocationLocks == null ? null : new LinkedHashSet(invocationLocks);
+ copy.localRollbackOnly = localRollbackOnly;
+ copy.optionOverrides = optionOverrides == null ? null : optionOverrides.copy();
+ copy.originLocal = originLocal;
+ copy.transaction = transaction;
+ copy.transactionContext = transactionContext;
+ }
+}
Added: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryImpl.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryImpl.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryImpl.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.mvcc;
+
+import java.util.Map.Entry;
+
+/**
+ * A basic map entry
+ */
+public class EntryImpl<K, V> implements Entry<K, V>
+{
+ private K key;
+ private V value;
+
+ public EntryImpl()
+ {
+ }
+
+ public EntryImpl(Entry<K, V> e)
+ {
+ this.key = e.getKey();
+ this.value = e.getValue();
+ }
+
+ public EntryImpl(K key, V value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+
+ public K getKey()
+ {
+ return key;
+ }
+
+ public V getValue()
+ {
+ return value;
+ }
+
+ public V setValue(V value)
+ {
+ V oldValue = this.value;
+ this.value = value;
+ return oldValue;
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ EntryImpl entry = (EntryImpl) o;
+
+ if (key != null ? !key.equals(entry.key) : entry.key != null) return false;
+ if (value != null ? !value.equals(entry.value) : entry.value != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (key != null ? key.hashCode() : 0);
+ result = 31 * result + (value != null ? value.hashCode() : 0);
+ return result;
+ }
+
+ public String toString()
+ {
+ return "EntryImpl{" +
+ "key=" + key +
+ ", value=" + value +
+ '}';
+ }
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryReference.java (from rev 6851, core/branches/flat/src/main/java/org/jboss/cache/mvcc/NodeReference.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryReference.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/EntryReference.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,106 @@
+/*
+ * 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.mvcc;
+
+import net.jcip.annotations.ThreadSafe;
+
+import java.util.Map.Entry;
+
+/**
+ * A node reference that delegates all calls to a different {@link org.jboss.cache.InternalNode}. Simple indirection
+ * is all this class does, allowing other processes to change the delegate.
+ * <p/>
+ * The delegate is a volatile field so the class is thread safe.
+ * <p/>
+ * This is used to wrap all {@link org.jboss.cache.invocation.NodeInvocationDelegate}s in the {@link org.jboss.cache.DataContainer}
+ * when using {@link org.jboss.cache.config.Configuration.NodeLockingScheme#MVCC} and {@link org.jboss.cache.lock.IsolationLevel#READ_COMMITTED}.
+ * <p/>
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @see org.jboss.cache.mvcc.ReadCommittedNode
+ * @since 3.0
+ */
+@ThreadSafe
+public class EntryReference<K, V> implements Entry<K, V>
+{
+ transient volatile Entry<K, V> delegate;
+
+ public EntryReference(Entry<K, V> delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ /**
+ * @return the InternalNode being delegated to.
+ */
+ public final Entry<K, V> getDelegate()
+ {
+ return delegate;
+ }
+
+ public K getKey()
+ {
+ return delegate.getKey();
+ }
+
+ public V getValue()
+ {
+ return delegate.getValue();
+ }
+
+ public V setValue(V value)
+ {
+ return delegate.setValue(value);
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ EntryReference that = (EntryReference) o;
+
+ if (delegate != null ? !delegate.equals(that.delegate) : that.delegate != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return (delegate != null ? delegate.hashCode() : 0);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "EntryReference{" +
+ "delegate=" + delegate +
+ '}';
+ }
+
+ public void setDelegate(Entry entry)
+ {
+ delegate = entry;
+ }
+}
\ No newline at end of file
Added: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntry.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/MVCCEntry.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.mvcc;
+
+import org.jboss.cache.InvocationContext;
+import org.jboss.starobrno.DataContainer;
+
+import java.util.Map.Entry;
+
+/**
+ * // TODO: MANIK: Document this
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public interface MVCCEntry extends Entry
+{
+ boolean isNullEntry();
+
+ void copyForUpdate(DataContainer container, boolean writeSkewCheck);
+
+ void commitUpdate(InvocationContext ctx, DataContainer container);
+
+ void rollbackUpdate();
+
+ boolean isChanged();
+
+ boolean isCreated();
+
+ void setCreated(boolean created);
+
+ boolean isDeleted();
+
+ void setDeleted(boolean deleted);
+
+ boolean isValid();
+
+ void setValid(boolean valid);
+}
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/NullMarkerEntry.java (from rev 6851, core/branches/flat/src/main/java/org/jboss/cache/mvcc/NullMarkerNode.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/NullMarkerEntry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/NullMarkerEntry.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,75 @@
+/*
+ * 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.mvcc;
+
+import org.jboss.starobrno.DataContainer;
+
+/**
+ * A marker node to represent a null node for repeatable read, so that a read that returns a null can continue to return
+ * null.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class NullMarkerEntry extends RepeatableReadEntry
+{
+ public NullMarkerEntry()
+ {
+ super(null);
+ }
+
+ /**
+ * @return always returns true
+ */
+ @Override
+ public boolean isNullEntry()
+ {
+ return true;
+ }
+
+ /**
+ * @return always returns true so that any get commands, upon getting this node, will ignore the node as though it were removed.
+ */
+ @Override
+ public boolean isDeleted()
+ {
+ return true;
+ }
+
+ /**
+ * @return always returns true so that any get commands, upon getting this node, will ignore the node as though it were invalid.
+ */
+ @Override
+ public boolean isValid()
+ {
+ return false;
+ }
+
+ /**
+ * A no-op.
+ */
+ @Override
+ public void copyForUpdate(DataContainer d, boolean b)
+ {
+ // no op
+ }
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/ReadCommittedEntry.java (from rev 6851, core/branches/flat/src/main/java/org/jboss/cache/mvcc/ReadCommittedNode.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/ReadCommittedEntry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/ReadCommittedEntry.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,226 @@
+/*
+ * 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.mvcc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.InvocationContext;
+import org.jboss.cache.mvcc.ReadCommittedNode;
+import org.jboss.starobrno.DataContainer;
+import static org.jboss.starobrno.mvcc.ReadCommittedEntry.Flags.*;
+
+import java.util.Map.Entry;
+
+/**
+ * A node delegate that encapsulates read committed semantics when writes are initiated, committed or rolled back.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class ReadCommittedEntry implements MVCCEntry
+{
+ private static final Log log = LogFactory.getLog(ReadCommittedNode.class);
+ private static final boolean trace = log.isTraceEnabled();
+
+ protected volatile Entry entry, backup;
+ protected byte flags = 0;
+
+ public Object getKey()
+ {
+ return entry.getKey();
+ }
+
+ public Object getValue()
+ {
+ return entry.getValue();
+ }
+
+ public Object setValue(Object value)
+ {
+ return entry.setValue(value);
+ }
+
+ protected static enum Flags
+ {
+ CHANGED(0x1), CREATED(0x2), DELETED(0x4), VALID(0x8);
+ final byte mask;
+
+ Flags(int mask)
+ {
+ this.mask = (byte) mask;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public ReadCommittedEntry(Entry entry)
+ {
+ setValid(true);
+ this.entry = entry;
+ }
+
+ /**
+ * Tests whether a flag is set.
+ *
+ * @param flag flag to test
+ * @return true if set, false otherwise.
+ */
+ protected final boolean isFlagSet(Flags flag)
+ {
+ return (flags & flag.mask) != 0;
+ }
+
+ /**
+ * Unility method that sets the value of the given flag to true.
+ *
+ * @param flag flag to set
+ */
+ protected final void setFlag(Flags flag)
+ {
+ flags |= flag.mask;
+ }
+
+ /**
+ * Utility method that sets the value of the flag to false.
+ *
+ * @param flag flag to unset
+ */
+ protected final void unsetFlag(Flags flag)
+ {
+ flags &= ~flag.mask;
+ }
+
+ public boolean isNullEntry()
+ {
+ return false;
+ }
+
+ public void copyForUpdate(DataContainer container, boolean writeSkewCheck)
+ {
+ if (isFlagSet(CHANGED)) return; // already copied
+
+ setFlag(CHANGED); // mark as changed
+ if (!isFlagSet(CREATED)) // if newly created, then nothing to copy.
+ {
+ backup = entry;
+ // don't copy the NodeReference but the InternalNode that the NodeReference delegates to.
+ Entry backupDelegationTarget = ((EntryReference) backup).getDelegate();
+ entry = copyEntry(backupDelegationTarget);
+ }
+ }
+
+ protected Entry copyEntry(Entry e)
+ {
+ if (e instanceof EntryReference)
+ {
+ return new EntryReference(copyEntry(e));
+ }
+ else
+ {
+ return new EntryImpl(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void commitUpdate(InvocationContext ctx, DataContainer container)
+ {
+ // only do stuff if there are changes.
+ if (isFlagSet(CHANGED))
+ {
+ if (trace)
+ log.trace("Updating entry [" + getKey() + "]. deleted=" + isDeleted() + " valid=" + isValid() + " changed=" + isChanged() + " created=" + isFlagSet(CREATED));
+ updateEntry(container);
+ container.putEntry(entry);
+ reset();
+ }
+ }
+
+ private void reset()
+ {
+ backup = null;
+ flags = 0;
+ setValid(true);
+ }
+
+ /**
+ * Updates state changes on the current node in the underlying data structure.
+ *
+ * @param ctx invocation context
+ * @param dataContainer data container
+ */
+ @SuppressWarnings("unchecked")
+ protected void updateEntry(DataContainer dataContainer)
+ {
+ // swap refs
+ if (!isFlagSet(CREATED)) ((EntryReference) backup).setDelegate(entry);
+ entry = backup;
+ }
+
+ public void rollbackUpdate()
+ {
+ entry = backup;
+ reset();
+ }
+
+ public boolean isChanged()
+ {
+ return isFlagSet(CHANGED);
+ }
+
+ public boolean isValid()
+ {
+ return isFlagSet(VALID);
+ }
+
+ public void setValid(boolean valid)
+ {
+ if (valid)
+ setFlag(VALID);
+ else
+ unsetFlag(VALID);
+ }
+
+ public boolean isCreated()
+ {
+ return isFlagSet(CREATED);
+ }
+
+ public void setCreated(boolean created)
+ {
+ if (created)
+ setFlag(CREATED);
+ else
+ unsetFlag(CREATED);
+ }
+
+ public boolean isDeleted()
+ {
+ return isFlagSet(DELETED);
+ }
+
+ public void setDeleted(boolean deleted)
+ {
+ if (deleted)
+ setFlag(DELETED);
+ else
+ unsetFlag(DELETED);
+ }
+}
\ No newline at end of file
Copied: core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/RepeatableReadEntry.java (from rev 6851, core/branches/flat/src/main/java/org/jboss/cache/mvcc/RepeatableReadNode.java)
===================================================================
--- core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/RepeatableReadEntry.java (rev 0)
+++ core/branches/flat/src/main/java/org/jboss/starobrno/mvcc/RepeatableReadEntry.java 2008-10-07 16:22:07 UTC (rev 6854)
@@ -0,0 +1,80 @@
+/*
+ * 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.mvcc;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.mvcc.RepeatableReadNode;
+import org.jboss.cache.optimistic.DataVersioningException;
+import org.jboss.starobrno.DataContainer;
+import static org.jboss.starobrno.mvcc.ReadCommittedEntry.Flags.CHANGED;
+
+import java.util.Map.Entry;
+
+/**
+ * A node delegate that encapsulates repeatable read semantics when writes are initiated, committed or rolled back.
+ *
+ * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
+ * @since 3.0
+ */
+public class RepeatableReadEntry extends ReadCommittedEntry
+{
+ private static final Log log = LogFactory.getLog(RepeatableReadNode.class);
+
+ public RepeatableReadEntry(Entry entry)
+ {
+ super(entry);
+ }
+
+ @Override
+ public void copyForUpdate(DataContainer container, boolean writeSkewCheck)
+ {
+ if (isFlagSet(CHANGED)) return; // already copied
+
+ // mark node as changed.
+ setFlag(CHANGED);
+
+ if (writeSkewCheck)
+ {
+ // check for write skew.
+ Entry actualEntry = null; // get this from somewhere - container.peekInternalNode(fqn, true);
+
+ if (actualEntry != null && actualEntry != entry)
+ {
+ String errormsg = new StringBuilder().append("Detected write skew on key [").append(getKey()).append("]. Another process has changed the node since we last read it!").toString();
+ if (log.isWarnEnabled()) log.warn(errormsg + ". Unable to copy node for update.");
+ throw new DataVersioningException(errormsg);
+ }
+ }
+
+ // make a backup copy
+ backup = entry;
+ entry = copyEntry(backup);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void updateEntry(DataContainer dataContainer)
+ {
+ entry = backup;
+ }
+}
\ No newline at end of file
16 years, 2 months
JBoss Cache SVN: r6853 - core/branches/flat/src/main/java/org/jboss/cache.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-10-07 11:37:41 -0400 (Tue, 07 Oct 2008)
New Revision: 6853
Modified:
core/branches/flat/src/main/java/org/jboss/cache/UnversionedNode.java
Log:
Fix it
Modified: core/branches/flat/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/branches/flat/src/main/java/org/jboss/cache/UnversionedNode.java 2008-10-07 15:11:47 UTC (rev 6852)
+++ core/branches/flat/src/main/java/org/jboss/cache/UnversionedNode.java 2008-10-07 15:37:41 UTC (rev 6853)
@@ -461,7 +461,7 @@
{
// replace key!
Entry<? extends K, ? extends V> e = data.entrySet().iterator().next();
- this.data = Collections.singletonMap(e.getKey(), e.getValue());
+ this.data = Collections.singletonMap((K)e.getKey(), (V)e.getValue());
}
else
{
16 years, 2 months