[infinispan-commits] Infinispan SVN: r366 - in trunk: core/src/main/java/org/infinispan/commands/remote and 3 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Jun 1 10:17:43 EDT 2009
Author: mircea.markus
Date: 2009-06-01 10:17:43 -0400 (Mon, 01 Jun 2009)
New Revision: 366
Modified:
trunk/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/stringbased/JdbcStringBasedCacheStore.java
trunk/core/src/main/java/org/infinispan/commands/remote/ClusteredGetCommand.java
trunk/core/src/main/java/org/infinispan/distribution/DistributionManagerImpl.java
trunk/core/src/main/java/org/infinispan/loaders/cluster/ClusterCacheLoader.java
trunk/core/src/test/java/org/infinispan/test/AbstractCacheTest.java
Log:
use InternalCacheValue vs InternalCacheEntry to avoid repeated serialization of the key
Modified: trunk/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/stringbased/JdbcStringBasedCacheStore.java
===================================================================
--- trunk/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/stringbased/JdbcStringBasedCacheStore.java 2009-06-01 12:50:30 UTC (rev 365)
+++ trunk/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/stringbased/JdbcStringBasedCacheStore.java 2009-06-01 14:17:43 UTC (rev 366)
@@ -2,6 +2,7 @@
import org.infinispan.Cache;
import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.container.entries.InternalCacheValue;
import org.infinispan.io.ByteBuffer;
import org.infinispan.loaders.CacheLoaderConfig;
import org.infinispan.loaders.CacheLoaderException;
@@ -99,7 +100,7 @@
try {
connection = connectionFactory.getConnection();
ps = connection.prepareStatement(sql);
- ByteBuffer byteBuffer = JdbcUtil.marshall(getMarshaller(), ed);
+ ByteBuffer byteBuffer = JdbcUtil.marshall(getMarshaller(), ed.toInternalCacheValue());
ps.setBinaryStream(1, byteBuffer.getStream(), byteBuffer.getLength());
ps.setLong(2, ed.getExpiryTime());
ps.setString(3, lockingKey);
@@ -147,7 +148,7 @@
InternalCacheEntry se = (InternalCacheEntry) objFromStream;
readStoredEntries++;
String key = key2StringMapper.getStringMapping(se.getKey());
- ByteBuffer buffer = JdbcUtil.marshall(getMarshaller(), se);
+ ByteBuffer buffer = JdbcUtil.marshall(getMarshaller(), se.toInternalCacheValue());
ps.setBinaryStream(1, buffer.getStream(), buffer.getLength());
ps.setLong(2, se.getExpiryTime());
ps.setString(3, key);
@@ -189,8 +190,9 @@
rs.setFetchSize(config.getFetchSize());
while (rs.next()) {
InputStream is = rs.getBinaryStream(1);
- InternalCacheEntry se = (InternalCacheEntry) JdbcUtil.unmarshall(getMarshaller(), is);
- marshaller.objectToObjectStream(se, objectOutput);
+ InternalCacheValue icv = (InternalCacheValue) JdbcUtil.unmarshall(getMarshaller(), is);
+ Object key = rs.getObject(2);
+ marshaller.objectToObjectStream(icv.toInternalCacheEntry(key), objectOutput);
}
marshaller.objectToObjectStream(STRING_STREAM_DELIMITER, objectOutput);
} catch (SQLException e) {
@@ -257,8 +259,9 @@
Set<InternalCacheEntry> result = new HashSet<InternalCacheEntry>();
while (rs.next()) {
InputStream inputStream = rs.getBinaryStream(1);
- InternalCacheEntry se = (InternalCacheEntry) JdbcUtil.unmarshall(getMarshaller(), inputStream);
- result.add(se);
+ InternalCacheValue icv = (InternalCacheValue) JdbcUtil.unmarshall(getMarshaller(), inputStream);
+ Object key = rs.getObject(2);
+ result.add(icv.toInternalCacheEntry(key));
}
return result;
} catch (SQLException e) {
@@ -284,7 +287,8 @@
rs = ps.executeQuery();
if (rs.next()) {
InputStream inputStream = rs.getBinaryStream(2);
- InternalCacheEntry storedEntry = (InternalCacheEntry) JdbcUtil.unmarshall(getMarshaller(), inputStream);
+ InternalCacheValue icv = (InternalCacheValue) JdbcUtil.unmarshall(getMarshaller(), inputStream);
+ InternalCacheEntry storedEntry = icv.toInternalCacheEntry(key);
if (storedEntry.isExpired()) {
if (log.isTraceEnabled()) {
log.trace("Not returning '" + storedEntry + "' as it is expired. It will be removed from DB by purging thread!");
Modified: trunk/core/src/main/java/org/infinispan/commands/remote/ClusteredGetCommand.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/commands/remote/ClusteredGetCommand.java 2009-06-01 12:50:30 UTC (rev 365)
+++ trunk/core/src/main/java/org/infinispan/commands/remote/ClusteredGetCommand.java 2009-06-01 14:17:43 UTC (rev 366)
@@ -23,8 +23,8 @@
import org.infinispan.CacheException;
import org.infinispan.container.DataContainer;
-import org.infinispan.container.entries.CacheEntry;
import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.container.entries.InternalCacheValue;
import org.infinispan.context.InvocationContext;
import org.infinispan.context.InvocationContextContainer;
import org.infinispan.loaders.CacheLoaderManager;
@@ -73,7 +73,7 @@
* @param context invocation context, ignored.
* @return returns an <code>CacheEntry</code> or null, if no entry is found.
*/
- public CacheEntry perform(InvocationContext context) throws Throwable {
+ public InternalCacheValue perform(InvocationContext context) throws Throwable {
if (key != null) {
InternalCacheEntry cacheEntry = dataContainer.get(key);
if (trace) log.trace("Found InternalCacheEntry {0} for key {1}", cacheEntry, key);
@@ -88,7 +88,7 @@
cacheEntry = cacheLoaderManager.getCacheLoader().load(key);
}
}
- return cacheEntry;
+ return cacheEntry != null ? cacheEntry.toInternalCacheValue() : null;
} else {
throw new CacheException("Invalid command. Missing key!");
}
Modified: trunk/core/src/main/java/org/infinispan/distribution/DistributionManagerImpl.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/distribution/DistributionManagerImpl.java 2009-06-01 12:50:30 UTC (rev 365)
+++ trunk/core/src/main/java/org/infinispan/distribution/DistributionManagerImpl.java 2009-06-01 14:17:43 UTC (rev 366)
@@ -5,6 +5,7 @@
import org.infinispan.config.Configuration;
import org.infinispan.container.entries.CacheEntry;
import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.container.entries.InternalCacheValue;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.annotations.Start;
import org.infinispan.factories.annotations.Stop;
@@ -99,7 +100,8 @@
if (!responses.isEmpty()) {
for (Response r : responses) {
if (r instanceof SuccessfulResponse) {
- return (InternalCacheEntry) ((SuccessfulResponse) r).getResponseValue();
+ InternalCacheValue cacheValue = (InternalCacheValue) ((SuccessfulResponse) r).getResponseValue();
+ return cacheValue.toInternalCacheEntry(key);
}
}
}
Modified: trunk/core/src/main/java/org/infinispan/loaders/cluster/ClusterCacheLoader.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/loaders/cluster/ClusterCacheLoader.java 2009-06-01 12:50:30 UTC (rev 365)
+++ trunk/core/src/main/java/org/infinispan/loaders/cluster/ClusterCacheLoader.java 2009-06-01 14:17:43 UTC (rev 366)
@@ -4,6 +4,7 @@
import org.infinispan.Cache;
import org.infinispan.commands.remote.ClusteredGetCommand;
import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.container.entries.InternalCacheValue;
import org.infinispan.context.InvocationContext;
import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.loaders.AbstractCacheLoader;
@@ -53,9 +54,9 @@
throw new CacheLoaderException("Response length is always 0 or 1, received: " + response);
Response firstResponse = response.get(0);
if (firstResponse.isSuccessful() && firstResponse instanceof SuccessfulResponse) {
- return (InternalCacheEntry) ((SuccessfulResponse) firstResponse).getResponseValue();
+ InternalCacheValue value = (InternalCacheValue) ((SuccessfulResponse) firstResponse).getResponseValue();
+ return value.toInternalCacheEntry(key);
}
-
String message = "Unknown response from remote cache: " + response;
log.error(message);
throw new CacheLoaderException(message);
Modified: trunk/core/src/test/java/org/infinispan/test/AbstractCacheTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/test/AbstractCacheTest.java 2009-06-01 12:50:30 UTC (rev 365)
+++ trunk/core/src/test/java/org/infinispan/test/AbstractCacheTest.java 2009-06-01 14:17:43 UTC (rev 366)
@@ -4,7 +4,6 @@
import org.infinispan.Cache;
import org.infinispan.config.Configuration;
import org.infinispan.container.DataContainer;
-import org.infinispan.context.InvocationContext;
import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.loaders.CacheLoaderManager;
import org.infinispan.manager.CacheManager;
@@ -46,7 +45,7 @@
removeInMemoryData(cache);
clearCacheLoader(cache);
clearReplicationQueues(cache);
- InvocationContext invocationContext = ((AdvancedCache) cache).getInvocationContextContainer().createInvocationContext();
+ ((AdvancedCache) cache).getInvocationContextContainer().createInvocationContext();
}
}
}
More information about the infinispan-commits
mailing list