From b75829884ffc3dd1aa098bc8f5ebca603fd01499 Mon Sep 17 00:00:00 2001 From: Luis Tobon Date: Thu, 18 Aug 2022 14:08:46 -0400 Subject: [PATCH] 1060 Update kryo library to 5.3.0 The project spring-statemachine-kryo is not compatible with JAVA 11. By updating the library the 5.3.0 version the project can be used in Java 11. All the changes in the clases were only to adapt to the api changes in the 5.3.0 librar --- build.gradle | 6 +- .../RedisStateMachineContextRepository.java | 13 +- ...tKryoStateMachineSerialisationService.java | 230 ++++++++---------- .../KryoStateMachineSerialisationService.java | 40 +-- .../kryo/MessageHeadersSerializer.java | 43 ++-- .../kryo/StateMachineContextSerializer.java | 85 ++++--- .../statemachine/kryo/UUIDSerializer.java | 48 ++-- .../StateMachineContextSerializerTests.java | 15 +- .../ZookeeperStateMachinePersist.java | 12 +- 9 files changed, 238 insertions(+), 254 deletions(-) diff --git a/build.gradle b/build.gradle index f1100ccea..135668b4e 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ buildscript { log4jVersion = '1.2.17' springBootVersion = '2.7.0' eclipsePersistenceVersion = '2.1.1' - kryoVersion = '4.0.2' + kryoVersion = '5.3.0' springCloudClusterVersion = '1.0.2.RELEASE' springShellVersion = '1.1.0.RELEASE' eclipseEmfXmiVersion = '2.11.1-v20150805-0538' @@ -95,7 +95,7 @@ configure(allprojects) { dependencies { dependency "log4j:log4j:$log4jVersion" dependency "org.eclipse.persistence:javax.persistence:$eclipsePersistenceVersion" - dependency "com.esotericsoftware:kryo-shaded:$kryoVersion" + dependency "com.esotericsoftware.kryo:kryo5:$kryoVersion" dependency "org.springframework.shell:spring-shell:$springShellVersion" dependency "org.eclipse.uml2:uml:$eclipseUml2UmlVersion" dependency "org.eclipse.uml2:types:$eclipseUml2TypesVersion" @@ -297,7 +297,7 @@ project('spring-statemachine-kryo') { dependencies { compile project(':spring-statemachine-core') - compile 'com.esotericsoftware:kryo-shaded' + compile 'com.esotericsoftware.kryo:kryo5' testCompile (project(':spring-statemachine-test')) { dep -> exclude group: 'junit', module: 'junit' diff --git a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisStateMachineContextRepository.java b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisStateMachineContextRepository.java index 95e8aeaac..d801aa98e 100644 --- a/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisStateMachineContextRepository.java +++ b/spring-statemachine-data/redis/src/main/java/org/springframework/statemachine/data/redis/RedisStateMachineContextRepository.java @@ -18,7 +18,9 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.UUID; - +import org.springframework.statemachine.kryo.StateMachineContextSerializer; +import org.springframework.statemachine.kryo.MessageHeadersSerializer; +import org.springframework.statemachine.kryo.UUIDSerializer; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.RedisTemplate; @@ -26,13 +28,10 @@ import org.springframework.messaging.MessageHeaders; import org.springframework.statemachine.StateMachineContext; import org.springframework.statemachine.StateMachineContextRepository; -import org.springframework.statemachine.kryo.MessageHeadersSerializer; -import org.springframework.statemachine.kryo.StateMachineContextSerializer; -import org.springframework.statemachine.kryo.UUIDSerializer; -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; +import com.esotericsoftware.kryo.kryo5.Kryo; +import com.esotericsoftware.kryo.kryo5.io.Input; +import com.esotericsoftware.kryo.kryo5.io.Output; /** * A {@link StateMachineContextRepository} backed by a redis and kryo serialization. diff --git a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/AbstractKryoStateMachineSerialisationService.java b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/AbstractKryoStateMachineSerialisationService.java index 4255b8600..29db29eed 100644 --- a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/AbstractKryoStateMachineSerialisationService.java +++ b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/AbstractKryoStateMachineSerialisationService.java @@ -1,3 +1,4 @@ +package org.springframework.statemachine.kryo; /* * Copyright 2017-2018 the original author or authors. * @@ -13,24 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.statemachine.kryo; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import com.esotericsoftware.kryo.kryo5.Kryo; +import com.esotericsoftware.kryo.kryo5.io.Input; +import com.esotericsoftware.kryo.kryo5.io.Output; +import com.esotericsoftware.kryo.kryo5.util.Pool; import org.springframework.statemachine.StateMachineContext; import org.springframework.statemachine.service.StateMachineSerialisationService; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; -import com.esotericsoftware.kryo.pool.KryoCallback; -import com.esotericsoftware.kryo.pool.KryoFactory; -import com.esotericsoftware.kryo.pool.KryoPool; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; /** * Abstract base implementation for {@link StateMachineSerialisationService} using kryo. @@ -42,115 +39,102 @@ */ public abstract class AbstractKryoStateMachineSerialisationService implements StateMachineSerialisationService { - protected final KryoPool pool; - - protected AbstractKryoStateMachineSerialisationService() { - KryoFactory factory = new KryoFactory() { - - @Override - public Kryo create() { - Kryo kryo = new Kryo(); - // kryo is really getting trouble checking things if class loaders - // doesn't match. for now just use below trick before we try - // to go fully on beans and get a bean class loader. - kryo.setClassLoader(ClassUtils.getDefaultClassLoader()); - configureKryoInstance(kryo); - return kryo; - } - }; - this.pool = new KryoPool.Builder(factory).softReferences().build(); - } - - @Override - public byte[] serialiseStateMachineContext(StateMachineContext context) throws Exception { - return encode(context); - } - - @SuppressWarnings("unchecked") - @Override - public StateMachineContext deserialiseStateMachineContext(byte[] data) throws Exception { - return decode(data, StateMachineContext.class); - } - - /** - * Subclasses implement this method to encode with Kryo. - * - * @param kryo the Kryo instance - * @param object the object to encode - * @param output the Kryo Output instance - */ - protected abstract void doEncode(Kryo kryo, Object object, Output output); - - /** - * Subclasses implement this method to decode with Kryo. - * - * @param kryo the Kryo instance - * @param input the Kryo Input instance - * @param type the class of the decoded object - * @param the type for decoded object - * @return the decoded object - */ - protected abstract T doDecode(Kryo kryo, Input input, Class type); - - /** - * Subclasses implement this to configure the kryo instance. - * This is invoked on each new Kryo instance when it is created. - * - * @param kryo the kryo instance - */ - protected abstract void configureKryoInstance(Kryo kryo); - - private byte[] encode(Object object) throws IOException { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - encode(object, bos); - byte[] bytes = bos.toByteArray(); - bos.close(); - return bytes; - } - - private void encode(final Object object, OutputStream outputStream) throws IOException { - Assert.notNull(object, "cannot encode a null object"); - Assert.notNull(outputStream, "'outputSteam' cannot be null"); - final Output output = (outputStream instanceof Output ? (Output) outputStream : new Output(outputStream)); - this.pool.run(new KryoCallback() { - - @Override - public Void execute(Kryo kryo) { - doEncode(kryo, object, output); - return null; - } - }); - output.close(); - } - - private T decode(byte[] bytes, Class type) throws IOException { - Assert.notNull(bytes, "'bytes' cannot be null"); - final Input input = new Input(bytes); - try { - return decode(input, type); - } - finally { - input.close(); - } - } - - private T decode(InputStream inputStream, final Class type) throws IOException { - Assert.notNull(inputStream, "'inputStream' cannot be null"); - Assert.notNull(type, "'type' cannot be null"); - final Input input = (inputStream instanceof Input ? (Input) inputStream : new Input(inputStream)); - T result = null; - try { - result = this.pool.run(new KryoCallback(){ - - @Override - public T execute(Kryo kryo) { - return doDecode(kryo, input, type); - } - }); - } - finally { - input.close(); - } - return result; - } + protected final Pool pool; + + protected AbstractKryoStateMachineSerialisationService() { + this.pool= new Pool(true,false,10) { + @Override + protected Kryo create() { + Kryo kryo=new Kryo(); + kryo.setClassLoader(ClassUtils.getDefaultClassLoader()); + configureKryoInstance(kryo); + return kryo; + } + }; + } + + @Override + public byte[] serialiseStateMachineContext(StateMachineContext context) throws Exception { + return encode(context); + } + + @SuppressWarnings("unchecked") + @Override + public StateMachineContext deserialiseStateMachineContext(byte[] data) throws Exception { + return decode(data, StateMachineContext.class); + } + + /** + * Subclasses implement this method to encode with Kryo. + * + * @param kryo the Kryo instance + * @param object the object to encode + * @param output the Kryo Output instance + */ + protected abstract void doEncode(Kryo kryo, Object object, Output output); + + /** + * Subclasses implement this method to decode with Kryo. + * + * @param kryo the Kryo instance + * @param input the Kryo Input instance + * @param type the class of the decoded object + * @param the type for decoded object + * @return the decoded object + */ + protected abstract T doDecode(Kryo kryo, Input input, Class type); + + /** + * Subclasses implement this to configure the kryo instance. + * This is invoked on each new Kryo instance when it is created. + * + * @param kryo the kryo instance + */ + protected abstract void configureKryoInstance(Kryo kryo); + + private byte[] encode(Object object) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + encode(object, bos); + byte[] bytes = bos.toByteArray(); + bos.close(); + return bytes; + } + + private void encode(final Object object, OutputStream outputStream) throws IOException { + Assert.notNull(object, "cannot encode a null object"); + Assert.notNull(outputStream, "'outputSteam' cannot be null"); + final Output output = (outputStream instanceof Output ? (Output) outputStream : new Output(outputStream)); + Kryo kryo=this.pool.obtain(); + try{ + doEncode(kryo,object,output); + }finally { + pool.free(kryo); + output.close(); + } + } + + private T decode(byte[] bytes, Class type) throws IOException { + Assert.notNull(bytes, "'bytes' cannot be null"); + final Input input = new Input(bytes); + try { + return decode(input, type); + } + finally { + input.close(); + } + } + + private T decode(InputStream inputStream, final Class type) throws IOException { + Assert.notNull(inputStream, "'inputStream' cannot be null"); + Assert.notNull(type, "'type' cannot be null"); + final Input input = (inputStream instanceof Input ? (Input) inputStream : new Input(inputStream)); + T result = null; + Kryo kryo=this.pool.obtain(); + try{ + return doDecode(kryo,input,type); + }finally { + pool.free(kryo); + input.close(); + } + } } diff --git a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/KryoStateMachineSerialisationService.java b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/KryoStateMachineSerialisationService.java index 45d71fb15..bf28a2ea5 100644 --- a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/KryoStateMachineSerialisationService.java +++ b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/KryoStateMachineSerialisationService.java @@ -1,3 +1,4 @@ +package org.springframework.statemachine.kryo; /* * Copyright 2017 the original author or authors. * @@ -13,17 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.statemachine.kryo; - -import java.util.UUID; +import com.esotericsoftware.kryo.kryo5.Kryo; +import com.esotericsoftware.kryo.kryo5.io.Input; +import com.esotericsoftware.kryo.kryo5.io.Output; import org.springframework.messaging.MessageHeaders; import org.springframework.statemachine.StateMachineContext; import org.springframework.statemachine.service.StateMachineSerialisationService; -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; +import java.util.UUID; /** * Implementation for {@link StateMachineSerialisationService} using kryo. @@ -35,20 +34,21 @@ */ public class KryoStateMachineSerialisationService extends AbstractKryoStateMachineSerialisationService { - @Override - protected void doEncode(Kryo kryo, Object object, Output output) { - kryo.writeObject(output, object); - } + @Override + protected void doEncode(Kryo kryo, Object object, Output output) { + kryo.writeObject(output, object); + } - @Override - protected T doDecode(Kryo kryo, Input input, Class type) { - return kryo.readObject(input, type); - } + @Override + protected T doDecode(Kryo kryo, Input input, Class type) { + return kryo.readObject(input, type); + } - @Override - protected void configureKryoInstance(Kryo kryo) { - kryo.addDefaultSerializer(StateMachineContext.class, new StateMachineContextSerializer()); - kryo.addDefaultSerializer(MessageHeaders.class, new MessageHeadersSerializer()); - kryo.addDefaultSerializer(UUID.class, new UUIDSerializer()); - } + @Override + protected void configureKryoInstance(Kryo kryo) { + kryo.setRegistrationRequired(false); + kryo.addDefaultSerializer(StateMachineContext.class, new StateMachineContextSerializer()); + kryo.addDefaultSerializer(MessageHeaders.class, new MessageHeadersSerializer()); + kryo.addDefaultSerializer(UUID.class, new UUIDSerializer()); + } } diff --git a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/MessageHeadersSerializer.java b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/MessageHeadersSerializer.java index 6de7e20b2..6a635ad7b 100644 --- a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/MessageHeadersSerializer.java +++ b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/MessageHeadersSerializer.java @@ -1,3 +1,4 @@ +package org.springframework.statemachine.kryo; /* * Copyright 2015 the original author or authors. * @@ -13,19 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.statemachine.kryo; + +import com.esotericsoftware.kryo.kryo5.Kryo; +import com.esotericsoftware.kryo.kryo5.Serializer; +import com.esotericsoftware.kryo.kryo5.io.Input; +import com.esotericsoftware.kryo.kryo5.io.Output; +import org.springframework.messaging.MessageHeaders; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import org.springframework.messaging.MessageHeaders; - -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.Serializer; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; - /** * Kryo {@link Serializer} for spring messaging message headers. * @@ -34,20 +33,20 @@ */ public class MessageHeadersSerializer extends Serializer { - @Override - public void write(Kryo kryo, Output output, MessageHeaders object) { - HashMap map = new HashMap(); - for (Entry entry : object.entrySet()) { - map.put(entry.getKey(), entry.getValue()); - } - kryo.writeClassAndObject(output, map); - } + @Override + public void write(Kryo kryo, Output output, MessageHeaders object) { + HashMap map = new HashMap(); + for (Entry entry : object.entrySet()) { + map.put(entry.getKey(), entry.getValue()); + } + kryo.writeClassAndObject(output, map); + } - @SuppressWarnings("unchecked") - @Override - public MessageHeaders read(Kryo kryo, Input input, Class type) { - Map eventHeaders = (Map) kryo.readClassAndObject(input); - return new MessageHeaders(eventHeaders); - } + @SuppressWarnings("unchecked") + @Override + public MessageHeaders read(Kryo kryo, Input input, Class aClass) { + Map eventHeaders = (Map) kryo.readClassAndObject(input); + return new MessageHeaders(eventHeaders); + } } diff --git a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/StateMachineContextSerializer.java b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/StateMachineContextSerializer.java index b72b08217..37b8f3ee4 100644 --- a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/StateMachineContextSerializer.java +++ b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/StateMachineContextSerializer.java @@ -1,3 +1,4 @@ +package org.springframework.statemachine.kryo; /* * Copyright 2015-2019 the original author or authors. * @@ -13,20 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.statemachine.kryo; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import com.esotericsoftware.kryo.kryo5.Kryo; +import com.esotericsoftware.kryo.kryo5.Serializer; +import com.esotericsoftware.kryo.kryo5.io.Input; +import com.esotericsoftware.kryo.kryo5.io.Output; import org.springframework.statemachine.StateMachineContext; import org.springframework.statemachine.support.DefaultExtendedState; import org.springframework.statemachine.support.DefaultStateMachineContext; -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.Serializer; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * Kryo {@link Serializer} for {@link StateMachineContext}. @@ -38,41 +37,41 @@ */ public class StateMachineContextSerializer extends Serializer> { - // NOTE: when structure of this serialisation is changed, see how things are tested - // in StateMachineContextSerializerTests. + // NOTE: when structure of this serialisation is changed, see how things are tested + // in StateMachineContextSerializerTests. - @Override - public void write(Kryo kryo, Output output, StateMachineContext context) { - kryo.writeClassAndObject(output, context.getEvent()); - kryo.writeClassAndObject(output, context.getState()); - kryo.writeClassAndObject(output, context.getEventHeaders()); - kryo.writeClassAndObject(output, context.getExtendedState() != null ? context.getExtendedState().getVariables() : null); - kryo.writeClassAndObject(output, context.getChilds()); - kryo.writeClassAndObject(output, context.getHistoryStates()); - kryo.writeClassAndObject(output, context.getId()); - // child refs were added after initial implementation, leaving this here - // in case it's starting to cause issues with any existing serialised contexts - // which doesn't have this field - // NOTE: PR #722 added fixes with new tests - kryo.writeClassAndObject(output, context.getChildReferences()); - } + @Override + public void write(Kryo kryo, Output output, StateMachineContext context) { + kryo.writeClassAndObject(output, context.getEvent()); + kryo.writeClassAndObject(output, context.getState()); + kryo.writeClassAndObject(output, context.getEventHeaders()); + kryo.writeClassAndObject(output, context.getExtendedState() != null ? context.getExtendedState().getVariables() : null); + kryo.writeClassAndObject(output, context.getChilds()); + kryo.writeClassAndObject(output, context.getHistoryStates()); + kryo.writeClassAndObject(output, context.getId()); + // child refs were added after initial implementation, leaving this here + // in case it's starting to cause issues with any existing serialised contexts + // which doesn't have this field + // NOTE: PR #722 added fixes with new tests + kryo.writeClassAndObject(output, context.getChildReferences()); + } - @SuppressWarnings("unchecked") - @Override - public StateMachineContext read(Kryo kryo, Input input, Class> clazz) { - E event = (E) kryo.readClassAndObject(input); - S state = (S) kryo.readClassAndObject(input); - Map eventHeaders = (Map) kryo.readClassAndObject(input); - Map variables = (Map) kryo.readClassAndObject(input); - List> childs = (List>) kryo.readClassAndObject(input); - Map historyStates = (Map) kryo.readClassAndObject(input); - String id = (String) kryo.readClassAndObject(input); - List childRefs = new ArrayList<>(); - if(input.canReadInt()) { - childRefs = (List) kryo.readClassAndObject(input); - } + @SuppressWarnings("unchecked") + @Override + public StateMachineContext read(Kryo kryo, Input input, Class> clazz) { + E event = (E) kryo.readClassAndObject(input); + S state = (S) kryo.readClassAndObject(input); + Map eventHeaders = (Map) kryo.readClassAndObject(input); + Map variables = (Map) kryo.readClassAndObject(input); + List> childs = (List>) kryo.readClassAndObject(input); + Map historyStates = (Map) kryo.readClassAndObject(input); + String id = (String) kryo.readClassAndObject(input); + List childRefs = new ArrayList<>(); + if(input.canReadInt()) { + childRefs = (List) kryo.readClassAndObject(input); + } - return new DefaultStateMachineContext(childRefs, childs, state, event, eventHeaders, - new DefaultExtendedState(variables), historyStates, id); - } + return new DefaultStateMachineContext(childRefs, childs, state, event, eventHeaders, + new DefaultExtendedState(variables), historyStates, id); + } } diff --git a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/UUIDSerializer.java b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/UUIDSerializer.java index a2622f9e3..1ac37e57b 100644 --- a/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/UUIDSerializer.java +++ b/spring-statemachine-kryo/src/main/java/org/springframework/statemachine/kryo/UUIDSerializer.java @@ -1,3 +1,4 @@ +package org.springframework.statemachine.kryo; /* * Copyright 2015 the original author or authors. * @@ -13,14 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.statemachine.kryo; -import java.util.UUID; +import com.esotericsoftware.kryo.kryo5.Kryo; +import com.esotericsoftware.kryo.kryo5.Serializer; +import com.esotericsoftware.kryo.kryo5.io.Input; +import com.esotericsoftware.kryo.kryo5.io.Output; -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.Serializer; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; +import java.util.UUID; /** * Kryo {@link Serializer} for {@link UUID}. @@ -30,21 +30,23 @@ */ public class UUIDSerializer extends Serializer { - /** - * Instantiates a new UUID serializer. - */ - public UUIDSerializer() { - setImmutable(true); - } - - @Override - public void write(final Kryo kryo, final Output output, final UUID uuid) { - output.writeLong(uuid.getMostSignificantBits()); - output.writeLong(uuid.getLeastSignificantBits()); - } - - @Override - public UUID read(final Kryo kryo, final Input input, final Class uuidClass) { - return new UUID(input.readLong(), input.readLong()); - } + /** + * Instantiates a new UUID serializer. + */ + public UUIDSerializer() { + setImmutable(true); + } + + @Override + public void write(final Kryo kryo, final Output output, final UUID uuid) { + output.writeLong(uuid.getMostSignificantBits()); + output.writeLong(uuid.getLeastSignificantBits()); + } + + @Override + public UUID read(final Kryo kryo,final Input input,final Class aClass) { + return new UUID(input.readLong(), input.readLong()); + } + } + diff --git a/spring-statemachine-kryo/src/test/java/org/springframework/statemachine/kryo/StateMachineContextSerializerTests.java b/spring-statemachine-kryo/src/test/java/org/springframework/statemachine/kryo/StateMachineContextSerializerTests.java index e30ac7b4f..40b151f88 100644 --- a/spring-statemachine-kryo/src/test/java/org/springframework/statemachine/kryo/StateMachineContextSerializerTests.java +++ b/spring-statemachine-kryo/src/test/java/org/springframework/statemachine/kryo/StateMachineContextSerializerTests.java @@ -29,10 +29,10 @@ import org.springframework.statemachine.support.DefaultExtendedState; import org.springframework.statemachine.support.DefaultStateMachineContext; -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.Serializer; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; +import com.esotericsoftware.kryo.kryo5.Kryo; +import com.esotericsoftware.kryo.kryo5.Serializer; +import com.esotericsoftware.kryo.kryo5.io.Input; +import com.esotericsoftware.kryo.kryo5.io.Output; /** * Tests for {@link StateMachineContextSerializer}. @@ -51,7 +51,7 @@ public void testContextWithChilds() { Kryo kryo = new Kryo(); StateMachineContextSerializer serializer = new StateMachineContextSerializer<>(); kryo.addDefaultSerializer(StateMachineContext.class, serializer); - + kryo.setRegistrationRequired(false); StateMachineContext child = new DefaultStateMachineContext(new ArrayList<>(), "child", "event1", new HashMap(), new DefaultExtendedState()); List> childs = new ArrayList<>(); @@ -76,7 +76,8 @@ public void testContextFromInitialVersionToCurrent() { // and current(V2). raw bytes from V1 to V2. Kryo kryoFrom = new Kryo(); Kryo kryoTo = new Kryo(); - + kryoFrom.setRegistrationRequired(false); + kryoTo.setRegistrationRequired(false); StateMachineContextSerializerV1 serializerV1 = new StateMachineContextSerializerV1<>(); kryoFrom.addDefaultSerializer(StateMachineContext.class, serializerV1); @@ -119,7 +120,7 @@ public void write(Kryo kryo, Output output, StateMachineContext context) { @SuppressWarnings("unchecked") @Override - public StateMachineContext read(Kryo kryo, Input input, Class> clazz) { + public StateMachineContext read(Kryo kryo, Input input, Class> clazz) { E event = (E) kryo.readClassAndObject(input); S state = (S) kryo.readClassAndObject(input); Map eventHeaders = (Map) kryo.readClassAndObject(input); diff --git a/spring-statemachine-zookeeper/src/main/java/org/springframework/statemachine/zookeeper/ZookeeperStateMachinePersist.java b/spring-statemachine-zookeeper/src/main/java/org/springframework/statemachine/zookeeper/ZookeeperStateMachinePersist.java index b3d334474..98c7675ea 100644 --- a/spring-statemachine-zookeeper/src/main/java/org/springframework/statemachine/zookeeper/ZookeeperStateMachinePersist.java +++ b/spring-statemachine-zookeeper/src/main/java/org/springframework/statemachine/zookeeper/ZookeeperStateMachinePersist.java @@ -29,14 +29,13 @@ import org.springframework.statemachine.StateMachineContext; import org.springframework.statemachine.StateMachineException; import org.springframework.statemachine.StateMachinePersist; -import org.springframework.statemachine.kryo.MessageHeadersSerializer; +import org.springframework.util.Assert; import org.springframework.statemachine.kryo.StateMachineContextSerializer; +import org.springframework.statemachine.kryo.MessageHeadersSerializer; import org.springframework.statemachine.kryo.UUIDSerializer; -import org.springframework.util.Assert; - -import com.esotericsoftware.kryo.Kryo; -import com.esotericsoftware.kryo.io.Input; -import com.esotericsoftware.kryo.io.Output; +import com.esotericsoftware.kryo.kryo5.Kryo; +import com.esotericsoftware.kryo.kryo5.io.Input; +import com.esotericsoftware.kryo.kryo5.io.Output; /** * {@link StateMachinePersist} using zookeeper as a storage and @@ -57,6 +56,7 @@ public class ZookeeperStateMachinePersist implements StateMachinePersist