use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class GatewayReceiverCommand method writeBatchException.
private static void writeBatchException(Message origMsg, List<BatchException70> exceptions, ServerConnection servConn, int batchId) throws IOException {
Message errorMsg = servConn.getErrorResponseMessage();
errorMsg.setMessageType(MessageType.EXCEPTION);
errorMsg.setNumberOfParts(2);
errorMsg.setTransactionId(origMsg.getTransactionId());
errorMsg.addObjPart(exceptions);
// errorMsg.addStringPart(be.toString());
errorMsg.send(servConn);
for (Exception e : exceptions) {
((GatewayReceiverStats) servConn.getCacheServerStats()).incExceptionsOccurred();
}
for (Exception be : exceptions) {
if (logger.isWarnEnabled()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.ProcessBatch_0_WROTE_BATCH_EXCEPTION, servConn.getName()), be);
}
}
}
use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class GetClientPartitionAttributesCommand method cmdExecute.
@SuppressWarnings("unchecked")
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
String regionFullPath = null;
regionFullPath = clientMessage.getPart(0).getString();
String errMessage = "";
if (regionFullPath == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL));
errMessage = LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL.toLocalizedString();
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Region region = serverConnection.getCache().getRegion(regionFullPath);
if (region == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH, regionFullPath));
errMessage = LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND.toLocalizedString() + regionFullPath;
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
try {
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PARTITION_ATTRIBUTES);
PartitionedRegion prRgion = (PartitionedRegion) region;
PartitionResolver partitionResolver = prRgion.getPartitionResolver();
// MINUMUM PARTS
int numParts = 2;
if (partitionResolver != null) {
numParts++;
}
responseMsg.setNumberOfParts(numParts);
// PART 1
responseMsg.addObjPart(prRgion.getTotalNumberOfBuckets());
// PART 2
if (partitionResolver != null) {
responseMsg.addObjPart(partitionResolver.getClass().toString().substring(6));
}
// PART 3
String leaderRegionPath = null;
PartitionedRegion leaderRegion = null;
String leaderRegionName = prRgion.getColocatedWith();
if (leaderRegionName != null) {
Cache cache = prRgion.getCache();
while (leaderRegionName != null) {
leaderRegion = (PartitionedRegion) cache.getRegion(leaderRegionName);
if (leaderRegion.getColocatedWith() == null) {
leaderRegionPath = leaderRegion.getFullPath();
break;
} else {
leaderRegionName = leaderRegion.getColocatedWith();
}
}
}
responseMsg.addObjPart(leaderRegionPath);
responseMsg.send();
clientMessage.clearParts();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
} finally {
serverConnection.setAsTrue(Command.RESPONDED);
}
}
use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class GetClientPartitionAttributesCommand66 method cmdExecute.
@SuppressWarnings("unchecked")
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
String regionFullPath = null;
regionFullPath = clientMessage.getPart(0).getString();
String errMessage = "";
if (regionFullPath == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL));
errMessage = LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL.toLocalizedString();
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Region region = serverConnection.getCache().getRegion(regionFullPath);
if (region == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH, regionFullPath));
errMessage = LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND.toLocalizedString() + regionFullPath;
writeErrorResponse(clientMessage, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
try {
Message responseMsg = serverConnection.getResponseMessage();
responseMsg.setTransactionId(clientMessage.getTransactionId());
responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PARTITION_ATTRIBUTES);
if (!(region instanceof PartitionedRegion)) {
responseMsg.setNumberOfParts(2);
responseMsg.addObjPart(-1);
responseMsg.addObjPart(region.getFullPath());
} else {
PartitionedRegion prRgion = (PartitionedRegion) region;
PartitionResolver partitionResolver = prRgion.getPartitionResolver();
// MINUMUM PARTS
int numParts = 2;
if (partitionResolver != null) {
numParts++;
}
if (prRgion.isFixedPartitionedRegion()) {
numParts++;
}
responseMsg.setNumberOfParts(numParts);
// PART 1
responseMsg.addObjPart(prRgion.getTotalNumberOfBuckets());
// PART 2
String leaderRegionPath = null;
PartitionedRegion leaderRegion = null;
String leaderRegionName = prRgion.getColocatedWith();
if (leaderRegionName != null) {
Cache cache = prRgion.getCache();
while (leaderRegionName != null) {
leaderRegion = (PartitionedRegion) cache.getRegion(leaderRegionName);
if (leaderRegion.getColocatedWith() == null) {
leaderRegionPath = leaderRegion.getFullPath();
break;
} else {
leaderRegionName = leaderRegion.getColocatedWith();
}
}
}
responseMsg.addObjPart(leaderRegionPath);
// PART 3
if (partitionResolver != null) {
responseMsg.addObjPart(partitionResolver.getClass().toString().substring(6));
}
// PART 4
if (prRgion.isFixedPartitionedRegion()) {
Set<FixedPartitionAttributes> fpaSet = null;
if (leaderRegion != null) {
fpaSet = PartitionedRegionHelper.getAllFixedPartitionAttributes(leaderRegion);
} else {
fpaSet = PartitionedRegionHelper.getAllFixedPartitionAttributes(prRgion);
}
responseMsg.addObjPart(fpaSet);
}
}
responseMsg.send();
clientMessage.clearParts();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
} finally {
serverConnection.setAsTrue(Command.RESPONDED);
}
}
use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class Put70 method writeReplyWithRefreshMetadata.
@Override
protected void writeReplyWithRefreshMetadata(Message origMsg, ServerConnection servConn, PartitionedRegion pr, boolean sendOldValue, boolean oldValueIsObject, Object oldValue, byte nwHopType, VersionTag versionTag) throws IOException {
Message replyMsg = servConn.getReplyMessage();
servConn.getCache().getCancelCriterion().checkCancelInProgress(null);
replyMsg.setMessageType(MessageType.REPLY);
int flags = 0;
int parts = 1;
// flags
parts++;
if (sendOldValue) {
flags |= PutOp.HAS_OLD_VALUE_FLAG;
if (oldValueIsObject) {
flags |= PutOp.OLD_VALUE_IS_OBJECT_FLAG;
}
parts++;
}
if (versionTag != null) {
flags |= PutOp.HAS_VERSION_TAG;
parts++;
}
replyMsg.setNumberOfParts(parts);
replyMsg.setTransactionId(origMsg.getTransactionId());
replyMsg.addBytesPart(new byte[] { pr.getMetadataVersion(), nwHopType });
replyMsg.addIntPart(flags);
if (sendOldValue) {
// if (logger.fineEnabled()) {
// logger.fine("sending old value in Put response");
// }
replyMsg.addObjPart(oldValue);
}
if (versionTag != null) {
replyMsg.addObjPart(versionTag);
}
replyMsg.send(servConn);
pr.getPrStats().incPRMetaDataSentCount();
if (logger.isTraceEnabled()) {
logger.trace("{}: rpl with REFRESH_METADATA tx: {} parts={}", servConn.getName(), origMsg.getTransactionId(), replyMsg.getNumberOfParts());
}
}
use of org.apache.geode.internal.cache.tier.sockets.Message in project geode by apache.
the class Put70 method writeReply.
@Override
protected void writeReply(Message origMsg, ServerConnection servConn, boolean sendOldValue, boolean oldValueIsObject, Object oldValue, VersionTag versionTag) throws IOException {
Message replyMsg = servConn.getReplyMessage();
servConn.getCache().getCancelCriterion().checkCancelInProgress(null);
replyMsg.setMessageType(MessageType.REPLY);
int flags = 0;
int parts = 2;
if (sendOldValue) {
flags |= PutOp.HAS_OLD_VALUE_FLAG;
if (oldValueIsObject) {
flags |= PutOp.OLD_VALUE_IS_OBJECT_FLAG;
}
parts++;
}
if (versionTag != null) {
flags |= PutOp.HAS_VERSION_TAG;
parts++;
}
replyMsg.setNumberOfParts(parts);
replyMsg.setTransactionId(origMsg.getTransactionId());
replyMsg.addBytesPart(okBytes());
replyMsg.addIntPart(flags);
if (sendOldValue) {
replyMsg.addObjPart(oldValue);
}
if (versionTag != null) {
replyMsg.addObjPart(versionTag);
}
replyMsg.send(servConn);
if (logger.isTraceEnabled()) {
logger.trace("{}: rpl tx: {} parts={}", servConn.getName(), origMsg.getTransactionId(), replyMsg.getNumberOfParts());
}
}
Aggregations