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();
}
}
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;
}
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);
}
}
}
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) {
}
}
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");
}
}
Aggregations