Package com.hazelcast.nio

Examples of com.hazelcast.nio.BufferObjectDataOutput


            return cd;
        }

        private void setClassDefBinary(ClassDefinitionImpl cd) {
            if (cd.getBinary() == null) {
                final BufferObjectDataOutput out = serializationService.pop();
                try {
                    cd.writeData(out);
                    final byte[] binary = out.toByteArray();
                    out.clear();
                    compress(binary, out);
                    cd.setBinary(out.toByteArray());
                } catch (IOException e) {
                    throw new HazelcastSerializationException(e);
                } finally {
                    serializationService.push(out);
                }
View Full Code Here


            return;
        }
        final Object actualValue;
        if (binary) {
            // WARNING: we can't pass original Data to the user
            BufferObjectDataOutput out = serializationService.createObjectDataOutput(value.totalSize());
            try {
                value.writeData(out);
                // buffer size is exactly equal to binary size, no need to copy array.
                actualValue = out.getBuffer();
            } catch (IOException e) {
                throw new HazelcastException(e);
            } finally {
                IOUtil.closeResource(out);
            }
View Full Code Here

        final Map<Long, Object> objectMap = new HashMap<Long, Object>(map.size());
        if (binary) {
            // WARNING: we can't pass original Data to the user
            // TODO: @mm - is there really an advantage of using binary storeAll?
            // since we need to do array copy for each item.
            BufferObjectDataOutput out = serializationService.createObjectDataOutput(OUTPUT_SIZE);
            try {
                for (Map.Entry<Long, Data> entry : map.entrySet()) {
                    entry.getValue().writeData(out);
                    objectMap.put(entry.getKey(), out.toByteArray());
                    out.clear();
                }
            } catch (IOException e) {
                throw new HazelcastException(e);
            } finally {
                IOUtil.closeResource(out);
View Full Code Here

        return null;
    }

    public void send(JoinMessage joinMessage) {
        if (!running) return;
        final BufferObjectDataOutput out = sendOutput;
        synchronized (sendLock) {
            try {
                out.writeByte(Packet.VERSION);
                out.writeObject(joinMessage);
                datagramPacketSend.setData(out.toByteArray());
                multicastSocket.send(datagramPacketSend);
                out.clear();
            } catch (IOException e) {
                logger.warning("You probably have too long Hazelcast configuration!", e);
            }
        }
    }
View Full Code Here

        return serializer.read(in);
    }

    @SuppressWarnings("unchecked")
    public byte[] write(Object object) throws IOException {
        final BufferObjectDataOutput out = service.pop();
        byte[] bytes;
        try {
            serializer.write(out, object);
            bytes = out.toByteArray();
        } finally {
            service.push(out);
        }
        return bytes;
    }
View Full Code Here

        if (!(out instanceof BufferObjectDataOutput)) {
            throw new IllegalArgumentException("ObjectDataOutput must be instance of BufferObjectDataOutput!");
        }
        ClassDefinition cd = context.lookupOrRegisterClassDefinition(p);

        BufferObjectDataOutput bufferedOut = (BufferObjectDataOutput) out;
        DefaultPortableWriter writer = new DefaultPortableWriter(this, bufferedOut, cd);
        p.writePortable(writer);
        writer.end();
    }
View Full Code Here

    private byte[] createReplicationData(List<Operation> tasks) throws IOException {
        byte[] data;
        NodeEngine nodeEngine = getNodeEngine();
        SerializationService serializationService = nodeEngine.getSerializationService();
        BufferObjectDataOutput out = serializationService.createObjectDataOutput(DEFAULT_DATA_OUTPUT_BUFFER_SIZE);
        try {
            out.writeInt(tasks.size());
            for (Operation task : tasks) {
                serializationService.writeObject(out, task);
            }
            data = out.toByteArray();
        } finally {
            closeResource(out);
        }
        return data;
    }
View Full Code Here

    private void spawnMigrationRequestTask(Address destination, long[] replicaVersions, Collection<Operation> tasks)
            throws IOException {
        NodeEngine nodeEngine = getNodeEngine();

        SerializationService serializationService = nodeEngine.getSerializationService();
        BufferObjectDataOutput out = createDataOutput(serializationService);

        out.writeInt(tasks.size());
        Iterator<Operation> iter = tasks.iterator();
        while (iter.hasNext()) {
            Operation task = iter.next();
            if (task instanceof NonThreadSafe) {
                serializationService.writeObject(out, task);
View Full Code Here

        // register class def
        transferClassDefinition(data, serializationService, serializationService2);

        // emulate socket write by writing data to stream
        BufferObjectDataOutput out = serializationService.createObjectDataOutput(1024);
        out.writeData(data);
        byte[] bytes = out.toByteArray();
        byte[] header = ((PortableDataOutput) out).getPortableHeader();

        // emulate socket read by reading data from stream
        BufferObjectDataInput in = serializationService2.createObjectDataInput(new DefaultData(0, bytes, 0, header));
        data = in.readData();
View Full Code Here

            Queue<BufferObjectDataOutput> outputQueue = map.get(t);
            if (outputQueue == null) {
                outputQueue = new ArrayDeque<BufferObjectDataOutput>(3);
                map.put(t, outputQueue);
            }
            BufferObjectDataOutput out = outputQueue.poll();
            if (out == null) {
                out = serializationService.createObjectDataOutput(bufferSize);
            }
            return out;
        }
View Full Code Here

TOP

Related Classes of com.hazelcast.nio.BufferObjectDataOutput

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.