use of org.apache.geode.cache.Cache in project geode by apache.
the class GatewaySenderCreateFunction method execute.
@Override
public void execute(FunctionContext context) {
ResultSender<Object> resultSender = context.getResultSender();
Cache cache = CacheFactory.getAnyInstance();
String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
GatewaySenderFunctionArgs gatewaySenderCreateArgs = (GatewaySenderFunctionArgs) context.getArguments();
try {
GatewaySender createdGatewaySender = createGatewaySender(cache, gatewaySenderCreateArgs);
XmlEntity xmlEntity = new XmlEntity(CacheXml.GATEWAY_SENDER, "id", gatewaySenderCreateArgs.getId());
resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format(CliStrings.CREATE_GATEWAYSENDER__MSG__GATEWAYSENDER_0_CREATED_ON_1, new Object[] { createdGatewaySender.getId(), memberNameOrId })));
} catch (GatewaySenderException e) {
resultSender.lastResult(handleException(memberNameOrId, e.getMessage(), e));
} catch (Exception e) {
String exceptionMsg = e.getMessage();
if (exceptionMsg == null) {
exceptionMsg = CliUtil.stackTraceAsString(e);
}
resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, e));
}
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class ListIndexFunction method execute.
public void execute(final FunctionContext context) {
try {
final Set<IndexDetails> indexDetailsSet = new HashSet<IndexDetails>();
final Cache cache = getCache();
final DistributedMember member = cache.getDistributedSystem().getDistributedMember();
for (final Index index : cache.getQueryService().getIndexes()) {
indexDetailsSet.add(new IndexDetails(member, index));
}
context.getResultSender().lastResult(indexDetailsSet);
} catch (Exception e) {
context.getResultSender().sendException(e);
}
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class MemberRegionFunction method execute.
@Override
public void execute(FunctionContext context) {
Object[] args = (Object[]) context.getArguments();
String region = (String) args[0];
String functionId = (String) args[1];
Cache cache = CacheFactory.getAnyInstance();
try {
Function function = FunctionService.getFunction(functionId);
if (function == null) {
context.getResultSender().lastResult("For region on a member did not get function " + functionId);
}
Execution execution = FunctionService.onRegion(cache.getRegion(region));
if (execution == null) {
context.getResultSender().lastResult("For region on a member could not execute");
} else {
execution.execute(function);
context.getResultSender().lastResult("succeeded in executing on region " + region);
}
} catch (FunctionException e) {
context.getResultSender().lastResult("FunctionException in MemberRegionFunction =" + e.getMessage());
} catch (Exception e) {
context.getResultSender().lastResult("Exception in MemberRegionFunction =" + e.getMessage());
}
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class MembersForRegionFunction method execute.
@Override
public void execute(FunctionContext context) {
Map<String, String> resultMap = new HashMap<String, String>();
try {
Cache cache = CacheFactory.getAnyInstance();
String memberNameOrId = cache.getDistributedSystem().getDistributedMember().getId();
Object args = (Object) context.getArguments();
String regionName = ((String) args);
Region<Object, Object> region = cache.getRegion(regionName);
if (region != null) {
resultMap.put(memberNameOrId, "" + region.getAttributes().getScope().isLocal());
} else {
String regionWithPrefix = Region.SEPARATOR + regionName;
region = cache.getRegion(regionWithPrefix);
if (region != null) {
resultMap.put(memberNameOrId, "" + region.getAttributes().getScope().isLocal());
} else {
resultMap.put("", "");
}
}
context.getResultSender().lastResult(resultMap);
} catch (Exception ex) {
Cache cache = CacheFactory.getAnyInstance();
logger.info("MembersForRegionFunction exception {}", ex.getMessage(), ex);
resultMap.put("", "");
context.getResultSender().lastResult(resultMap);
}
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class TXJUnitTest method closeCache.
protected void closeCache() {
if (this.cache != null) {
if (this.txMgr != null) {
try {
this.txMgr.rollback();
} catch (IllegalStateException ignore) {
}
}
this.region = null;
this.txMgr = null;
Cache c = this.cache;
this.cache = null;
c.close();
}
}
Aggregations