/** * Sends the given method call to this thread. * * @throws TimeoutException if this thread does not accept the request within a reasonable amount * of time */ private void sendRequest(String methodName, Object... arguments) throws Exception { if (!requestQueue.offer( new Request(methodName, arguments), TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { throw new TimeoutException(); } }
/** * Add a new object to the bag for others to borrow. * * @param bagEntry an object to add to the bag */ public void add(final T bagEntry) { if (closed) { LOGGER.info("ConcurrentBag has been closed, ignoring add()"); throw new IllegalStateException("ConcurrentBag has been closed, ignoring add()"); } sharedList.add(bagEntry); // spin until a thread takes it or none are waiting while (waiters.get() > 0 && bagEntry.getState() == STATE_NOT_IN_USE && !handoffQueue.offer(bagEntry)) { yield(); } }
/** * This method is used to make an item reserved via <code>reserve(T)</code> * available again for borrowing. * * @param bagEntry the item to unreserve */ public void unreserve(final T bagEntry) { if (bagEntry.compareAndSet(STATE_RESERVED, STATE_NOT_IN_USE)) { // spin until a thread takes it or none are waiting while (waiters.get() > 0 && !handoffQueue.offer(bagEntry)) { yield(); } } else { LOGGER.warn("Attempt to relinquish an object to the bag that was not reserved: {}", bagEntry); } }
/** * This method will return a borrowed object to the bag. Objects * that are borrowed from the bag but never "requited" will result * in a memory leak. * * @param bagEntry the value to return to the bag * @throws NullPointerException if value is null * @throws IllegalStateException if the bagEntry was not borrowed from the bag */ public void requite(final T bagEntry) { bagEntry.setState(STATE_NOT_IN_USE); for (int i = 0; waiters.get() > 0; i++) { if (bagEntry.getState() != STATE_NOT_IN_USE || handoffQueue.offer(bagEntry)) { return; } else if ((i & 0xff) == 0xff) { parkNanos(MICROSECONDS.toNanos(10)); } else { yield(); } } final List<Object> threadLocalList = threadList.get(); if (threadLocalList.size() < 50) { threadLocalList.add(weakThreadLocals ? new WeakReference<>(bagEntry) : bagEntry); } }
synced = sync.offer(stackTrace, waitMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException ignored) {
slopStorageEngine))); boolean offered = slopQueue.offer(versioned, voldemortConfig.getClientRoutingTimeoutMs(), TimeUnit.MILLISECONDS);
@Override public void trigger(Message<?> message) { Object key = this.correlationStrategy.getCorrelationKey(message); if (key == null) { throw new MessagingException(message, "Correlation Strategy returned null"); } SynchronousQueue<Message<?>> syncQueue = createOrObtainQueue(key); try { if (!syncQueue.offer(message, this.timeout, TimeUnit.MILLISECONDS)) { this.logger.error("Suspending thread timed out or did not arrive within timeout for: " + message); this.suspensions.remove(key); if (getDiscardChannel() != null) { this.messagingTemplate.send(getDiscardChannel(), message); } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); this.logger.error("Interrupted while waiting for the suspending thread for: " + message); this.suspensions.remove(key); } }
String codeString = Arrays.stream(code).collect(joining("\n")); GenerationRequest request = new GenerationRequest(codeString, annotationType); if (!requestQueue.offer(request, TIMEOUT_SECONDS, TimeUnit.SECONDS)) { throw new UncheckedTimeoutException("Code generation request timed out");
@Override public void stateChanged(LogFile logFile) { //try for a little while to notify run() method that there's a new file, then give up and drop on floor. try { stateChanges.offer(logFile, 1, TimeUnit.SECONDS); } catch (InterruptedException e) { //ignore } } }
/** * Try to give a job to a worker directly through the SynchronousQueue.<br> * Store it in the ConcurrentLinkedQueue if no worker is available. * @param token The token to process. */ public void put(final EventToken token) { if (!synchronousQueue.offer(token)) { concurrentLinkedQueue.offer(token); } }
void handleClosure() { try { // receiving the CLOSE message will cause the reading thread // to close the transfer. if ( !handoffQueue.offer(CLOSE, 600, TimeUnit.SECONDS) ) { // if after 5 minutes, no reader has taken the message, force close. open = false; } } catch ( InterruptedException e ) { Thread.currentThread().interrupt(); } }
@Override public void handle(T event) { if (filterRawType.isInstance(event) && filter.test(event)) { unregisterListener(this); result.offer(event); } } });
public void put(Thread t, long timeoutMS) throws InterruptedException, TimeoutException { if (!queue.offer(new WeightedQueue.Entry(t), timeoutMS, TimeUnit.MILLISECONDS)) throw new TimeoutException("Failed to acquire request scheduler slot for '" + key + "'"); }
public void put(Thread t, long timeoutMS) throws InterruptedException, TimeoutException { if (!queue.offer(new WeightedQueue.Entry(t), timeoutMS, TimeUnit.MILLISECONDS)) throw new TimeoutException("Failed to acquire request scheduler slot for '" + key + "'"); }
public void put(T obj, long timeout) { try { queue.offer(obj, timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { log.error("put synchronous obj error", e); } }
@Override public void deviceAdded(final Registry registry, @SuppressWarnings("rawtypes") final Device device) { @SuppressWarnings("unchecked") final Service<?, ?> connectionService = discoverConnectionService(device); if (connectionService == null) { return; } logger.debug("Found connection service {}", connectionService); foundServices.offer(connectionService); }
@Override public void requestDestroyed(ServletRequestEvent sre) { HttpServletRequest request = (HttpServletRequest) sre.getServletRequest(); log.info("LOG00000: requestDestroyed: {}", request); endRendezvous.offer(new Request( Request.Method.valueOf(request.getMethod().toUpperCase()), request.getRequestURI(), request.getParameterMap())); }
@Override public void requestInitialized(ServletRequestEvent sre) { HttpServletRequest request = (HttpServletRequest) sre.getServletRequest(); log.info("LOG00010: requestInitialized: {}", request); startRendezvous.offer(new Request( Request.Method.valueOf(request.getMethod().toUpperCase()), request.getRequestURI(), request.getParameterMap())); }
/** * Sends the given method call to this thread. * * @throws TimeoutException if this thread does not accept the request within a reasonable amount * of time */ private void sendRequest(String methodName, Object... arguments) throws Exception { if (!requestQueue.offer( new Request(methodName, arguments), TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) { throw new TimeoutException(); } }