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();
}
}
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();
}
}
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;
}
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);
}
}
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);
}
}
Aggregations