{
security.checkPermission(RPCService.ACCESS_RPC_SERVICE_PERMISSION);
}
if (state != State.STARTED)
{
throw new RPCException(
"Cannot execute any commands if the service is not started, the current state of the service is " + state);
}
final String commandId = command.getId();
if (commands.get(commandId) != command)
{
throw new RPCException("Command " + commandId + " unknown, please register your command first");
}
final Message msg = new Message();
setObject(msg, new MessageBody(dests.size() == 1 && dests != members ? dests.get(0) : null, commandId, args)); //NOSONAR
RspList rsps = SecurityHelper.doPrivilegedAction(new PrivilegedAction<RspList>()
{
public RspList run()
{
try
{
return castMessage(dests, msg, synchronous, timeout);
}
catch (Exception e)
{
LOG.error("Could not cast the message corresponding to the command " + commandId + ".", e);
}
return null;
}
});
if (LOG.isTraceEnabled())
LOG.trace("responses: " + rsps);
if (rsps == null)
throw new RPCException("Could not get the responses for command " + commandId + ".");
if (!synchronous)
return Collections.emptyList();// async case
if (LOG.isTraceEnabled())
{
LOG.trace("(" + getLocalAddress() + "): responses for command " + commandId + ":\n" + rsps);
}
List<Object> retval = new ArrayList<Object>(rsps.size());
for (Address dest : dests)
{
Rsp rsp = rsps.get(dest);
if (rsp == null || (rsp.wasSuspected() && !rsp.wasReceived()))
{
// The corresponding member has left
retval.add(new MemberHasLeftException("No response for the member " + dest
+ ", this member has probably left the cluster."));
}
else if (!rsp.wasReceived())
{
retval.add(new RPCException("Replication timeout for " + rsp.getSender() + ", rsp=" + rsp));
}
else
{
Object value = rsp.getValue();
if (value instanceof RPCException)