com.esotericsoftware.kryo
Class Context

java.lang.Object
  extended by com.esotericsoftware.kryo.Context

public class Context
extends java.lang.Object

Serves as thread local storage for serializers. A serializer instance can be used by multiple threads simultaneously, so should be thread safe. This class provides scratch buffers and object storage that serializers can use to remain thread safe.

Author:
Nathan Sweet
See Also:
Kryo.getContext()

Constructor Summary
Context()
           
 
Method Summary
 java.lang.Object get(Serializer serializer, java.lang.String key)
          Returns an object for a serializer instance from thread local storage, or null.
 java.lang.Object get(java.lang.String key)
          Returns an object from thread local storage, or null.
 java.nio.ByteBuffer getBuffer(int minimumSize)
          Returns a non-direct buffer of at least the specified size.
 java.util.ArrayList<java.nio.ByteBuffer> getBuffers(int count, int minimumSize)
          Returns a list containing at least the specified number of non-direct buffers, each at least the specified size.
 byte[] getByteArray(int minimumSize)
          Returns a byte array of at least the specified size.
 char[] getCharArray(int minimumSize)
          Returns a char array of at least the specified size.
 int[] getIntArray(int minimumSize)
          Returns an int array of at least the specified size.
 int getRemoteEntityID()
          Returns an identifier for the entity that either sent the serialized data or will be receiving the serialized data.
 java.lang.Object getTemp(Serializer serializer, java.lang.String key)
          Returns a temporary object for a serializer instance from thread local storage, or null.
 java.lang.Object getTemp(java.lang.String key)
          Returns a temporary object from thread local storage, or null.
 void put(Serializer serializer, java.lang.String key, java.lang.Object value)
          Stores an object for a serializer instance in thread local storage.
 void put(java.lang.String key, java.lang.Object value)
          Stores an object in thread local storage.
 void putTemp(Serializer serializer, java.lang.String key, java.lang.Object value)
          Stores a temporary object for a serializer instance in thread local storage.
 void putTemp(java.lang.String key, java.lang.Object value)
          Stores a temporary object in thread local storage.
 void reset()
          Clears temporary values that are only needed for serialization or deserialization per object graph.
 void setRemoteEntityID(int remoteEntityID)
          Sets the remote entity ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Context

public Context()
Method Detail

getBuffer

public java.nio.ByteBuffer getBuffer(int minimumSize)
Returns a non-direct buffer of at least the specified size.


getBuffers

public java.util.ArrayList<java.nio.ByteBuffer> getBuffers(int count,
                                                           int minimumSize)
Returns a list containing at least the specified number of non-direct buffers, each at least the specified size.


getCharArray

public char[] getCharArray(int minimumSize)
Returns a char array of at least the specified size.


getIntArray

public int[] getIntArray(int minimumSize)
Returns an int array of at least the specified size.


getByteArray

public byte[] getByteArray(int minimumSize)
Returns a byte array of at least the specified size.


put

public void put(java.lang.String key,
                java.lang.Object value)
Stores an object in thread local storage. This allows serializers to easily make repeated use of objects that are not thread safe.


get

public java.lang.Object get(java.lang.String key)
Returns an object from thread local storage, or null.

See Also:
put(Serializer, String, Object)

put

public void put(Serializer serializer,
                java.lang.String key,
                java.lang.Object value)
Stores an object for a serializer instance in thread local storage. This allows serializers to easily make repeated use of objects that are not thread safe.


get

public java.lang.Object get(Serializer serializer,
                            java.lang.String key)
Returns an object for a serializer instance from thread local storage, or null.

See Also:
put(Serializer, String, Object)

putTemp

public void putTemp(java.lang.String key,
                    java.lang.Object value)
Stores a temporary object in thread local storage. This allows serializers to easily make repeated use of objects that are not thread safe. The object will be removed after when the entire object graph has been serialized or deserialized.


getTemp

public java.lang.Object getTemp(java.lang.String key)
Returns a temporary object from thread local storage, or null.

See Also:
put(Serializer, String, Object)

putTemp

public void putTemp(Serializer serializer,
                    java.lang.String key,
                    java.lang.Object value)
Stores a temporary object for a serializer instance in thread local storage. This allows serializers to easily make repeated use of objects that are not thread safe. The object will be removed after when the entire object graph has been serialized or deserialized.


getTemp

public java.lang.Object getTemp(Serializer serializer,
                                java.lang.String key)
Returns a temporary object for a serializer instance from thread local storage, or null.

See Also:
put(Serializer, String, Object)

reset

public void reset()
Clears temporary values that are only needed for serialization or deserialization per object graph. When using the Kryo read and write methods, the context is automatically reset after an entire object graph is serialized or deserialized.


getRemoteEntityID

public int getRemoteEntityID()
Returns an identifier for the entity that either sent the serialized data or will be receiving the serialized data. Serailizers can use this knowledge during serialization. For example, see DeltaCompressor.

See Also:
Kryo.addListener(Kryo.Listener)

setRemoteEntityID

public void setRemoteEntityID(int remoteEntityID)
Sets the remote entity ID. Should be set before serialization or deserialization if a serializer is used that makes use of the remote entity ID.

See Also:
getRemoteEntityID()


Copyright © 2011. All Rights Reserved.