Package me.mabra.hellonzb.nntpclient.nioengine

Examples of me.mabra.hellonzb.nntpclient.nioengine.RspHandler


    {
      try
      {
        // create NIO client and background thread
        NettyNioClient client = new NettyNioClient(mainApp, false);
        RspHandler handler = new RspHandler(null, false);
        Thread t = new Thread(client);
        t.setDaemon(true);
        t.start();
       
        // test authentication
        client.testAuth(handler);
        start = System.nanoTime();
        while(!handler.isFinished())
        {
          curr = System.nanoTime();
          diff = curr - start;
          if(diff > (HelloNzbConstants.SERVER_TIMEOUT * NANO_MODIFIER))
            break;

          try
          {
            Thread.sleep(10);
          }
          catch(InterruptedException ex)
          {
            // do nothing ...
          }
        }
       
        if(client != null)
          client.shutdown(true, start + (HelloNzbConstants.SERVER_TIMEOUT * NANO_MODIFIER), false);
         
        mainApp.resetThreadView();
       
        if(diff > (HelloNzbConstants.SERVER_TIMEOUT * NANO_MODIFIER))
        {
          msg = mainApp.getLocaler().getBundleText("PopupServerConnectionError");
          error = true;
        }
        else if((handler.getError() == RspHandler.ERR_AUTH))          
        {
          msg = mainApp.getLocaler().getBundleText("PopupAuthFailed");
          error = true;
        }
      }
View Full Code Here


          break;
        String filename = seg.getDlFile().getFilename();
        logger.msg("Downloading next segment of file: " + filename, MyLogger.SEV_DEBUG);

        // create new response handler
        RspHandler newHandler = new RspHandler(seg, false);
        synchronized(activeRspHandlers)
        {
          activeRspHandlers.add(newHandler);
        }

        // map the new response handler to the download file
        mapHandlerToFile(newHandler, seg);

        // start data download and increase thread counter
        nioClient.fetchArticleData(seg.getGroups().firstElement(), seg.getArticleId(), newHandler);
        runningThreads++;
      }

      // Add finished response handlers from backup downloader to this.activeRspHandlers
      if(backupFileDownloader != null && backupFileDownloader.hasFinishedHandlers())
      {
        for(RspHandler handler : backupFileDownloader.getFinishedHandlers())
        {
          activeRspHandlers.add(handler);
          DownloadFileSegment seg = handler.dlFileSeg();
          dlFileRspHandlerMap.get(seg.getDlFile()).put(seg.getIndex(), handler);
        }
      }

      // check if the next element of the result set is already finished
      int actRspHdlsSize;
      synchronized(activeRspHandlers)
      {
        actRspHdlsSize = activeRspHandlers.size();
      }

      ArrayList<RspHandler> toRemoveVector = new ArrayList<>();
      for(int i = 0; i < actRspHdlsSize; i++)
      {
        RspHandler handler;
        synchronized(activeRspHandlers)
        {
          handler = activeRspHandlers.get(i);
        }

        // handle error response from NNTP server
        if(handler.getError() == RspHandler.ERR_NONE)
        {
          // no error, do nothing
        }
        else if(handler.getError() == RspHandler.ERR_AUTH)
        {
          // do nothing for this error (?)
        }
        else if(handler.getError() == RspHandler.ERR_FETCH_430)
        {
          // 430 No such article
          if(backupFileDownloader != null && !handler.isFromBackupDownloader())
          {
            // try to download this failed segment via the backup connection
            dlFileRspHandlerMap.get(handler.dlFileSeg().getDlFile()).remove(handler.dlFileSeg().getIndex());
            backupFileDownloader.addSegment(handler.dlFileSeg());
            toRemoveVector.add(handler);
            continue;
          }
          else
          {
            // no backup downloader, or already tried there...
            String msg = "Article not found on server (" + handler.getErrorMsg().trim() + ")";
            logger.msg(msg, MyLogger.SEV_WARNING);
            if(!tooMany430ErrorsSent && fetch430count++ > MAX_430_ERRORS)
            {
              EventQueue.invokeLater(new Runnable()
              {
                @Override
                public void run()
                {
                  mainApp.tooMany430Errors();
                }
              });

              tooMany430ErrorsSent = true;
              logger.msg("At least " + MAX_430_ERRORS + " articles have not been found on server(s).", MyLogger.SEV_WARNING);
            }
          }
        }
        else if(handler.getError() == RspHandler.ERR_FETCH)
        {
          // failed to fetch article (non-430)
          String msg = "Failed to fetch article <"
              + handler.dlFileSeg().getArticleId() + "> ("
              + handler.getErrorMsg() + ")";
          logger.msg(msg, MyLogger.SEV_WARNING);
        }
        else
        {
          // all other errors
          String msg = "Failed to fetch article <"
              + handler.dlFileSeg().getArticleId() + "> ("
              + handler.getErrorMsg() + ")";
          logger.msg(msg, MyLogger.SEV_WARNING);
          shutdown = true;
        }

        // update downloaded byte counter ...
        DownloadFile dlFile = handler.dlFileSeg().getDlFile();
        String filename = dlFile.getFilename();
        int bytes = 0;
        Integer bytesInt = downloadedBytes.get(filename);
        if(bytesInt != null)
          bytes = bytesInt;
        bytes += handler.newByteCount();
        downloadedBytes.put(filename, bytes);

        // ... and progres bar in main window
        int last = 0;
        Integer lastInt = lastProgBarUpdate.get(filename);
        if(lastInt != null)
          last = lastInt;
        last = updateProgressBar(bytes, last, dlFile);
        lastProgBarUpdate.put(filename, last);

        // all data downloaded?
        if(handler.isFinished())
        {
          if(handler.getError() == RspHandler.ERR_NONE)
            fetch430count = 0;

          toRemoveVector.add(handler);
          runningThreads--;
          decrSegCount(filename); // decrease main window segment counter

          // segment done, so check if whole download file is finished now
          dlFile.removeSegment(handler.dlFileSeg().getIndex());
          if(!dlFile.hasMoreSegments())
          {
            try
            {
              handleFinishedDlFile(dlFile);
View Full Code Here

          break;
        String filename = nextSeg.getDlFile().getFilename();
        logger.msg("Downloading from backup server next segment of file: " + filename, MyLogger.SEV_DEBUG);

        // create new response handler
        RspHandler newHandler = new RspHandler(nextSeg, true);
        synchronized(activeRspHandlers)
        {
          activeRspHandlers.add(newHandler);
        }

        // start data download and increase thread counter
        nioClient.fetchArticleData(nextSeg.getGroups().firstElement(), nextSeg.getArticleId(), newHandler);
        runningThreads++;
      }

      // check if the next element of the result set is already finished
      int actRspHdlsSize;
      synchronized(activeRspHandlers)
      {
        actRspHdlsSize = activeRspHandlers.size();
      }

      ArrayList<RspHandler> toRemoveVector = new ArrayList<>();
      for(int i = 0; i < actRspHdlsSize; i++)
      {
        RspHandler handler;
        synchronized(activeRspHandlers)
        {
          handler = activeRspHandlers.get(i);
        }

        // all data downloaded?
        if(handler.isFinished())
        {
          synchronized(finishedRspHandlers)
          {
            finishedRspHandlers.add(handler);
          }
View Full Code Here

TOP

Related Classes of me.mabra.hellonzb.nntpclient.nioengine.RspHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.