use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.
the class TestFunction method execute9.
public void execute9(FunctionContext context) {
if (context instanceof RegionFunctionContext) {
RegionFunctionContext rfContext = (RegionFunctionContext) context;
rfContext.getDataSet().getCache().getLogger().info("Executing function : TestFunction9.execute " + rfContext);
if (rfContext.getArguments() instanceof Boolean) {
rfContext.getResultSender().lastResult((Serializable) rfContext.getArguments());
} else if (rfContext.getArguments() instanceof String) {
String key = (String) rfContext.getArguments();
if (key.equals("TestingTimeOut")) {
// PRFunctionExecutionDUnitTest#testRemoteMultiKeyExecution_timeout
try {
synchronized (this) {
this.wait(2000);
}
} catch (InterruptedException e) {
rfContext.getDataSet().getCache().getLogger().warning("Got Exception : Thread Interrupted" + e);
}
}
if (context instanceof RegionFunctionContext) {
RegionFunctionContext prContext = (RegionFunctionContext) context;
if (PartitionRegionHelper.isPartitionedRegion(prContext.getDataSet())) {
rfContext.getResultSender().lastResult((Serializable) PartitionRegionHelper.getLocalDataForContext(prContext).get(key));
}
}
} else if (rfContext.getArguments() instanceof Set) {
Set origKeys = (Set) rfContext.getArguments();
ArrayList vals = new ArrayList();
for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
Object val = null;
if (context instanceof RegionFunctionContext) {
RegionFunctionContext prContext = (RegionFunctionContext) context;
val = PartitionRegionHelper.getLocalDataForContext(prContext).get(i.next());
} else {
val = rfContext.getDataSet().get(i.next());
}
if (i.hasNext())
rfContext.getResultSender().sendResult((Serializable) val);
else
rfContext.getResultSender().lastResult((Serializable) val);
if (val != null) {
vals.add(val);
}
}
} else if (rfContext.getArguments() instanceof HashMap) {
HashMap putData = (HashMap) rfContext.getArguments();
for (Iterator i = putData.entrySet().iterator(); i.hasNext(); ) {
Map.Entry me = (Map.Entry) i.next();
rfContext.getDataSet().put(me.getKey(), me.getValue());
}
rfContext.getResultSender().lastResult(Boolean.TRUE);
} else {
rfContext.getResultSender().lastResult(Boolean.TRUE);
}
} else {
}
context.getResultSender().lastResult("ABCD");
}
use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.
the class TestFunction method execute3.
public void execute3(FunctionContext context) {
if (context instanceof RegionFunctionContext) {
RegionFunctionContext prContext = (RegionFunctionContext) context;
prContext.getDataSet().getCache().getLogger().info("Executing function : TestFunction3.execute " + prContext);
if (prContext.getArguments() instanceof Set) {
Set origKeys = (Set) prContext.getArguments();
ArrayList vals = new ArrayList();
for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
Object val = PartitionRegionHelper.getLocalDataForContext(prContext).get(i.next());
if (val != null) {
vals.add(val);
}
}
prContext.getResultSender().lastResult(vals);
/* return vals; */
} else if (prContext.getFilter() != null) {
Set origKeys = prContext.getFilter();
ArrayList vals = new ArrayList();
for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
Object val = PartitionRegionHelper.getLocalDataForContext(prContext).get(i.next());
if (val != null) {
vals.add(val);
}
}
/* return vals; */
// prContext.getResultSender().sendResult(vals);
prContext.getResultSender().lastResult(vals);
} else {
/* return Boolean.FALSE; */
// prContext.getResultSender().sendResult(Boolean.FALSE);
prContext.getResultSender().lastResult(Boolean.FALSE);
}
} else {
/* return Boolean.FALSE; */
// context.getResultSender().sendResult(Boolean.FALSE);
context.getResultSender().lastResult(Boolean.FALSE);
}
}
use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.
the class RemoteTransactionDUnitTest method testNestedTxFunction.
@Test
public void testNestedTxFunction() {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore1 = host.getVM(1);
VM datastore2 = host.getVM(2);
initAccessorAndDataStore(accessor, datastore1, datastore2, 0);
class NestedTxFunction2 extends FunctionAdapter {
static final String id = "NestedTXFunction2";
@Override
public void execute(FunctionContext context) {
TXManagerImpl mgr = getGemfireCache().getTxManager();
assertNotNull(mgr.getTXState());
try {
mgr.commit();
fail("expected exceptio not thrown");
} catch (UnsupportedOperationInTransactionException e) {
}
context.getResultSender().lastResult(Boolean.TRUE);
}
@Override
public String getId() {
return id;
}
}
class NestedTxFunction extends FunctionAdapter {
static final String id = "NestedTXFunction";
@Override
public void execute(FunctionContext context) {
Region r = null;
if (context instanceof RegionFunctionContext) {
r = PartitionRegionHelper.getLocalDataForContext((RegionFunctionContext) context);
} else {
r = getGemfireCache().getRegion(CUSTOMER);
}
assertNotNull(getGemfireCache().getTxManager().getTXState());
PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
Set filter = new HashSet();
filter.add(expectedCustId);
LogWriterUtils.getLogWriter().info("SWAP:inside NestedTxFunc calling func2:");
r.put(expectedCustId, expectedCustomer);
FunctionService.onRegion(pr).withFilter(filter).execute(new NestedTxFunction2()).getResult();
assertNotNull(getGemfireCache().getTxManager().getTXState());
context.getResultSender().lastResult(Boolean.TRUE);
}
@Override
public boolean optimizeForWrite() {
return true;
}
@Override
public String getId() {
return id;
}
}
accessor.invoke(new SerializableCallable() {
public Object call() throws Exception {
TXManagerImpl mgr = getGemfireCache().getTxManager();
PartitionedRegion pr = (PartitionedRegion) getGemfireCache().getRegion(CUSTOMER);
mgr.begin();
Set filter = new HashSet();
filter.add(expectedCustId);
FunctionService.onRegion(pr).withFilter(filter).execute(new NestedTxFunction()).getResult();
assertNotNull(getGemfireCache().getTxManager().getTXState());
mgr.commit();
assertEquals(expectedCustomer, pr.get(expectedCustId));
return null;
}
});
}
use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.
the class LuceneGetPageFunction method execute.
@Override
public void execute(FunctionContext context) {
try {
RegionFunctionContext ctx = (RegionFunctionContext) context;
Region region = PartitionRegionHelper.getLocalDataForContext(ctx);
Set<?> keys = ctx.getFilter();
List<PageEntry> results = new PageResults(keys.size());
for (Object key : keys) {
PageEntry entry = getEntry(region, key);
if (entry != null) {
results.add(entry);
}
}
ctx.getResultSender().lastResult(results);
} catch (CacheClosedException | PrimaryBucketException e) {
logger.debug("Exception during lucene query function", e);
throw new InternalFunctionInvocationTargetException(e);
}
}
use of org.apache.geode.cache.execute.RegionFunctionContext in project geode by apache.
the class RegionSizeFunction method execute.
public void execute(FunctionContext context) {
RegionFunctionContext rfc = (RegionFunctionContext) context;
context.getResultSender().lastResult(rfc.getDataSet().size());
}
Aggregations