Search in sources :

Example 96 with Cache

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));
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) Cache(org.apache.geode.cache.Cache)

Example 97 with Cache

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);
    }
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) Index(org.apache.geode.cache.query.Index) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails) HashSet(java.util.HashSet) Cache(org.apache.geode.cache.Cache)

Example 98 with Cache

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());
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) Execution(org.apache.geode.cache.execute.Execution) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) Cache(org.apache.geode.cache.Cache)

Example 99 with Cache

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);
    }
}
Also used : HashMap(java.util.HashMap) Cache(org.apache.geode.cache.Cache)

Example 100 with Cache

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();
    }
}
Also used : Cache(org.apache.geode.cache.Cache)

Aggregations

Cache (org.apache.geode.cache.Cache)1044 Region (org.apache.geode.cache.Region)478 Test (org.junit.Test)476 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)292 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)277 VM (org.apache.geode.test.dunit.VM)264 Host (org.apache.geode.test.dunit.Host)230 AttributesFactory (org.apache.geode.cache.AttributesFactory)229 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)177 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)176 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)164 LocalRegion (org.apache.geode.internal.cache.LocalRegion)153 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)123 ClientCache (org.apache.geode.cache.client.ClientCache)117 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)112 Properties (java.util.Properties)101 CacheException (org.apache.geode.cache.CacheException)101 RegionAttributes (org.apache.geode.cache.RegionAttributes)99 QueryService (org.apache.geode.cache.query.QueryService)95 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)93