List of usage examples for org.apache.commons.collections15.buffer UnboundedFifoBuffer UnboundedFifoBuffer
public UnboundedFifoBuffer()
From source file:edu.cuny.cat.task.DispatchingTaskQueue.java
public DispatchingTaskQueue() { tasks = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer<DispatchingTask>()); }
From source file:edu.cuny.util.ResourcePool.java
public ResourcePool(final ResourceFactory<R> factory, final int initial_capacity) { this.factory = factory; this.buffer = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer<R>()); for (int i = 0; i < initial_capacity; i++) { addResource();/* w w w . ja va 2s .c o m*/ } }
From source file:edu.uci.ics.jung.algorithms.cluster.WeakComponentClusterer.java
/** * Extracts the weak components from a graph. * @param graph the graph whose weak components are to be extracted * @return the list of weak components/* w ww . j av a 2 s . c o m*/ */ public Set<Set<V>> transform(Graph<V, E> graph) { Set<Set<V>> clusterSet = new HashSet<Set<V>>(); HashSet<V> unvisitedVertices = new HashSet<V>(graph.getVertices()); while (!unvisitedVertices.isEmpty()) { Set<V> cluster = new HashSet<V>(); V root = unvisitedVertices.iterator().next(); unvisitedVertices.remove(root); cluster.add(root); Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(root); while (!queue.isEmpty()) { V currentVertex = queue.remove(); Collection<V> neighbors = graph.getNeighbors(currentVertex); for (V neighbor : neighbors) { if (unvisitedVertices.contains(neighbor)) { queue.add(neighbor); unvisitedVertices.remove(neighbor); cluster.add(neighbor); } } } clusterSet.add(cluster); } return clusterSet; }
From source file:edu.cuny.cat.comm.QueueBasedInfrastructureImpl.java
public QueueBasedInfrastructureImpl() { waitingClients = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer<QueueBasedCatpClientConnector>()); connections = Collections.synchronizedMap(new HashMap<Object, QueueBasedCatpConnection>()); idAllocator = new IdAllocator(); }
From source file:edu.cuny.cat.comm.CallBasedInfrastructureImpl.java
public CallBasedInfrastructureImpl() { waitingClients = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer<CallBasedCatpClientConnector>()); connections = Collections.synchronizedMap(new HashMap<Object, CallBasedCatpConnection>()); idAllocator = new IdAllocator(); }
From source file:edu.uci.ics.jung.algorithms.importance.BetweennessCentrality.java
protected void computeBetweenness(Graph<V, E> graph) { Map<V, BetweennessData> decorator = new HashMap<V, BetweennessData>(); Map<V, Number> bcVertexDecorator = vertexRankScores.get(getRankScoreKey()); bcVertexDecorator.clear();// w w w. j a v a 2 s .c om Map<E, Number> bcEdgeDecorator = edgeRankScores.get(getRankScoreKey()); bcEdgeDecorator.clear(); Collection<V> vertices = graph.getVertices(); for (V s : vertices) { initializeData(graph, decorator); decorator.get(s).numSPs = 1; decorator.get(s).distance = 0; Stack<V> stack = new Stack<V>(); Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(s); while (!queue.isEmpty()) { V v = queue.remove(); stack.push(v); for (V w : getGraph().getSuccessors(v)) { if (decorator.get(w).distance < 0) { queue.add(w); decorator.get(w).distance = decorator.get(v).distance + 1; } if (decorator.get(w).distance == decorator.get(v).distance + 1) { decorator.get(w).numSPs += decorator.get(v).numSPs; decorator.get(w).predecessors.add(v); } } } while (!stack.isEmpty()) { V w = stack.pop(); for (V v : decorator.get(w).predecessors) { double partialDependency = (decorator.get(v).numSPs / decorator.get(w).numSPs); partialDependency *= (1.0 + decorator.get(w).dependency); decorator.get(v).dependency += partialDependency; E currentEdge = getGraph().findEdge(v, w); double edgeValue = bcEdgeDecorator.get(currentEdge).doubleValue(); edgeValue += partialDependency; bcEdgeDecorator.put(currentEdge, edgeValue); } if (w != s) { double bcValue = bcVertexDecorator.get(w).doubleValue(); bcValue += decorator.get(w).dependency; bcVertexDecorator.put(w, bcValue); } } } if (graph instanceof UndirectedGraph) { for (V v : vertices) { double bcValue = bcVertexDecorator.get(v).doubleValue(); bcValue /= 2.0; bcVertexDecorator.put(v, bcValue); } for (E e : graph.getEdges()) { double bcValue = bcEdgeDecorator.get(e).doubleValue(); bcValue /= 2.0; bcEdgeDecorator.put(e, bcValue); } } for (V vertex : vertices) { decorator.remove(vertex); } }
From source file:edu.cuny.cat.comm.QueueBasedCatpConnection.java
public synchronized void open() throws ConnectionException { messages = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer<CatpMessage>()); notifyAll();/* ww w . j a v a 2s .c om*/ }
From source file:edu.uci.ics.jung.algorithms.flows.EdmondsKarpMaxFlow.java
protected boolean hasAugmentingPath() { mSinkPartitionNodes.clear();/*from w ww. j a v a2 s. c o m*/ mSourcePartitionNodes.clear(); mSinkPartitionNodes.addAll(mFlowGraph.getVertices()); Set<E> visitedEdgesMap = new HashSet<E>(); Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(source); while (!queue.isEmpty()) { V currentVertex = queue.remove(); mSinkPartitionNodes.remove(currentVertex); mSourcePartitionNodes.add(currentVertex); Number currentCapacity = parentCapacityMap.get(currentVertex); Collection<E> neighboringEdges = mFlowGraph.getOutEdges(currentVertex); for (E neighboringEdge : neighboringEdges) { V neighboringVertex = mFlowGraph.getDest(neighboringEdge); Number residualCapacity = residualCapacityMap.get(neighboringEdge); if (residualCapacity.intValue() <= 0 || visitedEdgesMap.contains(neighboringEdge)) continue; V neighborsParent = parentMap.get(neighboringVertex); Number neighborCapacity = parentCapacityMap.get(neighboringVertex); int newCapacity = Math.min(residualCapacity.intValue(), currentCapacity.intValue()); if ((neighborsParent == null) || newCapacity > neighborCapacity.intValue()) { parentMap.put(neighboringVertex, currentVertex); parentCapacityMap.put(neighboringVertex, new Integer(newCapacity)); visitedEdgesMap.add(neighboringEdge); if (neighboringVertex != target) { queue.add(neighboringVertex); } } } } boolean hasAugmentingPath = false; Number targetsParentCapacity = parentCapacityMap.get(target); if (targetsParentCapacity != null && targetsParentCapacity.intValue() > 0) { updateResidualCapacities(); hasAugmentingPath = true; } clearParentValues(); return hasAugmentingPath; }
From source file:edu.cuny.cat.server.ConnectionAdaptor.java
public ConnectionAdaptor(final ConnectionManager manager, final Connection<CatpMessage> conn) { eventEngine = Galaxy.getInstance().getDefaultTyped(EventEngine.class); this.manager = manager; controller = GameController.getInstance(); clock = controller.getClock();/*w w w . j av a 2 s .c o m*/ shoutValidator = controller.getShoutValidator(); transactionValidator = controller.getTransactionValidator(); chargeValidator = controller.getChargeValidator(); registry = controller.getRegistry(); timeController = controller.getTimeController(); proactiveSessions = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer<CatpProactiveSession>()); pendingRequestSessions = Collections.synchronizedMap(new HashMap<String, ShoutFromTraderSession>()); connection = ListenableConnection.makeReactiveConnection(conn); setExpectedReactiveSessions( new CatpReactiveSession[] { new CheckInSession(), new OracleSession("BeforeCheckIn") }); openConnection(); setState(ClientState.READY, ClientState.getCodeDesc(ClientState.READY) + " for checking in"); }
From source file:edu.cuny.cat.GameClient.java
/***************************************************************************** * //from w ww . ja v a 2 s .co m * constructors and setup * ****************************************************************************/ public GameClient() { eventEngine = Galaxy.getInstance().getTyped(Game.P_CAT, EventEngine.class); prng = Galaxy.getInstance().getTyped(Game.P_CAT, GlobalPRNG.class); infrast = Galaxy.getInstance().getTyped(Game.P_CAT, CatpInfrastructure.class); clientConnector = infrast.createClientConnector(); dispatcher = new SynchronousDispatcher(); eventListeners = new LinkedList<AuctionEventListener>(); proactiveSessions = BufferUtils.synchronizedBuffer(new UnboundedFifoBuffer<CatpProactiveSession>()); registry = createRegistry(); addAuctionEventListener(this); addAuctionEventListener(registry); }