@Override protected boolean recycle(ByteArrayOutput output) { if (output.getByteArrayOutputStream().getBufferSize() < MAX_POOLED_BUFFER_SIZE) { output.getByteArrayOutputStream().reset(); output.clear(); return true; } return false; // discard } }
protected DefaultDistributedCollectionService(PrimitiveType primitiveType, T collection) { super(primitiveType, DistributedCollectionClient.class); this.collection = collection; this.serializer = Serializer.using(Namespace.builder() .register(primitiveType.namespace()) .register(SessionId.class) .register(IteratorContext.class) .build()); }
byte[] encode(Object value) { return serializer.encode(value); }
<T> T decode(byte[] bytes) { return serializer.decode(bytes); }
/** * Builds a {@link Namespace} instance. * * @return KryoNamespace */ public Namespace build() { return build(NO_NAME); }
@Override protected ByteArrayOutput create(int bufferSize) { return new ByteArrayOutput(bufferSize, MAX_BUFFER_SIZE, new BufferAwareByteArrayOutputStream(bufferSize)); }
/** * Enables compatible serialization for serializable types. * * @return the serializer builder */ public SerializerBuilder withCompatibleSerialization() { return withCompatibleSerialization(true); }
/** * Deserializes given InputStream to an Object using Kryo instance in pool. * * @param stream input stream * @param <T> deserialized Object type * @return deserialized Object */ public <T> T deserialize(final InputStream stream) { return deserialize(stream, DEFAULT_BUFFER_SIZE); }
/** * Sets whether compatible serialization is enabled for serializable types. * * @param compatibleSerialization whether compatible serialization is enabled for user types * @return the serializer builder */ public SerializerBuilder withCompatibleSerialization(boolean compatibleSerialization) { namespaceBuilder.setCompatible(compatibleSerialization); return this; }
/** * Encodes the given object using the configured {@link #userSerializer}. * * @param object the object to encode * @param <T> the object type * @return the encoded bytes */ protected <T> byte[] encode(T object) { return object != null ? userSerializer.encode(object) : null; }
/** * Encodes the given object using the configured {@link #serializer}. * * @param object the object to encode * @param <T> the object type * @return the encoded bytes */ protected <T> byte[] encode(T object) { return object != null ? serializer.encode(object) : null; }