use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformAffinityFunction method assignPartitions.
/**
* {@inheritDoc}
*/
@Override
public List<List<ClusterNode>> assignPartitions(AffinityFunctionContext affCtx) {
if ((overrideFlags & FLAG_ASSIGN_PARTITIONS) == 0) {
assert baseFunc != null;
return baseFunc.assignPartitions(affCtx);
}
assert ctx != null;
assert ptr != 0;
assert affCtx != null;
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeLong(ptr);
// Write previous assignment
PlatformAffinityUtils.writeAffinityFunctionContext(affCtx, writer, ctx);
out.synchronize();
// Secondly, AffinityFunctionContext can't be changed by the user.
if (baseTarget != null)
baseTarget.setCurrentAffinityFunctionContext(affCtx);
try {
ctx.gateway().affinityFunctionAssignPartitions(mem.pointer());
} finally {
if (baseTarget != null)
baseTarget.setCurrentAffinityFunctionContext(null);
}
// Read result
return PlatformAffinityUtils.readPartitionAssignment(ctx.reader(mem), ctx);
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformAffinityFunction method partition.
/**
* {@inheritDoc}
*/
@Override
public int partition(Object key) {
if ((overrideFlags & FLAG_PARTITION) == 0) {
assert baseFunc != null;
return baseFunc.partition(key);
}
assert ctx != null;
assert ptr != 0;
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeLong(ptr);
writer.writeObject(key);
out.synchronize();
return ctx.gateway().affinityFunctionPartition(mem.pointer());
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformAffinityFunction method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws IgniteException {
// userFunc is null when there is nothing overridden
if (userFunc == null)
return;
assert ignite != null;
ctx = PlatformUtils.platformContext(ignite);
assert ctx != null;
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeObject(userFunc);
out.synchronize();
baseTarget = baseFunc != null ? new PlatformAffinityFunctionTarget(ctx, baseFunc) : null;
PlatformTargetProxyImpl baseTargetProxy = baseTarget != null ? new PlatformTargetProxyImpl(baseTarget, ctx) : null;
ptr = ctx.gateway().affinityFunctionInit(mem.pointer(), baseTargetProxy);
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformAffinityFunction method removeNode.
/**
* {@inheritDoc}
*/
@Override
public void removeNode(UUID nodeId) {
if ((overrideFlags & FLAG_REMOVE_NODE) == 0) {
assert baseFunc != null;
baseFunc.removeNode(nodeId);
return;
}
assert ctx != null;
assert ptr != 0;
try (PlatformMemory mem = ctx.memory().allocate()) {
PlatformOutputStream out = mem.output();
BinaryRawWriterEx writer = ctx.writer(out);
writer.writeLong(ptr);
writer.writeUuid(nodeId);
out.synchronize();
ctx.gateway().affinityFunctionRemoveNode(mem.pointer());
}
}
use of org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream in project ignite by apache.
the class PlatformContextImpl method getBinaryType.
/**
* {@inheritDoc}
*/
@Override
@Nullable
public BinaryMetadata getBinaryType(String typeName) {
try (PlatformMemory mem0 = mem.allocate()) {
PlatformOutputStream out = mem0.output();
BinaryRawWriterEx writer = writer(out);
writer.writeString(typeName);
out.synchronize();
if (gateway().binaryTypeGet(mem0.pointer()) == 0)
return null;
PlatformInputStream in = mem0.input();
in.synchronize();
return PlatformUtils.readBinaryMetadata(reader(in));
}
}
Aggregations