List of usage examples for java.util Queue add
boolean add(E e);
From source file:specminers.smartic.MergingBlock.java
public List<State<String>> getNodesByBreadthFirstSearch(Automaton<String> automaton) { LinkedList<State<String>> V = new LinkedList<>(); Queue<State<String>> Q = new LinkedBlockingDeque<>(); V.add(automaton.getInitialState());//w ww. j a v a2s .c o m Q.add(automaton.getInitialState()); while (!Q.isEmpty()) { State<String> t = Q.poll(); for (Step<String> delta : automaton.getDelta().get(t)) { State<String> u = delta.getDestination(); if (!V.contains(u)) { V.add(u); Q.add(u); } } } return V; }
From source file:org.callimachusproject.server.helpers.Exchange.java
public Exchange(Request request, Queue<Exchange> queue) throws IOException { assert request != null; assert queue != null; this.request = request; this.queue = queue; Header expect = request.getFirstHeader("Expect"); setExpectContinue(expect != null && expect.getValue().equalsIgnoreCase("100-continue")); synchronized (queue) { queue.add(this); }/*from w w w .j av a 2s. com*/ consumer = new Consumer(request); }
From source file:org.opencron.server.service.ExecuteService.java
/** * ? ???/*from w w w .java 2s. c o m*/ */ private boolean executeFlowJob(JobVo job) { if (!checkJobPermission(job.getAgentId(), job.getUserId())) return false; final long groupId = System.nanoTime() + Math.abs(new Random().nextInt());//??Id final Queue<JobVo> jobQueue = new LinkedBlockingQueue<JobVo>(); jobQueue.add(job); jobQueue.addAll(job.getChildren()); RunModel runModel = RunModel.getRunModel(job.getRunModel()); switch (runModel) { case SEQUENCE: return executeSequenceJob(groupId, jobQueue);// case SAMETIME: return executeSameTimeJob(groupId, jobQueue);// default: return false; } }
From source file:bwem.map.MapImpl.java
public WalkPosition breadthFirstSearch(final WalkPosition start, final Pred findCond, final Pred visitCond, final boolean connect8) { if (findCond.isTrue(getData().getMiniTile(start), start, this)) { return start; }/*from w w w. j a va2 s . c o m*/ final Set<WalkPosition> visited = new TreeSet<>((a, b) -> { int result = Integer.compare(a.getX(), b.getX()); if (result != 0) { return result; } return Integer.compare(a.getY(), b.getY()); }); final Queue<WalkPosition> toVisit = new ArrayDeque<>(); toVisit.add(start); visited.add(start); final WalkPosition[] dir8 = { new WalkPosition(-1, -1), new WalkPosition(0, -1), new WalkPosition(1, -1), new WalkPosition(-1, 0), new WalkPosition(1, 0), new WalkPosition(-1, 1), new WalkPosition(0, 1), new WalkPosition(1, 1) }; final WalkPosition[] dir4 = { new WalkPosition(0, -1), new WalkPosition(-1, 0), new WalkPosition(1, 0), new WalkPosition(0, 1) }; final WalkPosition[] directions = connect8 ? dir8 : dir4; while (!toVisit.isEmpty()) { final WalkPosition current = toVisit.remove(); for (final WalkPosition delta : directions) { final WalkPosition next = current.add(delta); if (getData().getMapData().isValid(next)) { final MiniTile miniTile = getData().getMiniTile(next, CheckMode.NO_CHECK); if (findCond.isTrue(miniTile, next, this)) { return next; } if (visitCond.isTrue(miniTile, next, this) && !visited.contains(next)) { toVisit.add(next); visited.add(next); } } } } //TODO: Are we supposed to return start or not? // bwem_assert(false); throw new IllegalStateException(); // return start; }
From source file:org.apache.camel.component.ibatis.IBatisPollingConsumer.java
/** * Polls the database//from w w w.j a v a 2 s .co m */ @Override protected int poll() throws Exception { // must reset for each poll shutdownRunningTask = null; pendingExchanges = 0; // poll data from the database IBatisEndpoint endpoint = getEndpoint(); if (LOG.isTraceEnabled()) { LOG.trace("Polling: " + endpoint); } List<Object> data = CastUtils.cast(endpoint.getProcessingStrategy().poll(this, getEndpoint())); // create a list of exchange objects with the data Queue<DataHolder> answer = new LinkedList<DataHolder>(); if (useIterator) { for (Object item : data) { Exchange exchange = createExchange(item); DataHolder holder = new DataHolder(); holder.exchange = exchange; holder.data = item; answer.add(holder); } } else { if (!data.isEmpty() || routeEmptyResultSet) { Exchange exchange = createExchange(data); DataHolder holder = new DataHolder(); holder.exchange = exchange; holder.data = data; answer.add(holder); } } // process all the exchanges in this batch return processBatch(CastUtils.cast(answer)); }
From source file:org.geotools.gce.imagemosaic.Utils.java
/** * Creates a mosaic for the provided input parameters. * /*from ww w. j a v a2s. c om*/ * @param location * path to the directory where to gather the elements for the * mosaic. * @param indexName * name to give to this mosaic * @param wildcard * wildcard to use for walking through files. We are using * commonsIO for this task * @param absolutePath * tells the catalogue builder to use absolute paths. * @param hints hints to control reader instantiations * @return <code>true</code> if everything is right, <code>false</code>if * something bad happens, in which case the reason should be logged * to the logger. */ static boolean createMosaic(final String location, final String indexName, final String wildcard, final boolean absolutePath, final Hints hints) { // create a mosaic index builder and set the relevant elements final CatalogBuilderConfiguration configuration = new CatalogBuilderConfiguration(); configuration.setAbsolute(absolutePath); configuration.setHints(hints); configuration.setRootMosaicDirectory(location); configuration.setIndexingDirectories(Arrays.asList(location)); configuration.setIndexName(indexName); // create the builder final CatalogBuilder catalogBuilder = new CatalogBuilder(configuration); // this is going to help us with catching exceptions and logging them final Queue<Throwable> exceptions = new LinkedList<Throwable>(); try { final CatalogBuilder.ProcessingEventListener listener = new CatalogBuilder.ProcessingEventListener() { @Override public void exceptionOccurred(ExceptionEvent event) { final Throwable t = event.getException(); exceptions.add(t); if (LOGGER.isLoggable(Level.SEVERE)) LOGGER.log(Level.SEVERE, t.getLocalizedMessage(), t); } @Override public void getNotification(ProcessingEvent event) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine(event.getMessage()); } }; catalogBuilder.addProcessingEventListener(listener); catalogBuilder.run(); } catch (Throwable e) { LOGGER.log(Level.SEVERE, "Unable to build mosaic", e); return false; } finally { catalogBuilder.dispose(); } // check that nothing bad happened if (exceptions.size() > 0) return false; return true; }
From source file:com.googlecode.concurrentlinkedhashmap.MultiThreadedTest.java
@Test(dataProvider = "builder") public void weightedConcurrency(Builder<Integer, List<Integer>> builder) { final ConcurrentLinkedHashMap<Integer, List<Integer>> map = builder.weigher(Weighers.<Integer>list()) .maximumWeightedCapacity(threads).concurrencyLevel(threads).build(); final Queue<List<Integer>> values = new ConcurrentLinkedQueue<List<Integer>>(); for (int i = 1; i <= threads; i++) { Integer[] array = new Integer[i]; Arrays.fill(array, Integer.MIN_VALUE); values.add(Arrays.asList(array)); }//from w ww .ja v a 2 s . c o m executeWithTimeOut(map, new Callable<Long>() { @Override public Long call() throws Exception { return timeTasks(threads, new Runnable() { @Override public void run() { List<Integer> value = values.poll(); for (int i = 0; i < iterations; i++) { map.put(i % 10, value); } } }); } }); }
From source file:it.geosolutions.geobatch.actions.ds2ds.Ds2dsAction.java
/** * Eventually unpacks compressed files.//from ww w . j a v a 2 s . co m * * @param fileEvent * @return * @throws ActionException */ private Queue<FileSystemEvent> unpackCompressedFiles(EventObject event) throws ActionException { Queue<FileSystemEvent> result = new LinkedList<FileSystemEvent>(); FileSystemEvent fileEvent = (FileSystemEvent) event; if (!fileEvent.getSource().exists()) { result.add(fileEvent); return result; } updateTask("Looking for compressed file"); try { String filePath = fileEvent.getSource().getAbsolutePath(); String uncompressedFolder = Extract.extract(filePath); if (!uncompressedFolder.equals(filePath)) { updateTask("Compressed file extracted to " + uncompressedFolder); Collector c = new Collector(null); List<File> fileList = c.collect(new File(uncompressedFolder)); if (fileList != null) { for (File file : fileList) { if (!file.isDirectory()) { result.add(new FileSystemEvent(file, fileEvent.getEventType())); } } } } else { // no compressed file, add as is updateTask("File is not compressed"); result.add(fileEvent); } } catch (Exception e) { throw new ActionException(this, e.getMessage()); } return result; }
From source file:org.openhab.binding.networkhealth.discovery.NetworkHealthDiscoveryService.java
/** * Takes the interfaceIPs and fetches every IP which can be assigned on their network * @param networkIPs The IPs which are assigned to the Network Interfaces * @return Every single IP which can be assigned on the Networks the computer is connected to *//*from ww w .j ava 2 s . c om*/ private Queue<String> getNetworkIPs(TreeSet<String> interfaceIPs) { Queue<String> networkIPs = new LinkedBlockingQueue<String>(); for (Iterator<String> it = interfaceIPs.iterator(); it.hasNext();) { try { // gets every ip which can be assigned on the given network SubnetUtils utils = new SubnetUtils(it.next()); String[] addresses = utils.getInfo().getAllAddresses(); for (int i = 0; i < addresses.length; i++) { networkIPs.add(addresses[i]); } } catch (Exception ex) { } } return networkIPs; }
From source file:de.mrapp.android.util.view.AbstractViewRecycler.java
/** * Adds an unused view to the cache./* w w w. j a va2 s. co m*/ * * @param view * The unused view, which should be added to the cache, as an instance of the class * {@link View}. The view may not be null * @param viewType * The view type, the unused view corresponds to, as an {@link Integer} value */ protected final void addUnusedView(@NonNull final View view, final int viewType) { if (useCache) { if (unusedViews == null) { unusedViews = new SparseArray<>(adapter.getViewTypeCount()); } Queue<View> queue = unusedViews.get(viewType); if (queue == null) { queue = new LinkedList<>(); unusedViews.put(viewType, queue); } queue.add(view); } }