/** * Reconstitutes this queue from a stream (that is, deserializes it). */ private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); for (;;) { @SuppressWarnings("unchecked") E item = (E) s.readObject(); if (item == null) break; else offer(item); } }
public boolean force(Runnable o) { if (threadPoolExecutor.isShutdown()) { throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); } // forces the item onto the queue, to be used if the task is rejected return super.offer(o); }
private void releaseSlot(final ByteSlot slot) { slot.reset(); slotsCache.offer(slot); }
public boolean offer(Runnable o) { int poolSize = threadPoolExecutor.getPoolSize(); // we are maxed out on threads, simply queue the object if (poolSize == threadPoolExecutor.getMaximumPoolSize()) { return super.offer(o); } // we have idle threads, just add it to the queue // note that we don't use getActiveCount(), see BZ 49730 if (threadPoolExecutor.getSubmittedTasksCount() <= poolSize) { return super.offer(o); } // if we have less threads than maximum force creation of a new // thread if (poolSize < threadPoolExecutor.getMaximumPoolSize()) { return false; } // if we reached here, we need to add it to the queue return super.offer(o); } }
slotsCache = new LinkedTransferQueue<>(); while (slotsCache.size() < numSlots) { slotsCache.offer(new ByteSlot());
@Override public boolean offer(E e) { // first try to transfer to a waiting worker thread if (!tryTransfer(e)) { // check if there might be spare capacity in the thread // pool executor int left = executor.getMaximumPoolSize() - executor.getCorePoolSize(); if (left > 0) { // reject queuing the task to force the thread pool // executor to add a worker if it can; combined // with ForceQueuePolicy, this causes the thread // pool to always scale up to max pool size and we // only queue when there is no spare capacity return false; } else { return super.offer(e); } } else { return true; } }
private void handleBatchRead(List<DataStoreRequest> operations) { for (DataStoreRequest dataStoreRequest : operations) { if (dataStoreRequest instanceof ReadBatchRequest) { this.batchReadOperations.offer((ReadBatchRequest) dataStoreRequest); } } }
@Override public boolean add(Runnable runnable) { return super.offer(runnable); } }
@Override public boolean add(Runnable runnable) { return super.offer(runnable); } }
@Override public boolean add(Runnable runnable) { return super.offer(runnable); } }
@Override public void remove(RemoveRequest request) { map.remove(request.key()); this.writeOperationsQueue.offer(request); }
public boolean force(Runnable o) { if (threadPoolExecutor.isShutdown()) { throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); } return super.offer(o); }
public boolean force(Runnable o) { if (threadPoolExecutor.isShutdown()) { throw new RejectedExecutionException("Executor not running, can't force a command into the queue"); } return super.offer(o); }
@Override public void sendMany(T... items) { flushSends(); if (!queue.tryTransfer(items)) { queue.offer(items); } }
public void addAll(BatchSetRequest request) { final List<String> keys = request.keys(); final List<String> values = request.values(); int index = 0; for (String key : keys) { String value = values.get(index); set(key, value); index++; } this.writeOperationsQueue.offer(request); }
public void addAll(BatchSetRequest request) { Map<String, String> newMap = new LinkedHashMap<>(request.payloadAsMap()); for (String blackListKey : keyblackList) { newMap.remove(blackListKey); } this.writeOperationsQueue.offer(new BatchSetRequest(request.messageId(), request.clientId(), newMap)); }
@Override public void sendBatch(Collection<T> items) { flushSends(); final Object[] array = Arry.objectArray(items); if (!queue.tryTransfer(array)) { queue.offer(array); } }
@Override public void sendBatch(Iterable<T> items) { flushSends(); final Object[] array = Arry.objectArray(items); if (!queue.tryTransfer(array)) { queue.offer(array); } }
private void handleSetAndBroadCastVerb(DataStoreRequest request) { if (debug) logger.info("RequestHandler::handleSetAndBroadCastVerb::", request); masterDataStore.set((SetRequest) request); SingleResult dataItem = new SingleResult(request.messageId(), request.clientId(), DataStoreSource.CLIENT, request.key(), request.payload()); broadCastQueue.offer(new BroadCastSendData(request.key(), dataItem.toBroadcastTextMessage())); }