use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class TestFunction method executeFunctionReturningArgs.
public void executeFunctionReturningArgs(FunctionContext context) {
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
LogWriter logger = ds.getLogWriter();
logger.info("Executing executeFunctionReturningArgs in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
if (!hasResult()) {
return;
}
Object[] args = (Object[]) context.getArguments();
if (args != null) {
context.getResultSender().lastResult(args[0]);
} else {
context.getResultSender().lastResult(Boolean.FALSE);
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class TestFunction method execute1.
public void execute1(FunctionContext context) {
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
LogWriter logger = ds.getLogWriter();
logger.info("Executing execute1 in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
if (!hasResult()) {
return;
}
if (context.getArguments() instanceof Boolean) {
// context.getResultSender().sendResult();
context.getResultSender().lastResult((Serializable) context.getArguments());
} else if (context.getArguments() instanceof String) {
/*
* String key = (String)context.getArguments(); return key;
*/
context.getResultSender().lastResult((Serializable) context.getArguments());
} else if (context.getArguments() instanceof Set) {
Set origKeys = (Set) context.getArguments();
ArrayList vals = new ArrayList();
for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
Object val = i.next();
if (val != null) {
vals.add(val);
}
}
/* return vals; */
context.getResultSender().lastResult(vals);
} else {
/* return Boolean.FALSE; */
context.getResultSender().lastResult(Boolean.FALSE);
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class TestFunction method execute2.
public void execute2(FunctionContext context) {
if (context instanceof RegionFunctionContext) {
RegionFunctionContext rfContext = (RegionFunctionContext) context;
rfContext.getDataSet().getCache().getLogger().info("Executing function : TestFunction2.execute " + rfContext);
if (rfContext.getArguments() instanceof Boolean) {
/* return rfContext.getArguments(); */
if (hasResult()) {
rfContext.getResultSender().lastResult((Serializable) rfContext.getArguments());
} else {
rfContext.getDataSet().getCache().getLogger().info("Executing function : TestFunction2.execute " + rfContext);
while (true && !rfContext.getDataSet().isDestroyed()) {
rfContext.getDataSet().getCache().getLogger().info("For Bug43513 ");
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
return;
}
}
}
} else if (rfContext.getArguments() instanceof String) {
String key = (String) rfContext.getArguments();
if (key.equals("TestingTimeOut")) {
// PRFunctionExecutionDUnitTest#testRemoteMultiKeyExecution_timeout
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
rfContext.getDataSet().getCache().getLogger().warning("Got Exception : Thread Interrupted" + e);
}
}
if (PartitionRegionHelper.isPartitionedRegion(rfContext.getDataSet())) {
/*
* return (Serializable)PartitionRegionHelper.getLocalDataForContext(rfContext).get(key);
*/
rfContext.getResultSender().lastResult((Serializable) PartitionRegionHelper.getLocalDataForContext(rfContext).get(key));
} else {
rfContext.getResultSender().lastResult((Serializable) rfContext.getDataSet().get(key));
}
/* return (Serializable)rfContext.getDataSet().get(key); */
} else if (rfContext.getArguments() instanceof Set) {
Set origKeys = (Set) rfContext.getArguments();
ArrayList vals = new ArrayList();
for (Object key : origKeys) {
Object val = PartitionRegionHelper.getLocalDataForContext(rfContext).get(key);
if (val != null) {
vals.add(val);
}
}
rfContext.getResultSender().lastResult(vals);
/* return vals; */
} 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.FALSE);
}
} else {
if (hasResult()) {
context.getResultSender().lastResult(Boolean.FALSE);
} else {
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
LogWriter logger = ds.getLogWriter();
logger.info("Executing in TestFunction on Server : " + ds.getDistributedMember() + "with Context : " + context);
while (ds.isConnected()) {
logger.fine("Just executing function in infinite loop for Bug43513");
try {
Thread.sleep(250);
} catch (InterruptedException e) {
return;
}
}
}
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class TestFunction method executeHAAndNonHAOnRegion.
public void executeHAAndNonHAOnRegion(FunctionContext context) {
List<CacheServer> servers = CacheFactory.getAnyInstance().getCacheServers();
ArrayList<String> args = (ArrayList<String>) context.getArguments();
RegionFunctionContext rfContext = (RegionFunctionContext) context;
rfContext.getDataSet().getCache().getLogger().info("Executing function : executeHAAndNonHAOnRegion " + rfContext);
Region r = CacheFactory.getAnyInstance().getRegion(args.get(0));
String testName = args.get(1);
Integer numTimesStopped = (Integer) r.get("stopped");
Integer numTimesSentResult = (Integer) r.get("sentresult");
if (context.isPossibleDuplicate()) {
if (testName.equals("regionExecutionHATwoServerDown")) {
if ((Integer) r.get("stopped") == 2) {
if (numTimesSentResult == null) {
r.put("sentresult", 1);
} else {
r.put("sentresult", ++numTimesSentResult);
}
context.getResultSender().lastResult(args.get(0));
} else {
r.put("stopped", ++numTimesStopped);
for (CacheServer s : servers) {
if (((CacheServerImpl) s).getSystem().getDistributedMember().equals(((GemFireCacheImpl) CacheFactory.getAnyInstance()).getMyId())) {
s.stop();
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
ds.disconnect();
}
}
}
} else if (testName.equals("regionExecutionHAOneServerDown")) {
if (numTimesSentResult == null) {
r.put("sentresult", 1);
} else {
r.put("sentresult", ++numTimesSentResult);
}
context.getResultSender().lastResult(args.get(0));
} else {
context.getResultSender().lastResult(args.get(0));
}
} else {
if (numTimesStopped == null) {
r.put("stopped", 1);
} else {
r.put("stopped", ++numTimesStopped);
}
for (CacheServer s : servers) {
if (((CacheServerImpl) s).getSystem().getDistributedMember().equals(((GemFireCacheImpl) CacheFactory.getAnyInstance()).getMyId())) {
s.stop();
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
ds.disconnect();
}
}
context.getResultSender().lastResult(args.get(0));
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class TestFunction method executeFunctionRunningForLongTime.
public void executeFunctionRunningForLongTime(FunctionContext context) {
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
LogWriter logger = ds.getLogWriter();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
logger.info("Exception in executeFunctionRunningForLongTime");
}
context.getResultSender().lastResult("Ran executeFunctionRunningForLongTime for 10000000");
}
Aggregations