Search in sources :

Example 26 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class ServerRegionFunctionExecutor method executeOnServerNoAck.

private void executeOnServerNoAck(Function function, byte hasResult) throws FunctionException {
    ServerRegionProxy srp = getServerRegionProxy();
    FunctionStats stats = FunctionStats.getFunctionStats(function.getId(), this.region.getSystem());
    try {
        validateExecution(function, null);
        long start = stats.startTime();
        stats.startFunctionExecution(false);
        srp.executeFunctionNoAck(this.region.getFullPath(), function, this, hasResult, false);
        stats.endFunctionExecution(start, false);
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(false);
        throw functionException;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(false);
        throw new FunctionException(exception);
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Example 27 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class ServerRegionFunctionExecutor method execute.

@Override
public ResultCollector execute(final String functionName) {
    if (functionName == null) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_INPUT_FUNCTION_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString());
    }
    this.isFnSerializationReqd = false;
    Function functionObject = FunctionService.getFunction(functionName);
    if (functionObject == null) {
        byte[] functionAttributes = getFunctionAttributes(functionName);
        if (functionAttributes == null) {
            ServerRegionProxy srp = getServerRegionProxy();
            Object obj = srp.getFunctionAttributes(functionName);
            functionAttributes = (byte[]) obj;
            addFunctionAttributes(functionName, functionAttributes);
        }
        boolean hasResult = ((functionAttributes[0] == 1) ? true : false);
        boolean isHA = ((functionAttributes[1] == 1) ? true : false);
        boolean optimizeForWrite = ((functionAttributes[2] == 1) ? true : false);
        return executeFunction(functionName, hasResult, isHA, optimizeForWrite);
    } else {
        return executeFunction(functionObject);
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) FunctionException(org.apache.geode.cache.execute.FunctionException)

Example 28 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class ServerRegionFunctionExecutor method executeOnServerNoAck.

private void executeOnServerNoAck(String functionId, byte hasResult, boolean isHA, boolean optimizeForWrite) throws FunctionException {
    ServerRegionProxy srp = getServerRegionProxy();
    FunctionStats stats = FunctionStats.getFunctionStats(functionId, this.region.getSystem());
    try {
        validateExecution(null, null);
        long start = stats.startTime();
        stats.startFunctionExecution(false);
        srp.executeFunctionNoAck(this.region.getFullPath(), functionId, this, hasResult, isHA, optimizeForWrite, false);
        stats.endFunctionExecution(start, false);
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(false);
        throw functionException;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(false);
        throw new FunctionException(exception);
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Example 29 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class LocalRegion method findObjectInSystem.

/**
   * 
   * Search for the value in a server (if one exists), then try a loader.
   * 
   * If we find a value, we put it in the cache.
   * 
   * @param preferCD return the CacheDeserializable, if that's what the value is.
   * @param requestingClient the client making the request, if any
   * @param clientEvent the client's event, if any. If not null, we set the version tag
   * @return the deserialized value
   */
protected Object findObjectInSystem(KeyInfo keyInfo, boolean isCreate, TXStateInterface tx, boolean generateCallbacks, Object localValue, boolean disableCopyOnRead, boolean preferCD, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones) throws CacheLoaderException, TimeoutException {
    final Object key = keyInfo.getKey();
    final Object aCallbackArgument = keyInfo.getCallbackArg();
    Object value = null;
    boolean fromServer = false;
    VersionTagHolder holder = null;
    /*
     * First lets try the server
     */
    ServerRegionProxy mySRP = getServerProxy();
    if (mySRP != null) {
        holder = new VersionTagHolder();
        value = mySRP.get(key, aCallbackArgument, holder);
        fromServer = value != null;
    }
    /*
     * If we didn't get anything from the server, try the loader
     */
    if (!fromServer || value == Token.TOMBSTONE) {
        // copy into local var to prevent race condition
        CacheLoader loader = basicGetLoader();
        if (loader != null) {
            final LoaderHelper loaderHelper = this.loaderHelperFactory.createLoaderHelper(key, aCallbackArgument, false, /* netSearchAllowed */
            true, /* netloadAllowed */
            null);
            CachePerfStats stats = getCachePerfStats();
            long statStart = stats.startLoad();
            try {
                value = loader.load(loaderHelper);
                fromServer = false;
            } finally {
                stats.endLoad(statStart);
            }
        }
    }
    // have concurrency checks enabled
    if (fromServer && value == Token.TOMBSTONE && !this.concurrencyChecksEnabled) {
        value = null;
    }
    /*
     * If we got a value back, let's put it in the cache.
     */
    RegionEntry re = null;
    if (value != null && !isMemoryThresholdReachedForLoad()) {
        long startPut = CachePerfStats.getStatTime();
        validateKey(key);
        Operation op;
        if (isCreate) {
            op = Operation.LOCAL_LOAD_CREATE;
        } else {
            op = Operation.LOCAL_LOAD_UPDATE;
        }
        @Released EntryEventImpl event = EntryEventImpl.create(this, op, key, value, aCallbackArgument, false, getMyId(), generateCallbacks);
        try {
            // already one there with the same version
            if (fromServer) {
                if (alreadyInvalid(key, event)) {
                    return null;
                }
                event.setFromServer(fromServer);
                event.setVersionTag(holder.getVersionTag());
                if (clientEvent != null) {
                    clientEvent.setVersionTag(holder.getVersionTag());
                }
            }
            // the value to the server
            if (!fromServer) {
                event.setNewEventId(this.cache.getDistributedSystem());
            }
            try {
                try {
                    re = basicPutEntry(event, 0L);
                    if (!fromServer && clientEvent != null) {
                        clientEvent.setVersionTag(event.getVersionTag());
                        clientEvent.isConcurrencyConflict(event.isConcurrencyConflict());
                    }
                    if (fromServer && event.getRawNewValue() == Token.TOMBSTONE) {
                        // tombstones are destroyed entries
                        return null;
                    }
                } catch (ConcurrentCacheModificationException ignore) {
                    // this means the value attempted to overwrite a newer modification and was rejected
                    if (logger.isDebugEnabled()) {
                        logger.debug("caught concurrent modification attempt when applying {}", event);
                    }
                    notifyBridgeClients(event);
                }
                if (!getDataView().isDeferredStats()) {
                    getCachePerfStats().endPut(startPut, event.isOriginRemote());
                }
            } catch (CacheWriterException cwe) {
                if (logger.isDebugEnabled()) {
                    logger.debug("findObjectInSystem: writer exception putting entry {}", event, cwe);
                }
            }
        } finally {
            event.release();
        }
    }
    if (isCreate) {
        recordMiss(re, key);
    }
    return value;
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) Operation(org.apache.geode.cache.Operation) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) LoaderHelper(org.apache.geode.cache.LoaderHelper) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) StoredObject(org.apache.geode.internal.offheap.StoredObject) CacheLoader(org.apache.geode.cache.CacheLoader) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 30 with ServerRegionProxy

use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.

the class LocalRegion method virtualPut.

/**
   * Subclasses should reimplement if needed
   */
boolean virtualPut(final EntryEventImpl event, final boolean ifNew, final boolean ifOld, Object expectedOldValue, boolean requireOldValue, final long lastModified, final boolean overwriteDestroyed) throws TimeoutException, CacheWriterException {
    if (!MemoryThresholds.isLowMemoryExceptionDisabled()) {
        checkIfAboveThreshold(event);
    }
    Operation originalOp = event.getOperation();
    RegionEntry oldEntry;
    try {
        oldEntry = this.entries.basicPut(event, lastModified, ifNew, ifOld, expectedOldValue, requireOldValue, overwriteDestroyed);
    } catch (ConcurrentCacheModificationException ignore) {
        // thread got around to doing so
        if (logger.isDebugEnabled()) {
            logger.debug("caught concurrent modification attempt when applying {}", event);
        }
        notifyBridgeClients(event);
        return false;
    }
    // for EMPTY clients, see if a concurrent map operation had an entry on the server
    ServerRegionProxy mySRP = getServerProxy();
    if (mySRP != null && this.dataPolicy == DataPolicy.EMPTY) {
        if (originalOp == Operation.PUT_IF_ABSENT) {
            return !event.hasOldValue();
        }
        if (originalOp == Operation.REPLACE && !requireOldValue) {
            // LocalRegion.serverPut throws an EntryNotFoundException if the operation failed
            return true;
        }
    }
    return oldEntry != null;
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Operation(org.apache.geode.cache.Operation) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)

Aggregations

ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)34 Connection (org.apache.geode.cache.client.internal.Connection)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 EventID (org.apache.geode.internal.cache.EventID)7 FunctionException (org.apache.geode.cache.execute.FunctionException)6 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)6 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)5 StoredObject (org.apache.geode.internal.offheap.StoredObject)5 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 Region (org.apache.geode.cache.Region)4 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)4 CacheException (org.apache.geode.cache.CacheException)3 CacheWriterException (org.apache.geode.cache.CacheWriterException)3 Operation (org.apache.geode.cache.Operation)3 VM (org.apache.geode.test.dunit.VM)3 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)2 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)2 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)2