コード例 #1
1
ファイル: SerializerHelper.java プロジェクト: mountain/talos
 public void writeRecommendations(Output output, Map<String, Recommendation> recommendations) {
   kryo.writeObject(output, recommendations.size());
   for (String key : recommendations.keySet()) {
     Recommendation rec = recommendations.get(key);
     rec.clean();
     kryo.writeObject(output, rec.source.key());
     kryo.writeObject(output, rec.target.key());
     kryo.writeObject(output, rec);
   }
 }
コード例 #2
0
 private static <T> T deserializeObjectByKryo(Kryo kryo, InputStream in, Class<T> clazz) {
   Input inp = new Input(in);
   kryo.setClassLoader(Utilities.getSessionSpecifiedClassLoader());
   T t = kryo.readObject(inp, clazz);
   inp.close();
   return t;
 }
コード例 #3
0
ファイル: Network.java プロジェクト: lituss/Lobby
 // This registers objects that are going to be sent over the network.
 public static void register(EndPoint endPoint) {
   Kryo kryo = endPoint.getKryo();
   kryo.register(RegisterName.class);
   kryo.register(String[].class);
   kryo.register(UpdateNames.class);
   kryo.register(ChatMessage.class);
 }
コード例 #4
0
 @Override
 public HostLocation read(Kryo kryo, Input input, Class<HostLocation> type) {
   DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input);
   PortNumber portNumber = (PortNumber) kryo.readClassAndObject(input);
   long time = input.readLong();
   return new HostLocation(deviceId, portNumber, time);
 }
コード例 #5
0
ファイル: ObjectSpace.java プロジェクト: ivansenic/inspectIT
    @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);
    }
コード例 #6
0
ファイル: KryoReader.java プロジェクト: kdatta/tinkerpop3
  /** Read the edges from the temp file and load them to the graph. */
  private void readFromTempEdges(final Input input, final Graph graphToWriteTo) {
    while (!input.eof()) {
      // in this case the outId is the id assigned by the graph
      Object next = kryo.readClassAndObject(input);
      while (!next.equals(EdgeTerminator.INSTANCE)) {
        final List<Object> edgeArgs = new ArrayList<>();
        final DetachedEdge detachedEdge = (DetachedEdge) next;
        final Vertex vOut =
            graphToWriteTo.v(detachedEdge.iterators().vertexIterator(Direction.OUT).next().id());
        final Vertex inV =
            graphToWriteTo.v(detachedEdge.iterators().vertexIterator(Direction.IN).next().id());

        detachedEdge
            .iterators()
            .propertyIterator()
            .forEachRemaining(p -> edgeArgs.addAll(Arrays.asList(p.key(), p.value())));
        // detachedEdge.iterators().hiddenPropertyIterator().forEachRemaining(p ->
        // edgeArgs.addAll(Arrays.asList(Graph.Key.hide(p.key()), p.value())));

        appendToArgList(edgeArgs, T.id, detachedEdge.id());

        vOut.addEdge(detachedEdge.label(), inV, edgeArgs.toArray());

        next = kryo.readClassAndObject(input);
      }

      // vertex terminator
      kryo.readClassAndObject(input);
    }
  }
コード例 #7
0
ファイル: SerializerHelper.java プロジェクト: mountain/talos
 public void writeVectorSets(Output output, Map<String, VectorSet> vectorSets) {
   kryo.writeObject(output, vectorSets.size());
   for (String key : vectorSets.keySet()) {
     VectorSet vectorSet = vectorSets.get(key);
     kryo.writeObject(output, vectorSet);
   }
 }
コード例 #8
0
ファイル: ObjectSpace.java プロジェクト: ivansenic/inspectIT
    @Override
    public void read(Kryo kryo, Input input) {
      objectID = input.readInt(true);

      int methodClassID = input.readInt(true);
      Class methodClass = kryo.getRegistration(methodClassID).getType();
      byte methodIndex = input.readByte();
      CachedMethod cachedMethod;
      try {
        cachedMethod = getMethods(kryo, methodClass)[methodIndex];
      } catch (IndexOutOfBoundsException ex) {
        throw new KryoException(
            "Invalid method index " + methodIndex + " for class: " + methodClass.getName());
      }
      method = cachedMethod.method;

      args = new Object[cachedMethod.serializers.length];
      for (int i = 0, n = args.length; i < n; i++) {
        Serializer serializer = cachedMethod.serializers[i];
        if (serializer != null) {
          args[i] = kryo.readObjectOrNull(input, method.getParameterTypes()[i], serializer);
        } else {
          args[i] = kryo.readClassAndObject(input);
        }
      }

      responseID = input.readByte();
    }
コード例 #9
0
ファイル: RmiTest.java プロジェクト: RebelKeithy/FTL-Hyperion
 public static void register(Kryo kryo) {
   kryo.register(TestObject.class);
   kryo.register(MessageWithTestObject.class);
   kryo.register(StackTraceElement.class);
   kryo.register(StackTraceElement[].class);
   kryo.register(UnsupportedOperationException.class);
   ObjectSpace.registerClasses(kryo);
 }
コード例 #10
0
 /**
  * register a class
  *
  * @param kryo
  * @param s name of a class - might not exist
  * @param handled Set of classes already handles
  */
 protected void doRegistration(final Kryo kryo, final Class pC) {
   if (kryo != null) {
     kryo.register(pC);
     // also register arrays of that class
     Class arrayType = Array.newInstance(pC, 0).getClass();
     kryo.register(arrayType);
   }
 }
コード例 #11
0
ファイル: KryoReader.java プロジェクト: kdatta/tinkerpop3
  private Vertex readVertex(
      final Direction directionRequested,
      final Function<DetachedVertex, Vertex> vertexMaker,
      final Function<DetachedEdge, Edge> edgeMaker,
      final Input input)
      throws IOException {
    if (null != directionRequested && null == edgeMaker)
      throw new IllegalArgumentException(
          "If a directionRequested is specified then an edgeAdder function should also be specified");

    this.headerReader.read(kryo, input);

    final DetachedVertex detachedVertex = (DetachedVertex) kryo.readClassAndObject(input);
    final Vertex v = vertexMaker.apply(detachedVertex);

    final boolean streamContainsEdgesInSomeDirection = input.readBoolean();
    if (!streamContainsEdgesInSomeDirection && directionRequested != null)
      throw new IllegalStateException(
          String.format(
              "The direction %s was requested but no attempt was made to serialize edges into this stream",
              directionRequested));

    // if there are edges in the stream and the direction is not present then the rest of the stream
    // is
    // simply ignored
    if (directionRequested != null) {
      final Direction directionsInStream = kryo.readObject(input, Direction.class);
      if (directionsInStream != Direction.BOTH && directionsInStream != directionRequested)
        throw new IllegalStateException(
            String.format(
                "Stream contains %s edges, but requesting %s",
                directionsInStream, directionRequested));

      final Direction firstDirection = kryo.readObject(input, Direction.class);
      if (firstDirection == Direction.OUT
          && (directionRequested == Direction.BOTH || directionRequested == Direction.OUT))
        readEdges(input, edgeMaker);
      else {
        // requested direction in, but BOTH must be serialized so skip this.  the
        // illegalstateexception
        // prior to this IF should  have caught a problem where IN is not supported at all
        if (firstDirection == Direction.OUT && directionRequested == Direction.IN) skipEdges(input);
      }

      if (directionRequested == Direction.BOTH || directionRequested == Direction.IN) {
        // if the first direction was OUT then it was either read or skipped.  in that case, the
        // marker
        // of the stream is currently ready to read the IN direction. otherwise it's in the perfect
        // place
        // to start reading edges
        if (firstDirection == Direction.OUT) kryo.readObject(input, Direction.class);

        readEdges(input, edgeMaker);
      }
    }

    return v;
  }
コード例 #12
0
ファイル: SampleObject.java プロジェクト: mdogan/test
 // Required by Kryo serialization.
 public void read(Kryo kryo, Input in) {
   intVal = kryo.readObject(in, Integer.class);
   floatVal = kryo.readObject(in, Float.class);
   shortVal = kryo.readObject(in, Short.class);
   byteArr = kryo.readObject(in, byte[].class);
   longArr = kryo.readObject(in, long[].class);
   dblArr = kryo.readObject(in, double[].class);
   str = kryo.readObject(in, String.class);
 }
コード例 #13
0
 @Override
 public Event fromBytes(byte[] bytes) {
   Kryo kryo = pool.borrow();
   try (Input in = new Input(bytes)) {
     return (Event) kryo.readClassAndObject(in);
   } finally {
     pool.release(kryo);
   }
 }
コード例 #14
0
ファイル: KryoReader.java プロジェクト: kdatta/tinkerpop3
 private void skipEdges(final Input input) {
   if (input.readBoolean()) {
     Object next = kryo.readClassAndObject(input);
     while (!next.equals(EdgeTerminator.INSTANCE)) {
       // next edge to skip or the terminator
       next = kryo.readClassAndObject(input);
     }
   }
 }
コード例 #15
0
ファイル: KryoReader.java プロジェクト: kdatta/tinkerpop3
 private void readEdges(final Input input, final Function<DetachedEdge, Edge> edgeMaker) {
   if (input.readBoolean()) {
     Object next = kryo.readClassAndObject(input);
     while (!next.equals(EdgeTerminator.INSTANCE)) {
       final DetachedEdge detachedEdge = (DetachedEdge) next;
       edgeMaker.apply(detachedEdge);
       next = kryo.readClassAndObject(input);
     }
   }
 }
コード例 #16
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);
   }
 }
コード例 #17
0
ファイル: SampleObject.java プロジェクト: mdogan/test
 // Required by Kryo serialization.
 public void write(Kryo kryo, Output out) {
   kryo.writeObject(out, intVal);
   kryo.writeObject(out, floatVal);
   kryo.writeObject(out, shortVal);
   kryo.writeObject(out, byteArr);
   kryo.writeObject(out, longArr);
   kryo.writeObject(out, dblArr);
   kryo.writeObject(out, str);
   out.flush();
 }
コード例 #18
0
 @Override
 public void write(Kryo kryo, Output output) {
   output.writeString(this.firstname);
   output.writeString(this.lastname);
   kryo.writeObjectOrNull(output, this.emailAddress, SerializableEmailAddress.class);
   output.writeInt(this.addresses.size());
   for (Address address : this.addresses) {
     kryo.writeObject(output, address);
   }
 }
コード例 #19
0
 public DbMessageLogger() {
   kryo =
       new Kryo() {
         public Serializer newSerializer(Class aClass) {
           if (SubListSerializer.canSerialize(aClass)) return new SubListSerializer(this);
           return super.newSerializer(aClass);
         }
       };
   kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer(kryo));
   kryo.setRegistrationOptional(true);
 }
コード例 #20
0
 @Override
 public void read(Kryo kryo, Input input) {
   this.firstname = input.readString();
   this.lastname = input.readString();
   this.emailAddress = kryo.readObjectOrNull(input, SerializableEmailAddress.class);
   this.addresses = new HashSet<Address>();
   int numAddresses = input.readInt();
   for (int i = 0; i < numAddresses; i++) {
     this.add(kryo.readObject(input, SerializableAddress.class));
   }
 }
コード例 #21
0
  /**
   * do the real work of registering all classes
   *
   * @param kryo
   */
  @Override
  public void registerClasses(@Nonnull Kryo kryo) {
    kryo.register(Object[].class);
    kryo.register(scala.Tuple2[].class);

    doRegistration(kryo, "scala.collection.mutable.WrappedArray$ofRef");
    doRegistration(kryo, "com.nielsen.perfengg.SparkD");

    // and many more similar nines

  }
コード例 #22
0
  /**
   * Checks if the given class is registered with the RPC service.
   *
   * @param throwableType the class to check
   * @return <code>true</code> if the given class is registered with the RPC service, <code>false
   *     </code> otherwise
   */
  private boolean isThrowableRegistered(final Class<? extends Throwable> throwableType) {

    final Kryo kryo = KryoUtil.getKryo();
    try {
      kryo.getRegistration(throwableType);
    } catch (final IllegalArgumentException e) {
      return false;
    }

    return true;
  }
コード例 #23
0
 @Before
 public void setUp() throws Exception {
   StoreConfig config = new StoreConfig();
   config.setDataFileName(DATA_FILE_NAME);
   config.setDataMappedMemorySize(DATA_MAPPED_BUFFER_SIZE);
   config.setInitialFileSize(DATA_FILE_SIZE);
   Kryo kryo = new Kryo();
   kryo.register(VertexImpl.class);
   TypeResolver.registerClass(VertexImpl.class, (byte) 0);
   store = new VertexStore(config, kryo);
   store.start();
 }
コード例 #24
0
 private static byte[] serializeObjectToKryo(Serializable object) {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   Output output = new Output(baos);
   Kryo kryo = borrowKryo();
   try {
     kryo.writeObject(output, object);
   } finally {
     releaseKryo(kryo);
   }
   output.close();
   return baos.toByteArray();
 }
コード例 #25
0
 public void write(Kryo kryo, Output output, EnumSet object) {
   Serializer serializer;
   if (object.isEmpty()) {
     EnumSet tmp = EnumSet.complementOf(object);
     if (tmp.isEmpty())
       throw new KryoException("An EnumSet must have a defined Enum to be serialized.");
     serializer = kryo.writeClass(output, tmp.iterator().next().getClass()).getSerializer();
   } else {
     serializer = kryo.writeClass(output, object.iterator().next().getClass()).getSerializer();
   }
   output.writeInt(object.size(), true);
   for (Object element : object) serializer.write(kryo, output, element);
 }
コード例 #26
0
  // This registers objects that are going to be sent over the network.
  public static void register(EndPoint endPoint) {
    Kryo kryo = endPoint.getKryo();
    kryo.register(RegisterName.class);
    kryo.register(String[].class);
    kryo.register(UpdateNames.class);
    kryo.register(ChatMessage.class);

    FieldSerializer<Data> dataClassSerializer = new FieldSerializer<Data>(kryo, Data.class);
    dataClassSerializer.getField("bytes").setClass(byte[].class, new ByteArraySerializer());
    dataClassSerializer.getField("string").setClass(String.class, new StringSerializer());
    dataClassSerializer.getField("string").setCanBeNull(true);
    kryo.register(Data.class, dataClassSerializer);
  }
コード例 #27
0
 public SerializablePage loadPage(InputStream in) {
   synchronized (serializeLock) {
     Input input = null;
     try {
       input = new Input(in);
       input.readString();
       kryo.readObject(input, UrlPageModel.class);
       return kryo.readObject(input, SerializablePage.class);
     } finally {
       IOUtils.closeQuietly(input);
     }
   }
 }
コード例 #28
0
 private static <T extends Serializable> T deserializeObjectFromKryo(
     byte[] bytes, Class<T> clazz) {
   Input inp = new Input(new ByteArrayInputStream(bytes));
   Kryo kryo = borrowKryo();
   T func = null;
   try {
     func = kryo.readObject(inp, clazz);
   } finally {
     releaseKryo(kryo);
   }
   inp.close();
   return func;
 }
コード例 #29
0
ファイル: Serializer.java プロジェクト: rucky2013/godzilla
  public static byte[] serialize(Object object) throws SerializeException {
    if (object == null) {
      throw new SerializeException("指向object对象指针为空");
    }

    Kryo kryo = kryoThreadLocal.get();
    ByteArrayOutputStream stream = new ByteArrayOutputStream(20000);
    Output output = new Output(stream);
    kryo.writeObject(output, object);
    output.close();

    return stream.toByteArray();
  }
コード例 #30
0
 public void savePage(
     OutputStream out, String title, UrlPageModel pageModel, SerializablePage page) {
   synchronized (serializeLock) {
     Output output = null;
     try {
       output = isHoneycomb() ? new KryoOutputHC(out) : new Output(out);
       output.writeString(title);
       kryo.writeObject(output, pageModel);
       kryo.writeObject(output, page);
     } finally {
       IOUtils.closeQuietly(output);
     }
   }
 }