@SuppressWarnings("unchecked") public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { StringBuffer sb = new StringBuffer(); Buffer nl = NotificationList.getInstance().getNotifications(); Iterator<String> it = nl.iterator(); while (it.hasNext()) { String notification = (String) it.next(); sb.append(notification); } nl.clear(); PrintWriter out = response.getWriter(); out.println(sb.toString()); }
public static void main(String[] args) { Driver driver = new Driver(); Driver.DataRate imuFreq = Driver.DataRate.FREQ_476_HZ; driver.setAccelerometerScale(Driver.AccelerometerScale.SCALE_PLUS_MINUS_2G); driver.setDatarate(imuFreq); driver.setUseFifoBuffer(true); AsyncPollingHelper helper = new AsyncPollingHelper(driver); try { helper.beginPolling(); Thread.sleep(2500); System.out.println("***Fetching data first 2.5 seconds***"); Buffer buffer = helper.getFifo(); while(!buffer.isEmpty()){ System.out.println(buffer.remove().toString()); } Thread.sleep(2500); System.out.println("***Fetching data second 2.5 seconds***"); while(!buffer.isEmpty()){ System.out.println(buffer.remove().toString()); } helper.endPolling(); System.out.println("***Fetching final data***"); while(!buffer.isEmpty()){ System.out.println(buffer.remove().toString()); } } catch (InterruptedException e) { e.printStackTrace(); } }
/** * Extracts the weak components from a graph. * @param aGraph the graph whose weak components are to be extracted * @return the list of weak components */ public ClusterSet extract(ArchetypeGraph aGraph) { ClusterSet clusterSet = new VertexClusterSet(aGraph); HashSet unvisitedVertices = new HashSet(); for (Iterator vIt=aGraph.getVertices().iterator(); vIt.hasNext();) { unvisitedVertices.add(vIt.next()); } while (!unvisitedVertices.isEmpty()) { Set weakComponentSet = new HashSet(); ArchetypeVertex root = (ArchetypeVertex) unvisitedVertices.iterator().next(); unvisitedVertices.remove(root); weakComponentSet.add(root); Buffer queue = new UnboundedFifoBuffer(); queue.add(root); while (!queue.isEmpty()) { ArchetypeVertex currentVertex = (ArchetypeVertex) queue.remove(); Set neighbors = currentVertex.getNeighbors(); for (Iterator nIt = neighbors.iterator(); nIt.hasNext();) { ArchetypeVertex neighbor = (ArchetypeVertex) nIt.next(); if (unvisitedVertices.contains(neighbor)) { queue.add(neighbor); unvisitedVertices.remove(neighbor); weakComponentSet.add(neighbor); } } } clusterSet.addCluster(weakComponentSet); } return clusterSet; }
public Buffer getFifo() { return fifo; }
public Buffer getNotifications() { return list; }
/** * Sets the queue of tasks. * * @param queue blocking queue of tasks. */ public void setQueue(Buffer queue) { this.tasksQueue = queue; }