Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Kryo


public class Network {
  static public final int port = 54555;

  // This registers objects that are going to be sent over the network.
  static public void register (EndPoint endPoint) {
    Kryo kryo = endPoint.getKryo();
    kryo.register(RegisterName.class);
    kryo.register(String[].class);
    kryo.register(UpdateNames.class);
    kryo.register(ChatMessage.class);
  }
View Full Code Here


        }
        this.versionedHeader = out.toBytes();
    }

    public Kryo createKryo() {
        final Kryo kryo = new Kryo(new GremlinClassResolver(), new MapReferenceResolver(), new DefaultStreamFactory());
        kryo.addDefaultSerializer(Map.Entry.class, new EntrySerializer());
        kryo.setRegistrationRequired(true);
        serializationList.forEach(p -> {
            final Function<Kryo, Serializer> serializer = p.getValue1();
            if (serializer == null)
                kryo.register(p.getValue0(), kryo.getDefaultSerializer(p.getValue0()), p.getValue2());
            else
                kryo.register(p.getValue0(), serializer.apply(kryo), p.getValue2());
        });
        return kryo;
    }
View Full Code Here

public class Network {
  static public final int port = 54555;

  // This registers objects that are going to be sent over the network.
  static public void register (EndPoint endPoint) {
    Kryo kryo = endPoint.getKryo();
    kryo.register(Login.class);
    kryo.register(RegistrationRequired.class);
    kryo.register(Register.class);
    kryo.register(AddCharacter.class);
    kryo.register(UpdateCharacter.class);
    kryo.register(RemoveCharacter.class);
    kryo.register(Character.class);
    kryo.register(MoveCharacter.class);
  }
View Full Code Here

public class SerializeUtil{
 
  private static Kryo kryo;

  public static Kryo createKryo(){
    kryo = new Kryo();
    FieldSerializer<MeasurePointData> someClassSerializer = new FieldSerializer<MeasurePointData>(kryo, MeasurePointData.class);
    someClassSerializer.getField("measurePointId").setSerializer(new MeasurePointIdSerializer());
    kryo.register(MeasurePointData.class, someClassSerializer);
    return kryo;
  }
View Full Code Here

    /**
     * override this to implement your own subclass of Kryo
     * default is new Kryo with StdInstantiatorStrategy.
     */
    public Kryo newKryo() {
      Kryo k = new Kryo();
      k.setInstantiatorStrategy(new StdInstantiatorStrategy());
      return k;
    }
View Full Code Here

    public final Kryo populatedKryo() {
        if (factory == null)
            factory = new KryoFactory(getConf());

        Kryo k = newKryo();
        decorateKryo(k);
        factory.populateKryo(k);
        return k;
    }
View Full Code Here

    public KryoCodec(KryoPool kryoPool) {
        this.kryoPool = kryoPool;
    }

    private Object decode(ByteBuffer bytes) {
        Kryo kryo = null;
        try {
            kryo = kryoPool.get();
            return kryo.readClassAndObject(new Input(new ByteArrayInputStream(bytes.array(), bytes
                    .arrayOffset() + bytes.position(), bytes.limit())));
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            }
View Full Code Here

        }
    }

    @Override
    public byte[] encodeValue(Object value) {
        Kryo kryo = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            Output output = new Output(baos);
            kryo = kryoPool.get();
            kryo.writeClassAndObject(output, value);
            output.close();
            return baos.toByteArray();
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
View Full Code Here

    public static class KryoPoolImpl implements KryoPool {

        private final Queue<Kryo> objects = new ConcurrentLinkedQueue<Kryo>();

        public Kryo get() {
            Kryo kryo;
            if ((kryo = objects.poll()) == null) {
                kryo = createInstance();
            }
            return kryo;
        }
View Full Code Here

         * Sub classes can customize the Kryo instance by overriding this method
         *
         * @return create Kryo instance
         */
        protected Kryo createInstance() {
            Kryo kryo = new Kryo();
            kryo.setReferences(false);
            return kryo;
        }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.Kryo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.