BinaryHandler not working? #203
-
Hello, return EmbeddedStorageFoundation.New()
.setConfiguration(StorageConfiguration.Builder()
.setStorageFileProvider(storageLiveFileProvider)
.setChannelCountProvider(StorageChannelCountProvider.New(channelCount))
.setBackupSetup(storageBackupSetup)
.createConfiguration())
.onConnectionFoundation(BinaryHandlersJDK8::registerJDK8TypeHandlers)
.onConnectionFoundation(BinaryHandlersJDK17::registerJDK17TypeHandlers)
.onConnectionFoundation(f -> f.registerCustomTypeHandler(new TsidHandler())) // THIS ONE!
.createEmbeddedStorageManager(); TSID (time sorted ids) is an economical and convenient 64-bit replacement for Java 128-bit UUIDs , which I would like ES to store as/convert to long values. However, when I put break points in the handler code below, none of the handler's methods get triggered (except the constructor). Why is ES ignoring my binary TsidHandler - what am I doing wrong? public class TsidHandler extends AbstractBinaryHandlerCustomValueFixedLength<Tsid, Long> {
public TsidHandler() {
super(Tsid.class, defineValueType(long.class));
}
private static long instanceState(final Tsid instance)
{
return instance.toLong();
}
private static long binaryState(final Binary data)
{
return data.read_long(0);
}
@Override
public void store(Binary data, Tsid instance, long objectId, PersistenceStoreHandler<Binary> handler) {
data.storeLong(this.typeId(), objectId, instance.toLong());
}
@Override
public Tsid create(final Binary data, final PersistenceLoadHandler handler) {
return Tsid.from(data.read_long(0));
}
/** actually never called, just to satisfy the interface */
@Override
public Long getValidationStateFromInstance(final Tsid instance) {
return instance.toLong();
}
/** actually never called, just to satisfy the interface */
@Override
public Long getValidationStateFromBinary(final Binary data) {
return binaryState(data);
}
@Override
public void validateState(Binary data, Tsid instance, PersistenceLoadHandler handler) {
long instanceState = instanceState(instance);
long binaryState = binaryState(data);
if(instanceState == binaryState) return;
throwInconsistentStateException(instance, instanceState, binaryState);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Put |
Beta Was this translation helpful? Give feedback.
-
Thanks @dtmarius ! Yes, it worked! If this is explicitly mentioned in the ES docs, then it is my fault, but otherwise - this is serious omission in the docs that need to be corrected, as the failure is silent and the developer might never detect it... |
Beta Was this translation helpful? Give feedback.
-
Hello, |
Beta Was this translation helpful? Give feedback.
-
@hrstoyanov Methods that I have found to register a CustomTypeHandler manually:
Conclusion |
Beta Was this translation helpful? Give feedback.
As a user I did not expect it to be order dependent, but maybe it is a feature to avoid conflict with default native custom type handlers, see my findings below, please.