Ejemplo n.º 1
0
 /** @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);
 }
Ejemplo n.º 2
0
 /** Creates the bid strategy based on the class specified in the config file */
 private void createBidStrategy() {
   try {
     bidStrategy =
         (BidStrategy) Class.forName(mina.getConfig().getBidStrategyClass()).newInstance();
   } catch (Exception e) {
     throw new SeekInnerCalmException(e);
   }
   bidStrategy.setStreamMgr(this);
 }
Ejemplo n.º 3
0
 public StreamVelocity getStreamVelocity() {
   return bidStrategy.getStreamVelocity();
 }
Ejemplo n.º 4
0
 public void setStreamVelocity(StreamVelocity sv) {
   bidStrategy.setStreamVelocity(sv);
 }
Ejemplo n.º 5
0
  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);
    }
  }