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