Search in sources :

Example 1 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class MulticastService method receive.

private JoinMessage receive() {
    try {
        try {
            multicastSocket.receive(datagramPacketReceive);
        } catch (IOException ignore) {
            return null;
        }
        try {
            final byte[] data = datagramPacketReceive.getData();
            final int offset = datagramPacketReceive.getOffset();
            final int length = datagramPacketReceive.getLength();
            final byte[] processed = inputProcessor != null ? inputProcessor.process(data, offset, length) : data;
            final BufferObjectDataInput input = node.getSerializationService().createObjectDataInput(processed);
            if (inputProcessor == null) {
                // If pre-processed the offset is already taken into account.
                input.position(offset);
            }
            final byte packetVersion = input.readByte();
            if (packetVersion != Packet.VERSION) {
                logger.warning("Received a JoinRequest with a different packet version, or encrypted. " + "Verify that the sender Node, doesn't have symmetric-encryption on. This -> " + Packet.VERSION + ", Incoming -> " + packetVersion + ", Sender -> " + datagramPacketReceive.getAddress());
                return null;
            }
            return input.readObject();
        } catch (Exception e) {
            if (e instanceof EOFException || e instanceof HazelcastSerializationException) {
                long now = System.currentTimeMillis();
                if (now - lastLoggedJoinSerializationFailure > JOIN_SERIALIZATION_ERROR_SUPPRESSION_MILLIS) {
                    lastLoggedJoinSerializationFailure = now;
                    logger.warning("Received a JoinRequest with an incompatible binary-format. " + "An old version of Hazelcast may be using the same multicast discovery port. " + "Are you running multiple Hazelcast clusters on this host? " + "(This message will be suppressed for 60 seconds). ");
                }
            } else if (e instanceof GeneralSecurityException) {
                logger.warning("Received a JoinRequest with an incompatible encoding. " + "Symmetric-encryption is enabled on this node, the remote node either doesn't have it on, " + "or it uses different cipher." + "(This message will be suppressed for 60 seconds). ");
            } else {
                throw e;
            }
        }
    } catch (Exception e) {
        logger.warning(e);
    }
    return null;
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) GeneralSecurityException(java.security.GeneralSecurityException) EOFException(java.io.EOFException) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) SocketException(java.net.SocketException) GeneralSecurityException(java.security.GeneralSecurityException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) EOFException(java.io.EOFException) UnknownHostException(java.net.UnknownHostException)

Example 2 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class SerializingGenericRecordCloner method build.

@Override
@Nonnull
public GenericRecord build() {
    try {
        for (FieldDescriptor field : schema.getFields()) {
            String fieldName = field.getFieldName();
            Writer writer = fields.get(fieldName);
            if (writer != null) {
                writer.write();
            } else {
                // Field is not overwritten. Write the field from the generic record.
                FieldKind fieldKind = field.getKind();
                fieldOperations(fieldKind).writeFieldFromRecordToWriter(cw, genericRecord, fieldName);
            }
        }
        cw.end();
        byte[] bytes = cw.toByteArray();
        Class associatedClass = genericRecord.getAssociatedClass();
        BufferObjectDataInput dataInput = bufferObjectDataInputFunc.apply(bytes);
        return new DefaultCompactReader(serializer, dataInput, schema, associatedClass, false);
    } catch (IOException e) {
        throw new HazelcastSerializationException(e);
    }
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) FieldKind(com.hazelcast.nio.serialization.FieldKind) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) Nonnull(javax.annotation.Nonnull)

Example 3 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class PortableContextImpl method lookupClassDefinition.

@Override
public ClassDefinition lookupClassDefinition(Data data) throws IOException {
    if (!data.isPortable()) {
        throw new IllegalArgumentException("Data is not Portable!");
    }
    BufferObjectDataInput in = serializationService.createObjectDataInput(data);
    int factoryId = in.readInt();
    int classId = in.readInt();
    int version = in.readInt();
    ClassDefinition classDefinition = lookupClassDefinition(factoryId, classId, version);
    if (classDefinition == null) {
        classDefinition = readClassDefinition(in, factoryId, classId, version);
    }
    return classDefinition;
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 4 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class Networking method handleFlowControlPacket.

private void handleFlowControlPacket(Address fromAddr, byte[] packet) throws IOException {
    BufferObjectDataInput input = createObjectDataInput(nodeEngine, packet);
    for (; ; ) {
        final long executionId = input.readLong();
        if (executionId == TERMINAL_EXECUTION_ID) {
            break;
        }
        final Map<SenderReceiverKey, SenderTasklet> senderMap = jobExecutionService.getSenderMap(executionId);
        for (; ; ) {
            final int vertexId = input.readInt();
            if (vertexId == TERMINAL_VERTEX_ID) {
                break;
            }
            int ordinal = input.readInt();
            int sendSeqLimitCompressed = input.readInt();
            final SenderTasklet t;
            if (senderMap != null && (t = senderMap.get(new SenderReceiverKey(vertexId, ordinal, fromAddr))) != null) {
                t.setSendSeqLimitCompressed(sendSeqLimitCompressed);
            }
        }
    }
}
Also used : SenderReceiverKey(com.hazelcast.jet.impl.execution.ExecutionContext.SenderReceiverKey) SenderTasklet(com.hazelcast.jet.impl.execution.SenderTasklet) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 5 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class AbstractSerializationService method toObject.

@Override
public final <T> T toObject(final Object object, Class aClass) {
    if (!(object instanceof Data)) {
        return (T) object;
    }
    Data data = (Data) object;
    if (isNullData(data)) {
        return null;
    }
    BufferPool pool = bufferPoolThreadLocal.get();
    BufferObjectDataInput in = pool.takeInputBuffer(data);
    try {
        ClassLocator.onStartDeserialization();
        final int typeId = data.getType();
        final SerializerAdapter serializer = serializerFor(typeId);
        if (serializer == null) {
            if (active) {
                throw newHazelcastSerializationException(typeId);
            }
            throw notActiveExceptionSupplier.get();
        }
        Object obj = serializer.read(in, aClass);
        if (managedContext != null) {
            obj = managedContext.initialize(obj);
        }
        return (T) obj;
    } catch (Throwable e) {
        throw handleException(e);
    } finally {
        ClassLocator.onFinishDeserialization();
        pool.returnInputBuffer(in);
    }
}
Also used : BufferPool(com.hazelcast.internal.serialization.impl.bufferpool.BufferPool) SerializationUtil.createSerializerAdapter(com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter) CompactWithSchemaStreamSerializerAdapter(com.hazelcast.internal.serialization.impl.compact.CompactWithSchemaStreamSerializerAdapter) CompactStreamSerializerAdapter(com.hazelcast.internal.serialization.impl.compact.CompactStreamSerializerAdapter) SerializationUtil.isNullData(com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData) Data(com.hazelcast.internal.serialization.Data) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Aggregations

BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)28 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)11 Data (com.hazelcast.internal.serialization.Data)10 BufferObjectDataOutput (com.hazelcast.internal.nio.BufferObjectDataOutput)6 HeapData (com.hazelcast.internal.serialization.impl.HeapData)5 IOException (java.io.IOException)5 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)2 SerializationUtil.isNullData (com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData)2 BufferPool (com.hazelcast.internal.serialization.impl.bufferpool.BufferPool)2 CompactStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactStreamSerializerAdapter)2 CompactWithSchemaStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactWithSchemaStreamSerializerAdapter)2 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 HazelcastException (com.hazelcast.core.HazelcastException)1 IOUtil.readData (com.hazelcast.internal.nio.IOUtil.readData)1 IOUtil.writeData (com.hazelcast.internal.nio.IOUtil.writeData)1