Search in sources :

Example 1 with RegionClearOperationContext

use of org.apache.geode.cache.operations.RegionClearOperationContext in project geode by apache.

the class ClearRegion method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
    Part regionNamePart = null, callbackArgPart = null;
    String regionName = null;
    Object callbackArg = null;
    Part eventPart = null;
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incReadClearRegionRequestTime(start - oldStart);
    }
    // Retrieve the data from the message parts
    regionNamePart = clientMessage.getPart(0);
    eventPart = clientMessage.getPart(1);
    // callbackArgPart = null; (redundant assignment)
    if (clientMessage.getNumberOfParts() > 2) {
        callbackArgPart = clientMessage.getPart(2);
        try {
            callbackArg = callbackArgPart.getObject();
        } catch (Exception e) {
            writeException(clientMessage, e, false, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
            return;
        }
    }
    regionName = regionNamePart.getString();
    if (logger.isDebugEnabled()) {
        logger.debug(serverConnection.getName() + ": Received clear region request (" + clientMessage.getPayloadLength() + " bytes) from " + serverConnection.getSocketString() + " for region " + regionName);
    }
    // Process the clear region request
    if (regionName == null) {
        logger.warn(LocalizedMessage.create(LocalizedStrings.ClearRegion_0_THE_INPUT_REGION_NAME_FOR_THE_CLEAR_REGION_REQUEST_IS_NULL, serverConnection.getName()));
        String errMessage = LocalizedStrings.ClearRegion_THE_INPUT_REGION_NAME_FOR_THE_CLEAR_REGION_REQUEST_IS_NULL.toLocalizedString();
        writeErrorResponse(clientMessage, MessageType.CLEAR_REGION_DATA_ERROR, errMessage, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    LocalRegion region = (LocalRegion) crHelper.getRegion(regionName);
    if (region == null) {
        String reason = LocalizedStrings.ClearRegion_WAS_NOT_FOUND_DURING_CLEAR_REGION_REGUEST.toLocalizedString();
        writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    ByteBuffer eventIdPartsBuffer = ByteBuffer.wrap(eventPart.getSerializedForm());
    long threadId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    long sequenceId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
    EventID eventId = new EventID(serverConnection.getEventMemberIDByteArray(), threadId, sequenceId);
    try {
        // Clear the region
        this.securityService.authorizeRegionWrite(regionName);
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            RegionClearOperationContext clearContext = authzRequest.clearAuthorize(regionName, callbackArg);
            callbackArg = clearContext.getCallbackArg();
        }
        region.basicBridgeClear(callbackArg, serverConnection.getProxyID(), true, /* boolean from cache Client */
        eventId);
    } catch (Exception e) {
        // If an interrupted exception is thrown , rethrow it
        checkForInterrupt(serverConnection, e);
        // If an exception occurs during the clear, preserve the connection
        writeException(clientMessage, e, false, serverConnection);
        serverConnection.setAsTrue(RESPONDED);
        return;
    }
    // Update the statistics and write the reply
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incProcessClearRegionTime(start - oldStart);
    }
    writeReply(clientMessage, serverConnection);
    serverConnection.setAsTrue(RESPONDED);
    if (logger.isDebugEnabled()) {
        logger.debug(serverConnection.getName() + ": Sent clear region response for region " + regionName);
    }
    stats.incWriteClearRegionResponseTime(DistributionStats.getStatTime() - start);
}
Also used : CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) Part(org.apache.geode.internal.cache.tier.sockets.Part) EventID(org.apache.geode.internal.cache.EventID) LocalRegion(org.apache.geode.internal.cache.LocalRegion) RegionClearOperationContext(org.apache.geode.cache.operations.RegionClearOperationContext) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException)

Example 2 with RegionClearOperationContext

use of org.apache.geode.cache.operations.RegionClearOperationContext in project geode by apache.

the class CacheClientProxy method getOperationContext.

private OperationContext getOperationContext(ClientMessage cmsg, String[] regionNameHolder) {
    ClientUpdateMessageImpl cmsgimpl = (ClientUpdateMessageImpl) cmsg;
    OperationContext opctxt = null;
    // TODO SW: Special handling for DynamicRegions; this should be reworked
    // when DynamicRegion API is deprecated
    String regionName = cmsgimpl.getRegionName();
    regionNameHolder[0] = regionName;
    if (cmsgimpl.isCreate()) {
        if (DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
            regionNameHolder[0] = (String) cmsgimpl.getKeyOfInterest();
            opctxt = new RegionCreateOperationContext(true);
        } else {
            PutOperationContext tmp = new PutOperationContext(cmsgimpl.getKeyOfInterest(), cmsgimpl.getValue(), cmsgimpl.valueIsObject(), PutOperationContext.CREATE, true);
            tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
            opctxt = tmp;
        }
    } else if (cmsgimpl.isUpdate()) {
        if (DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
            regionNameHolder[0] = (String) cmsgimpl.getKeyOfInterest();
            opctxt = new RegionCreateOperationContext(true);
        } else {
            PutOperationContext tmp = new PutOperationContext(cmsgimpl.getKeyOfInterest(), cmsgimpl.getValue(), cmsgimpl.valueIsObject(), PutOperationContext.UPDATE, true);
            tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
            opctxt = tmp;
        }
    } else if (cmsgimpl.isDestroy()) {
        if (DynamicRegionFactory.regionIsDynamicRegionList(regionName)) {
            regionNameHolder[0] = (String) cmsgimpl.getKeyOfInterest();
            opctxt = new RegionDestroyOperationContext(true);
        } else {
            DestroyOperationContext tmp = new DestroyOperationContext(cmsgimpl.getKeyOfInterest(), true);
            tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
            opctxt = tmp;
        }
    } else if (cmsgimpl.isDestroyRegion()) {
        opctxt = new RegionDestroyOperationContext(true);
    } else if (cmsgimpl.isInvalidate()) {
        InvalidateOperationContext tmp = new InvalidateOperationContext(cmsgimpl.getKeyOfInterest(), true);
        tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
        opctxt = tmp;
    } else if (cmsgimpl.isClearRegion()) {
        RegionClearOperationContext tmp = new RegionClearOperationContext(true);
        tmp.setCallbackArg(cmsgimpl.getCallbackArgument());
        opctxt = tmp;
    }
    return opctxt;
}
Also used : RegionCreateOperationContext(org.apache.geode.cache.operations.RegionCreateOperationContext) DestroyOperationContext(org.apache.geode.cache.operations.DestroyOperationContext) PutOperationContext(org.apache.geode.cache.operations.PutOperationContext) InvalidateOperationContext(org.apache.geode.cache.operations.InvalidateOperationContext) RegionClearOperationContext(org.apache.geode.cache.operations.RegionClearOperationContext) RegionDestroyOperationContext(org.apache.geode.cache.operations.RegionDestroyOperationContext) OperationContext(org.apache.geode.cache.operations.OperationContext) InvalidateOperationContext(org.apache.geode.cache.operations.InvalidateOperationContext) RegionCreateOperationContext(org.apache.geode.cache.operations.RegionCreateOperationContext) RegionDestroyOperationContext(org.apache.geode.cache.operations.RegionDestroyOperationContext) PutOperationContext(org.apache.geode.cache.operations.PutOperationContext) RegionClearOperationContext(org.apache.geode.cache.operations.RegionClearOperationContext) DestroyOperationContext(org.apache.geode.cache.operations.DestroyOperationContext) RegionDestroyOperationContext(org.apache.geode.cache.operations.RegionDestroyOperationContext)

Aggregations

RegionClearOperationContext (org.apache.geode.cache.operations.RegionClearOperationContext)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 DestroyOperationContext (org.apache.geode.cache.operations.DestroyOperationContext)1 InvalidateOperationContext (org.apache.geode.cache.operations.InvalidateOperationContext)1 OperationContext (org.apache.geode.cache.operations.OperationContext)1 PutOperationContext (org.apache.geode.cache.operations.PutOperationContext)1 RegionCreateOperationContext (org.apache.geode.cache.operations.RegionCreateOperationContext)1 RegionDestroyOperationContext (org.apache.geode.cache.operations.RegionDestroyOperationContext)1 EventID (org.apache.geode.internal.cache.EventID)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)1 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)1 Part (org.apache.geode.internal.cache.tier.sockets.Part)1 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)1