use of com.hazelcast.internal.nio.BufferObjectDataOutput in project hazelcast by hazelcast.
the class MulticastService method send.
public void send(JoinMessage joinMessage) {
if (!running) {
return;
}
final BufferObjectDataOutput out = sendOutput;
synchronized (sendLock) {
try {
out.writeByte(Packet.VERSION);
out.writeObject(joinMessage);
byte[] processed = outputProcessor != null ? outputProcessor.process(out.toByteArray()) : out.toByteArray();
datagramPacketSend.setData(processed);
multicastSocket.send(datagramPacketSend);
out.clear();
} catch (IOException e) {
// usually catching EPERM errno
// see https://github.com/hazelcast/hazelcast/issues/7198
// For details about the causes look at the following discussion:
// https://groups.google.com/forum/#!msg/comp.protocols.tcp-ip/Qou9Sfgr77E/mVQAPaeI-VUJ
logger.warning("Sending multicast datagram failed. Exception message saying the operation is not permitted " + "usually means the underlying OS is not able to send packets at a given pace. " + "It can be caused by starting several hazelcast members in parallel when the members send " + "their join message nearly at the same time.", e);
}
}
}
use of com.hazelcast.internal.nio.BufferObjectDataOutput in project hazelcast by hazelcast.
the class Networking method createFlowControlPacket.
private Map<Address, byte[]> createFlowControlPacket() throws IOException {
class MemberData {
final BufferObjectDataOutput output = createObjectDataOutput(nodeEngine, lastFlowPacketSize);
final Connection memberConnection;
Long startedExecutionId;
MemberData(Address address) {
memberConnection = getMemberConnection(nodeEngine, address);
}
}
Map<Address, MemberData> res = new HashMap<>();
for (ExecutionContext execCtx : jobExecutionService.getExecutionContexts()) {
Map<SenderReceiverKey, ReceiverTasklet> receiverMap = execCtx.receiverMap();
if (receiverMap == null) {
continue;
}
for (Entry<SenderReceiverKey, ReceiverTasklet> en : receiverMap.entrySet()) {
assert !en.getKey().address.equals(nodeEngine.getThisAddress());
MemberData md = res.computeIfAbsent(en.getKey().address, address -> new MemberData(address));
if (md.startedExecutionId == null) {
md.startedExecutionId = execCtx.executionId();
md.output.writeLong(md.startedExecutionId);
}
assert en.getKey().vertexId != TERMINAL_VERTEX_ID;
md.output.writeInt(en.getKey().vertexId);
md.output.writeInt(en.getKey().ordinal);
md.output.writeInt(en.getValue().updateAndGetSendSeqLimitCompressed(md.memberConnection));
}
for (MemberData md : res.values()) {
if (md.startedExecutionId != null) {
// write a mark to terminate values for an execution
md.output.writeInt(TERMINAL_VERTEX_ID);
md.startedExecutionId = null;
}
}
}
for (MemberData md : res.values()) {
assert md.output.position() > 0;
// write a mark to terminate all executions
// Execution IDs are generated using Flake ID generator and those are >0 normally, we
// use MIN_VALUE as a terminator.
md.output.writeLong(TERMINAL_EXECUTION_ID);
}
// finalize the packets
int maxSize = 0;
for (Entry<Address, MemberData> entry : res.entrySet()) {
byte[] data = entry.getValue().output.toByteArray();
// we break type safety to avoid creating a new map, we replace the values to a different type in place
@SuppressWarnings({ "unchecked", "rawtypes" }) Entry<Address, byte[]> entry1 = (Entry) entry;
entry1.setValue(data);
if (data.length > maxSize) {
maxSize = data.length;
}
}
lastFlowPacketSize = maxSize;
return (Map) res;
}
use of com.hazelcast.internal.nio.BufferObjectDataOutput in project hazelcast by hazelcast.
the class Networking method createStreamPacketHeader.
public static byte[] createStreamPacketHeader(NodeEngine nodeEngine, long executionId, int destinationVertexId, int ordinal) {
try (BufferObjectDataOutput output = createObjectDataOutput(nodeEngine, PACKET_HEADER_SIZE)) {
output.writeLong(executionId);
output.writeInt(destinationVertexId);
output.writeInt(ordinal);
return output.toByteArray();
} catch (IOException e) {
throw sneakyThrow(e);
}
}
use of com.hazelcast.internal.nio.BufferObjectDataOutput in project hazelcast by hazelcast.
the class ReceiverTaskletTest method pushObjects.
private void pushObjects(Object... objs) throws IOException {
final BufferObjectDataOutput out = serService.createObjectDataOutput();
// packet header
out.writeLong(0);
out.writeInt(0);
out.writeInt(0);
// the packet
out.writeInt(objs.length);
for (Object obj : objs) {
out.writeObject(obj);
// partition id
out.writeInt(Math.abs(obj.hashCode()));
}
queue.add(out.toByteArray());
}
use of com.hazelcast.internal.nio.BufferObjectDataOutput in project hazelcast by hazelcast.
the class BufferPoolTest method takeOutputBuffer_whenPooledInstance.
// ======================= out ==========================================
@Test
public void takeOutputBuffer_whenPooledInstance() {
BufferObjectDataOutput found1 = bufferPool.takeOutputBuffer();
bufferPool.returnOutputBuffer(found1);
BufferObjectDataOutput found2 = bufferPool.takeOutputBuffer();
assertSame(found1, found2);
}
Aggregations