1 18 package org.apache.activemq.transport.tcp; 19 20 import org.apache.activemq.command.Response; 21 22 27 public class ResponseHolder { 28 protected Response response; 29 protected Object lock = new Object (); 30 protected boolean notified; 31 32 35 public ResponseHolder() { 36 } 37 38 43 public void setResponse(Response r) { 44 synchronized (lock) { 45 this.response = r; 46 notified = true; 47 lock.notify(); 48 } 49 } 50 51 56 public Response getResponse() { 57 return getResponse(0); 58 } 59 60 66 public Response getResponse(int timeout) { 67 synchronized (lock) { 68 if (!notified) { 69 try { 70 lock.wait(timeout); 71 } 72 catch (InterruptedException e) { 73 Thread.currentThread().interrupt(); 74 } 75 } 76 } 77 return this.response; 78 } 79 80 83 public void close() { 84 synchronized (lock) { 85 notified = true; 86 lock.notifyAll(); 87 } 88 } 89 } 90 | Popular Tags |