Refine search
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. } }
public static Set<Class<?>> getImplementedInterfaces(Class<?> cl) { Set<Class<?>> interfaces = new HashSet<Class<?>>(); Deque<Class<?>> classes = new ArrayDeque<Class<?>>(); classes.add(cl); while (!classes.isEmpty()) { Class<?> c = classes.pop(); interfaces.addAll(Arrays.asList(c.getInterfaces())); if (c.getSuperclass() != null) { classes.add(c.getSuperclass()); } classes.addAll(Arrays.asList(c.getInterfaces())); } return interfaces; }
/** * Submit a fetch task if remainingBytes is smaller than prefetchTriggerBytes. */ private void fetchIfNeeded(long remainingBytes) { if ((fetchFutures.isEmpty() || fetchFutures.peekLast().isDone()) && remainingBytes <= prefetchConfig.getPrefetchTriggerBytes()) { Future<Void> fetchFuture = fetchExecutor.submit(() -> { fetch(); return null; }); fetchFutures.add(fetchFuture); } }
@Override public void run() { Deque<IgniteBiTuple<Integer, Path>> queue = new ArrayDeque<>(); queue.add(F.t(0, dir)); U.awaitQuiet(barrier); while (!queue.isEmpty()) { IgniteBiTuple<Integer, Path> t = queue.pollFirst(); int curDepth = t.getKey(); Path curPath = t.getValue(); if (curDepth <= depth) { int newDepth = curDepth + 1; // Create directories. for (int i = 0; i < entryCnt; i++) { Path subDir = new Path(curPath, "dir-" + newDepth + "-" + i); try { if (fs.mkdirs(subDir)) queue.addLast(F.t(newDepth, subDir)); } catch (IOException e) { err.compareAndSet(null, e); } } } } } }, THREAD_CNT);
private static void placePhi(MethodNode mth, int regNum, LiveVarAnalysis la) { List<BlockNode> blocks = mth.getBasicBlocks(); int blocksCount = blocks.size(); BitSet hasPhi = new BitSet(blocksCount); BitSet processed = new BitSet(blocksCount); Deque<BlockNode> workList = new LinkedList<>(); BitSet assignBlocks = la.getAssignBlocks(regNum); for (int id = assignBlocks.nextSetBit(0); id >= 0; id = assignBlocks.nextSetBit(id + 1)) { processed.set(id); workList.add(blocks.get(id)); } while (!workList.isEmpty()) { BlockNode block = workList.pop(); BitSet domFrontier = block.getDomFrontier(); for (int id = domFrontier.nextSetBit(0); id >= 0; id = domFrontier.nextSetBit(id + 1)) { if (!hasPhi.get(id) && la.isLive(id, regNum)) { BlockNode df = blocks.get(id); addPhi(mth, df, regNum); hasPhi.set(id); if (!processed.get(id)) { processed.set(id); workList.add(df); } } } } }
public static Operator<?> findOperatorByMarker(Operator<?> start, String marker) { Deque<Operator<?>> queue = new ArrayDeque<>(); queue.add(start); while (!queue.isEmpty()) { Operator<?> op = queue.remove(); if (marker.equals(op.getMarker())) { return op; } if (op.getChildOperators() != null) { queue.addAll(op.getChildOperators()); } } return null; }
@Override public void run() { Deque<IgniteBiTuple<Integer, Path>> queue = new ArrayDeque<>(); queue.add(F.t(0, dir)); U.awaitQuiet(barrier); while (!queue.isEmpty()) { IgniteBiTuple<Integer, Path> t = queue.pollFirst(); int curDepth = t.getKey(); Path curPath = t.getValue(); if (curDepth <= depth) { int newDepth = curDepth + 1; // Create directories. for (int i = 0; i < entryCnt; i++) { Path subDir = new Path(curPath, "dir-" + newDepth + "-" + i); try { fs.mkdir(subDir, FsPermission.getDefault(), true); } catch (IOException ignore) { err.set(true); } queue.addLast(F.t(newDepth, subDir)); } } } } }, THREAD_CNT);
private static Map<File, Long> doScan(File file) { final Map<File, Long> results = new HashMap<File, Long>(); final Deque<File> toScan = new ArrayDeque<File>(); toScan.add(file); while (!toScan.isEmpty()) { File next = toScan.pop(); if (next.isDirectory()) { results.put(next, next.lastModified()); File[] list = next.listFiles(); if (list != null) { for (File f : list) { toScan.push(new File(f.getAbsolutePath())); } } } } return results; }
static Map<File, Long> doScan(File file) { final Map<File, Long> results = new HashMap<File, Long>(); final Deque<File> toScan = new ArrayDeque<File>(); toScan.add(file); while (!toScan.isEmpty()) { File next = toScan.pop(); if (next.isDirectory()) { results.put(next, next.lastModified()); File[] list = next.listFiles(); if (list != null) { for (File f : list) { toScan.push(new File(f.getAbsolutePath())); } } } else { results.put(next, next.lastModified()); } } return results; }
private boolean checkExpression(ExprNodeDesc expr) { Deque<ExprNodeDesc> exprs = new LinkedList<ExprNodeDesc>(); exprs.add(expr); while (!exprs.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("Checking '%s'",expr.getExprString())); } ExprNodeDesc cur = exprs.removeFirst(); if (cur == null) continue; if (cur.getChildren() != null) { exprs.addAll(cur.getChildren()); } if (!doSkipUdfCheck && cur instanceof ExprNodeGenericFuncDesc) { ExprNodeGenericFuncDesc funcDesc = (ExprNodeGenericFuncDesc)cur; boolean isBuiltIn = FunctionRegistry.isBuiltInFuncExpr(funcDesc); if (!isBuiltIn) { if (!arePermanentFnsAllowed) { LOG.info("Not a built-in function: " + cur.getExprString() + " (permanent functions are disabled)"); return false; } if (!FunctionRegistry.isPermanentFunction(funcDesc)) { LOG.info("Not a built-in or permanent function: " + cur.getExprString()); return false; } } } } return true; }
private void initPartitions() { partitionIds = partitionIdsState.get(PARTITION_IDS_KEY, new LinkedList<>()); if (partitionIds.isEmpty()) { partitionIds.add(0L); partitionIdsState.put(PARTITION_IDS_KEY, partitionIds); } latestPartitionId = partitionIds.peekLast(); latestPartition = cache.pinAndGet(latestPartitionId); }
private boolean checkExpression(ExprNodeDesc expr) { Deque<ExprNodeDesc> exprs = new LinkedList<ExprNodeDesc>(); exprs.add(expr); while (!exprs.isEmpty()) { if (LOG.isDebugEnabled()) { LOG.debug(String.format("Checking '%s'",expr.getExprString())); } ExprNodeDesc cur = exprs.removeFirst(); if (cur == null) continue; if (cur.getChildren() != null) { exprs.addAll(cur.getChildren()); } if (!doSkipUdfCheck && cur instanceof ExprNodeGenericFuncDesc) { ExprNodeGenericFuncDesc funcDesc = (ExprNodeGenericFuncDesc)cur; boolean isBuiltIn = FunctionRegistry.isBuiltInFuncExpr(funcDesc); if (!isBuiltIn) { if (!arePermanentFnsAllowed) { LOG.info("Not a built-in function: " + cur.getExprString() + " (permanent functions are disabled)"); return false; } if (!FunctionRegistry.isPermanentFunction(funcDesc)) { LOG.info("Not a built-in or permanent function: " + cur.getExprString()); return false; } } } } return true; }
@Override public List<String> listRecursive(final String path) throws KeeperException { assertClusterIdFlagTrue(); final Deque<String> queue = newLinkedList(); final List<String> tree = newArrayList(); queue.add(path); tree.add(path); while (!queue.isEmpty()) { final String node = queue.pollFirst(); final List<String> children = getChildren(node); for (final String child : children) { final String childPath = node.replaceAll("/$", "") + "/" + child; queue.add(childPath); tree.add(childPath); } } return tree; }