Search in sources :

Example 1 with PlatformContext

use of org.apache.ignite.internal.processors.platform.PlatformContext in project ignite by apache.

the class PlatformContinuousQueryRemoteFilter method evaluate.

/**
 * {@inheritDoc}
 */
@Override
public boolean evaluate(CacheEntryEvent evt) throws CacheEntryListenerException {
    long ptr0 = ptr;
    if (ptr0 == 0)
        deploy();
    lock.readLock().lock();
    try {
        if (closed)
            throw new CacheEntryListenerException("Failed to evaluate the filter because it has been closed.");
        PlatformContext platformCtx = PlatformUtils.platformContext(grid);
        return PlatformUtils.evaluateContinuousQueryEvent(platformCtx, ptr, evt);
    } finally {
        lock.readLock().unlock();
    }
}
Also used : PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException)

Example 2 with PlatformContext

use of org.apache.ignite.internal.processors.platform.PlatformContext in project ignite by apache.

the class PlatformContinuousQueryRemoteFilter method deploy.

/**
 * Deploy filter to native platform.
 */
private void deploy() {
    lock.writeLock().lock();
    try {
        // 1. Do not deploy if the filter has been closed concurrently.
        if (closed)
            throw new CacheEntryListenerException("Failed to deploy the filter because it has been closed.");
        // 2. Deploy.
        PlatformContext ctx = PlatformUtils.platformContext(grid);
        try (PlatformMemory mem = ctx.memory().allocate()) {
            PlatformOutputStream out = mem.output();
            BinaryRawWriterEx writer = ctx.writer(out);
            writer.writeObject(filter);
            out.synchronize();
            ptr = ctx.gateway().continuousQueryFilterCreate(mem.pointer());
        } catch (Exception e) {
            // 3. Close in case of failure.
            close();
            throw new CacheEntryListenerException("Failed to deploy the filter.", e);
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) 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) IOException(java.io.IOException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException)

Example 3 with PlatformContext

use of org.apache.ignite.internal.processors.platform.PlatformContext in project ignite by apache.

the class PlatformUtils method errorData.

/**
 * Get error data.
 *
 * @param err Error.
 * @return Error data.
 */
public static byte[] errorData(Throwable err) {
    if (err instanceof PlatformExtendedException) {
        PlatformContext ctx = ((PlatformExtendedException) err).context();
        try (PlatformMemory mem = ctx.memory().allocate()) {
            // Write error data.
            PlatformOutputStream out = mem.output();
            BinaryRawWriterEx writer = ctx.writer(out);
            try {
                PlatformUtils.writeErrorData(err, writer, ctx.kernalContext().log(PlatformContext.class));
            } finally {
                out.synchronize();
            }
            // Read error data into separate array.
            PlatformInputStream in = mem.input();
            in.synchronize();
            int len = in.remaining();
            assert len > 0;
            byte[] arr = in.array();
            byte[] res = new byte[len];
            System.arraycopy(arr, 0, res, 0, len);
            return res;
        }
    } else
        return null;
}
Also used : PlatformExtendedException(org.apache.ignite.internal.processors.platform.PlatformExtendedException) PlatformInputStream(org.apache.ignite.internal.processors.platform.memory.PlatformInputStream) PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext) 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 4 with PlatformContext

use of org.apache.ignite.internal.processors.platform.PlatformContext in project ignite by apache.

the class ClientCacheScanQueryRequest method createFilter.

/**
 * Creates the filter.
 *
 * @return Filter.
 * @param ctx Context.
 */
private IgniteBiPredicate createFilter(ClientConnectionContext ctx) {
    if (filterObj == null)
        return null;
    switch(filterPlatform) {
        case FILTER_PLATFORM_JAVA:
            return ((BinaryObject) filterObj).deserialize();
        case FILTER_PLATFORM_DOTNET:
            PlatformContext platformCtx = ctx.kernalContext().platform().context();
            String curPlatform = platformCtx.platform();
            if (!PlatformUtils.PLATFORM_DOTNET.equals(curPlatform)) {
                throw new IgniteException("ScanQuery filter platform is " + PlatformUtils.PLATFORM_DOTNET + ", current platform is " + curPlatform);
            }
            return platformCtx.createCacheEntryFilter(filterObj, 0);
        case FILTER_PLATFORM_CPP:
        default:
            throw new UnsupportedOperationException("Invalid client ScanQuery filter code: " + filterPlatform);
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteException(org.apache.ignite.IgniteException) PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext)

Example 5 with PlatformContext

use of org.apache.ignite.internal.processors.platform.PlatformContext in project ignite by apache.

the class ClientCacheScanQueryRequest method createFilter.

/**
 * Creates the filter.
 *
 * @return Filter.
 * @param ctx Context.
 */
private static IgniteBiPredicate createFilter(GridKernalContext ctx, Object filterObj, byte filterPlatform) {
    if (filterObj == null)
        return null;
    switch(filterPlatform) {
        case ClientPlatform.JAVA:
            return ((BinaryObject) filterObj).deserialize();
        case ClientPlatform.DOTNET:
            PlatformContext platformCtx = ctx.platform().context();
            String curPlatform = platformCtx.platform();
            if (!PlatformUtils.PLATFORM_DOTNET.equals(curPlatform)) {
                throw new IgniteException("ScanQuery filter platform is " + PlatformUtils.PLATFORM_DOTNET + ", current platform is " + curPlatform);
            }
            return platformCtx.createCacheEntryFilter(filterObj, 0);
        case ClientPlatform.CPP:
        default:
            throw new UnsupportedOperationException("Invalid client ScanQuery filter code: " + filterPlatform);
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteException(org.apache.ignite.IgniteException) PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext)

Aggregations

PlatformContext (org.apache.ignite.internal.processors.platform.PlatformContext)9 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)4 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)4 IgniteException (org.apache.ignite.IgniteException)3 BinaryObject (org.apache.ignite.binary.BinaryObject)3 BinaryRawWriterEx (org.apache.ignite.internal.binary.BinaryRawWriterEx)3 CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)2 PlatformInputStream (org.apache.ignite.internal.processors.platform.memory.PlatformInputStream)2 IOException (java.io.IOException)1 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)1 PlatformExtendedException (org.apache.ignite.internal.processors.platform.PlatformExtendedException)1 PlatformProcessor (org.apache.ignite.internal.processors.platform.PlatformProcessor)1