* @param exchange the exchange to send
* @param timeout time to wait in milliseconds
* @return <code>true</code> if the exchange has been processed succesfully
*/
public boolean sendSync(Exchange exchange, long timeout) {
InternalExchange e = (InternalExchange) exchange;
Semaphore lock = e.getRole() == Role.Consumer ? e.getConsumerLock(true)
: e.getProviderLock(true);
try {
dispatch(e);
if (timeout > 0) {
if (!lock.tryAcquire(timeout, TimeUnit.MILLISECONDS)) {
throw new TimeoutException();
}
} else {
lock.acquire();
}
e.setRole(e.getRole() == Role.Consumer ? Role.Provider : Role.Consumer);
} catch (InterruptedException ex) {
exchange.setError(ex);
exchange.setStatus(Status.Error);
return false;
} catch (TimeoutException ex) {