List of usage examples for java.util Queue offer
boolean offer(E e);
From source file:com.clustercontrol.jobmanagement.util.JobMultiplicityCache.java
/** * ??//w w w . j av a 2s. c om * ?????????????????? * * @param facilityId * @return */ public static void kick(String facilityId) { m_log.debug("kick " + facilityId); boolean kickFlag = false; try { _lock.writeLock(); HashMap<String, Queue<JobSessionNodeEntityPK>> waitingCache = getWaitingCache(); HashMap<String, Queue<JobSessionNodeEntityPK>> runningCache = getRunningCache(); Queue<JobSessionNodeEntityPK> waitingQueue = waitingCache.get(facilityId); Queue<JobSessionNodeEntityPK> runningQueue = runningCache.get(facilityId); if (waitingQueue == null || waitingQueue.size() == 0) { return; } if (runningQueue == null) { runningQueue = new LinkedList<JobSessionNodeEntityPK>(); runningCache.put(facilityId, runningQueue); } if (isRunNow(facilityId)) { JpaTransactionManager jtm = new JpaTransactionManager(); try { jtm.begin(); JobSessionNodeEntityPK pk = waitingQueue.peek(); //// waitQueue??(??????) m_log.debug("kick remove waitQueue : " + pk); int status = new JobSessionNodeImpl().wait2running(pk); // ? if (status == 0) { m_log.debug("kick add runningQueue : " + pk); waitingQueue.poll(); //// waitQueue? runningQueue.offer(pk); //// runningQueue? kickFlag = true; } // ?????????? else if (status == 1) { m_log.debug("kick not add runningQueue : " + pk); waitingQueue.poll(); //// waitQueue? kickFlag = true; } jtm.commit(); } catch (Exception e) { m_log.warn("kick : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e); jtm.rollback(); } finally { jtm.close(); } } storeWaitingCache(waitingCache); storeRunningCache(runningCache); if (m_log.isDebugEnabled()) { for (JobSessionNodeEntityPK q : runningQueue) { m_log.debug("kick runningQueue : " + q); } for (JobSessionNodeEntityPK q : waitingQueue) { m_log.debug("kick waitQueue : " + q); } } if (kickFlag) { kick(facilityId); } } finally { _lock.writeUnlock(); } }
From source file:de.thomaskrille.dropwizard.environment_configuration.EnvironmentConfigurationFactory.java
private void replaceEnvironmentVariablesForObject(final Queue<JsonNode> q, final ObjectNode node) { Iterator<Map.Entry<String, JsonNode>> nodeIterator = node.fields(); while (nodeIterator.hasNext()) { Map.Entry<String, JsonNode> entry = nodeIterator.next(); if (entry.getValue().isContainerNode()) { q.offer(entry.getValue()); continue; }/*from w w w. ja v a 2 s .co m*/ if (!entry.getValue().isValueNode()) { continue; } String replacement = getReplacementForValue(entry.getValue()); if (replacement == null) { continue; } node.put(entry.getKey(), replacement); } }
From source file:org.dspace.app.xmlui.aspect.administrative.group.EditGroupForm.java
/** * Method to extensively check whether the first group has the second group as a distant * parent. This is used to avoid creating cycles like A->B, B->C, C->D, D->A which leads * all the groups involved to essentially include themselves. *///from w w w . j ava 2s.com private boolean isDescendant(Group descendant, Group ancestor, List<UUID> memberGroupIDs) throws SQLException { Queue<Group> toVisit = new LinkedList<Group>(); Group currentGroup; toVisit.offer(ancestor); // Initialize by adding a list of our current list of group members. for (UUID groupid : memberGroupIDs) { Group member = groupService.find(context, groupid); toVisit.offer(member); } while (!toVisit.isEmpty()) { // 1. Grab a group from the queue currentGroup = toVisit.poll(); // 2. See if it's the descendant we're looking for if (currentGroup.equals(descendant)) { return true; } // 3. If not, add that group's children to the queue for (Group nextBatch : currentGroup.getMemberGroups()) { toVisit.offer(nextBatch); } } return false; }
From source file:org.trend.hgraph.util.test.GenerateTestData.java
private void doGenerateTestData() throws IOException { HTable vertexTable = null;//from w w w. j a va 2 s . co m HTable edgeTable = null; Put put = null; long vIdx = 0; byte[] parentVertexKey = null; StopWatch timer = new StopWatch(); timer.start(); try { vertexTable = new HTable(this.getConf(), this.vertexTable); vertexTable.setAutoFlush(false); edgeTable = new HTable(this.getConf(), this.edgeTable); edgeTable.setAutoFlush(false); Queue<byte[]> parentVertexKeysQueue = new ArrayDeque<byte[]>(); int tmpEdgeCountPerVertex = 0; int edgeAcctCount = 0; Properties.Pair<Integer, Integer> pair = null; for (int rowCount = 0; rowCount < this.vertexCount; rowCount++) { put = generateVertexPut(); vertexTable.put(put); parentVertexKeysQueue.offer(put.getRow()); if (rowCount > 0) { vIdx = rowCount % tmpEdgeCountPerVertex; if (vIdx == 0) { parentVertexKey = parentVertexKeysQueue.poll(); edgeAcctCount++; if (this.isDistributionMode && !this.isFirstVertices[pair.key] && edgeAcctCount == tmpEdgeCountPerVertex) { this.addFirstVertex(Bytes.toString(parentVertexKey)); this.isFirstVertices[pair.key] = true; } pair = this.determineEdgeCountPerVertex(rowCount); tmpEdgeCountPerVertex = pair.value; edgeAcctCount = 0; } else if (vIdx > 0) { edgeAcctCount++; parentVertexKey = parentVertexKeysQueue.peek(); } else { throw new RuntimeException("vIdex:" + vIdx + " shall always not small than 0"); } put = generateEdgePut(rowCount, parentVertexKey, put.getRow()); edgeTable.put(put); } else { pair = this.determineEdgeCountPerVertex(rowCount); tmpEdgeCountPerVertex = pair.value; if (!this.isDistributionMode) this.addFirstVertex(Bytes.toString(put.getRow())); } } vertexTable.flushCommits(); edgeTable.flushCommits(); } catch (IOException e) { LOG.error("doGenerateTestData failed", e); throw e; } finally { if (null != vertexTable) vertexTable.close(); if (null != edgeTable) edgeTable.close(); timer.stop(); LOG.info("Time elapsed:" + timer.toString() + ", " + timer.getTime() + " for pushing " + this.vertexCount + " vertices test data to HBase"); LOG.info("first vertices id:" + this.firstVertices); } }
From source file:org.polymap.core.model2.engine.EntityRepositoryImpl.java
public EntityRepositoryImpl(final EntityRepositoryConfiguration config) { this.config = config; // init store getStore().init(new StoreRuntimeContextImpl()); // init infos log.info("Initialializing Composite types:"); Queue<Class<? extends Composite>> queue = new LinkedList(); queue.addAll(Arrays.asList(config.getEntities())); while (!queue.isEmpty()) { log.info(" Composite type: " + queue.peek()); CompositeInfoImpl info = new CompositeInfoImpl(queue.poll()); infos.put(info.getType(), info); // mixins queue.addAll(info.getMixins());// w ww. j ava2s . c om // Composite properties for (PropertyInfo propInfo : info.getProperties()) { if (Composite.class.isAssignableFrom(propInfo.getType())) { queue.offer(propInfo.getType()); } } } }
From source file:net.sf.nmedit.jpatch.impl.PBasicConnectionManager.java
public Collection<PConnector> graph(PConnector c) { Node n = nodemap.get(c);/*from w w w . j a v a 2 s .c o m*/ if (n == null) return Collections.<PConnector>emptyList(); Queue<Node> queue = new LinkedList<Node>(); Collection<PConnector> g = new LinkedList<PConnector>(); queue.offer(n.root()); while (!queue.isEmpty()) { n = queue.remove(); g.add(n.c); n.addChildNodes(queue); } return Collections.<PConnector>unmodifiableCollection(g); }
From source file:org.kuali.rice.krad.uif.lifecycle.ViewLifecyclePhaseBase.java
/** * {@inheritDoc}//from w w w . j a va 2 s . c om */ @Override public String toString() { StringBuilder sb = new StringBuilder(); Queue<ViewLifecyclePhase> toPrint = new LinkedList<ViewLifecyclePhase>(); toPrint.offer(this); while (!toPrint.isEmpty()) { ViewLifecyclePhase tp = toPrint.poll(); if (tp.getElement() == null) { sb.append("\n "); sb.append(tp.getClass().getSimpleName()); sb.append(" (recycled)"); continue; } String indent; if (tp == this) { sb.append("\nProcessed? "); sb.append(processed); indent = "\n"; } else { indent = "\n "; } sb.append(indent); sb.append(tp.getClass().getSimpleName()); sb.append(" "); sb.append(System.identityHashCode(tp)); sb.append(" "); sb.append(tp.getViewPath()); sb.append(" "); sb.append(tp.getElement().getClass().getSimpleName()); sb.append(" "); sb.append(tp.getElement().getId()); sb.append(" "); sb.append(pendingSuccessors); if (tp == this) { sb.append("\nPredecessor Phases:"); } ViewLifecyclePhase tpredecessor = tp.getPredecessor(); if (tpredecessor != null) { toPrint.add(tpredecessor); } } return sb.toString(); }
From source file:org.apache.streams.datasift.provider.DatasiftStreamProvider.java
@Override //This is a hack. It is only like this because of how perpetual streams work at the moment. Read list server to debate/vote for new interfaces. public StreamsResultSet readCurrent() { Queue<StreamsDatum> datums = Queues.newConcurrentLinkedQueue(); StreamsDatum datum = null;/*from w ww.j ava2s. co m*/ Interaction interaction; while (!this.interactions.isEmpty()) { interaction = this.interactions.poll(); try { datum = new StreamsDatum(this.mapper.writeValueAsString(interaction.getData()), interaction.getData().get("interaction").get("id").textValue()); } catch (JsonProcessingException jpe) { LOGGER.error("Exception while converting Interaction to String : {}", jpe); } if (datum != null) { while (!datums.offer(datum)) { Thread.yield(); } } } return new StreamsResultSet(datums); }
From source file:ubic.basecode.dataStructure.graph.DirectedGraph.java
/** * Fills in the topoSortOrder for each node. */// ww w . j a v a2s .com public void topoSort() { Queue<DirectedGraphNode<K, V>> q = new LinkedList<DirectedGraphNode<K, V>>(); int counter = 0; Map<DirectedGraphNode<K, V>, Integer> degrees = new HashMap<DirectedGraphNode<K, V>, Integer>(); /* Get the degrees of all items, and enqueue zero-indegree nodes */ for (K element : this.items.keySet()) { DirectedGraphNode<K, V> v = items.get(element); degrees.put(v, new Integer(v.inDegree())); if (degrees.get(v).intValue() == 0) { q.offer(v); } } while (!q.isEmpty()) { DirectedGraphNode<K, V> v = q.remove(); v.setTopoSortOrder(++counter); for (DirectedGraphNode<K, V> w : v.getChildNodes()) { /* decrement the degree of this node */ int inDegree = degrees.get(w).intValue(); inDegree--; degrees.put(w, new Integer(inDegree)); /* see if this now is one of the zero-indegree nodes */ if (inDegree == 0) { q.offer(w); } } } if (counter != items.size()) { throw new IllegalStateException( "Graph contains a cycle; " + counter + " items found, " + items.size() + " expected"); } }
From source file:org.kuali.rice.krad.uif.lifecycle.ApplyModelComponentPhase.java
/** * Applies the model data to a component of the View instance * * <p>/*www .ja va 2 s . co m*/ * TODO: Revise - The component is invoked to to apply the model data. Here the component can * generate any additional fields needed or alter the configured fields. After the component is * invoked a hook for custom helper service processing is invoked. Finally the method is * recursively called for all the component children * </p> * * {@inheritDoc} */ @Override protected void initializePendingTasks(Queue<ViewLifecycleTask<?>> tasks) { tasks.add(LifecycleTaskFactory.getTask(PopulateComponentContextTask.class, this)); tasks.add(LifecycleTaskFactory.getTask(EvaluateExpressionsTask.class, this)); tasks.add(LifecycleTaskFactory.getTask(SyncClientSideStateTask.class, this)); tasks.add(LifecycleTaskFactory.getTask(ApplyAuthAndPresentationLogicTask.class, this)); if (ViewLifecycle.isRefreshComponent(getViewPhase(), getViewPath())) { tasks.add(LifecycleTaskFactory.getTask(RefreshStateModifyTask.class, this)); } tasks.add(LifecycleTaskFactory.getTask(ComponentDefaultApplyModelTask.class, this)); getElement().initializePendingTasks(this, tasks); tasks.offer(LifecycleTaskFactory.getTask(RunComponentModifiersTask.class, this)); tasks.add(LifecycleTaskFactory.getTask(HelperCustomApplyModelTask.class, this)); tasks.add(LifecycleTaskFactory.getTask(SetReadOnlyOnDataBindingTask.class, this)); }