public boolean send(Address target, Response response) { checkNotNull(target, "Target is required!"); if (thisAddress.equals(target)) { throw new IllegalArgumentException("Target is this node! -> " + target + ", response: " + response); } byte[] bytes = serializationService.toBytes(response); Packet packet = newResponsePacket(bytes, response.isUrgent()); return transmit(target, packet); }
public boolean send(Address target, Response response) { checkNotNull(target, "Target is required!"); if (thisAddress.equals(target)) { throw new IllegalArgumentException("Target is this node! -> " + target + ", response: " + response); } byte[] bytes = serializationService.toBytes(response); Packet packet = newResponsePacket(bytes, response.isUrgent()); return transmit(target, packet); }
private void sendOpControlPacket(Address address, OperationControl opControl) { heartbeatPacketsSend.inc(); if (address.equals(thisAddress)) { scheduler.execute(new ProcessOperationControlTask(opControl)); } else { Packet packet = new Packet(serializationService.toBytes(opControl)) .setPacketType(Packet.Type.OPERATION) .raiseFlags(FLAG_OP_CONTROL | FLAG_URGENT); nodeEngine.getNode().getConnectionManager().transmit(packet, address); } } }
private void sendOpControlPacket(Address address, OperationControl opControl) { heartbeatPacketsSend.inc(); if (address.equals(thisAddress)) { scheduler.execute(new ProcessOperationControlTask(opControl)); } else { Packet packet = new Packet(serializationService.toBytes(opControl)) .setPacketType(Packet.Type.OPERATION) .raiseFlags(FLAG_OP_CONTROL | FLAG_URGENT); nodeEngine.getNode().getConnectionManager().transmit(packet, address); } } }
public boolean send(Operation op, Connection connection) { byte[] bytes = serializationService.toBytes(op); int partitionId = op.getPartitionId(); Packet packet = new Packet(bytes, partitionId).setPacketType(Packet.Type.OPERATION); if (op.isUrgent()) { packet.raiseFlags(FLAG_URGENT); } return node.getConnectionManager().transmit(packet, connection); } }
public boolean send(Operation op, Connection connection) { byte[] bytes = serializationService.toBytes(op); int partitionId = op.getPartitionId(); Packet packet = new Packet(bytes, partitionId).setPacketType(Packet.Type.OPERATION); if (op.isUrgent()) { packet.raiseFlags(FLAG_URGENT); } return node.getConnectionManager().transmit(packet, connection); } }
Packet toNormalResponsePacket(long callId, int backupAcks, boolean urgent, Object value) { byte[] bytes; boolean isData = value instanceof Data; if (isData) { Data data = (Data) value; int dataLengthInBytes = data.totalSize(); bytes = new byte[OFFSET_DATA_PAYLOAD + dataLengthInBytes]; writeInt(bytes, OFFSET_DATA_LENGTH, dataLengthInBytes, useBigEndian); // this is a crucial part. If data is NativeMemoryData, instead of calling Data.toByteArray which causes a // byte-array to be created and a intermediate copy of the data, we immediately copy the NativeMemoryData // into the bytes for the packet. data.copyTo(bytes, OFFSET_DATA_PAYLOAD); } else if (value == null) { // since there are many 'null' responses we optimize this case as well. bytes = new byte[OFFSET_NOT_DATA + INT_SIZE_IN_BYTES]; writeInt(bytes, OFFSET_NOT_DATA, CONSTANT_TYPE_NULL, useBigEndian); } else { // for regular object we currently can't guess how big the bytes will be; so we just hand it // over to the serializationService to deal with it. The negative part is that this does lead to // an intermediate copy of the data. bytes = serializationService.toBytes(value, OFFSET_NOT_DATA, false); } writeResponsePrologueBytes(bytes, NORMAL_RESPONSE, callId, urgent); // backup-acks (will fit in a byte) bytes[OFFSET_BACKUP_ACKS] = (byte) backupAcks; // isData bytes[OFFSET_IS_DATA] = (byte) (isData ? 1 : 0); //the remaining part of the byte array is already filled, so we are done. return newResponsePacket(bytes, urgent); }
Packet toNormalResponsePacket(long callId, int backupAcks, boolean urgent, Object value) { byte[] bytes; boolean isData = value instanceof Data; if (isData) { Data data = (Data) value; int dataLengthInBytes = data.totalSize(); bytes = new byte[OFFSET_DATA_PAYLOAD + dataLengthInBytes]; writeInt(bytes, OFFSET_DATA_LENGTH, dataLengthInBytes, useBigEndian); // this is a crucial part. If data is NativeMemoryData, instead of calling Data.toByteArray which causes a // byte-array to be created and a intermediate copy of the data, we immediately copy the NativeMemoryData // into the bytes for the packet. data.copyTo(bytes, OFFSET_DATA_PAYLOAD); } else if (value == null) { // since there are many 'null' responses we optimize this case as well. bytes = new byte[OFFSET_NOT_DATA + INT_SIZE_IN_BYTES]; writeInt(bytes, OFFSET_NOT_DATA, CONSTANT_TYPE_NULL, useBigEndian); } else { // for regular object we currently can't guess how big the bytes will be; so we just hand it // over to the serializationService to deal with it. The negative part is that this does lead to // an intermediate copy of the data. bytes = serializationService.toBytes(value, OFFSET_NOT_DATA, false); } writeResponsePrologueBytes(bytes, NORMAL_RESPONSE, callId, urgent); // backup-acks (will fit in a byte) bytes[OFFSET_BACKUP_ACKS] = (byte) backupAcks; // isData bytes[OFFSET_IS_DATA] = (byte) (isData ? 1 : 0); //the remaining part of the byte array is already filled, so we are done. return newResponsePacket(bytes, urgent); }
void sendBindRequest(TcpIpConnection connection, Address remoteEndPoint, boolean reply) { connection.setEndPoint(remoteEndPoint); ioService.onSuccessfulConnection(remoteEndPoint); //make sure bind packet is the first packet sent to the end point. if (logger.isFinestEnabled()) { logger.finest("Sending bind packet to " + remoteEndPoint); } BindMessage bind = new BindMessage(ioService.getThisAddress(), remoteEndPoint, reply); byte[] bytes = ioService.getSerializationService().toBytes(bind); Packet packet = new Packet(bytes).setPacketType(Packet.Type.BIND); connection.write(packet); //now you can send anything... }
void sendBindRequest(TcpIpConnection connection, Address remoteEndPoint, boolean reply) { connection.setEndPoint(remoteEndPoint); ioService.onSuccessfulConnection(remoteEndPoint); //make sure bind packet is the first packet sent to the end point. if (logger.isFinestEnabled()) { logger.finest("Sending bind packet to " + remoteEndPoint); } BindMessage bind = new BindMessage(ioService.getThisAddress(), remoteEndPoint, reply); byte[] bytes = ioService.getSerializationService().toBytes(bind); Packet packet = new Packet(bytes).setPacketType(Packet.Type.BIND); connection.write(packet); //now you can send anything... }
Packet packet = new Packet(serializationService.toBytes(eventEnvelope), orderKey) .setPacketType(Packet.Type.EVENT);
Packet packet = new Packet(serializationService.toBytes(eventEnvelope), orderKey) .setPacketType(Packet.Type.EVENT);