use of org.apache.geode.internal.cache.tier.sockets.ChunkedMessage in project geode by apache.
the class GetAll method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
Part regionNamePart = null, keysPart = null;
String regionName = null;
Object[] keys = null;
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
// Retrieve the region name from the message parts
regionNamePart = clientMessage.getPart(0);
regionName = regionNamePart.getString();
// Retrieve the keys array from the message parts
keysPart = clientMessage.getPart(1);
try {
keys = (Object[]) keysPart.getObject();
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
if (logger.isDebugEnabled()) {
StringBuffer buffer = new StringBuffer();
buffer.append(serverConnection.getName()).append(": Received getAll request (").append(clientMessage.getPayloadLength()).append(" bytes) from ").append(serverConnection.getSocketString()).append(" for region ").append(regionName).append(" keys ");
if (keys != null) {
for (int i = 0; i < keys.length; i++) {
buffer.append(keys[i]).append(" ");
}
} else {
buffer.append("NULL");
}
if (logger.isDebugEnabled()) {
logger.debug(buffer.toString());
}
}
// Process the getAll request
if (regionName == null) {
String message = null;
// if (regionName == null) (can only be null)
{
message = LocalizedStrings.GetAll_THE_INPUT_REGION_NAME_FOR_THE_GETALL_REQUEST_IS_NULL.toLocalizedString();
}
logger.warn("{}: {}", serverConnection.getName(), message);
writeChunkedErrorResponse(clientMessage, MessageType.GET_ALL_DATA_ERROR, message, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
if (region == null) {
String reason = " was not found during getAll request";
writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
// Send header
ChunkedMessage chunkedResponseMsg = serverConnection.getChunkedResponseMessage();
chunkedResponseMsg.setMessageType(MessageType.RESPONSE);
chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
chunkedResponseMsg.sendHeader();
// Send chunk response
try {
fillAndSendGetAllResponseChunks(region, regionName, keys, serverConnection);
serverConnection.setAsTrue(RESPONDED);
} catch (Exception e) {
// If an interrupted exception is thrown , rethrow it
checkForInterrupt(serverConnection, e);
// Otherwise, write an exception message and continue
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
}
use of org.apache.geode.internal.cache.tier.sockets.ChunkedMessage in project geode by apache.
the class GetAll70 method sendGetAllResponseChunk.
private static void sendGetAllResponseChunk(Region region, ObjectPartList list, boolean lastChunk, ServerConnection servConn) throws IOException {
ChunkedMessage chunkedResponseMsg = servConn.getChunkedResponseMessage();
chunkedResponseMsg.setNumberOfParts(1);
chunkedResponseMsg.setLastChunk(lastChunk);
chunkedResponseMsg.addObjPartNoCopying(list);
if (logger.isDebugEnabled()) {
logger.debug("{}: Sending {} getAll response chunk for region={}{}", servConn.getName(), (lastChunk ? " last " : " "), region.getFullPath(), (logger.isTraceEnabled() ? " values=" + list + " chunk=<" + chunkedResponseMsg + ">" : ""));
}
chunkedResponseMsg.sendChunk(servConn);
}
use of org.apache.geode.internal.cache.tier.sockets.ChunkedMessage in project geode by apache.
the class GetAll70 method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
Part regionNamePart = null, keysPart = null;
String regionName = null;
Object[] keys = null;
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
int partIdx = 0;
// Retrieve the region name from the message parts
regionNamePart = clientMessage.getPart(partIdx++);
regionName = regionNamePart.getString();
// Retrieve the keys array from the message parts
keysPart = clientMessage.getPart(partIdx++);
try {
keys = (Object[]) keysPart.getObject();
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
boolean requestSerializedValues;
requestSerializedValues = clientMessage.getPart(partIdx++).getInt() == 1;
if (logger.isDebugEnabled()) {
StringBuffer buffer = new StringBuffer();
buffer.append(serverConnection.getName()).append(": Received getAll request (").append(clientMessage.getPayloadLength()).append(" bytes) from ").append(serverConnection.getSocketString()).append(" for region ").append(regionName).append(" keys ");
if (keys != null) {
for (int i = 0; i < keys.length; i++) {
buffer.append(keys[i]).append(" ");
}
} else {
buffer.append("NULL");
}
logger.debug(buffer.toString());
}
// Process the getAll request
if (regionName == null) {
String message = null;
// if (regionName == null) (can only be null)
{
message = LocalizedStrings.GetAll_THE_INPUT_REGION_NAME_FOR_THE_GETALL_REQUEST_IS_NULL.toLocalizedString();
}
logger.warn("{}: {}", serverConnection.getName(), message);
writeChunkedErrorResponse(clientMessage, MessageType.GET_ALL_DATA_ERROR, message, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
if (region == null) {
String reason = " was not found during getAll request";
writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
// Send header
ChunkedMessage chunkedResponseMsg = serverConnection.getChunkedResponseMessage();
chunkedResponseMsg.setMessageType(MessageType.RESPONSE);
chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
chunkedResponseMsg.sendHeader();
// Send chunk response
try {
fillAndSendGetAllResponseChunks(region, regionName, keys, serverConnection, requestSerializedValues);
serverConnection.setAsTrue(RESPONDED);
} catch (Exception e) {
// If an interrupted exception is thrown , rethrow it
checkForInterrupt(serverConnection, e);
// Otherwise, write an exception message and continue
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
}
use of org.apache.geode.internal.cache.tier.sockets.ChunkedMessage in project geode by apache.
the class GetAllWithCallback method sendGetAllResponseChunk.
private static void sendGetAllResponseChunk(Region region, ObjectPartList list, boolean lastChunk, ServerConnection servConn) throws IOException {
ChunkedMessage chunkedResponseMsg = servConn.getChunkedResponseMessage();
chunkedResponseMsg.setNumberOfParts(1);
chunkedResponseMsg.setLastChunk(lastChunk);
chunkedResponseMsg.addObjPartNoCopying(list);
if (logger.isDebugEnabled()) {
logger.debug("{}: Sending {} getAll response chunk for region={}{}", servConn.getName(), (lastChunk ? " last " : " "), region.getFullPath(), (logger.isTraceEnabled() ? " values=" + list + " chunk=<" + chunkedResponseMsg + ">" : ""));
}
chunkedResponseMsg.sendChunk(servConn);
}
use of org.apache.geode.internal.cache.tier.sockets.ChunkedMessage in project geode by apache.
the class GetAllWithCallback method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
Part regionNamePart = null, keysPart = null, callbackPart = null;
String regionName = null;
Object[] keys = null;
Object callback = null;
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
int partIdx = 0;
// Retrieve the region name from the message parts
regionNamePart = clientMessage.getPart(partIdx++);
regionName = regionNamePart.getString();
// Retrieve the keys array from the message parts
keysPart = clientMessage.getPart(partIdx++);
try {
keys = (Object[]) keysPart.getObject();
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
callbackPart = clientMessage.getPart(partIdx++);
try {
callback = callbackPart.getObject();
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
if (logger.isDebugEnabled()) {
StringBuffer buffer = new StringBuffer();
buffer.append(serverConnection.getName()).append(": Received getAll request (").append(clientMessage.getPayloadLength()).append(" bytes) from ").append(serverConnection.getSocketString()).append(" for region ").append(regionName).append(" with callback ").append(callback).append(" keys ");
if (keys != null) {
for (int i = 0; i < keys.length; i++) {
buffer.append(keys[i]).append(" ");
}
} else {
buffer.append("NULL");
}
logger.debug(buffer.toString());
}
// Process the getAll request
if (regionName == null) {
String message = null;
// if (regionName == null) (can only be null)
{
message = LocalizedStrings.GetAll_THE_INPUT_REGION_NAME_FOR_THE_GETALL_REQUEST_IS_NULL.toLocalizedString();
}
logger.warn(LocalizedMessage.create(LocalizedStrings.TWO_ARG_COLON, new Object[] { serverConnection.getName(), message }));
writeChunkedErrorResponse(clientMessage, MessageType.GET_ALL_DATA_ERROR, message, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
LocalRegion region = (LocalRegion) serverConnection.getCache().getRegion(regionName);
if (region == null) {
String reason = " was not found during getAll request";
writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
// Send header
ChunkedMessage chunkedResponseMsg = serverConnection.getChunkedResponseMessage();
chunkedResponseMsg.setMessageType(MessageType.RESPONSE);
chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
chunkedResponseMsg.sendHeader();
// Send chunk response
try {
fillAndSendGetAllResponseChunks(region, regionName, keys, serverConnection, callback);
serverConnection.setAsTrue(RESPONDED);
} catch (Exception e) {
// If an interrupted exception is thrown , rethrow it
checkForInterrupt(serverConnection, e);
// Otherwise, write an exception message and continue
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
}
Aggregations