List of usage examples for java.util Queue offer
boolean offer(E e);
From source file:com.clustercontrol.jobmanagement.util.JobMultiplicityCache.java
/** * ??????//from w w w . ja v a 2 s.c o m * * ???? * * ?1. * ?running???runningQueue? * * ?2. * ?runnning????JobSessionNodeImpl().startNode() * ????startNode???????toRunning?? * (toRunning?waitQueue????????kick????) */ public static synchronized void refresh() { List<JobSessionJobEntityPK> execJobList = new ArrayList<JobSessionJobEntityPK>(); JpaTransactionManager jtm = new JpaTransactionManager(); if (!jtm.isNestedEm()) { m_log.warn("refresh() : transaction has not been begined."); jtm.close(); return; } m_log.info("cache refresh start"); long start = System.currentTimeMillis(); long time1, time2, time3; HinemosEntityManager em = jtm.getEntityManager(); try { _lock.writeLock(); HashMap<String, Queue<JobSessionNodeEntityPK>> runningCache = new HashMap<String, Queue<JobSessionNodeEntityPK>>(); storeWaitingCache(new HashMap<String, Queue<JobSessionNodeEntityPK>>()); // runningQueue?? { // ???? List<JobSessionNodeEntity> nodeList = em .createNamedQuery("JobSessionNodeEntity.findByStatus", JobSessionNodeEntity.class, ObjectPrivilegeMode.NONE) .setParameter("status", StatusConstant.TYPE_RUNNING).getResultList(); for (JobSessionNodeEntity node : nodeList) { String facilityId = node.getId().getFacilityId(); Queue<JobSessionNodeEntityPK> runningQueue = runningCache.get(facilityId); if (runningQueue == null) { runningQueue = new LinkedList<JobSessionNodeEntityPK>(); runningCache.put(facilityId, runningQueue); } m_log.debug("refresh add runningQueue : " + node.getId()); runningQueue.offer(node.getId()); } } storeRunningCache(runningCache); } finally { _lock.writeUnlock(); } time1 = System.currentTimeMillis() - start; start = System.currentTimeMillis(); // ????????list? { // ???? List<JobSessionJobEntity> jobList = em .createNamedQuery("JobSessionJobEntity.findByStatus", JobSessionJobEntity.class, ObjectPrivilegeMode.NONE) .setParameter("status", StatusConstant.TYPE_RUNNING).getResultList(); for (JobSessionJobEntity job : jobList) { if (job.getJobInfoEntity() == null || job.getJobInfoEntity().getJobType() == null) { m_log.info("wait job is deleted"); // ????????? continue; } if (job.getJobInfoEntity().getJobType() != JobConstant.TYPE_JOB && job.getJobInfoEntity().getJobType() != JobConstant.TYPE_APPROVALJOB && job.getJobInfoEntity().getJobType() != JobConstant.TYPE_MONITORJOB) { continue; } execJobList.add(job.getId()); } } time2 = System.currentTimeMillis() - start; start = System.currentTimeMillis(); // execJobList? for (JobSessionJobEntityPK id : execJobList) { try { m_log.info("refresh() startNode=" + id); new JobSessionNodeImpl().startNode(id.getSessionId(), id.getJobunitId(), id.getJobId()); } catch (InvalidRole e) { m_log.warn("refresh " + e.getMessage()); } catch (JobInfoNotFound e) { m_log.warn("refresh " + e.getMessage()); } } time3 = System.currentTimeMillis() - start; m_log.info("cache refresh end " + time1 + "+" + time2 + "+" + time3 + "ms"); print(); }
From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java
public static void prefixBindingPathNested(Component component, String addBindingPrefix) { @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); elementQueue.offer(component); try {/* ww w .j a v a 2 s . c om*/ while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (currentElement instanceof DataBinding) { if (LOG.isDebugEnabled()) { LOG.info("setting nested binding prefix '" + addBindingPrefix + "' on " + currentElement); } prefixBindingPath((DataBinding) currentElement, addBindingPrefix); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } }
From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java
/** * Get all nested children of a given component. * * @param component The component to search. * @return All nested children of the component. * @see ViewLifecycleUtils#getElementsForLifecycle(LifecycleElement) *///from w w w.j av a 2 s. co m public static List<Component> getAllNestedComponents(Component component) { if (component == null) { return Collections.emptyList(); } List<Component> components = Collections.emptyList(); @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); elementQueue.offer(component); try { while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (currentElement instanceof Component && currentElement != component) { if (components.isEmpty()) { components = new ArrayList<Component>(); } components.add((Component) currentElement); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } return components; }
From source file:org.languagetool.rules.AbstractCompoundRule.java
private void addToQueue(AnalyzedTokenReadings token, Queue<AnalyzedTokenReadings> prevTokens) { boolean inserted = prevTokens.offer(token); if (!inserted) { prevTokens.poll();/* w ww. jav a 2s . c o m*/ prevTokens.offer(token); } }
From source file:com.clustercontrol.jobmanagement.util.JobMultiplicityCache.java
/** * status?100(StatusConstant.TYPE_RUNNING)????????????? * * ???waitQueue???/*from ww w . ja v a2s . co m*/ * ???waitQueue????????kick?? * ?????waitQueue??? * ??????waitQueue???runningQueue? * @param facilityId */ public static boolean toRunning(JobSessionNodeEntityPK pk) { m_log.info("toRunning " + pk); String facilityId = pk.getFacilityId(); 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 = new LinkedList<JobSessionNodeEntityPK>(); waitingCache.put(facilityId, waitingQueue); } if (runningQueue == null) { runningQueue = new LinkedList<JobSessionNodeEntityPK>(); runningCache.put(facilityId, runningQueue); } if ((runningQueue == null || !runningQueue.contains(pk)) && !waitingQueue.contains(pk)) { m_log.debug("toRunning add waitQueue : " + pk); waitingQueue.offer(pk); } storeWaitingCache(waitingCache); storeRunningCache(runningCache); if (m_log.isDebugEnabled()) { for (JobSessionNodeEntityPK q : runningQueue) { m_log.debug("toRunning runningQueue : " + q); } for (JobSessionNodeEntityPK q : waitingQueue) { m_log.debug("toRunning waitQueue : " + q); } } // ?waitQueue??? kick(facilityId); } finally { _lock.writeUnlock(); } return true; }
From source file:com.naver.wordladder.WordLadder.java
public Node<String> getLeaf() { Queue<Node<String>> queue = new LinkedList<Node<String>>(); List<String> path = new ArrayList<String>(); queue.offer(new Node<String>(startString)); Node<String> currentNode; while ((currentNode = queue.poll()) != null) { String str = currentNode.getData(); path.add(str);// ww w . j a v a 2 s.co m Set<String> oneDistanceWords = getOneDistanceWords(str); for (String oneDistanceWord : oneDistanceWords) { if (path.contains(oneDistanceWord)) { continue; } Node<String> child = new Node<String>(oneDistanceWord); child.setParent(currentNode); if (calculateEditDistance(oneDistanceWord, endString) == 1) { //start end? ? ?. Node<String> leaf = new Node<String>(endString); leaf.setParent(child); return leaf; } queue.offer(child); } } return new Node<String>(startString); }
From source file:org.apache.lens.cube.parse.HQLParser.java
/** * Breadth first traversal of AST// ww w . j av a 2 s .c o m * * @param root node from where to start bft * @param visitor action to take on each visit * @throws LensException */ public static void bft(ASTNode root, ASTNodeVisitor visitor) throws LensException { if (root == null) { throw new NullPointerException("Root cannot be null"); } if (visitor == null) { throw new NullPointerException("Visitor cannot be null"); } Queue<TreeNode> queue = new LinkedList<>(); queue.add(new TreeNode(null, root)); while (!queue.isEmpty()) { TreeNode node = queue.poll(); visitor.visit(node); ASTNode astNode = node.getNode(); for (int i = 0; i < astNode.getChildCount(); i++) { queue.offer(new TreeNode(node, (ASTNode) astNode.getChild(i))); } } }
From source file:org.opentestsystem.shared.test.cooperation.StageImpl.java
@Override public synchronized void registerListeningQueue(CuePattern pattern, Queue<Cue> queue) { _listeningQueues.add(new ImmutablePair<>(pattern, queue)); for (Cue cue_i : _retainedCues) { if (pattern.isMatch(cue_i)) { if (!queue.offer(cue_i)) { _logger.warn("Cue {} rejected by listening queue", cue_i.getTag()); }//from w w w.jav a2 s . c om } } }
From source file:com.ibm.amc.feedback.FeedbackHandler.java
@Override public void actionStatusUpdated(final ActionStatus status) { if (logger.isEntryEnabled()) logger.entry("actionStatusUpdated", status); if (!status.isSynchronous()) { final String user = status.getUserId(); final Set<AsyncContext> contexts = feedbackListeners.remove(user); if (contexts == null) { // No one waiting - queue status if (logger.isDebugEnabled()) logger.debug("actionStatusUpdated", "Queuing status update for action " + status.getActionId()); queueActionStatus(status);//from w ww . j a v a2 s . c o m } else { // Request waiting - send response immediately if (logger.isDebugEnabled()) logger.debug("actionStatusUpdated", "Sending status update for action " + status.getActionId()); final Queue<ActionStatusResponse> queue = new LinkedList<ActionStatusResponse>(); queue.offer(new ActionStatusResponse(status)); for (AsyncContext ctx : contexts) { writeResponse(ctx.getResponse(), queue); ctx.complete(); } } } if (logger.isEntryEnabled()) logger.exit("actionStatusUpdated"); }
From source file:org.kuali.rice.krad.uif.util.ObjectPropertyUtils.java
/** * Locate the generic type declaration for a given target class in the generic type hierarchy of * the source class.//from w w w. j a v a 2s . c o m * * @param sourceClass The class representing the generic type hierarchy to scan. * @param targetClass The class representing the generic type declaration to locate within the * source class' hierarchy. * @return The generic type representing the target class within the source class' generic * hierarchy. */ public static Type findGenericType(Class<?> sourceClass, Class<?> targetClass) { if (!targetClass.isAssignableFrom(sourceClass)) { throw new IllegalArgumentException(targetClass + " is not assignable from " + sourceClass); } if (sourceClass.equals(targetClass)) { return sourceClass; } @SuppressWarnings("unchecked") Queue<Type> typeQueue = RecycleUtils.getInstance(LinkedList.class); typeQueue.offer(sourceClass); while (!typeQueue.isEmpty()) { Type type = typeQueue.poll(); Class<?> upperBound = getUpperBound(type); if (targetClass.equals(upperBound)) { return type; } Type genericSuper = upperBound.getGenericSuperclass(); if (genericSuper != null) { typeQueue.offer(genericSuper); } Type[] genericInterfaces = upperBound.getGenericInterfaces(); for (int i = 0; i < genericInterfaces.length; i++) { if (genericInterfaces[i] != null) { typeQueue.offer(genericInterfaces[i]); } } } throw new IllegalStateException(targetClass + " is assignable from " + sourceClass + " but could not be found in the generic type hierarchy"); }