Search in sources :

Example 76 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class RestAPIsWithSSLDUnitTest method closeCache.

private void closeCache() {
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && !cache.isClosed()) {
        cache.close();
        cache.getDistributedSystem().disconnect();
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 77 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class PartitionRegionHelper method getPartitionRegionInfo.

/**
   * Gathers details about the specified partitioned region. Returns null if the partitioned region
   * is not locally defined.
   * 
   * @param region the region to get info about
   * @return details about the specified partitioned region
   * @since GemFire 6.0
   */
public static PartitionRegionInfo getPartitionRegionInfo(final Region<?, ?> region) {
    try {
        PartitionedRegion partitionedRegion = isPartitionedCheck(region);
        InternalCache cache = (InternalCache) region.getCache();
        return partitionedRegion.getRedundancyProvider().buildPartitionedRegionInfo(false, cache.getInternalResourceManager().getLoadProbe());
    } catch (ClassCastException ignore) {
    // not a PR so return null
    }
    return null;
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 78 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class DSClock method cancelAndScheduleNewCacheTimerTask.

/**
   * Cancel the previous slow down task (If it exists) and schedule a new one.
   */
private void cancelAndScheduleNewCacheTimerTask(long offset) {
    InternalCache cache = GemFireCacheImpl.getInstance();
    if (cache != null && !cache.isClosed()) {
        if (this.cacheTimeTask != null) {
            this.cacheTimeTask.cancel();
        }
        cacheTimeTask = new CacheTimeTask(offset);
        SystemTimer timer = cache.getCCPTimer();
        timer.scheduleAtFixedRate(cacheTimeTask, 1, /* Start after 1ms */
        2);
        if (logger.isDebugEnabled()) {
            logger.debug("Started a timer task to suspend cache time for new lower offset of {}ms and current offset is: {}", offset, cacheTimeDelta);
        }
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) SystemTimer(org.apache.geode.internal.SystemTimer)

Example 79 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class MemberHealthEvaluator method checkCacheRequiredRolesMeet.

/**
   * The function keeps updating the health of the cache based on roles required by the regions and
   * their reliability policies.
   */
private void checkCacheRequiredRolesMeet(List status) {
    try {
        InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
        CachePerfStats cPStats = cache.getCachePerfStats();
        if (cPStats.getReliableRegionsMissingFullAccess() > 0) {
            // health is okay.
            int numRegions = cPStats.getReliableRegionsMissingFullAccess();
            status.add(okayHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_BUT_ARE_CONFIGURED_FOR_FULL_ACCESS.toLocalizedString(numRegions)));
        } else if (cPStats.getReliableRegionsMissingLimitedAccess() > 0) {
            // health is poor
            int numRegions = cPStats.getReliableRegionsMissingLimitedAccess();
            status.add(poorHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_AND_CONFIGURED_WITH_LIMITED_ACCESS.toLocalizedString(numRegions)));
        } else if (cPStats.getReliableRegionsMissingNoAccess() > 0) {
            // health is poor
            int numRegions = cPStats.getReliableRegionsMissingNoAccess();
            status.add(poorHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_AND_CONFIGURED_WITHOUT_ACCESS.toLocalizedString(numRegions)));
        }
    } catch (CancelException ignore) {
    }
}
Also used : CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) InternalCache(org.apache.geode.internal.cache.InternalCache) CancelException(org.apache.geode.CancelException)

Example 80 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class AddFreeItemToOrders method execute.

public void execute(FunctionContext context) {
    Region region = null;
    List<Object> vals = new ArrayList<Object>();
    List<Object> keys = new ArrayList<Object>();
    List<Object> argsList = new ArrayList<Object>();
    Object[] argsArray = null;
    if (context.getArguments() instanceof Boolean) {
    } else if (context.getArguments() instanceof String) {
        String arg = (String) context.getArguments();
    } else if (context.getArguments() instanceof Vector) {
    } else if (context.getArguments() instanceof Object[]) {
        argsArray = (Object[]) context.getArguments();
        argsList = Arrays.asList(argsArray);
    } else {
        System.out.println("AddFreeItemToOrders : Invalid Arguments");
    }
    InternalCache cache = null;
    try {
        cache = (InternalCache) CacheFactory.getAnyInstance();
        cache.getCacheConfig().setPdxReadSerialized(true);
        region = cache.getRegion("orders");
    } catch (CacheClosedException ex) {
        vals.add("NoCacheFoundResult");
        context.getResultSender().lastResult(vals);
    }
    String oql = "SELECT DISTINCT entry.key FROM /orders.entries entry WHERE entry.value.totalPrice > $1";
    Object[] queryArgs = new Object[1];
    queryArgs[0] = argsList.get(0);
    final Query query = cache.getQueryService().newQuery(oql);
    SelectResults result = null;
    try {
        result = (SelectResults) query.execute(queryArgs);
        int resultSize = result.size();
        if (result instanceof Collection<?>)
            for (Object item : result) {
                keys.add(item);
            }
    } catch (FunctionDomainException e) {
        if (cache != null)
            cache.getLogger().info("Caught FunctionDomainException while executing function AddFreeItemToOrders: " + e.getMessage());
    } catch (TypeMismatchException e) {
        if (cache != null)
            cache.getLogger().info("Caught TypeMismatchException while executing function AddFreeItemToOrders: " + e.getMessage());
    } catch (NameResolutionException e) {
        if (cache != null)
            cache.getLogger().info("Caught NameResolutionException while executing function AddFreeItemToOrders: " + e.getMessage());
    } catch (QueryInvocationTargetException e) {
        if (cache != null)
            cache.getLogger().info("Caught QueryInvocationTargetException while executing function AddFreeItemToOrders" + e.getMessage());
    }
    // class has to be in classpath.
    try {
        Item it = (Item) (argsList.get(1));
        for (Object key : keys) {
            Object obj = region.get(key);
            if (obj instanceof PdxInstance) {
                PdxInstance pi = (PdxInstance) obj;
                Order receivedOrder = (Order) pi.getObject();
                receivedOrder.addItem(it);
                region.put(key, receivedOrder);
            }
        }
        context.getResultSender().lastResult("success");
    } catch (ClassCastException e) {
        context.getResultSender().lastResult("failure");
    } catch (Exception e) {
        context.getResultSender().lastResult("failure");
    }
}
Also used : Query(org.apache.geode.cache.query.Query) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) SelectResults(org.apache.geode.cache.query.SelectResults) PdxInstance(org.apache.geode.pdx.PdxInstance) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) Vector(java.util.Vector)

Aggregations

InternalCache (org.apache.geode.internal.cache.InternalCache)267 DistributedMember (org.apache.geode.distributed.DistributedMember)78 Test (org.junit.Test)64 UnitTest (org.apache.geode.test.junit.categories.UnitTest)52 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)35 HashSet (java.util.HashSet)35 CliMetaData (org.apache.geode.management.cli.CliMetaData)34 CliCommand (org.springframework.shell.core.annotation.CliCommand)34 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)32 Region (org.apache.geode.cache.Region)31 Result (org.apache.geode.management.cli.Result)30 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)30 Expectations (org.jmock.Expectations)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)26 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)24 Set (java.util.Set)23 ResultCollector (org.apache.geode.cache.execute.ResultCollector)22 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)20