public interface CoderManager
Manages the collections of KeyCoder
s and ValueCoder
s that
encode and decode object values in Persistit™. An application should
register all KeyCoder
and ValueCoder
implementations before storing or accessing objects of the associated classes
in Persistit.
When Persistit is initialized, a instance of DefaultCoderManager
is
installed as the current CoderManager
. Applications can refer to
it through the method Persistit.getCoderManager()
.
Applications should register KeyCoder
and
ValueCoder
instances as follows:
Subsequently, any time the application appends an instance of aValueCoder vc1 = new MyClassValueCoder(); KeyCoder kc1 = new MyClassKeyCoder(); Persistit.getInstance().getCoderManager().registerValueCoder(MyClass.class, kc1); Persistit.getInstance().getCoderManager().registerKeyCoder(MyClass.class, kc1);
MyClass
to a Key
, the MyClassKeyCoder
will be used to convert the interior state of the MyClass
into a
representation within the Key
. Likewise, whenever the
application puts an object of class MyClass
into a
Value
, the registered MyClassValueCoder
will be
used to encode it. Persistit uses the lookupKeyCoder(java.lang.Class<?>)
and
lookupValueCoder(java.lang.Class<?>)
methods to acquire the appropriate coder.
An application may replace the default implementation provided by
DefaultCoderManager
. Such a custom implementation might, for
example, handle the relationship between certain classes and their associated
coders in a special way.
An application can create and install a customized CoderManager
as follows:
Note that theCoderManager myCoderManager = new MyCoderManager(Persistit.getInstance().getCoderManager()); Persistit.getInstance().setCoderManager(myCoderManager);
MyCoderManager
instance receives the
previously installed CoderManager
as an argument of its
constructor. The new CoderManager
should return the previously
installed one as the value of its getParent()
method, and the
lookupKeyCoder(java.lang.Class<?>)
and lookupValueCoder(java.lang.Class<?>)
should delegate any
lookups not handled by the customized CoderManager
back to the
parent.
The encoding of key values determines the ordering of traversal for
Exchange.traverse(com.persistit.Key.Direction, boolean)
and associated methods. See Key
for
definition of the ordering among the types for which built-in encoding
exists. The ordering of key values based on objects that are encoded by
custom KeyCoder
s is determined by the implementation of each
KeyCoder.
This code will insert two records incorporating the valuesExchange exchange = new Exchange(...); Object a = new MyClass1(); // where MyClass1 and MyClass2 Object b = new MyClass2(); // have registered KeyCoders exchange.to(a).store(); // store something with a's value as key exchange.to(b).store(); // store something with b's value as key exchange.to(Key.BEFORE) while (exchange.next()) { System.out.println(exchange.indexTo(-1).getTypeName()); }
a
and b
into Persistit, and will then traverse the
resulting tree and print the names of the classes of the key values. The
question is whether "MyClass2" will be printed before or after "MyClass2".
The answer depends on the order in which MyClass1 and MyClass2 were first
registered within Persistit. At the time a new class is first registered,
Persistit assigns a permanent int
-valued class handle to the
class. Whenever an instance of that class is encoded within either a
Key
or a Value
, that handle value, rather than the
class name, is used. This reduces disk, memory and CPU consumption whenever
Persistit stores or retrieves objects. Handles are assigned in increasing
numeric order as classes are registered. Thus if MyClass1
was
registered before MyClass2
, it will precede
MyClass2
in traversal order. Otherwise it will follow
MyClass2
.
Modifier and Type | Method and Description |
---|---|
CoderManager |
getParent()
Return the parent
CoderManager implementation, or
null if there is none. |
Map<Class<?>,? extends KeyCoder> |
getRegisteredKeyCoders()
Create a
Map of Class es to registered
KeyCoder s. |
Map<Class<?>,? extends ValueCoder> |
getRegisteredValueCoders()
Create a
Map of Class es to registered
ValueCoder s. |
ValueCoder |
getValueCoder(Class<?> clazz)
Return a
ValueCoder for the supplied Class . |
KeyCoder |
lookupKeyCoder(Class<?> clazz)
Returns the
KeyCoder registered for the supplied
Class , or null if no KeyCoder is
registered. |
ValueCoder |
lookupValueCoder(Class<?> clazz)
Returns the
ValueCoder registered for the supplied
Class , or null if no ValueCoder is
registered. |
KeyCoder |
registerKeyCoder(Class<?> clazz,
KeyCoder coder)
Register the provided
KeyCoder to encode and decode
instances of supplied class. |
ValueCoder |
registerValueCoder(Class<?> clazz,
ValueCoder coder)
Register the provided
ValueCoder to encode and decode
instances of supplied class. |
KeyCoder |
unregisterKeyCoder(Class<?> clazz)
Remove the registered
KeyCoder for the supplied class. |
int |
unregisterKeyCoder(KeyCoder coder)
Remove the supplied
KeyCoder from all classes to which it
was previously registered. |
ValueCoder |
unregisterValueCoder(Class<?> clazz)
Remove the registered
ValueCoder for the supplied class. |
int |
unregisterValueCoder(ValueCoder coder)
Remove the supplied
ValueCoder from all classes to which it
was previously registered. |
Map<Class<?>,? extends ValueCoder> getRegisteredValueCoders()
Map
of Class
es to registered
ValueCoder
s. The map is an unmodifiable, is sorted by class
name, and does not change with subsequent registrations or
unregistrations of ValueCoder
s.Map
of Class
es to
ValueCoder
s.Map<Class<?>,? extends KeyCoder> getRegisteredKeyCoders()
Map
of Class
es to registered
KeyCoder
s. The map is an unmodifiable, and is sorted by
class name, and does not change with subsequent registrations or
unregistrations of KeyCoder
s.Map
of Class
es to KeyCoder
s.KeyCoder registerKeyCoder(Class<?> clazz, KeyCoder coder)
KeyCoder
to encode and decode
instances of supplied class.clazz
- The Class for which this KeyCoder
will provide
encoding and decoding servicescoder
- The KeyCoder to registerKeyCoder
formerly registered for this
Class
, or null
if there was none.KeyCoder unregisterKeyCoder(Class<?> clazz)
KeyCoder
for the supplied class.clazz
- The Class
from which to remove a
KeyCoder
, if presentKeyCoder
that was removed, or null
if there was none.int unregisterKeyCoder(KeyCoder coder)
KeyCoder
from all classes to which it
was previously registered.coder
- The KeyCoder
to remove.KeyCoder
was registered
for.KeyCoder lookupKeyCoder(Class<?> clazz)
KeyCoder
registered for the supplied
Class
, or null
if no KeyCoder
is
registered.clazz
- The Class
KeyCoder
or null
if there is none.ValueCoder registerValueCoder(Class<?> clazz, ValueCoder coder)
ValueCoder
to encode and decode
instances of supplied class.clazz
- The Class for which this ValueCoder
will provide
encoding and decoding servicescoder
- The ValueCoder to registerValueCoder
that was removed, or
null
if there was none.ValueCoder unregisterValueCoder(Class<?> clazz)
ValueCoder
for the supplied class.clazz
- The Class
from which to remove a
ValueCoder
, if presentValueCoder
that was removed, or
null
if there was none.int unregisterValueCoder(ValueCoder coder)
ValueCoder
from all classes to which it
was previously registered.coder
- The ValueCoder
to remove.ValueCoder
was registered
for.ValueCoder lookupValueCoder(Class<?> clazz)
ValueCoder
registered for the supplied
Class
, or null
if no ValueCoder
is
registered.clazz
- The Class
ValueCoder
or null
if there is
none.ValueCoder getValueCoder(Class<?> clazz)
ValueCoder
for the supplied Class
. If
there is none registered, implicitly create one and register it.clazz
- CoderManager getParent()
CoderManager
implementation, or
null
if there is none.CoderManager
Copyright © 2025 Open Identity Platform Community. All rights reserved.