Package freenet.client

Examples of freenet.client.InsertException


    synchronized(this) {
      if(cancelled) return;
      cancelled = true;
    }
    // Must call onFailure so get removeFrom()'ed
    cb.onFailure(new InsertException(InsertExceptionMode.CANCELLED), this, context);
  }
View Full Code Here


      // Can we just insert it, and not bother with a redirect to it?
      // Thereby exploiting implicit manifest support, which will pick up on .metadata??
      // We ought to be able to !!
      block = new InsertBlock(outputBucket, new ClientMetadata(mimeType), targetURI);
    } catch (IOException e) {
      fail(new InsertException(InsertExceptionMode.BUCKET_ERROR, e, null), context);
      return;
    } finally {
      Closer.close(os);
    }
   
    boolean dc = dontCompress;
    if (!dontCompress) {
      dc = (archiveType == ARCHIVE_TYPE.ZIP);
    }
   
    // Treat it as a splitfile for purposes of determining reinsert count.
    SingleFileInserter sfi = new SingleFileInserter(parent, cb, block, false, ctx, realTimeFlag, dc, reportMetadataOnly, token, archiveType, true, null, true, persistent, 0, 0, null, cryptoAlgorithm, forceCryptoKey, -1);
    if(logMINOR)
      Logger.minor(this, "Inserting container: "+sfi+" for "+this);
    cb.onTransition(this, sfi, context);
    try {
      sfi.schedule(context);
    } catch (InsertException e) {
      fail(new InsertException(InsertExceptionMode.BUCKET_ERROR, e, null), context);
      return;
    }
  }
View Full Code Here

        return;
      } catch (MetadataUnresolvedException e) {
        try {
          x = resolve(e, x, null, null, context);
        } catch (IOException e1) {
          fail(new InsertException(InsertExceptionMode.INTERNAL_ERROR, e, null), context);
          return;
        }
      } catch (IOException e) {
        fail(new InsertException(InsertExceptionMode.INTERNAL_ERROR, e, null), context);
        return;
      }
    }
   
  }
View Full Code Here

        block.segment.onInsertedBlock(block.blockNumber, (ClientCHK) key);
    }

    @Override
    public void onFailure(LowLevelPutException e, SendableRequestItem keyNum, ClientContext context) {
        InsertException e1 = InsertException.constructFrom(e);
        if(keyNum == null) {
            storage.fail(e1);
        } else {
            BlockInsert block = (BlockInsert) keyNum;
            block.segment.onFailure(block.blockNumber, e1);
View Full Code Here

        sb.schedule(context);
        added = true;
      } catch (IOException e) {
        Logger.error(this, "Unable to insert USK date hints due to disk I/O error: "+e, e);
        if(!added) {
          cb.onFailure(new InsertException(InsertExceptionMode.BUCKET_ERROR, e, pubUSK.getSSK(edition).getURI()), this, context);
          return;
        } // Else try to insert the other hints.
      } catch (InsertException e) {
        Logger.error(this, "Unable to insert USK date hints due to error: "+e, e);
        if(!added) {
View Full Code Here

        synchronized(this) {
          data = null;
        }
      }
    }
    cb.onFailure(new InsertException(InsertExceptionMode.CANCELLED), this, context);
  }
View Full Code Here

          //started = true;
          System.out.println("Starting insert: running "+runningInserts);
        }
        long t1 = 0, t2 = 0;
        FreenetURI thisURI = null;
        InsertException f = null;
        try {
          t1 = System.currentTimeMillis();
          thisURI = client.insert(block, false, null);
          t2 = System.currentTimeMillis();
        } catch (InsertException e) {
          f = e;
        } finally {
          synchronized(InsertBatch.this) {
            runningInserts--;
            System.out.println("Completed insert: running "+runningInserts);
            //finished = true;
            if(thisURI != null) {
              uri = thisURI;
              insertTime = t2 - t1;
            } else {
              if(f != null)
                failed = f;
              else
                f = new InsertException(InsertExceptionMode.INTERNAL_ERROR);
            }
             
            InsertBatch.this.notifyAll();
          }
        }
View Full Code Here

      // even if you know the content. In the user interface, we will offer the option of inserting as a
      // random SSK to take advantage of this.
      boolean randomiseSplitfileKeys = randomiseSplitfileKeys(targetURI, ctx, persistent());

      if(data == null)
        throw new InsertException(InsertExceptionMode.BUCKET_ERROR, "No data to insert", null);

      boolean cancel = false;
      synchronized(this) {
        if(restart) {
          clearCountersOnRestart();
          if(currentState != null && !finished) {
            if(logMINOR) Logger.minor(this, "Can't restart, not finished and currentState != null : "+currentState);
            return false;
          }
          if(finished)
              startedStarting = false;
          finished = false;
        }
        if(startedStarting) {
          if(logMINOR) Logger.minor(this, "Can't "+(restart?"restart":"start")+" : startedStarting = true");
          return false;
        }
        startedStarting = true;
        if(currentState != null) {
          if(logMINOR) Logger.minor(this, "Can't "+(restart?"restart":"start")+" : currentState != null : "+currentState);
          return false;
        }
        cancel = this.cancelled;
        cryptoKey = null;
        if(overrideSplitfileCrypto != null) {
          cryptoKey = overrideSplitfileCrypto;
          if (cryptoKey.length != 32)
            throw new InsertException(InsertExceptionMode.INVALID_URI, "overrideSplitfileCryptoKey must be of length 32", null);
        } else if(randomiseSplitfileKeys) {
          cryptoKey = new byte[32];
          context.random.nextBytes(cryptoKey);
        }
        if(!cancel) {
          if(!binaryBlob) {
            ClientMetadata meta = cm;
            if(meta != null) meta = persistent() ? meta.clone() : meta;
            currentState =
              new SingleFileInserter(this, this, new InsertBlock(data, meta, targetURI), isMetadata, ctx, realTimeFlag,
                  false, false, null, null, false, targetFilename, false, persistent(), 0, 0, null, cryptoAlgorithm, cryptoKey, metadataThreshold);
          } else
            currentState =
              new BinaryBlobInserter(data, this, getClient(), false, priorityClass, ctx, context);
        }
      }
      if(cancel) {
        onFailure(new InsertException(InsertExceptionMode.CANCELLED), null, context);
        return false;
      }
      synchronized(this) {
        cancel = cancelled;
      }
      if(cancel) {
        onFailure(new InsertException(InsertExceptionMode.CANCELLED), null, context);
        return false;
      }
      if(logMINOR)
        Logger.minor(this, "Starting insert: "+currentState);
      if(currentState instanceof SingleFileInserter)
        ((SingleFileInserter)currentState).start(context);
      else
        currentState.schedule(context);
      synchronized(this) {
        cancel = cancelled;
      }
      if(cancel) {
        onFailure(new InsertException(InsertExceptionMode.CANCELLED), null, context);
        return false;
      }
    } catch (InsertException e) {
      Logger.error(this, "Failed to start insert: "+e, e);
      synchronized(this) {
        finished = true;
        currentState = null;
      }
      // notify the client that the insert could not even be started
      if (this.client!=null) {
        this.client.onFailure(e, this);
      }
    } catch (IOException e) {
      Logger.error(this, "Failed to start insert: "+e, e);
      synchronized(this) {
        finished = true;
        currentState = null;
      }
      // notify the client that the insert could not even be started
      if (this.client!=null) {
        this.client.onFailure(new InsertException(InsertExceptionMode.BUCKET_ERROR, e, null), this);
      }
    } catch (BinaryBlobFormatException e) {
      Logger.error(this, "Failed to start insert: "+e, e);
      synchronized(this) {
        finished = true;
        currentState = null;
      }
      // notify the client that the insert could not even be started
      if (this.client!=null) {
        this.client.onFailure(new InsertException(InsertExceptionMode.BINARY_BLOB_FORMAT_ERROR, e, null), this);
      }
    }
    if(logMINOR)
      Logger.minor(this, "Started "+this);
    return true;
View Full Code Here

      if(finished) return;
      super.cancel();
      oldState = currentState;
    }
    if(oldState != null) oldState.cancel(context);
    onFailure(new InsertException(InsertExceptionMode.CANCELLED), null, context);
  }
View Full Code Here

  /** Throw an InsertException if we have any meta-strings. They are not
   * valid for inserts, you must insert a directory to create a directory
   * structure. */
  public void checkInsertURI() throws InsertException {
    if(metaStr != null && metaStr.length > 0)
      throw new InsertException(InsertExceptionMode.META_STRINGS_NOT_SUPPORTED, this);
  }
View Full Code Here

TOP

Related Classes of freenet.client.InsertException

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.