Search in sources :

Example 6 with ChunkedMessage

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;
    }
}
Also used : Part(org.apache.geode.internal.cache.tier.sockets.Part) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage) IOException(java.io.IOException) NotAuthorizedException(org.apache.geode.security.NotAuthorizedException)

Example 7 with ChunkedMessage

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);
}
Also used : ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Example 8 with ChunkedMessage

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;
    }
}
Also used : Part(org.apache.geode.internal.cache.tier.sockets.Part) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage) NotAuthorizedException(org.apache.geode.security.NotAuthorizedException) IOException(java.io.IOException)

Example 9 with ChunkedMessage

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);
}
Also used : ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Example 10 with ChunkedMessage

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;
    }
}
Also used : Part(org.apache.geode.internal.cache.tier.sockets.Part) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage) IOException(java.io.IOException) NotAuthorizedException(org.apache.geode.security.NotAuthorizedException)

Aggregations

ChunkedMessage (org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)30 IOException (java.io.IOException)16 Part (org.apache.geode.internal.cache.tier.sockets.Part)15 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)12 FunctionException (org.apache.geode.cache.execute.FunctionException)11 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)11 Function (org.apache.geode.cache.execute.Function)8 ExecuteFunctionOperationContext (org.apache.geode.cache.operations.ExecuteFunctionOperationContext)8 MemberMappedArgument (org.apache.geode.internal.cache.execute.MemberMappedArgument)8 HandShake (org.apache.geode.internal.cache.tier.sockets.HandShake)8 LocalRegion (org.apache.geode.internal.cache.LocalRegion)7 ServerToClientFunctionResultSender (org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender)7 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)7 Region (org.apache.geode.cache.Region)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)5 PartitionedRegionFunctionExecutor (org.apache.geode.internal.cache.execute.PartitionedRegionFunctionExecutor)5 ServerToClientFunctionResultSender65 (org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender65)5 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)4 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)4