示例#1
0
    @Override
    public void write(Kryo kryo, Output output) {
      output.writeInt(objectID, true);

      int methodClassID = kryo.getRegistration(method.getDeclaringClass()).getId();
      output.writeInt(methodClassID, true);

      CachedMethod[] cachedMethods = getMethods(kryo, method.getDeclaringClass());
      CachedMethod cachedMethod = null;
      for (int i = 0, n = cachedMethods.length; i < n; i++) {
        cachedMethod = cachedMethods[i];
        if (cachedMethod.method.equals(method)) {
          output.writeByte(i);
          break;
        }
      }

      for (int i = 0, n = cachedMethod.serializers.length; i < n; i++) {
        Serializer serializer = cachedMethod.serializers[i];
        if (serializer != null) {
          kryo.writeObjectOrNull(output, args[i], serializer);
        } else {
          kryo.writeClassAndObject(output, args[i]);
        }
      }

      output.writeByte(responseID);
    }
示例#2
0
  /**
   * Reads through the all the edges for a vertex and writes the edges to a temp file which will be
   * read later.
   */
  private void readToEndOfEdgesAndWriteToTemp(final Input input, final Output output)
      throws IOException {
    Object next = kryo.readClassAndObject(input);
    while (!next.equals(EdgeTerminator.INSTANCE)) {
      kryo.writeClassAndObject(output, next);

      // next edge or terminator
      next = kryo.readClassAndObject(input);
    }

    // this should be the vertex terminator
    kryo.readClassAndObject(input);

    kryo.writeClassAndObject(output, EdgeTerminator.INSTANCE);
    kryo.writeClassAndObject(output, VertexTerminator.INSTANCE);
  }
  @Test
  public void test_kryo() {
    Kryo kryo = new Kryo();
    kryo.register(AdapterWfLaunchInfo.class);
    {
      Output output = new Output(1024);
      final AdapterWfLaunchInfo object = new AdapterWfLaunchInfo();
      object.setAdapterName("abc");
      kryo.writeClassAndObject(output, object);
      kryo.writeClassAndObject(output, new LogEvent());
      assertTrue(output.getBuffer().length > 0);

      Input input = new Input(output.getBuffer());
      assertEquals(AdapterWfLaunchInfo.class, kryo.readClassAndObject(input).getClass());
      assertEquals(LogEvent.class, kryo.readClassAndObject(input).getClass());
    }
  }
 private byte[] serialise(Message message) {
   // kryo.register(message.getClass());
   ByteBuffer buffer = ByteBuffer.allocate(bufferCapacity);
   kryo.writeClassAndObject(buffer, message);
   byte[] result = new byte[buffer.flip().limit()];
   buffer.get(result);
   return result;
 }
示例#5
0
 @Override
 public byte[] toBytes(Event event) {
   Kryo kryo = pool.borrow();
   try (Output out = new Output(new java.io.ByteArrayOutputStream())) {
     kryo.writeClassAndObject(out, event);
     return out.toBytes();
   } finally {
     pool.release(kryo);
   }
 }
示例#6
0
 @Override
 public CachedData encode(final Object obj) {
   final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
   try (final Output output = new Output(byteStream)) {
     kryo.writeClassAndObject(output, obj);
     output.flush();
     final byte[] bytes = byteStream.toByteArray();
     return new CachedData(0, bytes, bytes.length);
   }
 }
 @Override
 public void write(final Kryo kryo, final Output output, final List<?> obj) {
   try {
     final Object[] array = (Object[]) _arrayField.get(obj);
     output.writeInt(array.length, true);
     final Class<?> componentType = array.getClass().getComponentType();
     kryo.writeClass(output, componentType);
     for (final Object item : array) {
       kryo.writeClassAndObject(output, item);
     }
   } catch (final RuntimeException e) {
     // Don't eat and wrap RuntimeExceptions because the ObjectBuffer.write...
     // handles SerializationException specifically (resizing the buffer)...
     throw e;
   } catch (final Exception e) {
     throw new RuntimeException(e);
   }
 }
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  public void write(Connection connection, OutputStream outputStream, Object object) {
    Output output = new Output(outputStream);
    IKryoProvider kryoProvider = serializerQueue.poll();

    // if nothing is available in queue don't wait, create new one
    if (null == kryoProvider) {
      kryoProvider = createKryoProvider();
    }

    try {
      Kryo kryo = kryoProvider.getKryo();
      kryo.getContext().put("connection", connection);
      kryo.writeClassAndObject(output, object);
      output.flush();
    } finally {
      serializerQueue.offer(kryoProvider);
    }
  }
 @Override
 public void write(Kryo kryo, Output output, ExtensionCriterion object) {
   kryo.writeClassAndObject(output, object.extensionSelector().type());
   kryo.writeClassAndObject(output, object.deviceId());
   kryo.writeClassAndObject(output, object.extensionSelector().serialize());
 }
 @Override
 public void write(Kryo kryo, Output output, MastershipTerm object) {
   kryo.writeClassAndObject(output, object.master());
   output.writeInt(object.termNumber());
 }
示例#11
0
 @Override
 public void write(Kryo kryo, Output output) {
   kryo.writeClassAndObject(output, this.nodes);
   kryo.writeClassAndObject(output, this.funcs);
 }
 @Override
 public byte[] serialize(Object object) {
   kryoOut.clear();
   kryo.writeClassAndObject(kryoOut, object);
   return kryoOut.toBytes();
 }
 @Override
 public void write(Kryo kryo, Output output) {
   kryo.writeObject(output, getUser());
   output.writeString(getPassword());
   kryo.writeClassAndObject(output, getFriends());
 }
示例#14
0
 public void write(Kryo kryo, Output output, Map object) {
   Entry entry = (Entry) object.entrySet().iterator().next();
   kryo.writeClassAndObject(output, entry.getKey());
   kryo.writeClassAndObject(output, entry.getValue());
 }
 @Override
 public void write(Kryo kryo, Output output, HostLocation object) {
   kryo.writeClassAndObject(output, object.deviceId());
   kryo.writeClassAndObject(output, object.port());
   output.writeLong(object.time());
 }
 @Override
 public void write(final Kryo kryo, final Output output, final Object obj) {
   kryo.writeClassAndObject(output, Proxy.getInvocationHandler(obj));
   kryo.writeObject(output, obj.getClass().getInterfaces());
 }
示例#17
0
 public void write(Kryo kryo, Output output, Set object) {
   kryo.writeClassAndObject(output, object.iterator().next());
 }
示例#18
0
 public void write(Kryo kryo, Output output, Collection collection) {
   TreeSet treeSet = (TreeSet) collection;
   kryo.writeClassAndObject(output, treeSet.comparator());
   super.write(kryo, output, collection);
 }
示例#19
0
 public void write(Kryo kryo, Output output, Map map) {
   TreeMap treeMap = (TreeMap) map;
   kryo.writeClassAndObject(output, treeMap.comparator());
   super.write(kryo, output, map);
 }
 @Override
 public void write(Kryo kryo, Output output, OperationTree node) {
   kryo.writeClassAndObject(output, util.getOperation(node));
 }
示例#21
0
 public void write(Kryo kryo, Output output, List object) {
   kryo.writeClassAndObject(output, object.get(0));
 }