Package com.esotericsoftware.kryo

Examples of com.esotericsoftware.kryo.Kryo$Listener


  /** If true, Kryo will error if it sees a class that has not been registered
   */
  public KryoInstantiator setRegistrationRequired(final boolean req) {
    return new KryoInstantiator() {
      public Kryo newKryo() {
        Kryo k = KryoInstantiator.this.newKryo();
        /** Try to avoid calling this method if you don't need to.
         * We've been burned by binary compatibility with Kryo
         */
        if(k.isRegistrationRequired() != req) { k.setRegistrationRequired(req); }
        return k;
      }
    };
  }
View Full Code Here


  }

  public KryoInstantiator withRegistrar(final IKryoRegistrar r) {
    return new KryoInstantiator() {
      public Kryo newKryo() {
        Kryo k = KryoInstantiator.this.newKryo();
        r.apply(k);
        return k;
      }
    };
  }
View Full Code Here

    conf.set(DEFAULT_REGISTRATIONS, registrarsToString(defaultRegistrations));
  }

  // This one adds expeption annotations that the interface does not have
  protected Kryo newKryoWithEx() throws InstantiationException, IllegalAccessException {
    Kryo k = kryoClass.newInstance();
    k.setInstantiatorStrategy(instStratClass.newInstance());
    k.setRegistrationRequired(regRequired);
    for(IKryoRegistrar kr: registrations) {
      kr.apply(k);
    }
    for(IKryoRegistrar dkr: defaultRegistrations) {
      dkr.apply(k);
View Full Code Here

    }

    public <T> KryoPool getKryo(final ClassTag<T> tag, final Serializer<T> serializer){
        KryoInstantiator kryoInstantiator = new KryoInstantiator() {
            public Kryo newKryo() {
                Kryo k =super.newKryo();
                k.setInstantiatorStrategy(new StdInstantiatorStrategy());
                k.register(tag.runtimeClass(), serializer);
                return k;
            }
        };

       return KryoPool.withByteArrayOutputStream(1, kryoInstantiator);
View Full Code Here

    return data.values();
  }

  @Override
  public void persist(String path) {
    Kryo kryo = new Kryo();
    ObjectBuffer buffer = new ObjectBuffer(kryo, 100000);
    List<DataProvider> providers = registerClasses(kryo);
    try {
      FileOutputStream fileOutputStream = new FileOutputStream(path);
      buffer.writeObject(fileOutputStream, providers);
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  @Override
  public void load(String path) {
    Kryo kryo = new Kryo();
    List<DataProvider> providers = registerClasses(kryo);

    List<DataListener> listeners = new ArrayList<DataListener>();
    for (DataProvider provider : providers) {
      listeners.addAll(provider.getListeners());
View Full Code Here

    }

    @Override
    public ResponseMessage deserializeResponse(final ByteBuf msg) throws SerializationException {
        try {
            final Kryo kryo = kryoThreadLocal.get();
            final byte[] payload = new byte[msg.readableBytes()];
            msg.readBytes(payload);
            try (final Input input = new Input(payload)) {
                final Map<String, Object> responseData = (Map<String, Object>) kryo.readClassAndObject(input);
                final Map<String, Object> status = (Map<String,Object>) responseData.get(SerTokens.TOKEN_STATUS);
                final Map<String, Object> result = (Map<String,Object>) responseData.get(SerTokens.TOKEN_RESULT);
                return ResponseMessage.build(UUID.fromString(responseData.get(SerTokens.TOKEN_REQUEST).toString()))
                        .code(ResponseStatusCode.getFromValue((Integer) status.get(SerTokens.TOKEN_CODE)))
                        .statusMessage(Optional.ofNullable((String) status.get(SerTokens.TOKEN_MESSAGE)).orElse(""))
View Full Code Here

            final Map<String, Object> message = new HashMap<>();
            message.put(SerTokens.TOKEN_STATUS, status);
            message.put(SerTokens.TOKEN_RESULT, result);
            message.put(SerTokens.TOKEN_REQUEST, responseMessage.getRequestId() != null ? responseMessage.getRequestId() : null);

            final Kryo kryo = kryoThreadLocal.get();
            try (final OutputStream baos = new ByteArrayOutputStream()) {
                final Output output = new Output(baos);
                kryo.writeClassAndObject(output, message);

                final long size = output.total();
                if (size > Integer.MAX_VALUE)
                    throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));
View Full Code Here

    }

    @Override
    public RequestMessage deserializeRequest(final ByteBuf msg) throws SerializationException {
        try {
            final Kryo kryo = kryoThreadLocal.get();
            final byte[] payload = new byte[msg.readableBytes()];
            msg.readBytes(payload);
            try (final Input input = new Input(payload)) {
                final Map<String, Object> requestData = (Map<String, Object>) kryo.readClassAndObject(input);
                final RequestMessage.Builder builder = RequestMessage.build((String) requestData.get(SerTokens.TOKEN_OP))
                        .overrideRequestId((UUID) requestData.get(SerTokens.TOKEN_REQUEST))
                        .processor((String) requestData.get(SerTokens.TOKEN_PROCESSOR));
                final Map<String, Object> args = (Map<String, Object>) requestData.get(SerTokens.TOKEN_ARGS);
                args.forEach(builder::addArg);
View Full Code Here

    @Override
    public ByteBuf serializeRequestAsBinary(final RequestMessage requestMessage, final ByteBufAllocator allocator) throws SerializationException {
        ByteBuf encodedMessage = null;
        try {
            final Kryo kryo = kryoThreadLocal.get();
            try (final OutputStream baos = new ByteArrayOutputStream()) {
                final Output output = new Output(baos);
                final String mimeType = serializeToString ? MIME_TYPE_STRINGD : MIME_TYPE;
                output.writeByte(mimeType.length());
                output.write(mimeType.getBytes(UTF8));

                final Map<String, Object> request = new HashMap<>();
                request.put(SerTokens.TOKEN_REQUEST, requestMessage.getRequestId());
                request.put(SerTokens.TOKEN_PROCESSOR, requestMessage.getProcessor());
                request.put(SerTokens.TOKEN_OP, requestMessage.getOp());
                request.put(SerTokens.TOKEN_ARGS, requestMessage.getArgs());

                kryo.writeClassAndObject(output, request);

                final long size = output.total();
                if (size > Integer.MAX_VALUE)
                    throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.Kryo$Listener

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.