JBoss Cache SVN: r5317 - pojo/trunk/src/main/java/org/jboss/cache/pojo/collection.
by jbosscache-commits@lists.jboss.org
Author: jason.greene(a)jboss.com
Date: 2008-02-06 11:23:32 -0500 (Wed, 06 Feb 2008)
New Revision: 5317
Modified:
pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java
Log:
Remove legacy binding
Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java 2008-02-06 14:20:40 UTC (rev 5316)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java 2008-02-06 16:23:32 UTC (rev 5317)
@@ -51,39 +51,6 @@
InstanceAdvisor advisor = result._getInstanceAdvisor();
advisor.appendInterceptor(interceptor);
- // Also take care of just toString()
- try
- {
- String bindName = clazz.getName() + ".toString";
- HashMap<String, AdviceBinding> bindings = AspectManager.instance().getBindings();
- if (bindings.get(bindName) == null)
- {
- String bind = null;
- if (interceptor instanceof CachedListInterceptor)
- {
- bind = "execution(public String " + CachedListAbstract.class.getName() + "->toString())";
- } else if (interceptor instanceof CachedSetInterceptor)
- {
- bind = "execution(public String " + CachedSetImpl.class.getName() + "->toString())";
- } else if (interceptor instanceof CachedMapInterceptor)
- {
- bind = "execution(public String " + CachedMapImpl.class.getName() + "->toString())";
- } else
- {
- throw new IllegalStateException("CollectionInterceptorUtil.createProxy(). Non Collection interceptor"
- + interceptor);
- }
-
- AdviceBinding bindingm = new AdviceBinding(bindName, bind, null);
- AspectManager.instance().addBinding(bindingm);
- }
- }
- catch (ParseException e)
- {
- throw new PojoCacheException("PojoUtil._attachInterceptor(): can't parse the field binding: "
- + e);
- }
-
return result;
}
16 years, 3 months
JBoss Cache SVN: r5316 - in core/trunk/src: main/java/org/jboss/cache/config and 6 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-02-06 09:20:40 -0500 (Wed, 06 Feb 2008)
New Revision: 5316
Removed:
core/trunk/src/main/java/org/jboss/cache/marshall/JavaObjectStreamFactory.java
core/trunk/src/main/java/org/jboss/cache/marshall/ObjectSerializationFactory.java
core/trunk/src/main/java/org/jboss/cache/marshall/ObjectStreamFactory.java
Modified:
core/trunk/src/main/docbook/userguide/en/modules/configuration_reference.xml
core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
core/trunk/src/main/java/org/jboss/cache/marshall/Marshaller.java
core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
core/trunk/src/main/java/org/jboss/cache/marshall/io/ObjectStreamPool.java
core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/io/ObjectStreamPoolTest.java
Log:
Documented stream pool sizes, fixed more tests
Modified: core/trunk/src/main/docbook/userguide/en/modules/configuration_reference.xml
===================================================================
--- core/trunk/src/main/docbook/userguide/en/modules/configuration_reference.xml 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/docbook/userguide/en/modules/configuration_reference.xml 2008-02-06 14:20:40 UTC (rev 5316)
@@ -708,6 +708,34 @@
</para>
</entry>
</row>
+
+ <row>
+ <entry>
+ <para>ObjectInputStreamPoolSize and ObjectOutputStreamPoolSize</para>
+ </entry>
+
+ <entry>
+ <para>
+ Since JBoss Cache 2.1.0, object input and output streams - used to serialize and deserialize RPC
+ calls in a cluster - are pooled to reduce the overhead of constructing such streams. They are
+ reused
+ by making use of special resettable stream implementations.
+ </para>
+ <para>
+ by default, these stream pools are set at
+ <literal>50</literal>
+ objects each. You could increase or decrease the pool
+ size if, while profiling, you see a lot of threads blocking on
+ <literal>ObjectStreamPool.getInputStream()</literal>
+ or<literal>ObjectStreamPool.getOutputStream()</literal>. In general, having more streams is
+ better
+ than having fewer than needed. Based on your application, make sure you have more streams
+ available
+ than number of threads you expect to concurrently write to the cache.
+ </para>
+ </entry>
+ </row>
+
</tbody>
</tgroup>
</informaltable>
Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -187,6 +187,8 @@
private String marshallerClass;
private ShutdownHookBehavior shutdownHookBehavior = ShutdownHookBehavior.DEFAULT;
private boolean useLazyDeserialization = false;
+ private int objectInputStreamPoolSize = 50;
+ private int objectOutputStreamPoolSize = 50;
// ------------------------------------------------------------------------------------------------------------
// SETTERS - MAKE SURE ALL SETTERS PERFORM testImmutability()!!!
@@ -488,9 +490,34 @@
public void setUseLazyDeserialization(boolean useLazyDeserialization)
{
+ testImmutability("useLazyDeserialization");
this.useLazyDeserialization = useLazyDeserialization;
}
+ /**
+ * Initialises the size of the object input stream pool size, which defaults to 50.
+ *
+ * @param objectInputStreamPoolSize
+ * @since 2.1.0
+ */
+ public void setObjectInputStreamPoolSize(int objectInputStreamPoolSize)
+ {
+ testImmutability("objectInputStreamPoolSize");
+ this.objectInputStreamPoolSize = objectInputStreamPoolSize;
+ }
+
+ /**
+ * Initialises the size of the object output stream pool size, which defaults to 50.
+ *
+ * @param objectOutputStreamPoolSize
+ * @since 2.1.0
+ */
+ public void setObjectOutputStreamPoolSize(int objectOutputStreamPoolSize)
+ {
+ testImmutability("objectOutputStreamPoolSize");
+ this.objectOutputStreamPoolSize = objectOutputStreamPoolSize;
+ }
+
// ------------------------------------------------------------------------------------------------------------
// GETTERS
// ------------------------------------------------------------------------------------------------------------
@@ -680,6 +707,25 @@
}
/**
+ * @return the size of he object input stream pool
+ * @since 2.1.0
+ */
+ public int getObjectInputStreamPoolSize()
+ {
+ return objectInputStreamPoolSize;
+ }
+
+ /**
+ * @return the size of he object output stream pool
+ * @since 2.1.0
+ */
+ public int getObjectOutputStreamPoolSize()
+ {
+ return objectOutputStreamPoolSize;
+ }
+
+
+ /**
* Returns a {@link java.net.URL} to a default JGroups configuration file.
*
* @return a default JGroups config file
@@ -699,92 +745,93 @@
// OVERRIDDEN METHODS
// ------------------------------------------------------------------------------------------------------------
-
+ @Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
- final Configuration that = (Configuration) o;
+ Configuration that = (Configuration) o;
+ if (exposeManagementStatistics != that.exposeManagementStatistics) return false;
if (fetchInMemoryState != that.fetchInMemoryState) return false;
if (inactiveOnStartup != that.inactiveOnStartup) return false;
- if (stateRetrievalTimeout != that.stateRetrievalTimeout) return false;
if (lockAcquisitionTimeout != that.lockAcquisitionTimeout) return false;
+ if (lockParentForChildInsertRemove != that.lockParentForChildInsertRemove) return false;
if (nodeLockingOptimistic != that.nodeLockingOptimistic) return false;
+ if (objectInputStreamPoolSize != that.objectInputStreamPoolSize) return false;
+ if (objectOutputStreamPoolSize != that.objectOutputStreamPoolSize) return false;
if (replQueueInterval != that.replQueueInterval) return false;
if (replQueueMaxElements != that.replQueueMaxElements) return false;
if (replicationVersion != that.replicationVersion) return false;
+ if (stateRetrievalTimeout != that.stateRetrievalTimeout) return false;
if (syncCommitPhase != that.syncCommitPhase) return false;
if (syncReplTimeout != that.syncReplTimeout) return false;
if (syncRollbackPhase != that.syncRollbackPhase) return false;
- if (exposeManagementStatistics != that.exposeManagementStatistics) return false;
+ if (useLazyDeserialization != that.useLazyDeserialization) return false;
if (useRegionBasedMarshalling != that.useRegionBasedMarshalling) return false;
if (useReplQueue != that.useReplQueue) return false;
+ if (usingMultiplexer != that.usingMultiplexer) return false;
if (buddyReplicationConfig != null ? !buddyReplicationConfig.equals(that.buddyReplicationConfig) : that.buddyReplicationConfig != null)
- {
return false;
- }
if (cacheLoaderConfig != null ? !cacheLoaderConfig.equals(that.cacheLoaderConfig) : that.cacheLoaderConfig != null)
- {
return false;
- }
if (cacheMode != that.cacheMode) return false;
if (clusterConfig != null ? !clusterConfig.equals(that.clusterConfig) : that.clusterConfig != null) return false;
if (clusterName != null ? !clusterName.equals(that.clusterName) : that.clusterName != null) return false;
if (evictionConfig != null ? !evictionConfig.equals(that.evictionConfig) : that.evictionConfig != null)
- {
return false;
- }
if (isolationLevel != that.isolationLevel) return false;
+ if (marshaller != null ? !marshaller.equals(that.marshaller) : that.marshaller != null) return false;
+ if (marshallerClass != null ? !marshallerClass.equals(that.marshallerClass) : that.marshallerClass != null)
+ return false;
if (muxStackName != null ? !muxStackName.equals(that.muxStackName) : that.muxStackName != null) return false;
if (nodeLockingScheme != that.nodeLockingScheme) return false;
+ if (runtimeConfig != null ? !runtimeConfig.equals(that.runtimeConfig) : that.runtimeConfig != null) return false;
+ if (shutdownHookBehavior != that.shutdownHookBehavior) return false;
if (transactionManagerLookupClass != null ? !transactionManagerLookupClass.equals(that.transactionManagerLookupClass) : that.transactionManagerLookupClass != null)
- {
return false;
- }
- if (!safeEquals(runtimeConfig, that.runtimeConfig))
- {
- return false;
- }
- if (!safeEquals(marshallerClass, that.marshallerClass)) return false;
-
- if (lockParentForChildInsertRemove != that.lockParentForChildInsertRemove) return false;
-
return true;
}
+ @Override
public int hashCode()
{
- int result = 17;
- result = 29 * result + (clusterName != null ? clusterName.hashCode() : 0);
- result = 29 * result + (clusterConfig != null ? clusterConfig.hashCode() : 0);
- result = 29 * result + (useReplQueue ? 1 : 0);
- result = 29 * result + replQueueMaxElements;
- result = 29 * result + (int) (replQueueInterval ^ (replQueueInterval >>> 32));
- result = 29 * result + (exposeManagementStatistics ? 1 : 0);
- result = 29 * result + (fetchInMemoryState ? 1 : 0);
- result = 29 * result + (int) replicationVersion;
- result = 29 * result + (int) (lockAcquisitionTimeout ^ (lockAcquisitionTimeout >>> 32));
- result = 29 * result + (int) (syncReplTimeout ^ (syncReplTimeout >>> 32));
- result = 29 * result + (cacheMode != null ? cacheMode.hashCode() : 0);
- result = 29 * result + (inactiveOnStartup ? 1 : 0);
- result = 29 * result + (int) (stateRetrievalTimeout ^ (stateRetrievalTimeout >>> 32));
- result = 29 * result + (isolationLevel != null ? isolationLevel.hashCode() : 0);
- result = 29 * result + (evictionConfig != null ? evictionConfig.hashCode() : 0);
- result = 29 * result + (useRegionBasedMarshalling ? 1 : 0);
- result = 29 * result + (transactionManagerLookupClass != null ? transactionManagerLookupClass.hashCode() : 0);
- result = 29 * result + (cacheLoaderConfig != null ? cacheLoaderConfig.hashCode() : 0);
- result = 29 * result + (syncCommitPhase ? 1 : 0);
- result = 29 * result + (syncRollbackPhase ? 1 : 0);
- result = 29 * result + (buddyReplicationConfig != null ? buddyReplicationConfig.hashCode() : 0);
- result = 29 * result + (nodeLockingOptimistic ? 1 : 0);
- result = 29 * result + (nodeLockingScheme != null ? nodeLockingScheme.hashCode() : 0);
- result = 29 * result + (muxStackName != null ? muxStackName.hashCode() : 0);
- result = 29 * result + (runtimeConfig != null ? runtimeConfig.hashCode() : 0);
- result = 29 * result + (marshallerClass != null ? marshallerClass.hashCode() : 0);
- result = 29 * result + (lockParentForChildInsertRemove ? 1 : 0);
+ int result;
+ result = (marshaller != null ? marshaller.hashCode() : 0);
+ result = 31 * result + (clusterName != null ? clusterName.hashCode() : 0);
+ result = 31 * result + (clusterConfig != null ? clusterConfig.hashCode() : 0);
+ result = 31 * result + (useReplQueue ? 1 : 0);
+ result = 31 * result + replQueueMaxElements;
+ result = 31 * result + (int) (replQueueInterval ^ (replQueueInterval >>> 32));
+ result = 31 * result + (exposeManagementStatistics ? 1 : 0);
+ result = 31 * result + (fetchInMemoryState ? 1 : 0);
+ result = 31 * result + (int) replicationVersion;
+ result = 31 * result + (int) (lockAcquisitionTimeout ^ (lockAcquisitionTimeout >>> 32));
+ result = 31 * result + (int) (syncReplTimeout ^ (syncReplTimeout >>> 32));
+ result = 31 * result + (cacheMode != null ? cacheMode.hashCode() : 0);
+ result = 31 * result + (inactiveOnStartup ? 1 : 0);
+ result = 31 * result + (int) (stateRetrievalTimeout ^ (stateRetrievalTimeout >>> 32));
+ result = 31 * result + (isolationLevel != null ? isolationLevel.hashCode() : 0);
+ result = 31 * result + (lockParentForChildInsertRemove ? 1 : 0);
+ result = 31 * result + (evictionConfig != null ? evictionConfig.hashCode() : 0);
+ result = 31 * result + (useRegionBasedMarshalling ? 1 : 0);
+ result = 31 * result + (transactionManagerLookupClass != null ? transactionManagerLookupClass.hashCode() : 0);
+ result = 31 * result + (cacheLoaderConfig != null ? cacheLoaderConfig.hashCode() : 0);
+ result = 31 * result + (syncCommitPhase ? 1 : 0);
+ result = 31 * result + (syncRollbackPhase ? 1 : 0);
+ result = 31 * result + (buddyReplicationConfig != null ? buddyReplicationConfig.hashCode() : 0);
+ result = 31 * result + (nodeLockingOptimistic ? 1 : 0);
+ result = 31 * result + (nodeLockingScheme != null ? nodeLockingScheme.hashCode() : 0);
+ result = 31 * result + (muxStackName != null ? muxStackName.hashCode() : 0);
+ result = 31 * result + (usingMultiplexer ? 1 : 0);
+ result = 31 * result + (runtimeConfig != null ? runtimeConfig.hashCode() : 0);
+ result = 31 * result + (marshallerClass != null ? marshallerClass.hashCode() : 0);
+ result = 31 * result + (shutdownHookBehavior != null ? shutdownHookBehavior.hashCode() : 0);
+ result = 31 * result + (useLazyDeserialization ? 1 : 0);
+ result = 31 * result + objectInputStreamPoolSize;
+ result = 31 * result + objectOutputStreamPoolSize;
return result;
}
Modified: core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/factories/EmptyConstructorFactory.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -8,6 +8,7 @@
import org.jboss.cache.loader.CacheLoaderManager;
import org.jboss.cache.marshall.Marshaller;
import org.jboss.cache.marshall.VersionAwareMarshaller;
+import org.jboss.cache.marshall.io.ObjectStreamPool;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.remoting.jgroups.CacheMessageListener;
import org.jboss.cache.statetransfer.StateTransferManager;
@@ -21,7 +22,7 @@
*/
@DefaultFactoryFor(classes = {StateTransferManager.class, TransactionTable.class, RegionManager.class, Notifier.class,
CacheMessageListener.class, CacheLoaderManager.class, RemoteCacheInvocationDelegate.class, Marshaller.class,
- InvocationContextContainer.class})
+ InvocationContextContainer.class, ObjectStreamPool.class})
public class EmptyConstructorFactory extends ComponentFactory
{
@Override
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -389,7 +389,7 @@
// Object marshalledNode = ois.readObject();
// deserialize result
- Map<Object, Object> oldNode = (Map<Object, Object>) unmarshall(is);
+ Map<Object, Object> oldNode = (Map<Object, Object>) unmarshall(is);
return oldNode;
}
catch (Exception e)
@@ -454,7 +454,7 @@
{
// a hack to handles the incomp. of SQL server jdbc driver prior to SQL SERVER 2005
if (driverName != null && (driverName.contains("SQLSERVER")
- || driverName.contains("POSTGRESQL")))
+ || driverName.contains("POSTGRESQL")))
{
ps.setNull(2, Types.LONGVARBINARY);
}
@@ -535,7 +535,8 @@
ps.setString(2, name.toString());
- /*int rows = */ps.executeUpdate();
+ /*int rows = */
+ ps.executeUpdate();
// if (rows != 1)
// {
// throw new IllegalStateException("Expected one updated row but got " + rows);
@@ -704,7 +705,7 @@
protected byte[] marshall(Object obj) throws Exception
{
- return getMarshaller().objectToByteBuffer(obj);
+ return getMarshaller().objectToByteBuffer(obj, true);
}
private static String toUpperCase(String s)
@@ -723,10 +724,11 @@
{
@Override
- public Set<java.util.Map.Entry<Object, Object>> entrySet() {
+ public Set<java.util.Map.Entry<Object, Object>> entrySet()
+ {
throw new UnsupportedOperationException();
- }
-
+ }
+
};
}
Modified: core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoader.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/loader/FileCacheLoader.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -6,7 +6,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
import org.jboss.cache.lock.StripedLock;
-import org.jboss.cache.marshall.ObjectSerializationFactory;
+import org.jboss.util.stream.MarshalledValueInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -502,7 +502,7 @@
protected Object unmarshall(File from) throws Exception
{
FileInputStream fileIn = new FileInputStream(from);
- ObjectInputStream input = ObjectSerializationFactory.createObjectInputStream(fileIn);
+ ObjectInputStream input = new MarshalledValueInputStream(fileIn);
Object unmarshalledObj = getMarshaller().objectFromObjectStream(input);
input.close();
return unmarshalledObj;
@@ -511,7 +511,7 @@
protected void marshall(Object obj, File to) throws Exception
{
FileOutputStream fileOut = new FileOutputStream(to);
- ObjectOutputStream output = ObjectSerializationFactory.createObjectOutputStream(fileOut);
+ ObjectOutputStream output = new ObjectOutputStream(fileOut);
getMarshaller().objectToObjectStream(obj, output);
output.close();
}
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/AbstractMarshaller.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -68,33 +68,22 @@
// implement the basic contract set in RPcDispatcher.AbstractMarshaller
public byte[] objectToByteBuffer(Object obj) throws Exception
{
+ return objectToByteBuffer(obj, false);
+ }
+
+ public byte[] objectToByteBuffer(Object obj, boolean b) throws Exception
+ {
throw new RuntimeException("Needs to be overridden!");
-// ByteArrayOutputStream baos = new ByteArrayOutputStream();
-// ObjectOutputStream out = ObjectSerializationFactory.createObjectOutputStream(baos);
-// objectToObjectStream(obj, out);
-// out.close();
-// return baos.toByteArray();
}
public Object objectFromByteBuffer(byte[] bytes) throws Exception
{
throw new RuntimeException("Needs to be overridden!");
- //ObjectInputStream in = ObjectSerializationFactory.createObjectInputStream(bytes);
- //return objectFromObjectStream(in);
}
public Object objectFromStream(InputStream in) throws Exception
{
throw new RuntimeException("Needs to be overridden!");
- // by default just create an OIS from this IS and pass in to the relevant method
-// if (in instanceof ObjectInputStream)
-// {
-// return objectFromObjectStream((ObjectInputStream) in);
-// }
-// else
-// {
-// return objectFromObjectStream(ObjectSerializationFactory.createObjectInputStream(in));
-// }
}
/**
Deleted: core/trunk/src/main/java/org/jboss/cache/marshall/JavaObjectStreamFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/JavaObjectStreamFactory.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/JavaObjectStreamFactory.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -1,38 +0,0 @@
-package org.jboss.cache.marshall;
-
-import org.jboss.util.stream.MarshalledValueInputStream;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-
-/**
- * Standard Java implementation of ObjectStreamFactory
- *
- * @author Clebert Suconic
- * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
- * @since 1.4.1
- */
-class JavaObjectStreamFactory implements ObjectStreamFactory
-{
-
- public ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException
- {
- ByteArrayInputStream in = new ByteArrayInputStream(bytes);
- return new MarshalledValueInputStream(in);
- }
-
- public ObjectInputStream createObjectInputStream(InputStream in) throws IOException
- {
- return new MarshalledValueInputStream(in);
- }
-
- public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException
- {
- return new ObjectOutputStream(out);
- }
-
-}
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/Marshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/Marshaller.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/Marshaller.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -68,4 +68,14 @@
* @throws Exception
*/
void objectToObjectStream(Object obj, ObjectOutputStream out, Fqn region) throws Exception;
+
+ /**
+ * Same as {@link #objectToByteBuffer(Object)} except that you can optionally specify to write object stream headers.
+ * Useful if you intend to deserialize the stream with non-pooled input streams.
+ *
+ * @param o
+ * @param writeStreamHeaders
+ * @return
+ */
+ byte[] objectToByteBuffer(Object o, boolean writeStreamHeaders) throws Exception;
}
Deleted: core/trunk/src/main/java/org/jboss/cache/marshall/ObjectSerializationFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/ObjectSerializationFactory.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/ObjectSerializationFactory.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -1,76 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.cache.marshall;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-
-/**
- * Factory class for creating object output and inut streams, to allow for multiple mechanisms of serialization.
- * Java serialization is the only supported mechanism at this point.
- *
- * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik(a)jboss.org)</a>
- * @author <a href="mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
- * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
- */
-public class ObjectSerializationFactory
-{
- static ObjectStreamFactory factory = new JavaObjectStreamFactory();
-
- /*
- static
- {
- // start with the NEW property
- String propString = System.getProperty("jboss.serialization");
- if (propString == null)
- {
- // and now check legacy
- propString = System.getProperty("serialization.jboss");
- if (propString != null)
- log.info("The system property 'serialization.jboss' is deprecated and may be removed from future releases. Please use 'jboss.serialization' instead.");
- }
- useJBossSerialization = false; // default.
- if (propString != null) useJBossSerialization = Boolean.valueOf(propString);
-
- try
- {
- if (useJBossSerialization)
- {
- factory = (ObjectStreamFactory) Class.forName("org.jboss.cache.marshall.JBossObjectStreamFactory").newInstance();
- }
- }
- catch (Exception e)
- {
- log.error("Unable to load JBossObjectStreamFactory. Perhaps jboss-serialization jar not loaded?", e);
- log.error("Falling back to java serialization.");
- }
- }
- */
-
- public static ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException
- {
- return factory.createObjectOutputStream(out);
- }
-
- public static ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException
- {
- return factory.createObjectInputStream(bytes);
- }
-
- public static ObjectInputStream createObjectInputStream(InputStream in) throws IOException
- {
- return factory.createObjectInputStream(in);
- }
-
-// public static boolean useJBossSerialization()
-// {
-// return useJBossSerialization;
-// }
-}
Deleted: core/trunk/src/main/java/org/jboss/cache/marshall/ObjectStreamFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/ObjectStreamFactory.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/ObjectStreamFactory.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -1,23 +0,0 @@
-package org.jboss.cache.marshall;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-
-/**
- * ObjectStreamFactory
- *
- * @author Clebert Suconic
- * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a>
- * @since 1.4.1
- */
-public interface ObjectStreamFactory
-{
- public ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException;
-
- public ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException;
-
- public ObjectInputStream createObjectInputStream(InputStream in) throws IOException;
-}
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/VersionAwareMarshaller.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -8,7 +8,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.CacheException;
import org.jboss.cache.Fqn;
import org.jboss.cache.factories.ComponentRegistry;
import org.jboss.cache.factories.annotations.Inject;
@@ -16,7 +15,10 @@
import org.jboss.cache.marshall.io.ObjectStreamPool;
import org.jboss.cache.marshall.io.ReusableObjectOutputStream;
import org.jboss.cache.util.Util;
+import org.jboss.util.stream.MarshalledValueInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -48,9 +50,10 @@
ObjectStreamPool pool;
@Inject
- void injectComponentRegistry(ComponentRegistry componentRegistry)
+ void injectComponents(ComponentRegistry componentRegistry, ObjectStreamPool pool)
{
this.componentRegistry = componentRegistry;
+ this.pool = pool;
}
@Start
@@ -99,15 +102,6 @@
log.debug("Started with version " + replVersionString + " and versionInt " + versionInt);
log.debug("Using default marshaller class " + this.defaultMarshaller.getClass());
}
-
- try
- {
- pool = new ObjectStreamPool(25, 25);
- }
- catch (Exception e)
- {
- throw new CacheException(e);
- }
}
protected int getCustomMarshallerVersionInt()
@@ -158,9 +152,29 @@
}
}
- public byte[] objectToByteBuffer(Object obj) throws Exception
+ private byte[] useNonPooledStream(Object obj) throws Exception
{
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(baos);
+
+ out.writeShort(versionInt);
+ if (trace) log.trace("Wrote version " + versionInt);
+
+ //now marshall the contents of the object
+ defaultMarshaller.objectToObjectStream(obj, out);
+ out.close();
+
+ // and return bytes.
+ return baos.toByteArray();
+ }
+
+ @Override
+ public byte[] objectToByteBuffer(Object obj, boolean writeHeader) throws Exception
+ {
+ if (writeHeader) return useNonPooledStream(obj);
+
ReusableObjectOutputStream out = pool.getOutputStream();
+
try
{
out.writeShort(versionInt);
@@ -178,6 +192,7 @@
}
}
+ @Override
public Object objectFromByteBuffer(byte[] buf) throws Exception
{
Marshaller marshaller;
@@ -209,10 +224,35 @@
public Object objectFromStream(InputStream is) throws Exception
{
- int avbl = is.available();
- byte[] bytes = new byte[avbl];
- is.read(bytes, 0, avbl);
- return objectFromByteBuffer(bytes);
+ if (is instanceof ByteArrayInputStream)
+ {
+ int avbl = is.available();
+ byte[] bytes = new byte[avbl];
+ is.read(bytes, 0, avbl);
+ return objectFromByteBuffer(bytes);
+ }
+ else
+ {
+ // actually attempt to "stream" this stuff. We need to revert to an old-fashioned Object Input Stream since
+ // we don't have a reusable implementation for non-byte-backed streams as yet.
+ short versionId;
+ Marshaller marshaller;
+ ObjectInputStream in = new MarshalledValueInputStream(is);
+ try
+ {
+ versionId = in.readShort();
+ if (trace) log.trace("Read version " + versionId);
+ }
+ catch (Exception e)
+ {
+ log.error("Unable to read version id from first two bytes of stream, barfing.");
+ throw e;
+ }
+
+ marshaller = getMarshaller(versionId);
+
+ return marshaller.objectFromObjectStream(in);
+ }
}
public void objectToObjectStream(Object obj, ObjectOutputStream out, Fqn region) throws Exception
Modified: core/trunk/src/main/java/org/jboss/cache/marshall/io/ObjectStreamPool.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/marshall/io/ObjectStreamPool.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/main/java/org/jboss/cache/marshall/io/ObjectStreamPool.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -1,5 +1,11 @@
package org.jboss.cache.marshall.io;
+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 java.io.IOException;
import java.io.ObjectInputStream;
import java.util.concurrent.BlockingQueue;
@@ -15,22 +21,48 @@
{
BlockingQueue<ReusableObjectOutputStream> outputStreams;
BlockingQueue<ReusableObjectInputStream> inputStreams;
+ int numOutputStreams = 1, numInputStreams = 1;
+ Configuration configuration;
+ Log log = LogFactory.getLog(ObjectStreamPool.class);
- /**
- * Constructs the pool with a fixed number of object output and input streams
- *
- * @param numOutputStreams number of object output streams
- * @param numInputStreams number of object input streams
- * @throws InterruptedException
- * @throws IOException
- */
- public ObjectStreamPool(int numOutputStreams, int numInputStreams) throws InterruptedException, IOException
+ public ObjectStreamPool()
{
+ // for construction by the IOC framework
+ }
+
+ @Inject
+ public void injectDependencies(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ @Start
+ public void start() throws InterruptedException, IOException
+ {
+ if (configuration != null)
+ {
+ numInputStreams = configuration.getObjectInputStreamPoolSize();
+ numOutputStreams = configuration.getObjectOutputStreamPoolSize();
+ if (log.isDebugEnabled())
+ log.debug("Using stream sizes from configuration as input: " + numInputStreams + " and output: " + numOutputStreams);
+ }
+
outputStreams = new LinkedBlockingQueue<ReusableObjectOutputStream>();
inputStreams = new LinkedBlockingQueue<ReusableObjectInputStream>();
+ long start = 0;
+ if (log.isDebugEnabled())
+ {
+ log.debug("Creating " + numOutputStreams + " ReusableObjectOutputStreams and " + numInputStreams + " ReusableObjectInputStreams for pool");
+ start = System.currentTimeMillis();
+ }
for (int i = 0; i < numOutputStreams; i++) outputStreams.put(new ReusableObjectOutputStream());
for (int i = 0; i < numInputStreams; i++) inputStreams.put(new ReusableObjectInputStream());
+ if (log.isDebugEnabled())
+ {
+ log.debug("Initialised object stream pool in " + (System.currentTimeMillis() - start) + " millis");
+ }
+
}
/**
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -53,22 +53,28 @@
public void testVersionHeaderDefaultCurrent() throws Exception
{
+ ObjectStreamPool pool = new ObjectStreamPool();
+ pool.start();
+
VersionAwareMarshaller marshaller = createVAM(Version.getVersionString(Version.getVersionShort()));
+ marshaller.injectComponents(null, pool);
+
byte[] bytes = marshaller.objectToByteBuffer("Hello");
- ObjectStreamPool pool = new ObjectStreamPool(1, 1);
-
ObjectInputStream in = pool.getInputStream(bytes);
assertEquals("Version header short should be '21'", 21, in.readShort());
}
public void testVersionHeader200() throws Exception
{
+ ObjectStreamPool pool = new ObjectStreamPool();
+ pool.start();
+
VersionAwareMarshaller marshaller = createVAM("2.0.0.GA");
+ marshaller.injectComponents(null, pool);
+
byte[] bytes = marshaller.objectToByteBuffer("Hello");
- ObjectStreamPool pool = new ObjectStreamPool(1, 1);
-
ObjectInputStream in = pool.getInputStream(bytes);
assertEquals("Version header short should be '20'", 20, in.readShort());
}
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/io/ObjectStreamPoolTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/io/ObjectStreamPoolTest.java 2008-02-06 13:14:45 UTC (rev 5315)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/io/ObjectStreamPoolTest.java 2008-02-06 14:20:40 UTC (rev 5316)
@@ -24,7 +24,10 @@
@BeforeTest
public void setUp() throws IOException, InterruptedException
{
- pool = new ObjectStreamPool(1, 1);
+ pool = new ObjectStreamPool();
+ pool.numInputStreams = 1;
+ pool.numOutputStreams = 1;
+ pool.start();
}
@AfterMethod
@@ -240,6 +243,22 @@
assert ois.readShort() == 6;
}
+ public void testLargeObject() throws Exception
+ {
+ oos = pool.getOutputStream();
+ StringBuilder builder = new StringBuilder();
+ int targetSize = 1 << 22; // 4MB !!
+ System.out.println("target size: " + targetSize);
+ for (int i = 0; i < targetSize; i++) builder.append("X");
+ String fourMegString = builder.toString();
+ oos.writeObject(fourMegString);
+ byte[] asBytes = oos.getBytes();
+
+ ois = pool.getInputStream(asBytes);
+
+ assert ois.readObject().equals(fourMegString);
+ }
+
public void testReusableOutputStreamArraySize() throws InterruptedException, IOException
{
oos = pool.getOutputStream();
16 years, 3 months
JBoss Cache SVN: r5315 - core/trunk/src/test/java/org/jboss/cache/marshall.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-02-06 08:14:45 -0500 (Wed, 06 Feb 2008)
New Revision: 5315
Modified:
core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
Log:
Fixed broken tests
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-02-06 13:12:44 UTC (rev 5314)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/VersionAwareMarshallerTest.java 2008-02-06 13:14:45 UTC (rev 5315)
@@ -7,6 +7,7 @@
package org.jboss.cache.marshall;
import org.jboss.cache.Version;
+import org.jboss.cache.marshall.io.ObjectStreamPool;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.Test;
@@ -55,8 +56,9 @@
VersionAwareMarshaller marshaller = createVAM(Version.getVersionString(Version.getVersionShort()));
byte[] bytes = marshaller.objectToByteBuffer("Hello");
- // expect that this has been serialized using JBoss Serialization so use this to get an OIS.
- ObjectInputStream in = ObjectSerializationFactory.createObjectInputStream(bytes);
+ ObjectStreamPool pool = new ObjectStreamPool(1, 1);
+
+ ObjectInputStream in = pool.getInputStream(bytes);
assertEquals("Version header short should be '21'", 21, in.readShort());
}
@@ -65,8 +67,9 @@
VersionAwareMarshaller marshaller = createVAM("2.0.0.GA");
byte[] bytes = marshaller.objectToByteBuffer("Hello");
- // expect that this has been serialized using JBoss Serialization so use this to get an OIS.
- ObjectInputStream in = ObjectSerializationFactory.createObjectInputStream(bytes);
+ ObjectStreamPool pool = new ObjectStreamPool(1, 1);
+
+ ObjectInputStream in = pool.getInputStream(bytes);
assertEquals("Version header short should be '20'", 20, in.readShort());
}
16 years, 3 months
JBoss Cache SVN: r5314 - core/trunk/src/test/java/org/jboss/cache/interceptors.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-02-06 08:12:44 -0500 (Wed, 06 Feb 2008)
New Revision: 5314
Modified:
core/trunk/src/test/java/org/jboss/cache/interceptors/MarshalledValueInterceptorTest.java
Log:
Fixed broken tests
Modified: core/trunk/src/test/java/org/jboss/cache/interceptors/MarshalledValueInterceptorTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/interceptors/MarshalledValueInterceptorTest.java 2008-02-06 13:11:22 UTC (rev 5313)
+++ core/trunk/src/test/java/org/jboss/cache/interceptors/MarshalledValueInterceptorTest.java 2008-02-06 13:12:44 UTC (rev 5314)
@@ -33,7 +33,14 @@
{
c = (CacheSPI) new DefaultCacheFactory().createCache();
- System.out.println(CachePrinter.printCacheInterceptors(c));
+ assert TestingUtil.findInterceptor(c, MarshalledValueInterceptor.class) == null;
+
+ TestingUtil.killCaches(c);
+
+ c = (CacheSPI) new DefaultCacheFactory().createCache(false);
+ c.getConfiguration().setUseLazyDeserialization(true);
+ c.start();
+
assert TestingUtil.findInterceptor(c, MarshalledValueInterceptor.class) != null;
}
16 years, 3 months
JBoss Cache SVN: r5313 - in core/trunk/src/test/java/org/jboss/cache: loader and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-02-06 08:11:22 -0500 (Wed, 06 Feb 2008)
New Revision: 5313
Modified:
core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java
core/trunk/src/test/java/org/jboss/cache/loader/FileCacheLoaderTest.java
core/trunk/src/test/java/org/jboss/cache/marshall/MarshalledValueTest.java
Log:
Fixed broken tests
Modified: core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java 2008-02-06 03:25:50 UTC (rev 5312)
+++ core/trunk/src/test/java/org/jboss/cache/factories/CustomInterceptorChainTest.java 2008-02-06 13:11:22 UTC (rev 5313)
@@ -54,14 +54,14 @@
public void testInjectionAtHead()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 8 interceptors", 8, interceptors.size());
+ assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
Interceptor x = new TestInterceptor();
cache.addInterceptor(x, 0);
interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 9 interceptors", 9, interceptors.size());
+ assertEquals("Expecting 7 interceptors", 7, interceptors.size());
assertInterceptorLinkage(interceptors);
assertEquals(x, interceptors.get(0));
@@ -70,30 +70,30 @@
public void testInjectionAtTail()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 8 interceptors", 8, interceptors.size());
+ assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
Interceptor x = new TestInterceptor();
- cache.addInterceptor(x, 8);
+ cache.addInterceptor(x, 6);
interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 9 interceptors", 9, interceptors.size());
+ assertEquals("Expecting 7 interceptors", 7, interceptors.size());
assertInterceptorLinkage(interceptors);
- assertEquals(x, interceptors.get(8));
+ assertEquals(x, interceptors.get(6));
}
public void testInjectionInMiddle()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 8 interceptors", 8, interceptors.size());
+ assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
Interceptor x = new TestInterceptor();
cache.addInterceptor(x, 3);
interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 9 interceptors", 9, interceptors.size());
+ assertEquals("Expecting 7 interceptors", 7, interceptors.size());
assertInterceptorLinkage(interceptors);
assertEquals(x, interceptors.get(3));
@@ -102,7 +102,7 @@
public void testInjectionBeyondTail()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 8 interceptors", 8, interceptors.size());
+ assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
Interceptor x = new TestInterceptor();
@@ -121,13 +121,13 @@
{
List<Interceptor> interceptors = cache.getInterceptorChain();
Interceptor afterHead = interceptors.get(1);
- assertEquals("Expecting 8 interceptors", 8, interceptors.size());
+ assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
cache.removeInterceptor(0);
interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 7 interceptors", 7, interceptors.size());
+ assertEquals("Expecting 5 interceptors", 5, interceptors.size());
assertInterceptorLinkage(interceptors);
assertEquals(afterHead, interceptors.get(0));
@@ -137,7 +137,7 @@
{
List<Interceptor> interceptors = cache.getInterceptorChain();
Interceptor beforeTail = interceptors.get(4);
- assertEquals("Expecting 8 interceptors", 8, interceptors.size());
+ assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
cache.removeInterceptor(5);
@@ -146,7 +146,7 @@
System.out.println(interceptors);
- assertEquals("Expecting 7 interceptors", 7, interceptors.size());
+ assertEquals("Expecting 5 interceptors", 5, interceptors.size());
assertInterceptorLinkage(interceptors);
assertEquals(beforeTail, interceptors.get(4));
@@ -155,20 +155,20 @@
public void testRemoveAtMiddle()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 8 interceptors", 8, interceptors.size());
+ assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
cache.removeInterceptor(3);
interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 7 interceptors", 7, interceptors.size());
+ assertEquals("Expecting 5 interceptors", 5, interceptors.size());
assertInterceptorLinkage(interceptors);
}
public void testRemoveBeyondTail()
{
List<Interceptor> interceptors = cache.getInterceptorChain();
- assertEquals("Expecting 8 interceptors", 8, interceptors.size());
+ assertEquals("Expecting 6 interceptors", 6, interceptors.size());
assertInterceptorLinkage(interceptors);
try
Modified: core/trunk/src/test/java/org/jboss/cache/loader/FileCacheLoaderTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/loader/FileCacheLoaderTest.java 2008-02-06 03:25:50 UTC (rev 5312)
+++ core/trunk/src/test/java/org/jboss/cache/loader/FileCacheLoaderTest.java 2008-02-06 13:11:22 UTC (rev 5313)
@@ -1,11 +1,10 @@
package org.jboss.cache.loader;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.misc.TestingUtil;
import static org.testng.AssertJUnit.assertEquals;
import org.testng.annotations.Test;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.misc.TestingUtil;
-
@Test(groups = {"functional"})
public class FileCacheLoaderTest extends CacheLoaderTestsBase
{
@@ -22,13 +21,13 @@
FileCacheLoader fcl = new FileCacheLoader();
Object[][] data = new Object[][]{
- {"C:\\here\\there.txt", true},
- {"/home/here/there", true},
- {"/home/*/jboss", false},
- {"C:\\>/jgroups/jboss", false},
- {"/cache/jboss<", false},
- {"/pojocache|/galder", false},
- {"/pojocache/gal\"der", false}};
+ {"C:\\here\\there.txt", true},
+ {"/home/here/there", true},
+ {"/home/*/jboss", false},
+ {"C:\\>/jgroups/jboss", false},
+ {"/cache/jboss<", false},
+ {"/pojocache|/galder", false},
+ {"/pojocache/gal\"der", false}};
for (Object[] aData : data)
{
@@ -43,16 +42,16 @@
FileCacheLoader fcl = new FileCacheLoader();
Object[][] data = new Object[][]{
- {Fqn.fromString("/a/b/c/d/e"), true},
- {Fqn.fromString("/a/*/c/d/e"), false},
- {Fqn.fromString("/a/b/>/d/e"), false},
- {Fqn.fromString("/a/</c/d/e"), false},
- {Fqn.fromString("/|/b/c/d/e"), false},
- {Fqn.fromString("/|/b/c/d/e"), false},
- {Fqn.fromString("/a/b/c/d/\""), false},
- {Fqn.fromString("/a/b/c/d/\\"), false},
- {Fqn.fromString("/a/b/c/d///"), true},
- {Fqn.fromString("/a/b/c/:/e"), false},};
+ {Fqn.fromString("/a/b/c/d/e"), true},
+ {Fqn.fromString("/a/*/c/d/e"), false},
+ {Fqn.fromString("/a/b/>/d/e"), false},
+ {Fqn.fromString("/a/</c/d/e"), false},
+ {Fqn.fromString("/|/b/c/d/e"), false},
+ {Fqn.fromString("/|/b/c/d/e"), false},
+ {Fqn.fromString("/a/b/c/d/\""), false},
+ {Fqn.fromString("/a/b/c/d/\\"), false},
+ {Fqn.fromString("/a/b/c/d///"), true},
+ {Fqn.fromString("/a/b/c/:/e"), false},};
for (Object[] aData : data)
{
@@ -64,12 +63,15 @@
public void testIsLengthPortablePath()
{
+
+ // This now always returns true unless we are using a Windows OS older than version 4.0 (Windows 2000/NT)
+
FileCacheLoader fcl = new FileCacheLoader();
Object[][] data = new Object[][]{
- {"C:\\here\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\web_services\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\webservices\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\data.dat", true},
- {"C:\\there\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\web_services\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\webservices\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\data.dat", true},
- {"C:\\deerme\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\web_services\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\webservices\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\data.dat", false}};
+ {"C:\\here\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\web_services\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\webservices\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\data.dat", true},
+ {"C:\\there\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\web_services\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\webservices\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\data.dat", true},
+ {"C:\\deerme\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\web_services\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\webservices\\org\\jboss\\cache\\jgroups\\pojocache\\application\\server\\clustering\\portal\\data.dat", true}};
for (Object[] aData : data)
{
Modified: core/trunk/src/test/java/org/jboss/cache/marshall/MarshalledValueTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/marshall/MarshalledValueTest.java 2008-02-06 03:25:50 UTC (rev 5312)
+++ core/trunk/src/test/java/org/jboss/cache/marshall/MarshalledValueTest.java 2008-02-06 13:11:22 UTC (rev 5313)
@@ -46,8 +46,10 @@
@BeforeMethod
public void setUp()
{
- cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC));
- cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC));
+ cache1 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC, false));
+ cache2 = (CacheSPI<Object, Object>) new DefaultCacheFactory<Object, Object>().createCache(UnitTestCacheConfigurationFactory.createConfiguration(Configuration.CacheMode.REPL_SYNC, false));
+ cache1.getConfiguration().setUseLazyDeserialization(true);
+ cache2.getConfiguration().setUseLazyDeserialization(true);
assert TestingUtil.findInterceptor(cache1, MarshalledValueInterceptor.class) != null : "Marshalled value interceptor not in chain!";
assert TestingUtil.findInterceptor(cache2, MarshalledValueInterceptor.class) != null : "Marshalled value interceptor not in chain!";
16 years, 3 months
JBoss Cache SVN: r5312 - in core/trunk/src: main/java/org/jboss/cache/factories and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-02-05 22:25:50 -0500 (Tue, 05 Feb 2008)
New Revision: 5312
Removed:
core/trunk/src/main/java/org/jboss/cache/factories/LockTableFactory.java
Modified:
core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
core/trunk/src/test/java/org/jboss/cache/CallbackTest.java
core/trunk/src/test/java/org/jboss/cache/TreeCacheFunctionalTest.java
Log:
More cleanups
Modified: core/trunk/src/main/java/org/jboss/cache/CacheSPI.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2008-02-06 03:22:00 UTC (rev 5311)
+++ core/trunk/src/main/java/org/jboss/cache/CacheSPI.java 2008-02-06 03:25:50 UTC (rev 5312)
@@ -12,7 +12,6 @@
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.loader.CacheLoader;
import org.jboss.cache.loader.CacheLoaderManager;
-import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.Marshaller;
import org.jboss.cache.notifications.Notifier;
import org.jboss.cache.statetransfer.StateTransferManager;
@@ -22,7 +21,6 @@
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.List;
-import java.util.Map;
import java.util.Set;
/**
@@ -227,13 +225,6 @@
int getNumberOfNodes();
/**
- * Retrieves the current table of locks.
- *
- * @return lock table.
- */
- Map<Thread, List<NodeLock>> getLockTable();
-
- /**
* Returns the global transaction for this local transaction.
* Optionally creates a new global transaction if it does not exist.
*
Modified: core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-02-06 03:22:00 UTC (rev 5311)
+++ core/trunk/src/main/java/org/jboss/cache/factories/ComponentRegistry.java 2008-02-06 03:25:50 UTC (rev 5312)
@@ -104,7 +104,6 @@
s.add(BuddyManagerFactory.class);
s.add(EmptyConstructorFactory.class);
s.add(InterceptorChainFactory.class);
- s.add(LockTableFactory.class);
s.add(RuntimeConfigAwareFactory.class);
s.add(TransactionManagerFactory.class);
s.add(ReplicationQueueFactory.class);
Deleted: core/trunk/src/main/java/org/jboss/cache/factories/LockTableFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/LockTableFactory.java 2008-02-06 03:22:00 UTC (rev 5311)
+++ core/trunk/src/main/java/org/jboss/cache/factories/LockTableFactory.java 2008-02-06 03:25:50 UTC (rev 5312)
@@ -1,31 +0,0 @@
-package org.jboss.cache.factories;
-
-import org.jboss.cache.factories.annotations.DefaultFactoryFor;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Dead simple class to create a lock factory
- *
- * @author Manik Surtani (<a href="mailto:manik@jboss.org">manik(a)jboss.org</a>)
- * @since 2.1.0
- */
-@DefaultFactoryFor(classes = Map.class)
-public class LockTableFactory extends EmptyConstructorFactory
-{
- private static final String LOCK_MAP_COMPONENT_NAME = "LockTable";
-
- @Override
- @SuppressWarnings("unchecked")
- protected <T> T construct(String componentName, Class<T> componentType)
- {
- if (componentName.equals(LOCK_MAP_COMPONENT_NAME))
- return (T) new ConcurrentHashMap();
- else
- {
- log.warn("Unknown component name " + componentName);
- return null;
- }
- }
-}
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-02-06 03:22:00 UTC (rev 5311)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/CacheInvocationDelegate.java 2008-02-06 03:25:50 UTC (rev 5312)
@@ -7,11 +7,9 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.config.Option;
import org.jboss.cache.factories.InterceptorChainFactory;
-import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.interceptors.Interceptor;
import org.jboss.cache.loader.CacheLoaderManager;
-import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.Marshaller;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.marshall.MethodCallFactory;
@@ -51,7 +49,6 @@
private RPCManager rpcManager;
private RegionManager regionManager;
private Marshaller marshaller;
- private Map<Thread, List<NodeLock>> lockTable;
public CacheInvocationDelegate()
{
@@ -61,8 +58,7 @@
@Inject
private void injectDependencies(StateTransferManager stateTransferManager, CacheLoaderManager cacheLoaderManager, Notifier notifier,
TransactionManager transactionManager, BuddyManager buddyManager, TransactionTable transactionTable,
- RPCManager rpcManager, RegionManager regionManager, Marshaller marshaller,
- @ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable)
+ RPCManager rpcManager, RegionManager regionManager, Marshaller marshaller)
{
this.stateTransferManager = stateTransferManager;
this.cacheLoaderManager = cacheLoaderManager;
@@ -73,7 +69,6 @@
this.rpcManager = rpcManager;
this.regionManager = regionManager;
this.marshaller = marshaller;
- this.lockTable = lockTable;
}
private void reset()
@@ -87,7 +82,6 @@
this.rpcManager = null;
this.regionManager = null;
this.marshaller = null;
- this.lockTable = null;
}
@Override
@@ -177,11 +171,6 @@
return cache.getNumberOfNodes();
}
- public Map<Thread, List<NodeLock>> getLockTable()
- {
- return lockTable;
- }
-
public RegionManager getRegionManager()
{
return regionManager;
Modified: core/trunk/src/test/java/org/jboss/cache/CallbackTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/CallbackTest.java 2008-02-06 03:22:00 UTC (rev 5311)
+++ core/trunk/src/test/java/org/jboss/cache/CallbackTest.java 2008-02-06 03:25:50 UTC (rev 5312)
@@ -46,7 +46,7 @@
cache.put(FQN_A, null);
assertTrue(cache.exists(FQN_A));
assertTrue(cache.exists(FQN_B));//created by callback
- assertEquals(cache.getLockTable().size(), 0);
+ //assertEquals(cache.getLockTable().size(), 0);
System.out.println("cache locks:\n" + CachePrinter.printCacheLockingInfo(cache));
assertEquals(0, cache.getNumberOfLocksHeld());
}
@@ -59,7 +59,7 @@
cache.put(FQN_A, null);
assertTrue(cache.exists(FQN_A));
- assertEquals(cache.getLockTable().size(), 0);
+// assertEquals(cache.getLockTable().size(), 0);
System.out.println("cache locks:\n" + CachePrinter.printCacheLockingInfo(cache));
assertEquals(0, cache.getNumberOfLocksHeld());
}
@@ -74,7 +74,7 @@
cache.put("/a", null);
assertTrue(cache.exists(FQN_A));
assertTrue(cache.exists(FQN_B));
- assertEquals(cache.getLockTable().size(), 0);
+// assertEquals(cache.getLockTable().size(), 0);
System.out.println("cache locks:\n" + CachePrinter.printCacheLockingInfo(cache));
assertEquals(0, cache.getNumberOfLocksHeld());
}
Modified: core/trunk/src/test/java/org/jboss/cache/TreeCacheFunctionalTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/TreeCacheFunctionalTest.java 2008-02-06 03:22:00 UTC (rev 5311)
+++ core/trunk/src/test/java/org/jboss/cache/TreeCacheFunctionalTest.java 2008-02-06 03:25:50 UTC (rev 5312)
@@ -50,7 +50,7 @@
assertEquals(cache.get("/a/b/c", "age"), 38);
assertNotNull(cache.getNode("/a/b/c"));
assertEquals(0, cache.getNumberOfLocksHeld());
- assertEquals(0, cache.getLockTable().size());
+// assertEquals(0, cache.getLockTable().size());
}
@@ -91,7 +91,7 @@
assertEquals(cache.getNode("/a/b/c").getKeys().size(), 2);
assertEquals(cache.exists("/a/b/c"), true);
assertEquals(0, cache.getNumberOfLocksHeld());
- assertEquals(0, cache.getLockTable().size());
+// assertEquals(0, cache.getLockTable().size());
}
public void testRemove() throws CacheException
@@ -104,6 +104,6 @@
cache.removeNode("/a/b/c");
assertEquals(0, cache.getNumberOfLocksHeld());
- assertEquals(0, cache.getLockTable().size());
+// assertEquals(0, cache.getLockTable().size());
}
}
16 years, 3 months
JBoss Cache SVN: r5311 - in core/trunk/src: main/java/org/jboss/cache/factories and 4 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-02-05 22:22:00 -0500 (Tue, 05 Feb 2008)
New Revision: 5311
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
Log:
Improved performance in a few places, including:
1) Getting rid of the UnlockInterceptor and combining this with the pessimistic lock interceptor
2) Getting rid of the LockMap, which was only used to share invocation scope locks betweek the above 2 interceptors
3) Got rid of the ConcurrentHashSet in LockMap in favour of a synchronised LinkedList which performed better.
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-02-06 03:16:44 UTC (rev 5310)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-02-06 03:22:00 UTC (rev 5311)
@@ -7,10 +7,14 @@
package org.jboss.cache;
import org.jboss.cache.config.Option;
+import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.transaction.GlobalTransaction;
import javax.transaction.Transaction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
/**
* This context holds information specific to a method invocation.
@@ -150,6 +154,32 @@
return originLocal;
}
+ List<NodeLock> invocationLocks;
+
+ public List<NodeLock> getInvocationLocksAcquired()
+ {
+ return invocationLocks;
+ }
+
+ public void addInvocationLocksAcquired(Collection<NodeLock> locks)
+ {
+ // no need to worry about concurrency here - a context is only valid for a single thread.
+ if (invocationLocks == null) invocationLocks = new ArrayList<NodeLock>(5);
+ invocationLocks.addAll(locks);
+ }
+
+ public void addInvocationLockAcquired(NodeLock l)
+ {
+ // no need to worry about concurrency here - a context is only valid for a single thread.
+ if (invocationLocks == null) invocationLocks = new ArrayList<NodeLock>(5);
+ invocationLocks.add(l);
+ }
+
+ public void clearInvocationLocksAcquired()
+ {
+ invocationLocks = null;
+ }
+
/**
* If set to true, the invocation is assumed to have originated locally. If set to false,
* assumed to have originated from a remote cache.
@@ -198,6 +228,7 @@
optionOverrides = null;
originLocal = true;
txHasMods = false;
+ invocationLocks = null;
}
public InvocationContext clone() throws CloneNotSupportedException
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-02-06 03:16:44 UTC (rev 5310)
+++ core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-02-06 03:22:00 UTC (rev 5311)
@@ -115,7 +115,7 @@
if (!optimistic)
{
addInterceptor(first, PessimisticLockInterceptor.class);
- addInterceptor(first, UnlockInterceptor.class);
+// addInterceptor(first, UnlockInterceptor.class);
}
if (isUsingCacheLoaders())
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-02-06 03:16:44 UTC (rev 5310)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-02-06 03:22:00 UTC (rev 5311)
@@ -51,16 +51,13 @@
{
if (trace) log.trace("Invoked with method call " + ctx.getMethodCall());
- if (skipMethodCall(ctx))
- {
- return nextInterceptor(ctx);
- }
MethodCall m = ctx.getMethodCall();
- if (!overriddenMethods.contains(m.getMethodId()))
+ if (!overriddenMethods.contains(m.getMethodId()) || skipMethodCall(ctx))
{
- if (trace) log.trace("Not registered for any handlers, passing up the chain.");
+ if (trace) log.trace("Not registered for any handlers, or instructed to skip call. Passing up the chain.");
return nextInterceptor(ctx);
}
+
Object[] args = m.getArgs();
Object result;
switch (m.getMethodId())
@@ -288,7 +285,7 @@
}
/**
- * Handles {@link org.jboss.cache.CacheImpl#evict(org.jboss.cache.Fqn)}
+ * Handles evict()
*/
protected Object handleEvictMethod(InvocationContext ctx, Fqn fqn) throws Throwable
{
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-02-06 03:16:44 UTC (rev 5310)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-02-06 03:22:00 UTC (rev 5311)
@@ -12,7 +12,6 @@
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockingException;
@@ -24,7 +23,7 @@
import org.jboss.cache.transaction.TransactionTable;
import org.jgroups.Address;
-import java.util.Collections;
+import javax.transaction.Transaction;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -57,7 +56,6 @@
/**
* Map<Thread, List<NodeLock>>. Keys = threads, values = lists of locks held by that thread
*/
- private Map<Thread, List<NodeLock>> lockTable;
// private ThreadLocal<List<NodeLock>> lockTable;
private long lock_acquisition_timeout;
@@ -67,10 +65,10 @@
}
@Inject
- public void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
-// public void injectDependencies(@ComponentName("LockTable")ThreadLocal<List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
+ public void injectDependencies(Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
+// public void injectDependencies(@ComponentName("LockTable")Map<Thread, List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
{
- this.lockTable = lockTable;
+// this.lockTable = lockTable;
lock_acquisition_timeout = configuration.getLockAcquisitionTimeout();
this.cacheImpl = cacheImpl;
this.tx_table = txTable;
@@ -84,18 +82,55 @@
{
return super.invoke(ctx);
}
- catch (LockingException le)
+// catch (LockingException le)
+// {
+// if (trace) log.trace("Locking exception occured, cleaning up locks.", le);
+// releaseLocks(ctx);
+// throw le;
+// }
+// catch (TimeoutException te)
+// {
+// if (trace) log.trace("Locking exception occured, cleaning up locks.", te);
+// releaseLocks(ctx);
+// throw te;
+// }
+ finally
{
- if (trace) log.trace("Locking exception occured, cleaning up locks.", le);
- releaseLocks(ctx);
- throw le;
+ // This is functionality from the UnlockInterceptor:
+ // for non-tx calls, release any locks acquired. These used to be in a separate Map<Thread, List<NodeLock>> called a lockTable,
+ // but that has been dropped in facour of storing the invocation-specific locks in the invocation context. Cleaner to have it all
+ // in one place, plus much more performant.
+
+ if (ctx.getOptionOverrides() == null || !ctx.getOptionOverrides().isSuppressLocking())
+ {
+ Transaction tx = ctx.getTransaction();
+ if (tx == null || !isValid(tx))
+ { // no TX
+ List<NodeLock> locks = ctx.getInvocationLocksAcquired();
+ if (trace)
+ log.trace("Attempting to release locks on current thread. Locks for the invocation is " + locks);
+
+ if (locks != null && locks.size() > 0)
+ {
+ Thread currentThread = Thread.currentThread();
+ try
+ {
+ // make sure we release locks in *reverse* order!
+ for (int i = locks.size() - 1; i > -1; i--)
+ {
+ NodeLock nl = locks.get(i);
+ if (trace) log.trace("releasing lock for " + nl.getFqn() + ": " + nl);
+ nl.release(currentThread);
+ }
+ }
+ finally
+ {
+ ctx.clearInvocationLocksAcquired();
+ }
+ }
+ }
+ }
}
- catch (TimeoutException te)
- {
- if (trace) log.trace("Locking exception occured, cleaning up locks.", te);
- releaseLocks(ctx);
- throw te;
- }
}
/**
@@ -104,22 +139,27 @@
*/
private void releaseLocks(InvocationContext ctx)
{
- GlobalTransaction gtx = ctx.getGlobalTransaction();
- if (trace) log.trace("Releasing existing locks. Global tx?" + gtx);
- if (gtx != null)
- {
- TransactionEntry te = cache.getTransactionTable().get(gtx);
- te.releaseAllLocksFIFO(gtx);
- }
- else
- {
- Thread currentThread = Thread.currentThread();
- List<NodeLock> locks = getLocks(currentThread);
- for (NodeLock aLock : locks)
- {
- aLock.release(currentThread);
- }
- }
+ // This should not be necessary - the finally block above will take care of non-tx calls that need cleaning up, even
+ // if there is an exception.
+ // For tx calls, the TxManager will call a rollback to free up resources. -- MS
+
+// GlobalTransaction gtx = ctx.getGlobalTransaction();
+// if (trace) log.trace("Releasing existing locks. Global tx?" + gtx);
+// if (gtx != null)
+// {
+// TransactionEntry te = cache.getTransactionTable().get(gtx);
+// te.releaseAllLocksFIFO(gtx);
+// }
+// else
+// {
+// Thread currentThread = Thread.currentThread();
+// List<NodeLock> locks = ctx.getInvocationLocksAcquired();
+// if (locks != null)
+// for (NodeLock aLock : locks)
+// {
+// aLock.release(currentThread);
+// }
+// }
}
@@ -470,7 +510,7 @@
Fqn currentNodeFqn = currentNode.getFqn();
// actually acquire the lock we need. This method blocks.
- acquireNodeLock(currentNode, owner, gtx, lockTypeRequired, timeout);
+ acquireNodeLock(ctx, currentNode, owner, gtx, lockTypeRequired, timeout);
manageReverseRemove(gtx, currentNode, reverseRemoveCheck);
// make sure the lock we acquired isn't on a deleted node/is an orphan!!
@@ -556,8 +596,7 @@
}
else
{
- List<NodeLock> locks = getLocks(Thread.currentThread());
- locks.addAll(acquiredLocks);
+ ctx.addInvocationLocksAcquired(acquiredLocks);
}
}
}
@@ -589,7 +628,7 @@
return lockType == NodeLock.LockType.WRITE && isTargetNode;//write lock explicitly requested and this is the target to be written to.
}
- private void acquireNodeLock(NodeSPI node, Object owner, GlobalTransaction gtx, NodeLock.LockType lockType, long lockTimeout) throws LockingException, TimeoutException, InterruptedException
+ private void acquireNodeLock(InvocationContext ctx, NodeSPI node, Object owner, GlobalTransaction gtx, NodeLock.LockType lockType, long lockTimeout) throws LockingException, TimeoutException, InterruptedException
{
NodeLock lock = node.getLock();
boolean acquired = lock.acquire(owner, lockTimeout, lockType);
@@ -602,32 +641,11 @@
}
else
{
- Thread currentThread = Thread.currentThread();
- List<NodeLock> locks = getLocks(currentThread);
- if (!locks.contains(lock))
- {
- locks.add(lock);
- lockTable.put(currentThread, locks);
- }
+ ctx.addInvocationLockAcquired(lock);
}
}
}
- private List<NodeLock> getLocks(Thread currentThread)
- {
- // This sort of looks like a get/put race condition, but
- // since we key off the Thread, it's not
- List<NodeLock> locks = lockTable.get(currentThread);
- if (locks == null)
- {
- locks = Collections.synchronizedList(new LinkedList<NodeLock>());
-// lockTable.set(locks);
- lockTable.put(currentThread, locks);
- }
- return locks;
- }
-
-
/**
* Test if this node needs to be 'undeleted'
* reverse the "remove" if the node has been previously removed in the same tx, if this operation is a put()
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2008-02-06 03:16:44 UTC (rev 5310)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2008-02-06 03:22:00 UTC (rev 5311)
@@ -16,6 +16,7 @@
* @author Bela Ban
* @version $Id$
*/
+@Deprecated
public class UnlockInterceptor extends Interceptor
{
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2008-02-06 03:16:44 UTC (rev 5310)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2008-02-06 03:22:00 UTC (rev 5311)
@@ -6,11 +6,10 @@
*/
package org.jboss.cache.lock;
-import org.jboss.cache.util.concurrent.ConcurrentHashSet;
-
import java.util.Collection;
import java.util.Collections;
-import java.util.Set;
+import java.util.LinkedList;
+import java.util.List;
/**
* Provide lock ownership mapping.
@@ -28,8 +27,8 @@
// This is more efficient (lower CPU utilisation and better concurrency) than a CopyOnWriteArraySet or ConcurrentHashSet.
// for some reason this barfs with concurrent mod exceptions. Need to see why.
- // private final List<Object> readOwnerList_ = Collections.synchronizedList(new LinkedList<Object>());
- private final Set<Object> readOwnerList_ = new ConcurrentHashSet<Object>();
+ private final List<Object> readOwnerList_ = Collections.synchronizedList(new LinkedList<Object>());
+// private final Set<Object> readOwnerList_ = new ConcurrentHashSet<Object>();
/**
* Check whether this owner has reader or writer ownership.
@@ -49,7 +48,7 @@
switch (ownership)
{
case OWNER_ANY:
- return (writeOwner_ != null && caller.equals(writeOwner_) || readOwnerList_.contains(caller));
+ return ((writeOwner_ != null && caller.equals(writeOwner_)) || readOwnerList_.contains(caller));
case OWNER_READ:
return (readOwnerList_.contains(caller));
case OWNER_WRITE:
@@ -117,8 +116,8 @@
*/
public Collection<Object> readerOwners()
{
- //return Collections.unmodifiableList(readOwnerList_);
- return Collections.unmodifiableSet(readOwnerList_);
+ return readOwnerList_;
+// return Collections.unmodifiableSet(readOwnerList_);
}
public void releaseReaderOwners(LockStrategy lock)
Modified: core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-02-06 03:16:44 UTC (rev 5310)
+++ core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-02-06 03:22:00 UTC (rev 5311)
@@ -51,13 +51,12 @@
System.out.println("testBareConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(6, list.size());
+ assertEquals(5, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -75,13 +74,12 @@
System.out.println("testTxConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(6, list.size());
+ assertEquals(5, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -124,14 +122,13 @@
System.out.println("testSharedCacheLoaderConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(9, list.size());
+ assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CacheLoaderInterceptor.class, interceptors.next().getClass());
assertEquals(CacheStoreInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
@@ -154,14 +151,13 @@
System.out.println("testUnsharedCacheLoaderConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(9, list.size());
+ assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CacheLoaderInterceptor.class, interceptors.next().getClass());
assertEquals(CacheStoreInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
@@ -181,14 +177,13 @@
System.out.println("testTxAndRepl interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(7, list.size());
+ assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -314,14 +309,13 @@
List<Interceptor> list = getInterceptorChainFactory(cache).asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
- assertEquals(7, list.size());
+ assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
// ok, my replication chain looks good.
@@ -335,14 +329,13 @@
list = getInterceptorChainFactory(cache).asList(chain);
interceptors = list.iterator();
- assertEquals(7, list.size());
+ assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(InvalidationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -357,14 +350,13 @@
System.out.println("testCacheMgmtConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(7, list.size());
+ assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -389,14 +381,13 @@
System.out.println("testEvictionInterceptorConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(8, list.size());
+ assertEquals(7, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(EvictionInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
@@ -465,7 +456,7 @@
System.out.println("testEvictionInterceptorConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(9, list.size());
+ assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
@@ -473,7 +464,6 @@
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(DataGravitatorInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java 2008-02-06 03:16:44 UTC (rev 5310)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java 2008-02-06 03:22:00 UTC (rev 5311)
@@ -193,17 +193,10 @@
long end = System.currentTimeMillis() + DURATION;
long startTime = System.currentTimeMillis();
log.warn("Starting test");
+ int i = 0;
while (System.currentTimeMillis() < end)
{
- exec.execute(new Runnable()
- {
- public void run()
- {
- String k = getRandomString();
- String v = getRandomString();
- cache.put(fqns.get(r.nextInt(MAX_OVERALL_NODES)), k, v);
- }
- });
+ exec.execute(new MyRunnable(i++));
TestingUtil.sleepRandom(MAX_RANDOM_SLEEP_MILLIS);
}
log.warn("Finished generating runnables; awaiting executor completion");
@@ -214,6 +207,24 @@
log.warn("Finished test. " + printDuration(duration));
}
+ private class MyRunnable implements Runnable
+ {
+ int id;
+
+ private MyRunnable(int id)
+ {
+ this.id = id;
+ }
+
+ public void run()
+ {
+ if (id % 100 == 0) log.warn("Processing iteration " + id);
+ String k = getRandomString();
+ String v = getRandomString();
+ cache.put(fqns.get(r.nextInt(MAX_OVERALL_NODES)), k, v);
+ }
+ }
+
private String getRandomString()
{
StringBuilder sb = new StringBuilder();
16 years, 3 months
JBoss Cache SVN: r5310 - amazon-s3/trunk.
by jbosscache-commits@lists.jboss.org
Author: genman
Date: 2008-02-05 22:16:44 -0500 (Tue, 05 Feb 2008)
New Revision: 5310
Modified:
amazon-s3/trunk/pom.xml
Log:
use source 1.5
Modified: amazon-s3/trunk/pom.xml
===================================================================
--- amazon-s3/trunk/pom.xml 2008-02-06 03:09:24 UTC (rev 5309)
+++ amazon-s3/trunk/pom.xml 2008-02-06 03:16:44 UTC (rev 5310)
@@ -1,33 +1,40 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amazon</groupId>
<artifactId>amazon-s3-rest</artifactId>
<version>1.0.0.0-SNAPSHOT</version>
- <description>
- Cleaned-up version of the Amazon S3 REST access layer
- </description>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <systemProperties>
- <property>
- <name>accessKey</name>
- <value>TODO</value>
- </property>
- <property>
- <name>secretKey</name>
- <value>TODO</value>
- </property>
- </systemProperties>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <description>
+ Cleaned-up version of the Amazon S3 REST access layer
+ </description>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>accessKey</name>
+ <value>TODO</value>
+ </property>
+ <property>
+ <name>secretKey</name>
+ <value>TODO</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
<dependencies>
<dependency>
<groupId>junit</groupId>
@@ -36,4 +43,4 @@
<scope>test</scope>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
16 years, 3 months
JBoss Cache SVN: r5309 - in amazon-s3/trunk: src/main/java/com/amazon/s3 and 2 other directories.
by jbosscache-commits@lists.jboss.org
Author: genman
Date: 2008-02-05 22:09:24 -0500 (Tue, 05 Feb 2008)
New Revision: 5309
Removed:
amazon-s3/trunk/src/test/java/com/amazon/s3/S3Driver.java
Modified:
amazon-s3/trunk/pom.xml
amazon-s3/trunk/src/main/java/com/amazon/s3/CallingFormat.java
amazon-s3/trunk/src/main/java/com/amazon/s3/CanonicalString.java
amazon-s3/trunk/src/main/java/com/amazon/s3/Connection.java
amazon-s3/trunk/src/main/java/com/amazon/s3/GetResponse.java
amazon-s3/trunk/src/main/java/com/amazon/s3/Headers.java
amazon-s3/trunk/src/main/java/com/amazon/s3/ListAllBucketsResponse.java
amazon-s3/trunk/src/main/java/com/amazon/s3/ListResponse.java
amazon-s3/trunk/src/main/java/com/amazon/s3/LocationResponse.java
amazon-s3/trunk/src/main/java/com/amazon/s3/QueryGenerator.java
amazon-s3/trunk/src/main/java/com/amazon/s3/S3Object.java
amazon-s3/trunk/src/main/java/com/amazon/s3/UrlEncoder.java
amazon-s3/trunk/src/main/java/com/amazon/thirdparty/Base64.java
amazon-s3/trunk/src/test/java/com/amazon/s3/S3Test.java
Log:
Additional code clean-up
Modified: amazon-s3/trunk/pom.xml
===================================================================
--- amazon-s3/trunk/pom.xml 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/pom.xml 2008-02-06 03:09:24 UTC (rev 5309)
@@ -1,9 +1,39 @@
-<?xml version="1.0" encoding="UTF-8"?><project>
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.amazon</groupId>
<artifactId>amazon-s3-rest</artifactId>
<version>1.0.0.0-SNAPSHOT</version>
<description>
Cleaned-up version of the Amazon S3 REST access layer
- </description>
+ </description>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <property>
+ <name>accessKey</name>
+ <value>TODO</value>
+ </property>
+ <property>
+ <name>secretKey</name>
+ <value>TODO</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
\ No newline at end of file
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/CallingFormat.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/CallingFormat.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/CallingFormat.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -11,7 +11,6 @@
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -21,9 +20,9 @@
*/
public abstract class CallingFormat {
- protected static CallingFormat pathCallingFormat = new PathCallingFormat();
- protected static CallingFormat subdomainCallingFormat = new SubdomainCallingFormat();
- protected static CallingFormat vanityCallingFormat = new VanityCallingFormat();
+ private final static CallingFormat pathCallingFormat = new PathCallingFormat();
+ private final static CallingFormat subdomainCallingFormat = new SubdomainCallingFormat();
+ private final static CallingFormat vanityCallingFormat = new VanityCallingFormat();
public abstract boolean supportsLocatedBuckets();
@@ -45,8 +44,8 @@
String argumentValue;
boolean firstRun = true;
if (pathArgs != null) {
- for (Iterator<String> argumentIterator = pathArgs.keySet().iterator(); argumentIterator.hasNext(); ) {
- String argument = argumentIterator.next();
+ for (Map.Entry<String, String> me : pathArgs.entrySet()) {
+ String argument = me.getKey();
if (firstRun) {
firstRun = false;
pathArgsString.append("?");
@@ -54,7 +53,7 @@
pathArgsString.append("&");
}
- argumentValue = pathArgs.get(argument);
+ argumentValue = me.getValue();
pathArgsString.append(argument);
if (argumentValue != null) {
pathArgsString.append("=");
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/CanonicalString.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/CanonicalString.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/CanonicalString.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -3,7 +3,6 @@
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -50,8 +49,8 @@
public static String make(Method method, Bucket bucket, String key, Map<String, String> pathArgs,
Headers headers, String expires)
{
- StringBuilder buf = new StringBuilder();
- buf.append(method + "\n");
+ StringBuilder buf = new StringBuilder(128);
+ buf.append(method.name()).append("\n");
// Add all interesting headers to a list, then sort them. "Interesting"
// is defined as Content-MD5, Content-Type, Date, and x-amz-
@@ -92,12 +91,12 @@
}
// Finally, add all the interesting headers (i.e.: all that startwith x-amz- ;-))
- for (Iterator<String> i = interestingHeaders.keySet().iterator(); i.hasNext(); ) {
- String headerKey = i.next();
+ for (Map.Entry<String, String> me : interestingHeaders.entrySet()) {
+ String headerKey = me.getKey();
if (headerKey.startsWith(AMAZON_HEADER_PREFIX)) {
- buf.append(headerKey).append(':').append(interestingHeaders.get(headerKey));
+ buf.append(headerKey).append(':').append(me.getValue());
} else {
- buf.append(interestingHeaders.get(headerKey));
+ buf.append(me.getValue());
}
buf.append("\n");
}
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/Connection.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/Connection.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/Connection.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -254,8 +254,11 @@
return new Response(request);
}
- public Response put(Bucket bucket, String key, S3Object object) {
- return put(bucket, key, object);
+ /**
+ * Writes an object to S3.
+ */
+ public Response put(Bucket bucket, String key, S3Object object) throws IOException {
+ return put(bucket, key, object, null);
}
/**
@@ -271,9 +274,12 @@
return new GetResponse(makeRequest(Method.GET, bucket, key, null, headers));
}
- public GetResponse get(Bucket bucket, String key)
+ /**
+ * Reads an object from S3.
+ */
+ public GetResponse get(Bucket bucket, String key) throws IOException
{
- return get(bucket, key);
+ return get(bucket, key, null);
}
/**
@@ -292,9 +298,9 @@
/**
* Deletes an object from S3.
*/
- public Response delete(Bucket bucket, String key)
+ public Response delete(Bucket bucket, String key) throws IOException
{
- return delete(bucket, key);
+ return delete(bucket, key, null);
}
/**
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/GetResponse.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/GetResponse.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/GetResponse.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -63,4 +63,12 @@
public S3Object getObject() {
return object;
}
+
+ /**
+ * Returns a debug string.
+ */
+ @Override
+ public String toString() {
+ return super.toString() + " object=" + object;
+ }
}
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/Headers.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/Headers.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/Headers.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -66,6 +66,13 @@
return headers.get(header);
}
+ public String getValue(String header) {
+ List<String> values = getValues(header);
+ if (values == null || values.isEmpty())
+ return null;
+ return values.get(0);
+ }
+
/**
* Returns the number of headers.
*/
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/ListAllBucketsResponse.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/ListAllBucketsResponse.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/ListAllBucketsResponse.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -95,4 +95,10 @@
}
+
+ @Override
+ public String toString() {
+ return super.toString() +
+ " entries=" + entries;
+ }
}
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/ListResponse.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/ListResponse.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/ListResponse.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -80,7 +80,10 @@
return isTruncated;
}
- public class CommonPrefixEntry {
+ /**
+ * Prefix entry.
+ */
+ public static class CommonPrefixEntry {
/**
* The prefix common to the delimited keys it represents
@@ -131,11 +134,12 @@
} else if (name.equals("CommonPrefixes")){
this.commonPrefixEntry = new CommonPrefixEntry();
}
+ this.currText = new StringBuilder();
}
public void endElement(String uri, String name, String qName) {
if (name.equals("Name")) {
- name = this.currText.toString();
+ ListResponse.this.name = this.currText.toString();
}
// this prefix is the one we echo back from the request
else if (name.equals("Prefix") && this.isEchoedPrefix) {
@@ -178,8 +182,6 @@
else if (name.equals("Prefix")) {
this.commonPrefixEntry.prefix = this.currText.toString();
}
- if(this.currText.length() != 0)
- this.currText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
@@ -232,5 +234,18 @@
public String getNextMarker() {
return this.nextMarker;
}
+
+ @Override
+ public String toString() {
+ return super.toString() +
+ " name=" + name +
+ " prefix=" + prefix +
+ " marker=" + marker +
+ " maxKeys=" + maxKeys +
+ " isTruncated=" + isTruncated +
+ " nextMarker=" + nextMarker +
+ " entries=" + entries +
+ " prefix=" + commonPrefixEntries;
+ }
}
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/LocationResponse.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/LocationResponse.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/LocationResponse.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -71,4 +71,10 @@
this.currText.append(ch, start, length);
}
}
+
+ @Override
+ public String toString() {
+ return super.toString() + " location=" + location;
+ }
+
}
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/QueryGenerator.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/QueryGenerator.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/QueryGenerator.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -126,6 +126,9 @@
if (object != null) {
metadata = object.getMetadata();
}
+ if (headers == null) {
+ headers = new Headers();
+ }
return generateURL(Method.PUT, bucket, UrlEncoder.encode(key), headers.mergeMetadata(metadata));
}
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/S3Object.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/S3Object.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/S3Object.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -9,8 +9,6 @@
package com.amazon.s3;
-
-
/**
* A representation of a single object stored in S3.
*/
Modified: amazon-s3/trunk/src/main/java/com/amazon/s3/UrlEncoder.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/s3/UrlEncoder.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/s3/UrlEncoder.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -12,10 +12,10 @@
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-
-
-public class UrlEncoder {
+class UrlEncoder {
+ private UrlEncoder() {}
+
static String encode(String unencoded) {
try {
return URLEncoder.encode(unencoded, "UTF-8");
Modified: amazon-s3/trunk/src/main/java/com/amazon/thirdparty/Base64.java
===================================================================
--- amazon-s3/trunk/src/main/java/com/amazon/thirdparty/Base64.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/main/java/com/amazon/thirdparty/Base64.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -773,226 +773,6 @@
- /**
- * Attempts to decode Base64 data and deserialize a Java
- * Object within. Returns <tt>null</tt> if there was an error.
- *
- * @param encodedObject The Base64 data to decode
- * @return The decoded and deserialized object
- * @since 1.5
- */
- public static Object decodeToObject( String encodedObject )
- {
- // Decode and gunzip if necessary
- byte[] objBytes = decode( encodedObject );
-
- java.io.ByteArrayInputStream bais = null;
- java.io.ObjectInputStream ois = null;
- Object obj = null;
-
- try
- {
- bais = new java.io.ByteArrayInputStream( objBytes );
- ois = new java.io.ObjectInputStream( bais );
-
- obj = ois.readObject();
- } // end try
- catch( java.io.IOException e )
- {
- e.printStackTrace();
- obj = null;
- } // end catch
- catch( java.lang.ClassNotFoundException e )
- {
- e.printStackTrace();
- obj = null;
- } // end catch
- finally
- {
- try{ bais.close(); } catch( Exception e ){}
- try{ ois.close(); } catch( Exception e ){}
- } // end finally
-
- return obj;
- } // end decodeObject
-
-
-
- /**
- * Convenience method for encoding data to a file.
- *
- * @param dataToEncode byte array of data to encode in base64 form
- * @param filename Filename for saving encoded data
- * @return <tt>true</tt> if successful, <tt>false</tt> otherwise
- *
- * @since 2.1
- */
- public static boolean encodeToFile( byte[] dataToEncode, String filename )
- {
- boolean success = false;
- Base64.OutputStream bos = null;
- try
- {
- bos = new Base64.OutputStream(
- new java.io.FileOutputStream( filename ), Base64.ENCODE );
- bos.write( dataToEncode );
- success = true;
- } // end try
- catch( java.io.IOException e )
- {
-
- success = false;
- } // end catch: IOException
- finally
- {
- try{ bos.close(); } catch( Exception e ){}
- } // end finally
-
- return success;
- } // end encodeToFile
-
-
- /**
- * Convenience method for decoding data to a file.
- *
- * @param dataToDecode Base64-encoded data as a string
- * @param filename Filename for saving decoded data
- * @return <tt>true</tt> if successful, <tt>false</tt> otherwise
- *
- * @since 2.1
- */
- public static boolean decodeToFile( String dataToDecode, String filename )
- {
- boolean success = false;
- Base64.OutputStream bos = null;
- try
- {
- bos = new Base64.OutputStream(
- new java.io.FileOutputStream( filename ), Base64.DECODE );
- bos.write( dataToDecode.getBytes( PREFERRED_ENCODING ) );
- success = true;
- } // end try
- catch( java.io.IOException e )
- {
- success = false;
- } // end catch: IOException
- finally
- {
- try{ bos.close(); } catch( Exception e ){}
- } // end finally
-
- return success;
- } // end decodeToFile
-
-
-
-
- /**
- * Convenience method for reading a base64-encoded
- * file and decoding it.
- *
- * @param filename Filename for reading encoded data
- * @return decoded byte array or null if unsuccessful
- *
- * @since 2.1
- */
- public static byte[] decodeFromFile( String filename )
- {
- byte[] decodedData = null;
- Base64.InputStream bis = null;
- try
- {
- // Set up some useful variables
- java.io.File file = new java.io.File( filename );
- byte[] buffer = null;
- int length = 0;
- int numBytes = 0;
-
- // Check for size of file
- if( file.length() > Integer.MAX_VALUE )
- {
- System.err.println( "File is too big for this convenience method (" + file.length() + " bytes)." );
- return null;
- } // end if: file too big for int index
- buffer = new byte[ (int)file.length() ];
-
- // Open a stream
- bis = new Base64.InputStream(
- new java.io.BufferedInputStream(
- new java.io.FileInputStream( file ) ), Base64.DECODE );
-
- // Read until done
- while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 )
- length += numBytes;
-
- // Save in a variable to return
- decodedData = new byte[ length ];
- System.arraycopy( buffer, 0, decodedData, 0, length );
-
- } // end try
- catch( java.io.IOException e )
- {
- System.err.println( "Error decoding from file " + filename );
- } // end catch: IOException
- finally
- {
- try{ bis.close(); } catch( Exception e) {}
- } // end finally
-
- return decodedData;
- } // end decodeFromFile
-
-
-
- /**
- * Convenience method for reading a binary file
- * and base64-encoding it.
- *
- * @param filename Filename for reading binary data
- * @return base64-encoded string or null if unsuccessful
- *
- * @since 2.1
- */
- public static String encodeFromFile( String filename )
- {
- String encodedData = null;
- Base64.InputStream bis = null;
- try
- {
- // Set up some useful variables
- java.io.File file = new java.io.File( filename );
- byte[] buffer = new byte[ (int)(file.length() * 1.4) ];
- int length = 0;
- int numBytes = 0;
-
- // Open a stream
- bis = new Base64.InputStream(
- new java.io.BufferedInputStream(
- new java.io.FileInputStream( file ) ), Base64.ENCODE );
-
- // Read until done
- while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 )
- length += numBytes;
-
- // Save in a variable to return
- encodedData = new String( buffer, 0, length, Base64.PREFERRED_ENCODING );
-
- } // end try
- catch( java.io.IOException e )
- {
- System.err.println( "Error encoding from file " + filename );
- } // end catch: IOException
- finally
- {
- try{ bis.close(); } catch( Exception e) {}
- } // end finally
-
- return encodedData;
- } // end encodeFromFile
-
-
-
-
/* ******** I N N E R C L A S S I N P U T S T R E A M ******** */
Deleted: amazon-s3/trunk/src/test/java/com/amazon/s3/S3Driver.java
===================================================================
--- amazon-s3/trunk/src/test/java/com/amazon/s3/S3Driver.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/test/java/com/amazon/s3/S3Driver.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -1,139 +0,0 @@
-package com.amazon.s3;
-// This software code is made available "AS IS" without warranties of any
-// kind. You may copy, display, modify and redistribute the software
-// code either by itself or as incorporated into your code; provided that
-// you do not remove any proprietary notices. Your use of this software
-// code is at your own risk and you waive any claim against Amazon
-// Digital Services, Inc. or its affiliates with respect to your use of
-// this software code. (c) 2006-2007 Amazon Digital Services, Inc. or its
-// affiliates.
-
-
-public class S3Driver {
-
- static final String awsAccessKeyId = "1CK9DVFVC6GRDSP6Z9G2"; //<INSERT YOUR AWS ACCESS KEY ID HERE>";
- static final String awsSecretAccessKey = "<INSERT YOUR AWS SECRET ACCESS KEY HERE>";
-
-
- // convert the bucket to lowercase for vanity domains
- // the bucket name must be lowercase since DNS is case-insensitive
- static final Bucket bucket = new Bucket(awsAccessKeyId.toLowerCase() + "-test-bucket");
- static final String keyName = "test-key";
-
- public static void main(String args[]) throws Exception {
- if (awsAccessKeyId.startsWith("<INSERT")) {
- System.err.println("Please examine S3Driver.java and update it with your credentials");
- System.exit(-1);
- }
-
- Connection conn =
- new Connection(awsAccessKeyId, awsSecretAccessKey);
- QueryGenerator generator =
- new QueryGenerator(awsAccessKeyId, awsSecretAccessKey);
-
- // Check if the bucket exists. The high availability engineering of
- // Amazon S3 is focused on get, put, list, and delete operations.
- // Because bucket operations work against a centralized, global
- // resource space, it is not appropriate to make bucket create or
- // delete calls on the high availability code path of your application.
- // It is better to create or delete buckets in a separate initialization
- // or setup routine that you run less often.
- if (!conn.exists(bucket))
- {
- System.out.println("----- creating bucket -----");
- System.out.println(conn.create(bucket, Connection.LOCATION_DEFAULT, null).getResponseMessage());
- // sample creating an EU located bucket.
- // (note path-style urls will not work with location-constrained buckets)
- //System.out.println(conn.createBucket(bucketName, AWSAuthConnection.LOCATION_EU, null).connection.getResponseMessage());
- }
-
- System.out.println("----- listing bucket -----");
- System.out.println(conn.list(bucket).getEntries());
-
- System.out.println("----- bucket location -----");
- System.out.println(conn.getLocation(bucket).getLocation());
-
- System.out.println("----- putting object -----");
- S3Object object = new S3Object("this is a test".getBytes(), null);
- Headers headers = new Headers();
- headers.put("Content-Type", "text/plain");
- System.out.println(
- conn.put(bucket, keyName, object, headers).getResponseMessage()
- );
-
- System.out.println("----- listing bucket -----");
- System.out.println(conn.list(bucket, null, null, null, null).getEntries());
-
- System.out.println("----- getting object -----");
- System.out.println(
- new String(conn.get(bucket, keyName, null).getObject().getData())
- );
-
- System.out.println("----- query string auth example -----");
- generator.setExpiresIn(60 * 1000);
-
- System.out.println("Try this url in your web browser (it will only work for 60 seconds)\n");
- System.out.println(generator.get(bucket, keyName, null));
- System.out.print("\npress enter> ");
- System.in.read();
-
- System.out.println("\nNow try just the url without the query string arguments. It should fail.\n");
- System.out.println(generator.makeBareURL(bucket, keyName));
- System.out.print("\npress enter> ");
- System.in.read();
-
- System.out.println("----- putting object with metadata and public read acl -----");
-
- Headers metadata = new Headers();
- metadata.put("blah", "foo");
- object = new S3Object("this is a publicly readable test".getBytes(), new Headers(metadata));
-
- headers = new Headers();
- headers.put("x-amz-acl", "public-read");
- headers.put("Content-Type", "text/plain");
-
- System.out.println(
- conn.put(bucket, keyName + "-public", object, headers).getResponseMessage()
- );
-
- System.out.println("----- anonymous read test -----");
- System.out.println("\nYou should be able to try this in your browser\n");
- System.out.println(generator.makeBareURL(bucket, keyName + "-public"));
- System.out.print("\npress enter> ");
- System.in.read();
-
- System.out.println("----- path style url example -----");
- System.out.println("\nNon-location-constrained buckets can also be specified as part of the url path. (This was the original url style supported by S3.)");
- System.out.println("\nTry this url out in your browser (it will only be valid for 60 seconds)\n");
- generator.setCallingFormat(CallingFormat.getPathCallingFormat());
- // could also have been done like this:
- // generator = new QueryStringAuthGenerator(awsAccessKeyId, awsSecretAccessKey, true, Utils.DEFAULT_HOST, CallingFormat.getPathCallingFormat());
- generator.setExpiresIn(60 * 1000);
- System.out.println(generator.get(bucket, keyName, null));
- System.out.print("\npress enter> ");
- System.in.read();
-
- System.out.println("----- getting object's acl -----");
- System.out.println(new String(conn.getACL(bucket, keyName, null).getObject().getData()));
-
- System.out.println("----- deleting objects -----");
- System.out.println(
- conn.delete(bucket, keyName, null).getResponseMessage()
- );
- System.out.println(
- conn.delete(bucket, keyName + "-public", null).getResponseMessage()
- );
-
- System.out.println("----- listing bucket -----");
- System.out.println(conn.list(bucket, null, null, null, null).getEntries());
-
- System.out.println("----- listing all my buckets -----");
- System.out.println(conn.listAllBuckets().getEntries());
-
- System.out.println("----- deleting bucket -----");
- System.out.println(
- conn.delete(bucket).getResponseMessage()
- );
- }
-
-}
Modified: amazon-s3/trunk/src/test/java/com/amazon/s3/S3Test.java
===================================================================
--- amazon-s3/trunk/src/test/java/com/amazon/s3/S3Test.java 2008-02-06 01:49:23 UTC (rev 5308)
+++ amazon-s3/trunk/src/test/java/com/amazon/s3/S3Test.java 2008-02-06 03:09:24 UTC (rev 5309)
@@ -14,29 +14,34 @@
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+
public class S3Test {
- // static final String awsAccessKeyId = "<INSERT YOUR AWS ACCESS KEY ID HERE>";
- // static final String awsSecretAccessKey = "<INSERT YOUR AWS SECRET ACCESS KEY HERE>";
- static final String awsAccessKeyId = "1CK9DVFVC6GRDSP6Z9G2"; //<INSERT YOUR AWS ACCESS KEY ID HERE>";
- static final String awsSecretAccessKey = "";
-
- // for subdomains (bucket.s3.amazonaws.com),
- // the bucket name must be lowercase since DNS is case-insensitive
- static final Bucket bucket = new Bucket(awsAccessKeyId.toLowerCase() + "-test-bucket");
- static int assertionCount = 0;
+
+ String awsAccessKeyId = System.getProperty("accessKey");
+ String awsSecretAccessKey = System.getProperty("secretKey");
+ Bucket bucket;
static final int UnspecifiedMaxKeys = -1;
- public static void main(String args[]) throws Exception {
- if (awsAccessKeyId.startsWith("<INSERT")) {
- System.err.println("Please examine S3Test.java and update it with your credentials");
- System.exit(-1);
- }
-
+ @Before
+ public void setUp() {
+ if (awsAccessKeyId == null)
+ throw new IllegalStateException("accessKey system propery null");
+ if (awsSecretAccessKey == null)
+ throw new IllegalStateException("secretKey system propery null");
+
+ // for subdomains (bucket.s3.amazonaws.com),
+ // the bucket name must be lowercase since DNS is case-insensitive
+ bucket = new Bucket(awsAccessKeyId.toLowerCase() + "-test-bucket");
+ }
+
+ @Test
+ public void testMe() throws Exception {
// test all operation for both regular and vanity domains
// regular: http://s3.amazonaws.com/key
// subdomain: http://bucket.s3.amazonaws.com/key
@@ -47,9 +52,8 @@
test(CallingFormat.getSubdomainCallingFormat(), Connection.LOCATION_EU, true, Connection.DEFAULT_HOST);
}
- private static void test(CallingFormat format, String location, boolean secure, String server) throws Exception
+ private void test(CallingFormat format, String location, boolean secure, String server) throws Exception
{
- assertionCount = 0;
System.out.println((secure ? "http" : "https") + " / " + server + " / " +
((location == null) ? "<no-location>" : location) + " / " +
format.getClass().getName());
@@ -70,6 +74,7 @@
HttpURLConnection.HTTP_OK,
listBucketResponse.getResponseCode());
assertEquals("list wasn't empty", 0, listBucketResponse.getEntries().size());
+ System.out.println(listBucketResponse);
verifyBucketResponseParameters(listBucketResponse, bucket, "", "", UnspecifiedMaxKeys, null, false, null);
// start delimiter tests
@@ -118,7 +123,7 @@
verifyBucketResponseParameters(listBucketResponse, bucket, "", "", UnspecifiedMaxKeys, "/", false, null);
// root "directory" with a max-keys of "1"
- listBucketResponse = conn.list(bucket, null, null, new Integer( 1 ), "/", null);
+ listBucketResponse = conn.list(bucket, null, null, 1, "/", null);
assertEquals(
"couldn't get list",
HttpURLConnection.HTTP_OK,
@@ -128,7 +133,7 @@
verifyBucketResponseParameters(listBucketResponse, bucket, "", "", 1, "/", true, "example.txt");
// root "directory" with a max-keys of "2"
- listBucketResponse = conn.list(bucket, null, null, new Integer( 2 ), "/", null);
+ listBucketResponse = conn.list(bucket, null, null, 2, "/", null);
assertEquals(
"couldn't get list",
HttpURLConnection.HTTP_OK,
@@ -179,7 +184,7 @@
HttpURLConnection.HTTP_OK,
response.getResponseCode());
- Map metadata = new HashMap();
+ Map<String, List<String>> metadata = new HashMap<String, List<String>>();
metadata.put("title", Arrays.asList(new String[] { "title" }));
response = conn.put(bucket, key, new S3Object(text.getBytes(), new Headers(metadata)), null);
assertEquals(
@@ -196,12 +201,8 @@
assertEquals("didn't get the right metadata back", 1, getResponse.getObject().getMetadata().size());
assertEquals(
"didn't get the right metadata back",
- 1,
- ((List)getResponse.getObject().getMetadata().getValues("title")).size());
- assertEquals(
- "didn't get the right metadata back",
"title",
- ((List)getResponse.getObject().getMetadata().getValues("title")).get(0));
+ getResponse.getObject().getMetadata().getValue("title"));
assertEquals(
"didn't get the right content-length",
""+text.length(),
@@ -225,12 +226,8 @@
assertEquals("didn't get the right metadata back", getResponse.getObject().getMetadata().size(), 1);
assertEquals(
"didn't get the right metadata back",
- 1,
- ((List)getResponse.getObject().getMetadata().getValues("title")).size());
- assertEquals(
- "didn't get the right metadata back",
titleWithSpaces.trim(),
- ((List)getResponse.getObject().getMetadata().getValues("title")).get(0));
+ getResponse.getObject().getMetadata().getValue("title"));
String weirdKey = "&=//%# ++++";
response = conn.put(bucket, weirdKey, new S3Object(text.getBytes(), null), null);
@@ -299,7 +296,7 @@
"couldn't list bucket",
HttpURLConnection.HTTP_OK,
listBucketResponse.getResponseCode());
- List entries = listBucketResponse.getEntries();
+ List<Entry> entries = listBucketResponse.getEntries();
assertEquals("didn't get back the right number of entries", 2, entries.size());
// depends on weirdKey < $key
assertEquals("first key isn't right", weirdKey, ((Entry)entries.get(0)).getKey());
@@ -317,8 +314,7 @@
listBucketResponse.getEntries().size());
verifyBucketResponseParameters(listBucketResponse, bucket, "", "", 1, null, true, null);
- for (Iterator it = entries.iterator(); it.hasNext(); ) {
- Entry entry = (Entry)it.next();
+ for (Entry entry : entries) {
response = conn.delete(bucket, entry.getKey(), null);
assertEquals(
"couldn't delete entry",
@@ -331,7 +327,7 @@
"couldn't list all my buckets",
HttpURLConnection.HTTP_OK,
listAllMyBucketsResponse.getResponseCode());
- List buckets = listAllMyBucketsResponse.getEntries();
+ List<Bucket> buckets = listAllMyBucketsResponse.getEntries();
response = conn.delete(bucket);
assertEquals(
@@ -418,8 +414,6 @@
"DELETE",
HttpURLConnection.HTTP_NO_CONTENT,
"delete bucket");
-
- System.out.println("OK (" + assertionCount + " tests passed)");
}
private static void verifyBucketResponseParameters( ListResponse listBucketResponse,
@@ -439,14 +433,12 @@
private static void assertEquals(String message, int expected, int actual) {
- assertionCount++;
if (expected != actual) {
throw new RuntimeException(message + ": expected " + expected + " but got " + actual);
}
}
private static void assertEquals(String message, byte[] expected, byte[] actual) {
- assertionCount++;
if (! Arrays.equals(expected, actual)) {
throw new RuntimeException(
message +
@@ -458,14 +450,12 @@
}
private static void assertEquals(String message, Object expected, Object actual) {
- assertionCount++;
if (expected != actual && (actual == null || ! actual.equals(expected))) {
throw new RuntimeException(message + ": expected " + expected + " but got " + actual);
}
}
private static void assertEquals(String message, boolean expected, boolean actual) {
- assertionCount++;
if (expected != actual) {
throw new RuntimeException(message + ": expected " + expected + " but got " + actual);
}
@@ -495,4 +485,123 @@
assertEquals(message, code, connection.getResponseCode());
}
+
+ private void readline() throws IOException {
+ // TODO
+ // System.in.read();
+ }
+
+ @Test
+ public void testDriver() throws Exception {
+ Bucket bucket = new Bucket(awsAccessKeyId.toLowerCase() + "-test-bucket");
+ String keyName = "KEY";
+
+ Connection conn = new Connection(awsAccessKeyId, awsSecretAccessKey);
+ QueryGenerator generator = new QueryGenerator(awsAccessKeyId, awsSecretAccessKey);
+
+ // Check if the bucket exists. The high availability engineering of
+ // Amazon S3 is focused on get, put, list, and delete operations.
+ // Because bucket operations work against a centralized, global
+ // resource space, it is not appropriate to make bucket create or
+ // delete calls on the high availability code path of your application.
+ // It is better to create or delete buckets in a separate initialization
+ // or setup routine that you run less often.
+ if (!conn.exists(bucket))
+ {
+ System.out.println("----- creating bucket -----");
+ System.out.println(conn.create(bucket, Connection.LOCATION_DEFAULT, null).getResponseMessage());
+ // sample creating an EU located bucket.
+ // (note path-style urls will not work with location-constrained buckets)
+ //System.out.println(conn.createBucket(bucketName, AWSAuthConnection.LOCATION_EU, null).connection.getResponseMessage());
+ }
+
+ System.out.println("----- listing bucket -----");
+ System.out.println(conn.list(bucket).getEntries());
+
+ System.out.println("----- bucket location -----");
+ System.out.println(conn.getLocation(bucket).getLocation());
+
+ System.out.println("----- putting object -----");
+ S3Object object = new S3Object("this is a test".getBytes(), null);
+ Headers headers = new Headers();
+ headers.put("Content-Type", "text/plain");
+ System.out.println(
+ conn.put(bucket, keyName, object, headers).getResponseMessage()
+ );
+
+ System.out.println("----- listing bucket -----");
+ System.out.println(conn.list(bucket, null, null, null, null).getEntries());
+
+ System.out.println("----- getting object -----");
+ System.out.println(
+ new String(conn.get(bucket, keyName, null).getObject().getData())
+ );
+
+ System.out.println("----- query string auth example -----");
+ generator.setExpiresIn(60 * 1000);
+
+ System.out.println("Try this url in your web browser (it will only work for 60 seconds)\n");
+ System.out.println(generator.get(bucket, keyName, null));
+ System.out.print("\npress enter> ");
+ readline();
+
+ System.out.println("\nNow try just the url without the query string arguments. It should fail.\n");
+ System.out.println(generator.makeBareURL(bucket, keyName));
+ System.out.print("\npress enter> ");
+ readline();
+
+ System.out.println("----- putting object with metadata and public read acl -----");
+
+ Headers metadata = new Headers();
+ metadata.put("blah", "foo");
+ object = new S3Object("this is a publicly readable test".getBytes(), new Headers(metadata));
+
+ headers = new Headers();
+ headers.put("x-amz-acl", "public-read");
+ headers.put("Content-Type", "text/plain");
+
+ System.out.println(
+ conn.put(bucket, keyName + "-public", object, headers).getResponseMessage()
+ );
+
+ System.out.println("----- anonymous read test -----");
+ System.out.println("\nYou should be able to try this in your browser\n");
+ System.out.println(generator.makeBareURL(bucket, keyName + "-public"));
+ System.out.print("\npress enter> ");
+ readline();
+
+ System.out.println("----- path style url example -----");
+ System.out.println("\nNon-location-constrained buckets can also be specified as part of the url path. (This was the original url style supported by S3.)");
+ System.out.println("\nTry this url out in your browser (it will only be valid for 60 seconds)\n");
+ generator.setCallingFormat(CallingFormat.getPathCallingFormat());
+ // could also have been done like this:
+ // generator = new QueryStringAuthGenerator(awsAccessKeyId, awsSecretAccessKey, true, Utils.DEFAULT_HOST, CallingFormat.getPathCallingFormat());
+ generator.setExpiresIn(60 * 1000);
+ System.out.println(generator.get(bucket, keyName, null));
+ System.out.print("\npress enter> ");
+ readline();
+
+ System.out.println("----- getting object's acl -----");
+ System.out.println(new String(conn.getACL(bucket, keyName, null).getObject().getData()));
+
+ System.out.println("----- deleting objects -----");
+ System.out.println(
+ conn.delete(bucket, keyName, null).getResponseMessage()
+ );
+ System.out.println(
+ conn.delete(bucket, keyName + "-public", null).getResponseMessage()
+ );
+
+ System.out.println("----- listing bucket -----");
+ System.out.println(conn.list(bucket, null, null, null, null).getEntries());
+
+ System.out.println("----- listing all my buckets -----");
+ System.out.println(conn.listAllBuckets().getEntries());
+
+ System.out.println("----- deleting bucket -----");
+ System.out.println(
+ conn.delete(bucket).getResponseMessage()
+ );
+ }
+
}
16 years, 3 months
JBoss Cache SVN: r5308 - in core/trunk/src/main/java/org/jboss/cache: interceptors and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-02-05 20:49:23 -0500 (Tue, 05 Feb 2008)
New Revision: 5308
Modified:
core/trunk/src/main/java/org/jboss/cache/NodeSPI.java
core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
Log:
Used indexes rather than Fqn comparison to determine when the lock loop completes.
Modified: core/trunk/src/main/java/org/jboss/cache/NodeSPI.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/NodeSPI.java 2008-02-06 01:48:37 UTC (rev 5307)
+++ core/trunk/src/main/java/org/jboss/cache/NodeSPI.java 2008-02-06 01:49:23 UTC (rev 5308)
@@ -259,6 +259,18 @@
NodeSPI<K, V> addChildDirect(Fqn f, boolean notify);
/**
+ * Same as {@link #addChildDirect(Fqn, boolean)} except that it just takes a child name
+ *
+ * @param childName name of child
+ * @param notify if true, notification events are sent; if false, they are not
+ * @return child node
+ * @throws org.jboss.cache.lock.LockingException
+ * if locking was not obtained
+ * @see #addChild(Fqn)
+ */
+ NodeSPI<K, V> addChildDirect(Object childName, boolean notify);
+
+ /**
* Directly adds the node passed in to the children map of the current node. Will throw a CacheException if
* <tt>child.getFqn().getParent().equals(getFqn())</tt> returns false.
*
Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-02-06 01:48:37 UTC (rev 5307)
+++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-02-06 01:49:23 UTC (rev 5308)
@@ -452,6 +452,12 @@
}
+ public NodeSPI addChildDirect(Object childName, boolean notify)
+ {
+ GlobalTransaction gtx = cache.getInvocationContext().getGlobalTransaction();
+ return getOrCreateChild(childName, gtx, true, notify);
+ }
+
public void clearDataDirect()
{
if (data != null) data.clear();
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-02-06 01:48:37 UTC (rev 5307)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-02-06 01:49:23 UTC (rev 5308)
@@ -14,7 +14,10 @@
import org.jboss.cache.config.Configuration;
import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.Inject;
-import org.jboss.cache.lock.*;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.lock.LockingException;
+import org.jboss.cache.lock.NodeLock;
+import org.jboss.cache.lock.TimeoutException;
import org.jboss.cache.marshall.MethodDeclarations;
import org.jboss.cache.transaction.GlobalTransaction;
import org.jboss.cache.transaction.TransactionEntry;
@@ -80,14 +83,16 @@
try
{
return super.invoke(ctx);
- } catch (LockingException le)
+ }
+ catch (LockingException le)
{
- if (trace) log.trace("Locking exception occured, cleaning up locks." , le);
+ if (trace) log.trace("Locking exception occured, cleaning up locks.", le);
releaseLocks(ctx);
throw le;
- } catch (TimeoutException te)
+ }
+ catch (TimeoutException te)
{
- if (trace) log.trace("Locking exception occured, cleaning up locks." , te);
+ if (trace) log.trace("Locking exception occured, cleaning up locks.", te);
releaseLocks(ctx);
throw te;
}
@@ -103,9 +108,10 @@
if (trace) log.trace("Releasing existing locks. Global tx?" + gtx);
if (gtx != null)
{
- TransactionEntry te = cache.getTransactionTable().get(gtx);
+ TransactionEntry te = cache.getTransactionTable().get(gtx);
te.releaseAllLocksFIFO(gtx);
- } else
+ }
+ else
{
Thread currentThread = Thread.currentThread();
List<NodeLock> locks = getLocks(currentThread);
@@ -113,7 +119,7 @@
{
aLock.release(currentThread);
}
- }
+ }
}
@@ -284,7 +290,8 @@
{
if (trace) log.trace("There were new nodes created, skiping notification on delete");
Object[] args = ctx.getMethodCall().getArgs();
- if (trace) log.trace("Changing 'skipNotification' for method '_remove' from " + args[args.length - 1] + " to true");
+ if (trace)
+ log.trace("Changing 'skipNotification' for method '_remove' from " + args[args.length - 1] + " to true");
args[args.length - 1] = Boolean.TRUE;
}
@@ -403,10 +410,10 @@
* 2) acquireWriteLockOnParent is true. If so AND {@link org.jboss.cache.Node#isLockForChildInsertRemove()} then a read
* lock will be aquired for the parent of the node.
*
- * @param createIfNotExists if true, then missing nodes will be cretaed on the fly. If false, method returns if we
- * reach a node that does not exists
- * @param reverseRemoveCheck see {@link #manageReverseRemove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.NodeSPI, boolean)}
- * @param createdNodes a list to which any nodes created can register their Fqns so that calling code is aware of which nodes have been newly created.
+ * @param createIfNotExists if true, then missing nodes will be cretaed on the fly. If false, method returns if we
+ * reach a node that does not exists
+ * @param reverseRemoveCheck see {@link #manageReverseRemove(org.jboss.cache.transaction.GlobalTransaction, org.jboss.cache.NodeSPI, boolean)}
+ * @param createdNodes a list to which any nodes created can register their Fqns so that calling code is aware of which nodes have been newly created.
* @param skipNotification
*/
private boolean lock(InvocationContext ctx, Fqn fqn, NodeLock.LockType lockType, boolean createIfNotExists, long timeout,
@@ -429,6 +436,8 @@
NodeSPI parent = null;
Object childName = null;
int currentIndex = -1;
+ int targetFqnSize = fqn.size();
+
do
{
if (currentNode == null)
@@ -436,7 +445,7 @@
if (createIfNotExists)
{
// if the new node is to be marked as deleted, do not notify!
- currentNode = parent.addChildDirect(new Fqn(childName), !skipNotification);
+ currentNode = parent.addChildDirect(childName, !skipNotification);
created = true;
if (trace) log.trace("Child node was null, so created child node " + childName);
if (createdNodes != null) createdNodes.add(currentNode);
@@ -452,6 +461,7 @@
{
if (!currentNode.isValid() && createIfNotExists) currentNode.setValid(true, false);
}
+
NodeLock.LockType lockTypeRequired = NodeLock.LockType.READ;
if (created || writeLockNeeded(ctx, lockType, currentIndex, acquireWriteLockOnParent, createIfNotExists, fqn, currentNode))
{
@@ -479,8 +489,10 @@
// crap!
if (trace) log.trace("Parent has been deleted again. Go through the lock method all over again.");
currentNode = rootNode;
+ currentIndex = -1;
parent = null;
- } else
+ }
+ else
{
currentNode = parent;
currentIndex--;
@@ -491,13 +503,19 @@
}
if (trace) log.trace("Moving one level up, current node is :" + currentNode);
}
- } else
+ }
+ else
{
- if (currentNodeFqn.equals(fqn))//we've just processed the last child
+ // we have succeeded in acquiring this lock. Increment the current index since we have gained one level of depth in the tree.
+ currentIndex++;
+
+ // now test if this is the final level and if we can quit the loop:
+ //if (currentNodeFqn.equals(fqn))//we've just processed the last child
+ if (currentIndex == targetFqnSize)
{
break;
}
- if (!fqn.isChildOrEquals(currentNode.getFqn()))
+ if (!fqn.isChildOrEquals(currentNode.getFqn())) // Does this ever happen? Perhaps with a move(), I suppose? - MS
{
String message = new StringBuffer("currentNode instance changed the FQN(").append(currentNode.getFqn())
.append(") and do not match the FQN on which we want to acquire lock(").append(fqn).append(")").toString();
@@ -505,9 +523,9 @@
throw new LockingException(message);
}
parent = currentNode;
- currentIndex = currentNodeFqn.size();
- currentNode = currentNode.getChildDirect(fqn.get(currentIndex));
+
childName = fqn.get(currentIndex);
+ currentNode = currentNode.getChildDirect(childName);
}
} while (true);
return created;
@@ -616,7 +634,7 @@
*/
private void manageReverseRemove(GlobalTransaction gtx, NodeSPI childNode, boolean reverseRemoveCheck)
{
- boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && tx_table.isNodeRemovedInTx(gtx,childNode.getFqn());
+ boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && tx_table.isNodeRemovedInTx(gtx, childNode.getFqn());
if (gtx != null && needToReverseRemove)
{
childNode.markAsDeleted(false);
Modified: core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2008-02-06 01:48:37 UTC (rev 5307)
+++ core/trunk/src/main/java/org/jboss/cache/invocation/NodeInvocationDelegate.java 2008-02-06 01:49:23 UTC (rev 5308)
@@ -162,6 +162,11 @@
return node.addChildDirect(f, notify);
}
+ public NodeSPI<K, V> addChildDirect(Object childName, boolean notify)
+ {
+ return node.addChildDirect(childName, notify);
+ }
+
public void addChildDirect(NodeSPI<K, V> child)
{
node.addChildDirect(child);
16 years, 3 months