public void setRandomize(boolean randomize) {
this.randomize = randomize;
}
public void oneway(Object o) throws IOException {
Command command = (Command)o;
Exception error = null;
try {
synchronized (reconnectMutex) {
// Keep trying until the message is sent.
for (int i = 0; !disposed; i++) {
try {
// Wait for transport to be connected.
while (connectedTransport == null && !disposed && connectionFailure == null) {
LOG.trace("Waiting for transport to reconnect.");
try {
reconnectMutex.wait(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.debug("Interupted: " + e, e);
}
}
if (connectedTransport == null) {
// Previous loop may have exited due to use being
// disposed.
if (disposed) {
error = new IOException("Transport disposed.");
} else if (connectionFailure != null) {
error = connectionFailure;
} else {
error = new IOException("Unexpected failure.");
}
break;
}
// If it was a request and it was not being tracked by
// the state tracker,
// then hold it in the requestMap so that we can replay
// it later.
Tracked tracked = stateTracker.track(command);
if (tracked != null && tracked.isWaitingForResponse()) {
requestMap.put(Integer.valueOf(command.getCommandId()), tracked);
} else if (tracked == null && command.isResponseRequired()) {
requestMap.put(Integer.valueOf(command.getCommandId()), command);
}
// Send the message.
try {
connectedTransport.oneway(command);
} catch (IOException e) {
// If the command was not tracked.. we will retry in
// this method
if (tracked == null) {
// since we will retry in this method.. take it
// out of the request
// map so that it is not sent 2 times on
// recovery
if (command.isResponseRequired()) {
requestMap.remove(Integer.valueOf(command.getCommandId()));
}
// Rethrow the exception so it will handled by
// the outer catch
throw e;