public class AffinityKey<K> extends Object implements Externalizable
affinityKey(Object)
method will be used for key-to-node
affinity.
Note that the equals(Object)
and hashCode()
methods
delegate directly to the wrapped cache key provided by key()
method.
This class is optional and does not have to be used. It only provides
extra convenience whenever custom affinity mapping is required. Here is
an example of how Person
objects can be collocated with
Company
objects they belong to:
Object personKey = new AffinityKey(myPersonId, myCompanyId); // Both, the company and the person objects will be cached on the same node. cache.put(myCompanyId, new Company(..)); cache.put(personKey, new Person(..));
For more information and examples of cache affinity refer to
AffinityKeyMapper
and @AffinityKeyMapped
documentation.
Constructor and Description |
---|
AffinityKey()
Empty constructor.
|
AffinityKey(K key)
Initializes key wrapper for a given key.
|
AffinityKey(K key,
Object affKey)
Initializes key together with its affinity key counter-part.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
affinityKey()
Gets affinity key to use for affinity mapping.
|
void |
affinityKey(Object affKey)
Sets affinity key to use for affinity mapping.
|
boolean |
equals(Object obj)
Equality check which delegates to the underlying key equality.
|
int |
hashCode()
Hash code implementation which delegates to the underlying
key() . |
K |
key()
Gets wrapped key.
|
void |
key(K key)
Sets wrapped key.
|
void |
readExternal(ObjectInput in) |
String |
toString() |
void |
writeExternal(ObjectOutput out) |
public AffinityKey()
public AffinityKey(K key)
key
- Key.public K key()
public void key(K key)
key
- Wrapped key.public <T> T affinityKey()
key
value will be returned.
This method is annotated with AffinityKeyMapped
and will be picked up
by GridCacheDefaultAffinityKeyMapper
automatically.
public void affinityKey(Object affKey)
key
value will be returned.affKey
- Affinity key to use for affinity mapping.public void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public int hashCode()
key()
. Note, however,
that different subclasses of AffinityKey
will produce different hash codes.
Users should override this method if different behavior is desired.
public boolean equals(Object obj)
AffinityKey
will never be equal.
Users should override this method if different behavior is desired.
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.7.2 Release Date : February 6 2019