Package com.aelitis.azureus.plugins.extseed

Examples of com.aelitis.azureus.plugins.extseed.ExternalSeedException


       
        int  retry_secs = http_downloader.getLast503RetrySecs();
       
        setReconnectDelay( retry_secs * 1000, true );
       
        throw( new ExternalSeedException( "Server temporarily unavailable, retrying in " + retry_secs + " seconds" ));
       
      }else{
       
        throw( ese );
      }
    }catch( MalformedURLException e ){
     
      throw( new ExternalSeedException( "URL encode fails", e ));
    }
  }
View Full Code Here


 
    throws ExternalSeedException
  {
    if ( current_request_index >= requests.size()){
     
      throw( new ExternalSeedException( "Insufficient buffers to satisfy request" ));
    }
   
    current_request = (PeerReadRequest)requests.get(current_request_index++);
   
    current_buffer = new byte[ current_request.getLength()];
View Full Code Here

      req = requests.get(0)
    }
   
    if ( req.isCancelled()){
     
      throw( new ExternalSeedException( "Request cancelled" ));
    }
   
    return( reader.getPermittedBytes());
  }
View Full Code Here

     
          int  retry_secs = http_downloader.getLast503RetrySecs();
         
          setReconnectDelay( retry_secs * 1000, true );
         
          throw( new ExternalSeedException( "Server temporarily unavailable, retrying in " + retry_secs + " seconds" ));
             
            }else{
             
              throw(ese);                 
            }
          }
    }else{
     
      long  request_end = request_start + request_length;
     
      // System.out.println( "Req: start=" + request_start + ", len=" + request_length );
     
      final  byte[][] overlap_buffer       = { null };
      final  int[]   overlap_buffer_position   = { 0 };
     
        // we've got to multiplex the (possible) multiple request buffers onto (possible) multi files
     
      for (int i=0;i<http_downloaders.length;i++){
       
        long  this_start   = downloader_offsets[i];
        long  this_end  = this_start + downloader_lengths[i];

        if ( this_end <= request_start ){
         
          continue;
        }
         
        if ( this_start >= request_end ){
         
          break;
        }
       
        long  sub_request_start   = Math.max( request_start,   this_start );
        long  sub_request_end    = Math.min( request_end,  this_end );
 
        final int  sub_len = (int)( sub_request_end - sub_request_start );
       
        if ( sub_len == 0 ){
         
          continue;
        }
       
        ExternalSeedHTTPDownloader http_downloader = http_downloaders[i];
       
        // System.out.println( "    sub_req: start=" + sub_request_start + ", len=" + sub_len + ",url=" + http_downloader.getURL());
       
        ExternalSeedHTTPDownloaderListener sub_request =
          new ExternalSeedHTTPDownloaderListener()
          {
            private int bytes_read;
             
            private byte[]  current_buffer       = overlap_buffer[0];
            private int    current_buffer_position  = overlap_buffer_position[0];
            private int    current_buffer_length  = current_buffer==null?-1:Math.min( current_buffer.length, current_buffer_position + sub_len );
           
            public byte[]
                getBuffer()
               
                  throws ExternalSeedException
                {
              if ( current_buffer == null ){
               
                current_buffer       = listener.getBuffer();
                current_buffer_position  = 0;
                current_buffer_length  = Math.min( current_buffer.length, sub_len - bytes_read );
              }
             
              return( current_buffer );
                }
               
                public void
                setBufferPosition(
                  int  position )
                {
                  current_buffer_position  = position;
                 
                  listener.setBufferPosition( position );
                }
               
                public int
                getBufferPosition()
                {
                  return( current_buffer_position );
                }
               
                public int
                getBufferLength()
                {
                  return( current_buffer_length );
                }
               
                public int
                getPermittedBytes()
               
                  throws ExternalSeedException
                {
                  return( listener.getPermittedBytes());
                }
               
                public int
                getPermittedTime()
                { 
                  return( listener.getPermittedTime());
                }
               
                public void
                reportBytesRead(
                  int    num )
                {
                  bytes_read += num;
                 
                  listener.reportBytesRead( num );
                }
               
                public boolean
                isCancelled()
                {
                  return( listener.isCancelled());
                }
               
                public void
                done()
                {
                    // the current buffer is full up to the declared length
                 
                  int rem = current_buffer.length - current_buffer_length;
                 
                  if ( bytes_read == sub_len ){
                   
                      // this request is complete. save any partial buffer for
                      // next request
                   
                    if ( rem == 0 ){
                     
                      overlap_buffer[0]       = null;
                      overlap_buffer_position[0= 0;
                     
                    }else{
                     
                      overlap_buffer[0]      = current_buffer;
                      overlap_buffer_position[0= current_buffer_length;
                    }
                  }
                 
                    // prepare for next buffer if needed
                 
                  current_buffer = null;
                 
                  if ( rem == 0 ){
                   
                    listener.done();
                  }
                }
          };
         
            try{
          http_downloader.downloadRange(
              sub_request_start - this_start,
              sub_len,
              sub_request,
              isTransient());
   
            }catch( ExternalSeedException ese ){
             
              if ( http_downloader.getLastResponse() == 503 && http_downloader.getLast503RetrySecs() >= 0 ){
       
            int  retry_secs = http_downloader.getLast503RetrySecs();
           
            setReconnectDelay( retry_secs * 1000, true );
           
            throw( new ExternalSeedException( "Server temporarily unavailable, retrying in " + retry_secs + " seconds" ));
               
              }else{
               
                throw(ese);                 
              }
View Full Code Here

            }
          }
         
          outcome = "Connection failed: data too short - " + length + "/" + pos + " [" + log_str + "]";
         
          throw( new ExternalSeedException( outcome ));
        }
       
        outcome = "read " + pos + " bytes";
       
        // System.out.println( "download length: " + pos );
       
      }else{
       
        outcome = "Connection failed: " + connection.getResponseMessage();
       
        ExternalSeedException  error = new ExternalSeedException( outcome );
       
        error.setPermanentFailure( true );
       
        throw( error );
      }
    }catch( IOException e ){
     
      if ( con_fail_is_perm_fail && !connected ){
       
        outcome = "Connection failed: " + e.getMessage();
       
        ExternalSeedException  error = new ExternalSeedException( outcome );
       
        error.setPermanentFailure( true );
       
        throw( error );

      }else{
       
        outcome =  "Connection failed: " + Debug.getNestedExceptionMessage( e );
               
                if ( last_response_retry_after_secs >= 0){
                 
                    outcome += ", Retry-After: " + last_response_retry_after_secs + " seconds";
                }
                       
        ExternalSeedException excep = new ExternalSeedException( outcome, e );
       
        if ( e instanceof FileNotFoundException ){
         
          excep.setPermanentFailure( true );
        }
       
        throw( excep );
      }
    }catch( Throwable e ){
     
      if ( e instanceof ExternalSeedException ){
       
        throw((ExternalSeedException)e);
      }
     
      outcome = "Connection failed: " + Debug.getNestedExceptionMessage( e );
     
      throw( new ExternalSeedException("Connection failed", e ));
     
    }finally{
     
      SESecurityManager.unsetThreadPasswordHandler();
View Full Code Here

            }else{
             
              log_str =  new String( buffer, 0, buffer_pos>64?64:buffer_pos );
            }
           
            throw( new ExternalSeedException("Connection failed: data too short - " + length + "/" + pos + " [last=" + log_str + "]" ));
          }
         
          // System.out.println( "download length: " + pos );
                   
        }else if (   response == 503 ){
         
            // webseed support for temp unavail - read the data
         
          String  data_str = "";
         
          while( true ){
           
            byte[]  buffer = new byte[1];
           
            int  len = is.read( buffer );
           
            if ( len < 0 ){
             
              break;
            }
           
            data_str += (char)buffer[0];
          }
         
          last_response_retry_after_secs = Integer.parseInt( data_str );
       
            // this gets trapped below and turned into an appropriate ExternalSeedException
         
          throw( new IOException( "Server overloaded" ));
         
        }else{
         
          ExternalSeedException  error = new ExternalSeedException("Connection failed: " + response_str );
         
          error.setPermanentFailure( true );
         
          throw( error );
        }
      }finally{
       
        is.close();
      }
     
    }catch( IOException e ){
     
      if ( con_fail_is_perm_fail && !connected ){
       
        ExternalSeedException  error = new ExternalSeedException("Connection failed: " + e.getMessage());
       
        error.setPermanentFailure( true );
       
        throw( error );

      }else{
       
        String outcome =  "Connection failed: " + Debug.getNestedExceptionMessage( e );

        if ( last_response_retry_after_secs >= 0 ){
                   
          outcome += ", Retry-After: " + last_response_retry_after_secs + " seconds";
              }

        throw( new ExternalSeedException( outcome, e ));
      }
    }catch( Throwable e ){
           
      if ( e instanceof ExternalSeedException ){
       
        throw((ExternalSeedException)e);
      }
     
      throw( new ExternalSeedException("Connection failed", e ));
     
    }finally{
     
      if ( socket != null ){
       
View Full Code Here

        return;
      }
     
      if ( listener.isCancelled()){
       
        throw( new ExternalSeedException( "request cancelled" ));
      }
    }
  }
View Full Code Here

      }
    }
   
    if ( to_destroy != null ){
     
      to_destroy.destroy( new ExternalSeedException( "deactivated" ));
    }
  }
View Full Code Here

    ExternalSeedHTTPDownloaderListener  listener,
    boolean                con_fail_is_perm_fail )
 
    throws ExternalSeedException
  {
    throw( new ExternalSeedException( "not supported" ));
  }
View Full Code Here

    ExternalSeedHTTPDownloaderListener  listener,
    boolean                con_fail_is_perm_fail )
             
      throws ExternalSeedException
  {
    throw( new ExternalSeedException( "not supported" ));
  }
View Full Code Here

TOP

Related Classes of com.aelitis.azureus.plugins.extseed.ExternalSeedException

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.