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");
}
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class PoolImpl method generatePoolOrCacheCancelledException.
private RuntimeException generatePoolOrCacheCancelledException(Throwable e) {
RuntimeException re = getCancelCriterion().generateCancelledException(e);
if (re != null) {
return re;
}
InternalCache cache = GemFireCacheImpl.getInstance();
if (cache == null) {
if (cacheCriterion != null) {
return cacheCriterion.generateCancelledException(e);
}
} else {
if (cacheCriterion == null || cacheCriterion != cache.getCancelCriterion()) {
cacheCriterion = cache.getCancelCriterion();
}
return cacheCriterion.generateCancelledException(e);
}
return null;
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class PoolImpl method createAuthenticatedCacheView.
public RegionService createAuthenticatedCacheView(Properties properties) {
if (!this.multiuserSecureModeEnabled) {
throw new UnsupportedOperationException("Operation not supported when multiuser-authentication is false.");
}
if (properties == null || properties.isEmpty()) {
throw new IllegalArgumentException("Security properties cannot be empty.");
}
Cache cache = CacheFactory.getInstance(InternalDistributedSystem.getAnyInstance());
Properties props = new Properties();
for (Entry<Object, Object> entry : properties.entrySet()) {
props.setProperty((String) entry.getKey(), (String) entry.getValue());
}
ProxyCache proxy = new ProxyCache(props, (InternalCache) cache, this);
synchronized (this.proxyCacheList) {
this.proxyCacheList.add(proxy);
}
return proxy;
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class AbstractIndex method verifyAndGetPdxDomainObject.
// package-private to avoid synthetic accessor
Object verifyAndGetPdxDomainObject(Object value) {
if (value instanceof StructImpl) {
// Doing hasPdx check first, since its cheaper.
if (((StructImpl) value).isHasPdx() && !((InternalCache) this.region.getCache()).getPdxReadSerializedByAnyGemFireServices()) {
// Set the pdx values for the struct object.
StructImpl v = (StructImpl) value;
Object[] fieldValues = v.getPdxFieldValues();
return new StructImpl((StructTypeImpl) v.getStructType(), fieldValues);
}
} else if (value instanceof PdxInstance && !((InternalCache) this.region.getCache()).getPdxReadSerializedByAnyGemFireServices()) {
return ((PdxInstance) value).getObject();
}
return value;
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class ClusterConfigurationServiceEndToEndDUnitTest method shutdownAll.
private void shutdownAll() throws IOException {
VM locatorAndMgr = getHost(0).getVM(3);
locatorAndMgr.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
ShutdownAllRequest.send(cache.getInternalDistributedSystem().getDistributionManager(), -1);
return null;
}
});
locatorAndMgr.invoke(SharedConfigurationTestUtils.cleanupLocator);
// Clean up the directories
if (!serverNames.isEmpty()) {
for (String serverName : serverNames) {
final File serverDir = new File(serverName);
FileUtils.cleanDirectory(serverDir);
FileUtils.deleteDirectory(serverDir);
}
}
serverNames.clear();
}
Aggregations