Code example for ReentrantLock

0
 
public class SimpleHttpResponseHandler extends SimpleChannelUpstreamHandler 
{ 
  private byte[] _receivedBytes = null;
  private HttpResponse _response = null;
  private Lock _lock = new ReentrantLock();
  private Condition _hasResponseCondition = _lock.newCondition();
  private boolean _hasResponse = false;
 
  @Override 
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
  { 
    _response = (HttpResponse) e.getMessage();
    ChannelBuffer content = _response.getContent();
    _receivedBytes = new byte[content.readableBytes()];
    content.getBytes(0, _receivedBytes);
    _lock.lock();
    try 
    { 
      _hasResponse = true;
      _hasResponseCondition.signalAll();