Exemplo n.º 1
1
 /**
  * Add the given operation to the tail of this queue.
  *
  * @param operation the operation to be added to the queue
  */
 public void enqueue(IndexOperation operation) {
   synchronized (nonQueryOperations) {
     if (operation instanceof RemoveResourceOperation) {
       Resource resource = ((RemoveResourceOperation) operation).getResource();
       for (int i = nonQueryOperations.size() - 1; i >= 0; i--) {
         if (nonQueryOperations.get(i).removeWhenResourceRemoved(resource)) {
           nonQueryOperations.remove(i);
         }
       }
       for (int i = queryOperations.size() - 1; i >= 0; i--) {
         if (queryOperations.get(i).removeWhenResourceRemoved(resource)) {
           queryOperations.remove(i);
         }
       }
     }
     if (operation.isQuery()) {
       queryOperations.add(operation);
     } else {
       nonQueryOperations.add(operation);
     }
     nonQueryOperations.notifyAll();
   }
 }
 public IndexOperation peekNext() throws AnalyticsException {
   try {
     byte[] data;
     if (this.secondaryProcessedCount < this.secondaryQueueInitialCount) {
       /* the following will not end up in strict FIFO, but it's
        * rare that the secondary queue processing will also fail,
        * and even when that happens, it's unlikely you need strict
        * ordered retrieval of records then */
       data = this.secondaryQueue.peek();
       this.secondaryQueue.enqueue(data);
       this.secondaryQueue.dequeue();
     } else {
       data = this.primaryQueue.peek();
       this.secondaryQueue.enqueue(data);
       this.primaryQueue.dequeue();
     }
     this.secondaryProcessedCount++;
     IndexOperation indexOp = IndexOperation.fromBytes(data);
     this.removedDataSize += indexOp.getByteSize();
     if (this.removedDataSize > QUEUE_CLEANUP_THRESHOLD) {
       this.primaryQueue.gc();
       this.secondaryQueue.gc();
       this.removedDataSize = 0;
       if (log.isDebugEnabled()) {
         log.debug("Queue GC: " + this.primaryQueue + "|" + this.secondaryQueue);
       }
     }
     return indexOp;
   } catch (IOException e) {
     throw new AnalyticsException("Error in index data peekNext: " + e.getMessage(), e);
   }
 }
 public void enqueue(IndexOperation indexOp) throws AnalyticsException {
   try {
     this.primaryQueue.enqueue(indexOp.getBytes());
   } catch (IOException e) {
     throw new AnalyticsException("Error in index data enqueue: " + e.getMessage(), e);
   }
 }
 public static IndexOperation fromBytes(byte[] data) {
   IndexOperation result = (IndexOperation) GenericUtils.deserializeObject(data);
   result.setByteSize(data.length);
   return result;
 }