Code example for BlockingQueue

Methods: add, take

0
    EventBufferEntry entry = null;
 
    try 
    { 
      _freePoolTakeLatency.resume();
      entry = _freePool.take();
    } finally { 
      _freePoolTakeLatency.suspend();
    } 
 
    entry.setType(type);
    entry.setTimeStamp(rowId); //Hack: Using TimeStamp field for rowId
 
    try 
    { 
      _bufferPutLatency.resume();
      _buffer.put(entry);
    } finally { 
      _bufferPutLatency.suspend();
    } 
      } 
 
  public boolean readNextEvent(EventProcessor processor)
  { 
    EventBufferEntry entry = null;
    try 
    { 
      _bufferTakeLatency.resume();
      entry = _buffer.take();
    } catch (InterruptedException ie) {
      LOG.error("Got interrupted while waiting for next event !!", ie);
      processor.process(_eofEntry,_scn);
      return false; 
    } finally { 
      _bufferTakeLatency.suspend();
    } 
 
 
    boolean success = false;
    try 
    { 
      _handlerLatency.resume();
      success = processor.process(entry,_scn);
    } finally { 
      _handlerLatency.suspend();
    } 
 
    try 
    { 
      _freePoolPutLatency.resume();
      _freePool.put(entry);
    } catch (InterruptedException ie) {
      LOG.error("Got interrupted while waiting for returning to free pool !!", ie);
      processor.process(_eofEntry,_scn);
    } finally { 
      _freePoolPutLatency.suspend();
    } 
 
    return success;
  } 
 
  public boolean appendEvent(DbusEventKey key,
                             DbusEventKey seederChunkKey,
                             short pPartitionId,
                             short lPartitionId,
                             long timeStamp,
                             short srcId,
                             byte[] schemaId,
                             byte[] value,
                             boolean enableTracing,
                             boolean isReplicated,
                             DbusEventsStatisticsCollector statsCollector)
  { 
    DbusEventInfo eventInfo = new DbusEventInfo(null, 0L, pPartitionId, lPartitionId,
                                                timeStamp, srcId, schemaId, value, enableTracing,
                                                false); 
    eventInfo.setReplicated(isReplicated);
    return appendEvent(key, seederChunkKey, eventInfo, statsCollector);
  } 
 
  public boolean appendEvent(DbusEventKey key,
                             DbusEventKey seederChunkKey,
                             DbusEventInfo eventInfo,
                             DbusEventsStatisticsCollector statsCollector)
  { 
    EventBufferEntry entry = null;
    try 
    { 
      _freePoolTakeLatency.resume();
      entry = _freePool.take();
    } catch (InterruptedException ie) {
      LOG.error("Got interrupted while waiting for free pool !!", ie);
      try { addSpecialEvent(EventType.EVENT_EOF, 0); } catch (InterruptedException ie2) {};
      _freePool.add(entry); //Adding back to pool
      return false; //TODO: Work on graceful shutdown 
    } finally { 
      _freePoolTakeLatency.suspend();
    } 
 
    entry.reset(key,
                seederChunkKey,
                eventInfo.getpPartitionId(), eventInfo.getlPartitionId(),
                eventInfo.getTimeStampInNanos(), eventInfo.getSrcId(), eventInfo.getSchemaId(),
                eventInfo.getValueBytes(), eventInfo.isEnableTracing(), eventInfo.isReplicated(), statsCollector);
 
 
    try 
    { 
      _bufferPutLatency.resume();
      _buffer.put(entry);
    } catch (InterruptedException ie) {
      LOG.error("Got interrupted while putting to busy pool !!", ie);
      try { addSpecialEvent(EventType.EVENT_EOF, 0); } catch (InterruptedException ie2) {};
      _freePool.add(entry); //Adding back to pool
      return false; //TODO: Work on graceful shutdown 
    } finally { 
      _bufferPutLatency.suspend();
    } 
    return true;