public Object request(Object command, int timeout) throws IOException { FutureResponse response = asyncRequest(command, null); return response.getResult(timeout); }
public FutureResponse asyncRequest(Object o, ResponseCallback responseCallback) throws IOException { Command command = (Command) o; command.setCommandId(sequenceGenerator.getNextSequenceId()); command.setResponseRequired(true); FutureResponse future = new FutureResponse(responseCallback, this); IOException priorError = null; synchronized (requestMap) { priorError = this.error; if (priorError == null) { requestMap.put(new Integer(command.getCommandId()), future); } } if (priorError != null) { future.set(new ExceptionResponse(priorError)); throw priorError; } next.oneway(command); return future; }
public Response getResult() throws IOException { boolean hasInterruptPending = Thread.interrupted(); try { return responseSlot.take(); } catch (InterruptedException e) { hasInterruptPending = false; throw dealWithInterrupt(e); } finally { if (hasInterruptPending) { Thread.currentThread().interrupt(); } } }
private void dispose(IOException error) { ArrayList<FutureResponse> requests=null; synchronized(requestMap) { if( this.error==null) { this.error = error; requests = new ArrayList<FutureResponse>(requestMap.values()); requestMap.clear(); } } if( requests!=null ) { for (Iterator<FutureResponse> iter = requests.iterator(); iter.hasNext();) { FutureResponse fr = iter.next(); fr.set(new ExceptionResponse(error)); } } }
public void onCommand(Object o) { Command command = null; if (o instanceof Command) { command = (Command)o; } else { throw new ClassCastException("Object cannot be converted to a Command, Object: " + o); } if (command.isResponse()) { Response response = (Response)command; FutureResponse future = null; synchronized (requestMap) { future = requestMap.remove(Integer.valueOf(response.getCorrelationId())); } if (future != null) { future.set(response); } else { if (debug) { LOG.debug("Received unexpected response: {" + command + "}for command id: " + response.getCorrelationId()); } } } else { getTransportListener().onCommand(command); } }
public Object request(Object command) throws IOException { FutureResponse response = asyncRequest(command, null); return response.getResult(); }
protected void doStop(ServiceStopper serviceStopper) throws IOException { brokerControl.removeBrokerModelChangedListener(this); brokerControl.removeMessageDistribution(this); IOException stopped = new IOException("stopped"); ArrayList<MultiCallback> requests; synchronized (requestMap) { requests = new ArrayList<>(requestMap.keySet()); requestMap.clear(); } for (MultiCallback multiCallback : requests) { FutureResponse futureResponse = new FutureResponse(multiCallback.getCallback()); futureResponse.set(new ExceptionResponse(stopped)); multiCallback.onCompletion(futureResponse); } }
private void dispose(IOException error) { ArrayList<FutureResponse> requests=null; synchronized(requestMap) { if( this.error==null) { this.error = error; requests = new ArrayList<FutureResponse>(requestMap.values()); requestMap.clear(); } } if( requests!=null ) { for (Iterator<FutureResponse> iter = requests.iterator(); iter.hasNext();) { FutureResponse fr = iter.next(); fr.set(new ExceptionResponse(error)); } } }
public Response getResult(int timeout) throws IOException { final boolean wasInterrupted = Thread.interrupted(); try { Response result = responseSlot.poll(timeout, TimeUnit.MILLISECONDS); if (result == null && timeout > 0) { throw new RequestTimedOutIOException(); } return result; } catch (InterruptedException e) { throw dealWithInterrupt(e); } finally { if (wasInterrupted) { Thread.currentThread().interrupt(); } } }
@Override public Object request(Object o, int timeout) throws IOException { final Command command = (Command)o; FutureResponse response = asyncRequest(command, null); while (timeout > 0) { int time = timeout; if (timeout > requestTimeout) { time = requestTimeout; } Response result = response.getResult(time); if (result != null) { return result; } onMissingResponse(command, response); timeout -= time; } return response.getResult(0); }
protected void doStop(ServiceStopper serviceStopper) throws IOException { brokerControl.removeBrokerModelChangedListener(this); brokerControl.removeMessageDistribution(this); IOException stopped = new IOException("stopped"); ArrayList<MultiCallback> requests; synchronized (requestMap) { requests = new ArrayList<>(requestMap.keySet()); requestMap.clear(); } for (MultiCallback multiCallback : requests) { FutureResponse futureResponse = new FutureResponse(multiCallback.getCallback()); futureResponse.set(new ExceptionResponse(stopped)); multiCallback.onCompletion(futureResponse); } }
private void dispose(IOException error) { ArrayList<FutureResponse> requests=null; synchronized(requestMap) { if( this.error==null) { this.error = error; requests = new ArrayList<FutureResponse>(requestMap.values()); requestMap.clear(); } } if( requests!=null ) { for (Iterator<FutureResponse> iter = requests.iterator(); iter.hasNext();) { FutureResponse fr = iter.next(); fr.set(new ExceptionResponse(error)); } } }
public Response getResult() throws IOException { boolean hasInterruptPending = Thread.interrupted(); try { return responseSlot.take(); } catch (InterruptedException e) { hasInterruptPending = false; throw dealWithInterrupt(e); } finally { if (hasInterruptPending) { Thread.currentThread().interrupt(); } } }
@Override public Object request(Object o) throws IOException { final Command command = (Command)o; FutureResponse response = asyncRequest(command, null); while (true) { Response result = response.getResult(requestTimeout); if (result != null) { return result; } onMissingResponse(command, response); } }
public FutureResponse asyncRequest(Object o, ResponseCallback responseCallback) throws IOException { Command command = (Command) o; command.setCommandId(sequenceGenerator.getNextSequenceId()); command.setResponseRequired(true); FutureResponse future = new FutureResponse(responseCallback, this); IOException priorError = null; synchronized (requestMap) { priorError = this.error; if (priorError == null) { requestMap.put(new Integer(command.getCommandId()), future); } } if (priorError != null) { future.set(new ExceptionResponse(priorError)); throw priorError; } next.oneway(command); return future; }
private void dispose(IOException error) { ArrayList<FutureResponse> requests=null; synchronized(requestMap) { if( this.error==null) { this.error = error; requests = new ArrayList<FutureResponse>(requestMap.values()); requestMap.clear(); } } if( requests!=null ) { for (Iterator<FutureResponse> iter = requests.iterator(); iter.hasNext();) { FutureResponse fr = iter.next(); fr.set(new ExceptionResponse(error)); } } }
public Response getResult() throws IOException { boolean hasInterruptPending = Thread.interrupted(); try { return responseSlot.take(); } catch (InterruptedException e) { hasInterruptPending = false; throw dealWithInterrupt(e); } finally { if (hasInterruptPending) { Thread.currentThread().interrupt(); } } }
@Override public void onCompletion(FutureResponse resp) { try { Response reply = resp.getResult(); reply.setCorrelationId(correlationId); remoteBroker.oneway(reply); //increment counter when messages are received in duplex mode networkBridgeStatistics.getReceivedCount().increment(); } catch (IOException error) { LOG.error("Exception: {} on duplex forward of: {}", error, message); serviceRemoteException(error); } } });
public FutureResponse asyncRequest(Object o, ResponseCallback responseCallback) throws IOException { Command command = (Command) o; command.setCommandId(sequenceGenerator.getNextSequenceId()); command.setResponseRequired(true); FutureResponse future = new FutureResponse(responseCallback, this); IOException priorError = null; synchronized (requestMap) { priorError = this.error; if (priorError == null) { requestMap.put(new Integer(command.getCommandId()), future); } } if (priorError != null) { future.set(new ExceptionResponse(priorError)); throw priorError; } next.oneway(command); return future; }
private void dispose(IOException error) { ArrayList<FutureResponse> requests=null; synchronized(requestMap) { if( this.error==null) { this.error = error; requests = new ArrayList<FutureResponse>(requestMap.values()); requestMap.clear(); } } if( requests!=null ) { for (Iterator<FutureResponse> iter = requests.iterator(); iter.hasNext();) { FutureResponse fr = iter.next(); fr.set(new ExceptionResponse(error)); } } }