[infinispan-commits] Infinispan SVN: r1832 - trunk/core/src/main/java/org/infinispan/affinity.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon May 24 07:43:20 EDT 2010
Author: mircea.markus
Date: 2010-05-24 07:43:20 -0400 (Mon, 24 May 2010)
New Revision: 1832
Added:
trunk/core/src/main/java/org/infinispan/affinity/KeyGenerator.java
trunk/core/src/main/java/org/infinispan/affinity/RndKeyGenerator.java
Removed:
trunk/core/src/main/java/org/infinispan/affinity/KeyProvider.java
trunk/core/src/main/java/org/infinispan/affinity/RndKeyProvider.java
Modified:
trunk/core/src/main/java/org/infinispan/affinity/KeyAffinityService.java
trunk/core/src/main/java/org/infinispan/affinity/KeyAffinityServiceFactory.java
Log:
design for ISPN-232
Modified: trunk/core/src/main/java/org/infinispan/affinity/KeyAffinityService.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/affinity/KeyAffinityService.java 2010-05-24 10:09:24 UTC (rev 1831)
+++ trunk/core/src/main/java/org/infinispan/affinity/KeyAffinityService.java 2010-05-24 11:43:20 UTC (rev 1832)
@@ -5,14 +5,45 @@
import java.util.concurrent.Executor;
/**
+ * Defines a service that generates keys to be mapped to specific nodes in a distributed(vs. replicated) cluster.
+ * The service is instantiated through through one of the factory methods from {@link org.infinispan.affinity.KeyAffinityServiceFactory}.
+ * <p/>
+ * Sample usage:
+ * <p/>
+ * <code>
+ * Cache>String,Long< cache = getDistributedCache();
+ * KeyAffinityService<String> service = KeyAffinityServiceFactory.newKeyAffinityService(cache, 100);
+ * ...
+ * String sessionId = sessionObject.getId();
+ * String newCollocatedSession = service.getCollocatedKey(sessionId);
*
+ * //this will reside on the same node in the cluster
+ * cache.put(newCollocatedSession, someInfo);
+ * </code>
+ * <p/>
+ * Uniqueness: the service does not guarantee that the generated keys are unique. It relies on an
+ * {@link org.infinispan.affinity.KeyGenerator} for obtaining and distributing the generated keys. If key uniqueness is
+ * needed that should be enforced in the generator.
+ * <p/>
+ * The service might also drop key generated through the {@link org.infinispan.affinity.KeyGenerator}.
*
+ * @see org.infinispan.affinity.KeyAffinityServiceFactory
* @author Mircea.Markus at jboss.com
* @since 4.1
*/
public interface KeyAffinityService<K> {
-
- public K getKeyForAddress(Address address);
- public K getCollocatedKey(K otherKey);
+ /**
+ * Returns a key that will be distributed on the cluster node identified by address.
+ * @param address identifying the cluster node.
+ * @return a key object
+ */
+ K getKeyForAddress(Address address);
+
+ /**
+ * Returns a key that will be distributed on the same node as the supplied key.
+ * @param otherKey the key for which we need a collocation
+ * @return a key object
+ */
+ K getCollocatedKey(K otherKey);
}
Modified: trunk/core/src/main/java/org/infinispan/affinity/KeyAffinityServiceFactory.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/affinity/KeyAffinityServiceFactory.java 2010-05-24 10:09:24 UTC (rev 1831)
+++ trunk/core/src/main/java/org/infinispan/affinity/KeyAffinityServiceFactory.java 2010-05-24 11:43:20 UTC (rev 1832)
@@ -8,8 +8,16 @@
import java.util.concurrent.Executors;
/**
- * // TODO: Document this
+ * Factory for {@link org.infinispan.affinity.KeyAffinityService}.
+ * Services build by this factory have the following characteristics:
+ * <ul>
+ * <li>are run asynchronously by a thread that can be plugged through an {@link org.infinispan.executors.ExecutorFactory} </li>
+ * <li>for key generation, the {@link org.infinispan.distribution.ConsistentHash} function of a distributed cache is used. Service does not make sense for replicated caches.</li>
+ * <li>for each address cluster member (identified by an {@link org.infinispan.remoting.transport.Address} member, a fixed number of keys is generated</li>
+ * </ul>
*
+ * @see org.infinispan.affinity.KeyAffinityService
+ *
* @author Mircea.Markus at jboss.com
* @since 4.1
*/
@@ -20,26 +28,26 @@
*
* @param cache the distributed cache for which this service runs
* @param ex used for obtaining a thread that async generates keys.
- * @param keyProvider allows one to control how the generated keys look like.
+ * @param keyGenerator allows one to control how the generated keys look like.
* @param keyBufferSize the number of generated keys per {@link org.infinispan.remoting.transport.Address}.
* @return an {@link org.infinispan.affinity.KeyAffinityService} implementation.
* @throws IllegalStateException if the supplied cache is not DIST.
*/
- public static <K,V> KeyAffinityService<K> newKeyAffinityService(Cache<K,V> cache, ExecutorFactory ex, KeyProvider keyProvider, int keyBufferSize) {
+ public static <K,V> KeyAffinityService<K> newKeyAffinityService(Cache<K,V> cache, ExecutorFactory ex, KeyGenerator keyGenerator, int keyBufferSize) {
return null;
}
/**
* Same as {@link #newKeyAffinityService(org.infinispan.Cache,org.infinispan.executors.ExecutorFactory,
- * KeyProvider,int)} with the an {@link org.infinispan.affinity.RndKeyProvider}.
+ * KeyGenerator ,int)} with the an {@link RndKeyGenerator}.
*/
public static <K,V> KeyAffinityService newKeyAffinityService(Cache<K,V> cache, ExecutorFactory ex, int keyBufferSize) {
- return newKeyAffinityService(cache, ex, new RndKeyProvider(), keyBufferSize);
+ return newKeyAffinityService(cache, ex, new RndKeyGenerator(), keyBufferSize);
}
/**
* Same as {@link #newKeyAffinityService(org.infinispan.Cache,org.infinispan.executors.ExecutorFactory,
- * KeyProvider,int)} with the an {@link org.infinispan.affinity.RndKeyProvider} and an
+ * KeyGenerator ,int)} with the an {@link RndKeyGenerator} and an
* {@link java.util.concurrent.Executors#newSingleThreadExecutor()} executor.
*/
public static <K,V> KeyAffinityService newKeyAffinityService(Cache<K,V> cache, int keyBufferSize) {
@@ -48,6 +56,6 @@
public ExecutorService getExecutor(Properties p) {
return Executors.newSingleThreadExecutor();
}
- }, new RndKeyProvider(), keyBufferSize);
+ }, new RndKeyGenerator(), keyBufferSize);
}
}
Copied: trunk/core/src/main/java/org/infinispan/affinity/KeyGenerator.java (from rev 1831, trunk/core/src/main/java/org/infinispan/affinity/KeyProvider.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/affinity/KeyGenerator.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/affinity/KeyGenerator.java 2010-05-24 11:43:20 UTC (rev 1832)
@@ -0,0 +1,12 @@
+package org.infinispan.affinity;
+
+/**
+ * Used for generating keys; used by {@link org.infinispan.affinity.KeyAffinityService} to generate the affinity keys.
+ * It offers the possibility to generate keys in a particular format.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.1
+ */
+public interface KeyGenerator<K> {
+ public K getKey();
+}
Deleted: trunk/core/src/main/java/org/infinispan/affinity/KeyProvider.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/affinity/KeyProvider.java 2010-05-24 10:09:24 UTC (rev 1831)
+++ trunk/core/src/main/java/org/infinispan/affinity/KeyProvider.java 2010-05-24 11:43:20 UTC (rev 1832)
@@ -1,12 +0,0 @@
-package org.infinispan.affinity;
-
-/**
- * Used for generating keys; used by {@link org.infinispan.affinity.KeyAffinityService} to generate the affinity keys.
- * It offers the possibility to generate keys in a particular format.
- *
- * @author Mircea.Markus at jboss.com
- * @since 4.1
- */
-public interface KeyProvider {
- public Object getKey();
-}
Copied: trunk/core/src/main/java/org/infinispan/affinity/RndKeyGenerator.java (from rev 1831, trunk/core/src/main/java/org/infinispan/affinity/RndKeyProvider.java)
===================================================================
--- trunk/core/src/main/java/org/infinispan/affinity/RndKeyGenerator.java (rev 0)
+++ trunk/core/src/main/java/org/infinispan/affinity/RndKeyGenerator.java 2010-05-24 11:43:20 UTC (rev 1832)
@@ -0,0 +1,20 @@
+package org.infinispan.affinity;
+
+import java.util.Random;
+
+/**
+ * Key provider that relies on {@link java.util.Random}'s distribution to generate keys.
+ * It doesn't offer any guarantee that the keys are unique.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.1
+ */
+public class RndKeyGenerator implements KeyGenerator {
+
+ public static final Random rnd = new Random();
+
+ @Override
+ public Object getKey() {
+ return rnd.nextLong();
+ }
+}
Deleted: trunk/core/src/main/java/org/infinispan/affinity/RndKeyProvider.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/affinity/RndKeyProvider.java 2010-05-24 10:09:24 UTC (rev 1831)
+++ trunk/core/src/main/java/org/infinispan/affinity/RndKeyProvider.java 2010-05-24 11:43:20 UTC (rev 1832)
@@ -1,20 +0,0 @@
-package org.infinispan.affinity;
-
-import java.util.Random;
-
-/**
- * Key provider that relies on {@link java.util.Random}'s distribution to generate keys.
- * It doesn't offer any guarantee that the keys are unique.
- *
- * @author Mircea.Markus at jboss.com
- * @since 4.1
- */
-public class RndKeyProvider implements KeyProvider {
-
- public static final Random rnd = new Random();
-
- @Override
- public Object getKey() {
- return rnd.nextLong();
- }
-}
More information about the infinispan-commits
mailing list