use of com.hazelcast.jet.impl.util.ObjectWithPartitionId in project hazelcast-jet by hazelcast.
the class SenderTasklet method tryFillOutputBuffer.
private boolean tryFillOutputBuffer() {
try {
// header size + slot for writtenCount
outputBuffer.position(bufPosPastHeader + Bits.INT_SIZE_IN_BYTES);
int writtenCount = 0;
for (Object item; outputBuffer.position() < packetSizeLimit && isWithinLimit(sentSeq, sendSeqLimitCompressed) && (item = inbox.poll()) != null; writtenCount++) {
ObjectWithPartitionId itemWithpId = item instanceof ObjectWithPartitionId ? (ObjectWithPartitionId) item : new ObjectWithPartitionId(item, -1);
final int mark = outputBuffer.position();
outputBuffer.writeObject(itemWithpId.getItem());
sentSeq += estimatedMemoryFootprint(outputBuffer.position() - mark);
outputBuffer.writeInt(itemWithpId.getPartitionId());
}
outputBuffer.writeInt(bufPosPastHeader, writtenCount);
return writtenCount > 0;
} catch (IOException e) {
throw rethrow(e);
}
}
use of com.hazelcast.jet.impl.util.ObjectWithPartitionId in project hazelcast by hazelcast.
the class SenderTasklet method tryFillOutputBuffer.
private boolean tryFillOutputBuffer() {
try {
// header size + slot for writtenCount
outputBuffer.position(bufPosPastHeader + Bits.INT_SIZE_IN_BYTES);
int writtenCount = 0;
for (Object item; outputBuffer.position() < packetSizeLimit && isWithinLimit(sentSeq, sendSeqLimitCompressed) && (item = inbox.poll()) != null; writtenCount++) {
ObjectWithPartitionId itemWithPId = item instanceof ObjectWithPartitionId ? (ObjectWithPartitionId) item : new ObjectWithPartitionId(item, -1);
final int mark = outputBuffer.position();
outputBuffer.writeObject(itemWithPId.getItem());
sentSeq += estimatedMemoryFootprint(outputBuffer.position() - mark);
outputBuffer.writeInt(itemWithPId.getPartitionId());
}
outputBuffer.writeInt(bufPosPastHeader, writtenCount);
bytesOutCounter.inc(outputBuffer.position());
itemsOutCounter.inc(writtenCount);
return writtenCount > 0;
} catch (IOException e) {
throw rethrow(e);
}
}
use of com.hazelcast.jet.impl.util.ObjectWithPartitionId in project hazelcast by hazelcast.
the class SenderTasklet method tryFillInbox.
private void tryFillInbox() {
if (!inbox.isEmpty()) {
progTracker.notDone();
return;
}
if (instreamExhausted) {
return;
}
progTracker.notDone();
final ProgressState result = inboundEdgeStream.drainTo(addToInboxFunction);
progTracker.madeProgress(result.isMadeProgress());
instreamExhausted = result.isDone();
if (instreamExhausted) {
inbox.add(new ObjectWithPartitionId(DONE_ITEM, -1));
}
}
use of com.hazelcast.jet.impl.util.ObjectWithPartitionId in project hazelcast by hazelcast.
the class ExecutionPlan method memberToSenderConveyorMap.
/**
* Creates (if absent) for the given edge one sender tasklet per remote member,
* each with a single conveyor with a number of producer queues feeding it.
* Populates the {@link #senderMap} and {@link #tasklets} fields.
*/
private Map<Address, ConcurrentConveyor<Object>> memberToSenderConveyorMap(Map<String, Map<Address, ConcurrentConveyor<Object>>> edgeSenderConveyorMap, EdgeDef edge, String jobPrefix, InternalSerializationService jobSerializationService) {
assert !edge.isLocal() : "Edge is not distributed";
return edgeSenderConveyorMap.computeIfAbsent(edge.edgeId(), x -> {
final Map<Address, ConcurrentConveyor<Object>> addrToConveyor = new HashMap<>();
for (Address destAddr : remoteMembers.get()) {
final ConcurrentConveyor<Object> conveyor = createConveyorArray(1, edge.sourceVertex().localParallelism(), edge.getConfig().getQueueSize())[0];
@SuppressWarnings("unchecked") ComparatorEx<Object> origComparator = (ComparatorEx<Object>) edge.getOrderComparator();
ComparatorEx<ObjectWithPartitionId> adaptedComparator = origComparator == null ? null : (l, r) -> origComparator.compare(l.getItem(), r.getItem());
final InboundEdgeStream inboundEdgeStream = newEdgeStream(edge, conveyor, jobPrefix + "/toVertex:" + edge.destVertex().name() + "-toMember:" + destAddr, adaptedComparator);
final int destVertexId = edge.destVertex().vertexId();
final SenderTasklet t = new SenderTasklet(inboundEdgeStream, nodeEngine, destAddr, memberConnections.get(destAddr), destVertexId, edge.getConfig().getPacketSizeLimit(), executionId, edge.sourceVertex().name(), edge.sourceOrdinal(), jobSerializationService);
senderMap.computeIfAbsent(destVertexId, xx -> new HashMap<>()).computeIfAbsent(edge.destOrdinal(), xx -> new HashMap<>()).put(destAddr, t);
tasklets.add(t);
addrToConveyor.put(destAddr, conveyor);
}
return addrToConveyor;
});
}
use of com.hazelcast.jet.impl.util.ObjectWithPartitionId in project hazelcast-jet by hazelcast.
the class SenderTasklet method tryFillInbox.
private void tryFillInbox() {
if (!inbox.isEmpty()) {
progTracker.notDone();
return;
}
if (instreamExhausted) {
return;
}
progTracker.notDone();
final ProgressState result = inboundEdgeStream.drainTo(inbox::add);
progTracker.madeProgress(result.isMadeProgress());
instreamExhausted = result.isDone();
if (instreamExhausted) {
inbox.add(new ObjectWithPartitionId(DONE_ITEM, -1));
}
}
Aggregations