@Override public Response getResponse(CacheRpcCommand command, Object returnValue) { if (command.getCommandId() == ClusteredGetCommand.COMMAND_ID) { if (returnValue == null) return null; ClusteredGetCommand clusteredGet = (ClusteredGetCommand) command; if (distributionManager.isAffectedByRehash(clusteredGet.getKey())) return UnsureResponse.INSTANCE; return SuccessfulResponse.create(returnValue); } else if (command instanceof SingleRpcCommand) { SingleRpcCommand src = (SingleRpcCommand) command; ReplicableCommand c = src.getCommand(); byte commandId = c.getCommandId(); if (c instanceof WriteCommand) { if (returnValue == null) return null; // check if this is successful. WriteCommand wc = (WriteCommand) c; return handleWriteCommand(wc, returnValue); } else if (commandId == MapCombineCommand.COMMAND_ID || commandId == ReduceCommand.COMMAND_ID || commandId == DistributedExecuteCommand.COMMAND_ID) { // Even null values should be wrapped in this case. return SuccessfulResponse.create(returnValue); } else if (c.isReturnValueExpected()) { if (returnValue == null) return null; return SuccessfulResponse.create(returnValue); } } else if (command.isReturnValueExpected()) { return SuccessfulResponse.create(returnValue); } return null; // no unnecessary response values! }
protected Response handleWriteCommand(WriteCommand wc, Object returnValue) { if (wc.isSuccessful()) { return wc.isReturnValueExpected() ? SuccessfulResponse.create(returnValue) : null; } else return UnsuccessfulResponse.INSTANCE; }