Refine search
/** Close and remove all idle connections in the pool. */ public void evictAll() { List<RealConnection> evictedConnections = new ArrayList<>(); synchronized (this) { for (Iterator<RealConnection> i = connections.iterator(); i.hasNext(); ) { RealConnection connection = i.next(); if (connection.allocations.isEmpty()) { connection.noNewStreams = true; evictedConnections.add(connection); i.remove(); } } } for (RealConnection connection : evictedConnections) { closeQuietly(connection.socket()); } }
/** * @param ses Session. */ public void resend(GridNioSession ses) { assert ses instanceof GridSelectorNioSessionImpl; GridNioRecoveryDescriptor recoveryDesc = ses.outRecoveryDescriptor(); if (recoveryDesc != null && !recoveryDesc.messagesRequests().isEmpty()) { Deque<SessionWriteRequest> futs = recoveryDesc.messagesRequests(); if (log.isDebugEnabled()) log.debug("Resend messages [rmtNode=" + recoveryDesc.node().id() + ", msgCnt=" + futs.size() + ']'); GridSelectorNioSessionImpl ses0 = (GridSelectorNioSessionImpl)ses; SessionWriteRequest fut0 = futs.iterator().next(); for (SessionWriteRequest fut : futs) { fut.messageThread(true); fut.resetSession(ses0); } ses0.resend(futs); // Wake up worker. ses0.offerStateChange((GridNioServer.SessionChangeRequest)fut0); } }
private void promoteCalls() { if (runningAsyncCalls.size() >= maxRequests) return; // Already running max capacity. if (readyAsyncCalls.isEmpty()) return; // No ready calls to promote. for (Iterator<AsyncCall> i = readyAsyncCalls.iterator(); i.hasNext(); ) { AsyncCall call = i.next(); if (runningCallsForHost(call) < maxRequestsPerHost) { i.remove(); runningAsyncCalls.add(call); executorService().execute(call); } if (runningAsyncCalls.size() >= maxRequests) return; // Reached max capacity. } }
@Override public T parent() { Iterator<PathAwareVisitor.PathElement<T>> iterator = deque.iterator(); if (iterator.hasNext()) { iterator.next(); if (iterator.hasNext()) { return iterator.next().getElement(); } } throw new NoSuchElementException("Path is either empty or has only one element. There is no parent"); }
/** Close and remove all idle connections in the pool. */ public void evictAll() { List<RealConnection> evictedConnections = new ArrayList<>(); synchronized (this) { for (Iterator<RealConnection> i = connections.iterator(); i.hasNext(); ) { RealConnection connection = i.next(); if (connection.allocations.isEmpty()) { connection.noNewStreams = true; evictedConnections.add(connection); i.remove(); } } } for (RealConnection connection : evictedConnections) { closeQuietly(connection.socket()); } }
/** * Acknowledges the session ids. * @param checkpointId The id of the current checkout to acknowledge ids for. * @param uniqueIds The checkpointed unique ids which are ignored here. They only serve as a * means of de-duplicating messages when the acknowledgment after a checkpoint * fails. */ @Override protected final void acknowledgeIDs(long checkpointId, Set<UId> uniqueIds) { LOG.debug("Acknowledging ids for checkpoint {}", checkpointId); Iterator<Tuple2<Long, List<SessionId>>> iterator = sessionIdsPerSnapshot.iterator(); while (iterator.hasNext()) { final Tuple2<Long, List<SessionId>> next = iterator.next(); long id = next.f0; if (id <= checkpointId) { acknowledgeSessionIDs(next.f1); // remove ids for this session iterator.remove(); } } }
/** * Promotes eligible calls from {@link #readyAsyncCalls} to {@link #runningAsyncCalls} and runs * them on the executor service. Must not be called with synchronization because executing calls * can call into user code. * * @return true if the dispatcher is currently running calls. */ private boolean promoteAndExecute() { assert (!Thread.holdsLock(this)); List<AsyncCall> executableCalls = new ArrayList<>(); boolean isRunning; synchronized (this) { for (Iterator<AsyncCall> i = readyAsyncCalls.iterator(); i.hasNext(); ) { AsyncCall asyncCall = i.next(); if (runningAsyncCalls.size() >= maxRequests) break; // Max capacity. if (runningCallsForHost(asyncCall) >= maxRequestsPerHost) continue; // Host max capacity. i.remove(); executableCalls.add(asyncCall); runningAsyncCalls.add(asyncCall); } isRunning = runningCallsCount() > 0; } for (int i = 0, size = executableCalls.size(); i < size; i++) { AsyncCall asyncCall = executableCalls.get(i); asyncCall.executeOn(executorService()); } return isRunning; }
synchronized String out() { final StringBuilder builder = new StringBuilder(); final Iterator<Chunk> iterator = chunks.iterator(); while (iterator.hasNext()) { final Chunk chunk = iterator.next(); builder.append('['); for (int i = chunk.startIndex; i < chunk.cursor; i++) { builder.append('(').append(chunk.keys[i]).append(": ") .append(chunk.values[i]).append(')').append(' '); } builder.append(']'); if (iterator.hasNext()) { builder.append("->"); } } return builder.toString(); }
/** Close and remove all idle connections in the pool. */ public void evictAll() { List<RealConnection> evictedConnections = new ArrayList<>(); synchronized (this) { for (Iterator<RealConnection> i = connections.iterator(); i.hasNext(); ) { RealConnection connection = i.next(); if (connection.allocations.isEmpty()) { connection.noNewStreams = true; evictedConnections.add(connection); i.remove(); } } } for (RealConnection connection : evictedConnections) { closeQuietly(connection.socket()); } }
@Override public void reset() { Iterator<FireableStoreEventHolder<K, V>> iterator = events.iterator(); while (iterator.hasNext()) { FireableStoreEventHolder<K, V> next = iterator.next(); if (ordered) { BlockingQueue<FireableStoreEventHolder<K, V>> orderedQueue = getOrderedQueue(next); orderedQueue.remove(next); fireWaiters(listeners, orderedQueue); } iterator.remove(); } }
@Override public String getProperty(String name) { String value = writeSettings.getProperty(name); if (value == null) { Iterator<Settings> toCheck = settingsList.iterator(); while (value == null && toCheck.hasNext()) { Settings next = toCheck.next(); value = next.getProperty(name); } } return value; }
protected void adjustTabuList(int tabuStepIndex, Collection<? extends Object> tabus) { int totalTabuListSize = workingTabuSize + workingFadingTabuSize; // is at least 1 // Remove the oldest tabu(s) for (Iterator<Object> it = tabuSequenceDeque.iterator(); it.hasNext();) { Object oldTabu = it.next(); Integer oldTabuStepIndexInteger = tabuToStepIndexMap.get(oldTabu); if (oldTabuStepIndexInteger == null) { throw new IllegalStateException("HashCode stability violation: the hashCode() of tabu (" + oldTabu + ") of class (" + oldTabu.getClass() + ") changed during planning, since it was inserted in the tabu Map or Set."); } int oldTabuStepCount = tabuStepIndex - oldTabuStepIndexInteger; // at least 1 if (oldTabuStepCount < totalTabuListSize) { break; } it.remove(); tabuToStepIndexMap.remove(oldTabu); } // Add the new tabu(s) for (Object tabu : tabus) { // Push tabu to the end of the line if (tabuToStepIndexMap.containsKey(tabu)) { tabuToStepIndexMap.remove(tabu); tabuSequenceDeque.remove(tabu); } tabuToStepIndexMap.put(tabu, tabuStepIndex); tabuSequenceDeque.add(tabu); } }
protected List<StackItem> getMethodParams(String desc, boolean isStatic) { Type[] argTypes = Type.getArgumentTypes(desc); int idx = argTypes.length - 1; List<StackItem> items = new ArrayList<>(); Iterator<StackItem> it = state.fState.stack.iterator(); while (it.hasNext() && idx >= 0) { Type t = argTypes[idx]; items.add(0, it.next()); if (t.equals(Type.LONG_TYPE) || t.equals(Type.DOUBLE_TYPE)) { it.next(); } idx--; } if (!isStatic && it.hasNext()) { items.add(0, it.next()); } return items; } }