Search in sources :

Example 31 with PlatformOutputStream

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);
    }
}
Also used : PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 32 with PlatformOutputStream

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());
    }
}
Also used : PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 33 with PlatformOutputStream

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);
    }
}
Also used : PlatformTargetProxyImpl(org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 34 with PlatformOutputStream

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());
    }
}
Also used : PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory)

Example 35 with PlatformOutputStream

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));
    }
}
Also used : PlatformInputStream(org.apache.ignite.internal.processors.platform.memory.PlatformInputStream) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)51 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)48 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)46 BinaryRawReaderEx (org.apache.ignite.internal.binary.BinaryRawReaderEx)11 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IgniteException (org.apache.ignite.IgniteException)7 PlatformContext (org.apache.ignite.internal.processors.platform.PlatformContext)4 PlatformNativeException (org.apache.ignite.internal.processors.platform.PlatformNativeException)4 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)3 PlatformExtendedException (org.apache.ignite.internal.processors.platform.PlatformExtendedException)3 Nullable (org.jetbrains.annotations.Nullable)3 CacheException (javax.cache.CacheException)2 PlatformTargetProxyImpl (org.apache.ignite.internal.processors.platform.PlatformTargetProxyImpl)2 IOException (java.io.IOException)1 Map (java.util.Map)1 CacheEntryEvent (javax.cache.event.CacheEntryEvent)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ComputeJobResultPolicy (org.apache.ignite.compute.ComputeJobResultPolicy)1 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)1