示例#1
0
 /** @see net.gaia.taskprocessor.api.processor.TaskProcessor#getPendingTaskCount() */
 public int getPendingTaskCount() {
   int cantidadPendiente = 0;
   for (int i = 0; i < colasCompartidas.length; i++) {
     final BlockingDeque<SubmittedTask> colaCompartida = colasCompartidas[i];
     cantidadPendiente += colaCompartida.size();
   }
   return cantidadPendiente;
 }
 private long testingBlockingDequeLinkedBlockingDeque() {
   BlockingDeque<Object> array = new LinkedBlockingDeque<Object>();
   long start = System.currentTimeMillis();
   for (int i = 0; i < getMax(); i++) {
     array.add(i);
   }
   long end = System.currentTimeMillis();
   long time = (end - start);
   refreshTotalTime(time);
   return time;
 }
  @Test
  public void shouldPollForTransactedMessagesFromTheInboxBlockingDeque() {
    BlockingDeque<TransactedMessage> inbox = mock(BlockingDeque.class);
    ExecutorService executorService = mock(ExecutorService.class);
    ClientSocketWrapper socket = mock(ClientSocketWrapper.class);

    when(inbox.poll()).thenReturn(new TransactedMessage(0, 0, 1000L));

    PerformanceReporter performanceReporter =
        new PerformanceReporter(inbox, 5, executorService, socket);
    performanceReporter.run();

    verify(inbox, atLeast(5)).poll();
  }
  @Test
  @Ignore
  public void drainToWithEmptyDeque() {
    BlockingDeque<String> deque = new TransactionalLinkedList<String>();

    Collection<String> c = new LinkedList<String>();
    long version = stm.getTime();
    int result = deque.drainTo(c);
    assertEquals(0, result);

    assertEquals(version, stm.getTime());
    assertTrue(c.isEmpty());
    assertEquals(0, deque.size());
    testIncomplete();
  }
  private void refreshAll(final boolean updateSelection) {

    queue.clear();

    // We use a job for this as the file list can be large
    final Job refresh =
        new Job("Refresh Image Monitor") {
          @Override
          protected IStatus run(IProgressMonitor monitor) {

            Display.getDefault()
                .asyncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        galleryGroup.clearAll();
                        galleryGroup.setItemCount(info.getSize());
                        galleryGroup.setExpanded(true);
                        galleryGroup.setText(info.getName());

                        gallery.update();
                        gallery.getParent().layout(new Control[] {gallery});

                        GalleryItem item = galleryGroup.getItem(galleryGroup.getItemCount() - 1);
                        gallery.setSelection(new GalleryItem[] {item});
                      }
                    });

            return Status.OK_STATUS;
          }
        };
    refresh.setPriority(Job.INTERACTIVE);
    refresh.schedule();
  }
示例#6
0
文件: Bpm200.java 项目: emorency/onyx
 public BpmMessage read() {
   try {
     return messageQueue.poll(100, TimeUnit.MILLISECONDS);
   } catch (InterruptedException e) {
     throw new RuntimeException(e);
   }
 }
示例#7
0
 private InboundTransferTask addTransfer(Address source, Set<Integer> segmentsFromSource) {
   synchronized (this) {
     segmentsFromSource.removeAll(
         transfersBySegment.keySet()); // already in progress segments are excluded
     if (!segmentsFromSource.isEmpty()) {
       InboundTransferTask inboundTransfer =
           new InboundTransferTask(
               segmentsFromSource,
               source,
               cacheTopology.getTopologyId(),
               this,
               rpcManager,
               commandsFactory,
               timeout,
               cacheName);
       for (int segmentId : segmentsFromSource) {
         transfersBySegment.put(segmentId, inboundTransfer);
       }
       List<InboundTransferTask> inboundTransfers =
           transfersBySource.get(inboundTransfer.getSource());
       if (inboundTransfers == null) {
         inboundTransfers = new ArrayList<InboundTransferTask>();
         transfersBySource.put(inboundTransfer.getSource(), inboundTransfers);
       }
       inboundTransfers.add(inboundTransfer);
       taskQueue.add(inboundTransfer);
       return inboundTransfer;
     } else {
       return null;
     }
   }
 }
示例#8
0
  @Stop(priority = 20)
  @Override
  public void stop() {
    if (trace) {
      log.tracef(
          "Shutting down StateConsumer of cache %s on node %s", cacheName, rpcManager.getAddress());
    }

    try {
      synchronized (this) {
        // cancel all inbound transfers
        taskQueue.clear();
        for (Iterator<List<InboundTransferTask>> it = transfersBySource.values().iterator();
            it.hasNext(); ) {
          List<InboundTransferTask> inboundTransfers = it.next();
          it.remove();
          for (InboundTransferTask inboundTransfer : inboundTransfers) {
            inboundTransfer.cancel();
          }
        }
        transfersBySource.clear();
        transfersBySegment.clear();
      }
    } catch (Throwable t) {
      log.errorf(
          t,
          "Failed to stop StateConsumer of cache %s on node %s",
          cacheName,
          rpcManager.getAddress());
    }
  }
示例#9
0
 @Override
 public void close() throws IOException {
   LOG.info("Closing event channel");
   closed = true;
   queue.add(shutdownEvent);
   notifyClosing();
 }
示例#10
0
 private static BlockingDeque<String> load(String name, BlockingDeque<String> queue)
     throws IOException {
   queue.clear();
   File saveFile = new File(Publisher.SAVE_FOLDER + "qidian-bobo-" + name + ".sav");
   if (saveFile.isFile()) {
     BufferedReader reader = new BufferedReader(new FileReader(saveFile));
     String line;
     while (null != (line = reader.readLine())) {
       if (!line.isEmpty()) {
         queue.add(line);
       }
     }
     reader.close();
   }
   return queue;
 }
  @Ignore
  @Test
  public void drainToWithNonEmptyDeque() {
    BlockingDeque<String> deque = new TransactionalLinkedList<String>();
    deque.add("1");
    deque.add("2");
    deque.add("3");

    Collection<String> c = new LinkedList<String>();
    long version = stm.getTime();
    int result = deque.drainTo(c);
    assertEquals(3, result);
    assertEquals(version + 1, stm.getTime());
    assertEquals("[1, 2, 3]", c.toString());
    assertEquals(0, deque.size());
    testIncomplete();
  }
 @Override
 public T get() {
   try {
     return pool.takeFirst();
   } catch (InterruptedException ex) {
     throw new ARQException(
         "Failed to get an item from the pool (InterruptedException): " + ex.getMessage());
   }
 }
  public void clear() {
    queue.clear();
    galleryGroup.clearAll();
    galleryGroup.setItemCount(0);
    galleryGroup.setExpanded(true);
    galleryGroup.setText(groupLabel);

    gallery.update();
  }
  public void dispose() {
    queue.clear();
    queue.add(new ImageItem()); // stops queue.

    if (gallery != null && !gallery.isDisposed()) {
      // Dispose images, may be a lot!
      for (int i = 0; i < gallery.getItemCount(); ++i) {
        if (gallery.getItem(i).getImage() != null) {
          gallery.getItem(i).getImage().dispose();
        }
      }
      gallery.dispose();
    }

    // Nullify variables
    gallery = null;
    galleryGroup = null;
    queue = null;
    imageThread = null;
  }
示例#15
0
 /**
  * Return the next event or null if closed
  *
  * @return
  */
 public OutboundEvent pop() {
   OutboundEvent event;
   try {
     event = queue.take();
     if (closed || event == shutdownEvent) return null;
     if (closed) return null;
     return event;
   } catch (InterruptedException e) {
     return null;
   }
 }
  public DualChannelPool(RabbitMQConnectionFactory connectionFactory, int connectionPoolSize) {

    dualChannelPool = new LinkedBlockingDeque<>();
    try {
      Connection connection = connectionFactory.createConnection();
      for (int i = 0; i < connectionPoolSize; i++) {
        Channel channel = connection.createChannel();
        QueueingConsumer consumer = new QueueingConsumer(channel);
        String replyQueueName = channel.queueDeclare().getQueue();
        dualChannelPool.add(new DualChannel(connection, channel, consumer, replyQueueName));
      }
    } catch (IOException e) {
      throw new AxisRabbitMQException("Error creating dual channel pool", e);
    }
  }
示例#17
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    Log.v(TAG, "AMQP onStartCommand");

    String msg = intent.getStringExtra(Constants.AMQP_PUBLISH_MESSAGE);

    if (msg == null) return 0;
    try {
      Log.d(TAG, "[q] " + msg);
      publishQueue.putLast(msg);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    return 1;
  }
示例#18
0
  @Override
  protected void onHandleIntent(Intent intent) {

    Log.v(TAG, "AMQP on Handle Event");

    String msg = intent.getStringExtra(Constants.AMQP_PUBLISH_MESSAGE);

    if (msg == null) return;
    try {
      Log.d(TAG, "[q] " + msg);
      publishQueue.putLast(msg);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
  public static void onEvent(SelectionEvent ev) throws Exception {
    // Allocate a ByteBuffer from a RingBuffer
    ByteBuffer buffer = bufferPool.take();
    if (buffer.position() > 0) {
      buffer.clear();
    }

    SocketChannel channel = channels.get(ev.id);
    SelectionKey key = selectionKeys.get(ev.id);

    // System.out.println("ops:" + key.interestOps());

    try {
      int read = safeRead(channel, buffer);
      while (read > 0) {
        safeWrite(channel, msg.duplicate());

        // Read the data into memory
        buffer.flip();
        byte[] bytes = new byte[buffer.remaining()];
        buffer.get(bytes);
        // String input = new String(bytes);
        buffer.clear();
        read = safeRead(channel, buffer);
      }
      if (read < 0) {
        key.cancel();
        channel.close();
        selectionKeys.remove(ev.id);
      }
    } finally {
      // Put the ByteBuffer back into the RingBuffer for
      // re-use
      bufferPool.add(buffer);
    }
  }
示例#20
0
 private boolean removeTransfer(InboundTransferTask inboundTransfer) {
   synchronized (this) {
     taskQueue.remove(inboundTransfer);
     List<InboundTransferTask> transfers = transfersBySource.get(inboundTransfer.getSource());
     if (transfers != null) {
       if (transfers.remove(inboundTransfer)) {
         if (transfers.isEmpty()) {
           transfersBySource.remove(inboundTransfer.getSource());
         }
         transfersBySegment.keySet().removeAll(inboundTransfer.getSegments());
         return true;
       }
     }
   }
   return false;
 }
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((arrayBlockingQueue == null) ? 0 : arrayBlockingQueue.hashCode());
   result = prime * result + ((arrayDeque == null) ? 0 : arrayDeque.hashCode());
   result = prime * result + ((arrayList == null) ? 0 : arrayList.hashCode());
   result = prime * result + ((bar == null) ? 0 : bar.hashCode());
   result = prime * result + ((blockingDeque == null) ? 0 : blockingDeque.hashCode());
   result = prime * result + ((blockingQueue == null) ? 0 : blockingQueue.hashCode());
   result = prime * result + ((collection == null) ? 0 : collection.hashCode());
   result =
       prime * result + ((concurrentLinkedQueue == null) ? 0 : concurrentLinkedQueue.hashCode());
   result =
       prime * result + ((concurrentSkipListSet == null) ? 0 : concurrentSkipListSet.hashCode());
   result =
       prime * result + ((copyOnWriteArrayList == null) ? 0 : copyOnWriteArrayList.hashCode());
   result =
       prime * result + ((copyOnWriteArraySet == null) ? 0 : copyOnWriteArraySet.hashCode());
   result = prime * result + ((deque == null) ? 0 : deque.hashCode());
   result = prime * result + ((hashSet == null) ? 0 : hashSet.hashCode());
   result =
       prime * result + ((linkedBlockingDeque == null) ? 0 : linkedBlockingDeque.hashCode());
   result =
       prime * result + ((linkedBlockingQueue == null) ? 0 : linkedBlockingQueue.hashCode());
   result = prime * result + ((linkedHashSet == null) ? 0 : linkedHashSet.hashCode());
   result = prime * result + ((linkedList == null) ? 0 : linkedList.hashCode());
   result = prime * result + ((list == null) ? 0 : list.hashCode());
   result = prime * result + ((name == null) ? 0 : name.hashCode());
   result = prime * result + ((navigableSet == null) ? 0 : navigableSet.hashCode());
   result =
       prime * result + ((priorityBlockingQueue == null) ? 0 : priorityBlockingQueue.hashCode());
   result = prime * result + ((priorityQueue == null) ? 0 : priorityQueue.hashCode());
   result = prime * result + ((queue == null) ? 0 : queue.hashCode());
   result = prime * result + ((set == null) ? 0 : set.hashCode());
   result = prime * result + ((sortedSet == null) ? 0 : sortedSet.hashCode());
   result = prime * result + ((stack == null) ? 0 : stack.hashCode());
   result = prime * result + ((treeSet == null) ? 0 : treeSet.hashCode());
   result = prime * result + ((vector == null) ? 0 : vector.hashCode());
   return result;
 }
 public void clear() {
   dualChannelPool.clear();
 }
 public void push(DualChannel dualChannel) {
   dualChannelPool.push(dualChannel);
 }
 public DualChannel take() throws InterruptedException {
   return dualChannelPool.take();
 }
示例#25
0
 /**
  * Agrega la tarea pasada a una cola compartida de los workers para ser procesada.<br>
  * Se agrega a una cola aleatoreamente confiando en la normalidad de la distribución de manera que
  * las tareas sean distribuidas al azar pero normalmente entre todos los workers
  *
  * @param runnableTask La tarea a ejecutar
  */
 private void executeNow(final SubmittedRunnableTask runnableTask) {
   final int indiceDeColaElegida = ThreadLocalRandom.current().nextInt(colasCompartidas.length);
   final BlockingDeque<SubmittedTask> colaElegida = colasCompartidas[indiceDeColaElegida];
   colaElegida.offer(runnableTask);
 }
示例#26
0
文件: Bpm200.java 项目: emorency/onyx
 public List<BpmMessage> readAll() {
   List<BpmMessage> messages = new LinkedList<BpmMessage>();
   messageQueue.drainTo(messages);
   return Collections.unmodifiableList(messages);
 }
示例#27
0
文件: Bpm200.java 项目: emorency/onyx
 public void putBack(BpmMessage message) {
   messageQueue.addFirst(message);
 }
示例#28
0
文件: Bpm200.java 项目: emorency/onyx
 public void send(BpmMessage msg) {
   writeQueue.add(msg);
 }
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   PojoFoo other = (PojoFoo) obj;
   if (arrayBlockingQueue == null) {
     if (other.arrayBlockingQueue != null) return false;
   } else if (!arrayBlockingQueue.equals(other.arrayBlockingQueue)) return false;
   if (arrayDeque == null) {
     if (other.arrayDeque != null) return false;
   } else if (!arrayDeque.equals(other.arrayDeque)) return false;
   if (arrayList == null) {
     if (other.arrayList != null) return false;
   } else if (!arrayList.equals(other.arrayList)) return false;
   if (bar == null) {
     if (other.bar != null) return false;
   } else if (!bar.equals(other.bar)) return false;
   if (blockingDeque == null) {
     if (other.blockingDeque != null) return false;
   } else if (!blockingDeque.equals(other.blockingDeque)) return false;
   if (blockingQueue == null) {
     if (other.blockingQueue != null) return false;
   } else if (!blockingQueue.equals(other.blockingQueue)) return false;
   if (collection == null) {
     if (other.collection != null) return false;
   } else if (!collection.equals(other.collection)) return false;
   if (concurrentLinkedQueue == null) {
     if (other.concurrentLinkedQueue != null) return false;
   } else if (!concurrentLinkedQueue.equals(other.concurrentLinkedQueue)) return false;
   if (concurrentSkipListSet == null) {
     if (other.concurrentSkipListSet != null) return false;
   } else if (!concurrentSkipListSet.equals(other.concurrentSkipListSet)) return false;
   if (copyOnWriteArrayList == null) {
     if (other.copyOnWriteArrayList != null) return false;
   } else if (!copyOnWriteArrayList.equals(other.copyOnWriteArrayList)) return false;
   if (copyOnWriteArraySet == null) {
     if (other.copyOnWriteArraySet != null) return false;
   } else if (!copyOnWriteArraySet.equals(other.copyOnWriteArraySet)) return false;
   if (deque == null) {
     if (other.deque != null) return false;
   } else if (!deque.equals(other.deque)) return false;
   if (hashSet == null) {
     if (other.hashSet != null) return false;
   } else if (!hashSet.equals(other.hashSet)) return false;
   if (linkedBlockingDeque == null) {
     if (other.linkedBlockingDeque != null) return false;
   } else if (!linkedBlockingDeque.equals(other.linkedBlockingDeque)) return false;
   if (linkedBlockingQueue == null) {
     if (other.linkedBlockingQueue != null) return false;
   } else if (!linkedBlockingQueue.equals(other.linkedBlockingQueue)) return false;
   if (linkedHashSet == null) {
     if (other.linkedHashSet != null) return false;
   } else if (!linkedHashSet.equals(other.linkedHashSet)) return false;
   if (linkedList == null) {
     if (other.linkedList != null) return false;
   } else if (!linkedList.equals(other.linkedList)) return false;
   if (list == null) {
     if (other.list != null) return false;
   } else if (!list.equals(other.list)) return false;
   if (name == null) {
     if (other.name != null) return false;
   } else if (!name.equals(other.name)) return false;
   if (navigableSet == null) {
     if (other.navigableSet != null) return false;
   } else if (!navigableSet.equals(other.navigableSet)) return false;
   if (priorityBlockingQueue == null) {
     if (other.priorityBlockingQueue != null) return false;
   } else if (!priorityBlockingQueue.equals(other.priorityBlockingQueue)) return false;
   if (priorityQueue == null) {
     if (other.priorityQueue != null) return false;
   } else if (!priorityQueue.equals(other.priorityQueue)) return false;
   if (queue == null) {
     if (other.queue != null) return false;
   } else if (!queue.equals(other.queue)) return false;
   if (set == null) {
     if (other.set != null) return false;
   } else if (!set.equals(other.set)) return false;
   if (sortedSet == null) {
     if (other.sortedSet != null) return false;
   } else if (!sortedSet.equals(other.sortedSet)) return false;
   if (stack == null) {
     if (other.stack != null) return false;
   } else if (!stack.equals(other.stack)) return false;
   if (treeSet == null) {
     if (other.treeSet != null) return false;
   } else if (!treeSet.equals(other.treeSet)) return false;
   if (vector == null) {
     if (other.vector != null) return false;
   } else if (!vector.equals(other.vector)) return false;
   return true;
 }
 @Override
 public boolean isEmpty() {
   return pool.isEmpty();
 }