
org.springframework.statemachine.kryo.StateMachineContextSerializer Maven / Gradle / Ivy
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.statemachine.kryo;
import java.util.List;
import java.util.Map;
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;
/**
* Kryo {@link Serializer} for {@link StateMachineContext}.
*
* @author Janne Valkealahti
*
* @param the type of state
* @param the type of event
*/
public class StateMachineContextSerializer extends Serializer> {
@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().getVariables());
kryo.writeClassAndObject(output, context.getChilds());
}
@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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy