Search in sources :

Example 6 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)

Example 7 with InternalCache

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

Example 8 with InternalCache

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

Example 9 with InternalCache

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;
}
Also used : StructImpl(org.apache.geode.cache.query.internal.StructImpl) PdxInstance(org.apache.geode.pdx.PdxInstance) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 10 with InternalCache

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();
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalCache(org.apache.geode.internal.cache.InternalCache) File(java.io.File) IgnoredException.addIgnoredException(org.apache.geode.test.dunit.IgnoredException.addIgnoredException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

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