Code example for BlockingQueue

Methods: add

0
 
  public void sendNextCommand(UIAScriptRequest r) {
    if (responseQueue.size() != 0) {
      System.err.println("adding command but reponse not read.");
    } 
    requestQueue.add(r);
  } 
 
  public UIAScriptRequest getNextCommand() throws InterruptedException { 
    UIAScriptRequest res = requestQueue.take();
    return res;
  } 
 
  public void setNextResponse(UIAScriptResponse r) {
    responseQueue.add(r);
  } 
 
  public UIAScriptResponse waitForResponse() throws InterruptedException { 
    UIAScriptResponse res = responseQueue.poll(IOSCapabilities.COMMAND_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    if (res == null)
      throw new TimeoutException("waiting for UIAScriptResponse");