Package com.hazelcast.partition
Class PartitionAwareKey<K,P> 
java.lang.Object
com.hazelcast.partition.PartitionAwareKey<K,P> 
- Type Parameters:
- K- the key type
- P- the partitionKey type
- All Implemented Interfaces:
- DataSerializable,- PartitionAware<Object>
public final class PartitionAwareKey<K,P> 
extends Object
implements PartitionAware<Object>, DataSerializable
A 
PartitionAware key. This is useful in combination with a Map where you want to control the
 partition of a key.- 
Constructor SummaryConstructors
- 
Method Summary
- 
Constructor Details- 
PartitionAwareKeyCreates a new PartitionAwareKey.- Parameters:
- key- the key
- partitionKey- the partitionKey
- Throws:
- IllegalArgumentException- if key or partitionKey is null.
 
 
- 
- 
Method Details- 
getKeyGets the key (not the partitionKey).- Returns:
- the key (not the partitionKey)
 
- 
getPartitionKeyDescription copied from interface:PartitionAwareThe key that will be used by Hazelcast to specify the partition. You should give the same key for objects that you want to be in the same partition.The contract of PartitionAware.getPartitionKey()method is as follows:Let us define toData(o)as serialized form of given object obtained by using Hazelcast Serialization configured for the cluster (the exact method used isSerializationService.toDatafrom an internal SPI).Assume PartitionAware a, bare objects (e.g. IMap keys) andT pk1 = a.getPartitionKey(), pk2 = b.getPartitionKey()are partition key values.Then PartitionAware.getPartitionKey()implementation must obey the following contract:- (mandatory) Deterministic partitioning: if a.equals(b)then eithertoData(a.getPartitionKey()).equals(toData(b.getPartitionKey()))ora.getPartitionKey() == null && b.getPartitionKey() == null
- (recommended) Reasonable partitioning: if a.equals(b)thena.getPartitionKey().equals(b.getPartitionKey())
- (recommended) Reasonable partitioning key serialization (if custom
         serialization is used): if pk1.equals(pk2)thentoData(pk1).equals(toData(pk2))
- The above stated conditions must hold when the PartitionAware.getPartitionKey()is invoked any number of times on any member or client, regardless of time (note that some partitioned data structures support persistence) and if the JVM is restarted, regardless of client/member version and JVM version (across all JVMs ever used in given deployment), timezone, locale and similar differences in the environment.
 Notes: - PartitionAware.getPartitionKey()contract is similar to- hashCode()but with stricter long-term requirements.
- Partition key is not compared directly, only serialized form is compared or used to calculate partition id.
- For unequal objects PartitionAware.getPartitionKey()may return the same or different values according to specific partitioning use case needs.
 - Specified by:
- getPartitionKeyin interface- PartitionAware<K>
- Returns:
- the key that specifies the partition. Returning nullorthiswill cause the result as if the object did not implementPartitionAware. If the returned key itself implementsPartitionAware, this fact will be ignored and the key will be treated as a plain object.
 
- (mandatory) Deterministic partitioning: if 
- 
writeDataDescription copied from interface:DataSerializableWrites object fields to output stream- Specified by:
- writeDatain interface- DataSerializable
- Parameters:
- out- output
- Throws:
- IOException- if an I/O error occurs. In particular, an- IOExceptionmay be thrown if the output stream has been closed.
 
- 
readDataDescription copied from interface:DataSerializableReads fields from the input stream- Specified by:
- readDatain interface- DataSerializable
- Parameters:
- in- input
- Throws:
- IOException- if an I/O error occurs. In particular, an- IOExceptionmay be thrown if the input stream has been closed.
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
 
-