/** @syncpriority 200 */ public void notifyDeadConnection(ConnectionPair pair) { synchronized (this) { streamConns.removeConnectionPair(pair); if (pair instanceof LCPair) { prm.notifyDeadConnection(pair.getCC().getNodeId()); if (streamConns.getNumListenConns() < mina.getConfig().getMaxSources()) requestCachedSources(); bidStrategy.cleanup(pair.getCC().getNodeId()); // Make note of them in case they come back LCPair lcp = (LCPair) pair; SourceStatus sourceStat = lcp.getLastSourceStatus(); if (sourceStat != null) { StreamStatus streamStat = lcp.getLastStreamStatus(); if (streamStat == null) throw new SeekInnerCalmException(); mina.getSourceMgr().cachePossiblyDeadSource(sourceStat, streamStat); } } if (streamConns.getNumBroadcastConns() == 0 && streamConns.getNumListenConns() == 0) { try { pageBuf.sleep(); } catch (IOException e) { log.error("Error sleeping page buffer", e); stop(); } } } if (isReceiving()) mina.getEventMgr().fireReceptionConnsChanged(streamId); }
/** @syncpriority 200 */ public synchronized void stopReception() { log.info("Stopping reception for stream " + streamId); if (!receiving) // Leftover thread return; receiving = false; // If we're still wanting to hear about sources, keep track of the ones we're receiving from if (checkWantingSources()) { for (LCPair lcp : streamConns.getAllListenConns()) { mina.getSourceMgr() .cacheSourceUntilReady(lcp.getLastSourceStatus(), lcp.getLastStreamStatus()); } } streamConns.closeAllListenConns(); }
/** The streamvelocity dictates how fast we want this stream (slower = cheaper) */ public void setStreamVelocity(String sid, StreamVelocity sv) { bidStrategy.setStreamVelocity(sid, sv); // After the velocity is changed, we might want to inc/dec our bid to our sources for (LCPair lcp : scm.getListenConns(sid)) { buyMgr.possiblyRebid(lcp.getCC().getNodeId()); } }
public Set<String> getSourceNodeIds() { Set<String> result = mina.getSourceMgr().getReadyNodeIds(streamId); for (ConnectionPair lcp : streamConns.getAllListenConns()) { result.add(lcp.getCC().getNodeDescriptor().getId()); } return result; }
/** Returns a list of node ids */ public synchronized List<String> getConnectedSources() { ConnectionPair[] lcs = streamConns.getAllListenConns(); List<String> result = new ArrayList<String>(lcs.length); for (int i = 0; i < lcs.length; i++) { result.add(lcs[i].getCC().getNodeId()); } return result; }
public List<String> getConnectedSources(String sid) { LCPair[] arrr = scm.getListenConns(sid); List<String> result = new ArrayList<String>(); for (LCPair lcp : arrr) { result.add(lcp.getCC().getNodeId()); } return result; }
/** @syncpriority 90 */ public void abort() { log.fatal("Mina instance ABORTING!"); ccm.prepareForShutdown(); scm.abort(); ccm.abort(); netMgr.stop(); started = false; log.fatal("Mina instance stopped"); }
/** @syncpriority 200 */ public synchronized void stopRebroadcast() { if (!rebroadcasting) throw new SeekInnerCalmException(); rebroadcasting = false; log.info("Ceasing rebroadcast for stream " + streamId); // If we are broadcasting, it means we completed our reception and // became a broadcaster - so keep our broadcast conns alive, and don't // de-advertise ourselves if (!broadcasting) { streamConns.closeAllBroadcastConns(); deadvertiseStream(); } }
/** @syncpriority 200 */ public void stop() throws MinaException { log.fatal("Mina instance stopping"); ccm.prepareForShutdown(); scm.closeAllStreamConns(); streamMgr.stop(); sourceMgr.stop(); streamAdvertiser.cancel(); ccm.stop(); netMgr.stop(); badNodes.clear(); started = false; log.fatal("Mina instance stopped"); }
/** @syncpriority 200 */ public synchronized void stop() { log.debug("SM for " + streamId + " stopping"); if (broadcasting) stopBroadcast(); if (rebroadcasting) stopRebroadcast(); if (receiving) stopReception(); listeners.clear(); checkWantingSources(); streamConns.closeAll(); mina.getSmRegister().unregisterSM(streamId); if (pageBuf != null) { pageBuf.stop(); pageBuf.close(); } }
public void setAllStreamVelocitiesExcept(String streamId, StreamVelocity sv) { String[] receivingSids = streamMgr.getReceivingStreamIds(); // After the velocity is changed, we might want to inc/dec our bid to our sources Set<String> rebidNodeIds = new HashSet<String>(); for (String sid : receivingSids) { if (!sid.equals(streamId)) { bidStrategy.setStreamVelocity(sid, sv); for (LCPair lcp : scm.getListenConns(sid)) { rebidNodeIds.add(lcp.getCC().getNodeId()); } } } for (String nodeId : rebidNodeIds) { buyMgr.possiblyRebid(nodeId); } }
/** @syncpriority 200 */ public synchronized void stopBroadcast() { if (!broadcasting) throw new SeekInnerCalmException(); broadcasting = false; deadvertiseStream(); streamConns.closeAllBroadcastConns(); }
public void foundSource(SourceStatus sourceStat, StreamStatus streamStat) { String fromNodeId = sourceStat.getFromNode().getId(); String sourceId = fromNodeId; if (streamStat.getTotalPages() != 0) { long totalPages = streamStat.getTotalPages(); if (pageBuf == null) this.totalPages = totalPages; else { if (pageBuf.getTotalPages() <= 0) pageBuf.setTotalPages(totalPages); else { if (pageBuf.getTotalPages() != totalPages) { log.error( "Node " + sourceId + " advertised total pages " + totalPages + " for stream " + streamId + ", but I have already recorded " + pageBuf.getTotalPages()); return; } } } } if (streamConns.haveListenConnWithId(sourceId)) return; // If we're not receiving, then we're just caching sources to pass to an external listener - so // cache it if (!receiving) { mina.getSourceMgr().cacheSourceUntilReady(sourceStat, streamStat); notifyListenersOfSource(sourceId); return; } // Not listening to this node - let's see if we should if (mina.getConfig().isAgoric()) { if (!bidStrategy.worthConnectingTo(new AuctionState(sourceStat.getAuctionState()))) { log.debug( "Not connecting to node " + sourceId + " for " + streamId + " - bid strategy says no"); mina.getSourceMgr().cacheSourceUntilAgoricsAcceptable(sourceStat, streamStat); return; } } // Check that they have data useful to us if (pageBuf != null) { StreamPosition sp = new StreamPosition(streamStat.getLastContiguousPage(), streamStat.getPageMap()); if (sp.highestIncludedPage() <= pageBuf.getLastContiguousPage()) { // Useless at the moment - cache them and ask again later mina.getSourceMgr().cacheSourceUntilDataAvailable(sourceStat, streamStat); return; } } // This is a useful source - let our listeners know notifyListenersOfSource(sourceId); if (streamConns.getNumListenConns() >= mina.getConfig().getMaxSources()) { mina.getSourceMgr().cacheSourceUntilReady(sourceStat, streamStat); return; } try { streamConns.makeListenConnectionTo(sourceStat); } catch (MinaConnectionException e) { log.error("Caught MinaConnectionException when attempting to connect to " + sourceId); } }
/** @syncpriority 160 */ public StreamingDetails getStreamingDetails() { return streamConns.getStreamingDetails(); }
/** @syncpriority 160 */ private void updateStreamStatus() { StreamStatus ss = buildStreamStatus(null); for (BCPair bcPair : streamConns.getBroadcastConns()) { bcPair.getCC().sendMessage("StreamStatus", ss); } }
/** @syncpriority 160 */ public int numSources() { int result = mina.getSourceMgr().numReadySources(streamId); result += streamConns.getNumListenConns(); return result; }
/** @syncpriority 200 */ public synchronized void abort() { streamConns.abort(); mina.getSmRegister().unregisterSM(streamId); }