Exemplo n.º 1
0
 public StreamStatus buildStreamStatus(String toNodeId) {
   StreamStatus.Builder bldr = StreamStatus.newBuilder();
   if (toNodeId != null) {
     bldr.setToNodeId(toNodeId);
     bldr.setFromNodeId(mina.getMyNodeId());
   }
   bldr.setStreamId(streamId);
   if (pageBuf.getTotalPages() > 0) bldr.setTotalPages(pageBuf.getTotalPages());
   StreamPosition sp = pageBuf.getStreamPosition();
   bldr.setLastContiguousPage(sp.getLastContiguousPage());
   if (sp.getPageMap() > 0) bldr.setPageMap(sp.getPageMap());
   return bldr.build();
 }
Exemplo n.º 2
0
 /** @syncpriority 200 */
 public synchronized void startBroadcast() {
   if (broadcasting) throw new SeekInnerCalmException();
   log.debug("Starting pagebuffer for " + streamId);
   pageBuf.start();
   broadcasting = true;
   log.info("Starting broadcast of " + pageBuf.getTotalPages() + " pages for " + streamId);
   // If we're already rebroadcasting, this means that we've completed
   // reception and are now a broadcaster - so we don't need to announce
   // ourselves again
   if (rebroadcasting) rebroadcasting = false;
   else mina.getStreamAdvertiser().advertiseStream(streamId);
 }
Exemplo n.º 3
0
 /** @syncpriority 200 */
 public void receivePage(Page p) {
   synchronized (this) {
     // We might have already stopped receiving, in which case the
     // pagebuf will be closed
     if (!isReceiving()) return;
     try {
       pageBuf.putPage(p);
     } catch (IOException e) {
       log.error("Error putting page into buffer", e);
       stop();
       return;
     }
   }
   prm.notifyPageReceived(p.getPageNumber());
   updateStreamStatus();
   if (isReceiving() && !isRebroadcasting()) startRebroadcast();
   if (pageBuf.getLastContiguousPage() == (pageBuf.getTotalPages() - 1)) receptionCompleted();
 }
Exemplo n.º 4
0
 public void setPageBuffer(PageBuffer pageBuf) {
   this.pageBuf = pageBuf;
   if (pageBuf.getTotalPages() <= 0) pageBuf.setTotalPages(totalPages);
 }
Exemplo 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);
    }
  }