Class KryoStateMachineSerialisationService<S,E>

java.lang.Object
org.springframework.statemachine.kryo.AbstractKryoStateMachineSerialisationService<S,E>
org.springframework.statemachine.kryo.KryoStateMachineSerialisationService<S,E>
Type Parameters:
S - the type of state
E - the type of event
All Implemented Interfaces:
StateMachineSerialisationService<S,E>

public class KryoStateMachineSerialisationService<S,E> extends AbstractKryoStateMachineSerialisationService<S,E>
Implementation for StateMachineSerialisationService using kryo.
  • Constructor Details

    • KryoStateMachineSerialisationService

      public KryoStateMachineSerialisationService()
      Instantiates a new kryo state machine serialisation service with no extra class registrations beyond the framework defaults.
    • KryoStateMachineSerialisationService

      public KryoStateMachineSerialisationService(Consumer<com.esotericsoftware.kryo.Kryo> kryoCustomizer)
      Instantiates a new kryo state machine serialisation service with an application-supplied Kryo customizer.

      The customizer is invoked once per Kryo instance after the framework's safe-by-default registrations have been applied (via KryoStateMachineSerialisationDefaults.registerDefaults(Kryo)). Use it to register application-specific types — typically the S and E enums used by the state machine — so they are accepted by the registration-required allowlist:

      
       new KryoStateMachineSerialisationService<>(kryo -> {
           kryo.register(MyStates.class);
           kryo.register(MyEvents.class);
       })
       
      Parameters:
      kryoCustomizer - callback applied to each new Kryo instance; may be null
      Since:
      4.0.2
  • Method Details

    • doEncode

      protected void doEncode(com.esotericsoftware.kryo.Kryo kryo, Object object, com.esotericsoftware.kryo.io.Output output)
      Description copied from class: AbstractKryoStateMachineSerialisationService
      Subclasses implement this method to encode with Kryo.
      Specified by:
      doEncode in class AbstractKryoStateMachineSerialisationService<S,E>
      Parameters:
      kryo - the Kryo instance
      object - the object to encode
      output - the Kryo Output instance
    • doDecode

      protected <T> T doDecode(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input, Class<T> type)
      Description copied from class: AbstractKryoStateMachineSerialisationService
      Subclasses implement this method to decode with Kryo.
      Specified by:
      doDecode in class AbstractKryoStateMachineSerialisationService<S,E>
      Type Parameters:
      T - the type for decoded object
      Parameters:
      kryo - the Kryo instance
      input - the Kryo Input instance
      type - the class of the decoded object
      Returns:
      the decoded object
    • configureKryoInstance

      protected void configureKryoInstance(com.esotericsoftware.kryo.Kryo kryo)
      Applies the optional kryoCustomizer supplied at construction time. Subclasses may override this to register additional types on top of the framework defaults and the customizer.
      Specified by:
      configureKryoInstance in class AbstractKryoStateMachineSerialisationService<S,E>
      Parameters:
      kryo - the kryo instance