public void removeFrom(ObjectContainer container) {
   container.activate(data, 1);
   data.removeFrom(container);
   container.activate(targetURI, 5);
   targetURI.removeFrom(container);
   container.delete(this);
 }
 public void realRemoveFrom(ObjectContainer container) {
   synchronized (this) {
     if (reallyRemoved) Logger.error(this, "Calling realRemoveFrom() twice on " + this);
     reallyRemoved = true;
   }
   bucket.removeFrom(container);
   container.delete(this);
 }
 public void freeData(ObjectContainer container, boolean persistForever) {
   if (data != null) {
     if (persistForever) container.activate(data, 1);
     data.free();
     if (persistForever) data.removeFrom(container);
     data = null;
   }
   if (persistForever) container.delete(this);
 }
Beispiel #4
0
 @Override
 protected void freeData(ObjectContainer container) {
   Bucket data;
   synchronized (this) {
     data = returnBucket;
     returnBucket = null;
   }
   if (data != null) {
     if (persistenceType == PERSIST_FOREVER) container.activate(data, 5);
     data.free();
     if (persistenceType == PERSIST_FOREVER) data.removeFrom(container);
     if (persistenceType == PERSIST_FOREVER) container.store(this);
   }
 }
 @Override
 public void onSuccess(Object keyNum, ObjectContainer container, ClientContext context) {
   if (logMINOR) Logger.minor(this, "Succeeded (" + this + "): " + token);
   if (persistent) container.activate(parent, 1);
   if (parent.isCancelled()) {
     fail(new InsertException(InsertException.CANCELLED), container, context);
     return;
   }
   synchronized (this) {
     if (extraInserts > 0) {
       if (++completedInserts <= extraInserts) {
         if (logMINOR)
           Logger.minor(
               this,
               "Completed inserts "
                   + completedInserts
                   + " of extra inserts "
                   + extraInserts
                   + " on "
                   + this);
         if (persistent) container.store(this);
         return; // Let it repeat until we've done enough inserts. It hasn't been unregistered yet.
       }
     }
     if (finished) {
       // Normal with persistence.
       Logger.normal(this, "Block already completed: " + this);
       return;
     }
     finished = true;
   }
   if (persistent) {
     container.store(this);
     container.activate(sourceData, 1);
   }
   if (freeData) {
     sourceData.free();
     if (persistent) sourceData.removeFrom(container);
     sourceData = null;
     if (persistent) container.store(this);
   }
   parent.completedBlock(false, container, context);
   unregister(container, context, getPriorityClass(container));
   if (persistent) container.activate(cb, 1);
   if (logMINOR) Logger.minor(this, "Calling onSuccess for " + cb);
   cb.onSuccess(this, container, context);
   if (persistent) container.deactivate(cb, 1);
 }
Beispiel #6
0
 /**
  * Must be called just after construction, but within a transaction.
  *
  * @throws IdentifierCollisionException If the identifier is already in use.
  */
 @Override
 void register(ObjectContainer container, boolean noTags) throws IdentifierCollisionException {
   if (client != null) assert (this.persistenceType == client.persistenceType);
   if (persistenceType != PERSIST_CONNECTION)
     try {
       client.register(this, container);
     } catch (IdentifierCollisionException e) {
       returnBucket.free();
       if (persistenceType == PERSIST_FOREVER) returnBucket.removeFrom(container);
       throw e;
     }
   if (persistenceType != PERSIST_CONNECTION && !noTags) {
     FCPMessage msg = persistentTagMessage(container);
     client.queueClientRequestMessage(msg, 0, container);
   }
 }
 public void removeFrom(ObjectContainer container, ClientContext context) {
   if (logMINOR) Logger.minor(this, "removeFrom() on " + this);
   container.activate(uri, 5);
   uri.removeFrom(container);
   if (resultingURI != null) {
     container.activate(resultingURI, 5);
     resultingURI.removeFrom(container);
   }
   // cb, parent are responsible for removing themselves
   // ctx is passed in and unmodified - usually the ClientPutter removes it
   container.activate(errors, 5);
   errors.removeFrom(container);
   if (freeData && sourceData != null && container.ext().isStored(sourceData)) {
     Logger.error(this, "Data not removed!");
     container.activate(sourceData, 1);
     sourceData.removeFrom(container);
   }
   container.delete(this);
 }
 private void fail(
     InsertException e, boolean forceFatal, ObjectContainer container, ClientContext context) {
   synchronized (this) {
     if (finished) return;
     finished = true;
   }
   if (persistent) container.store(this);
   if (e.isFatal() || forceFatal) parent.fatallyFailedBlock(container, context);
   else parent.failedBlock(container, context);
   unregister(container, context, getPriorityClass(container));
   if (freeData) {
     if (persistent) container.activate(sourceData, 1);
     sourceData.free();
     if (persistent) sourceData.removeFrom(container);
     sourceData = null;
     if (persistent) container.store(this);
   }
   if (persistent) container.activate(cb, 1);
   cb.onFailure(e, this, container, context);
 }
 protected void onSuccess(
     Bucket data,
     boolean fromStore,
     Integer token,
     int blockNo,
     ClientKeyBlock block,
     ObjectContainer container,
     ClientContext context) {
   if (persistent) {
     container.activate(this, 1);
     container.activate(segment, 1);
     container.activate(parent, 1);
   }
   if (parent.isCancelled()) {
     data.free();
     if (persistent) data.removeFrom(container);
     onFailure(new FetchException(FetchException.CANCELLED), token, container, context);
     return;
   }
   segment.onSuccess(data, blockNo, block, container, context, this);
 }
 public void cancel(ObjectContainer container, ClientContext context) {
   synchronized (this) {
     if (finished) return;
     finished = true;
   }
   boolean wasActive = true;
   if (persistent) {
     container.store(this);
     wasActive = container.ext().isActive(cb);
     if (!wasActive) container.activate(cb, 1);
     container.activate(sourceData, 1);
   }
   if (freeData) {
     sourceData.free();
     if (persistent) sourceData.removeFrom(container);
     sourceData = null;
     if (persistent) container.store(this);
   }
   super.unregister(container, context, getPriorityClass(container));
   cb.onFailure(new InsertException(InsertException.CANCELLED), this, container, context);
   if (!wasActive) container.deactivate(cb, 1);
 }
 @Override
 public void removeFrom(ObjectContainer container) {
   underlying.removeFrom(container);
   container.delete(this);
 }
Beispiel #12
0
  public void onSuccess(FetchResult result, ClientGetter state, ObjectContainer container) {
    Logger.minor(this, "Succeeded: " + identifier);
    Bucket data = result.asBucket();
    if (persistenceType == PERSIST_FOREVER) {
      if (data != null) container.activate(data, 5);
      if (returnBucket != null) container.activate(returnBucket, 5);
      container.activate(client, 1);
      if (tempFile != null) container.activate(tempFile, 5);
      if (targetFile != null) container.activate(targetFile, 5);
    }
    if (returnBucket != data && !binaryBlob) {
      boolean failed = true;
      synchronized (this) {
        if (finished) {
          Logger.error(
              this,
              "Already finished but onSuccess() for " + this + " data = " + data,
              new Exception("debug"));
          data.free();
          if (persistenceType == PERSIST_FOREVER) data.removeFrom(container);
          return; // Already failed - bucket error maybe??
        }
        if (returnType == ClientGetMessage.RETURN_TYPE_DIRECT && returnBucket == null) {
          // Lost bucket for some reason e.g. bucket error (caused by IOException) on previous try??
          // Recover...
          returnBucket = data;
          failed = false;
        }
      }
      if (failed && persistenceType == PERSIST_FOREVER) {
        if (container.ext().getID(returnBucket) == container.ext().getID(data)) {
          Logger.error(
              this,
              "DB4O BUG DETECTED WITHOUT ARRAY HANDLING! EVIL HORRIBLE BUG! UID(returnBucket)="
                  + container.ext().getID(returnBucket)
                  + " for "
                  + returnBucket
                  + " active="
                  + container.ext().isActive(returnBucket)
                  + " stored = "
                  + container.ext().isStored(returnBucket)
                  + " but UID(data)="
                  + container.ext().getID(data)
                  + " for "
                  + data
                  + " active = "
                  + container.ext().isActive(data)
                  + " stored = "
                  + container.ext().isStored(data));
          // Succeed anyway, hope that the returned bucket is consistent...
          returnBucket = data;
          failed = false;
        }
      }
      if (failed) {
        Logger.error(
            this,
            "returnBucket = " + returnBucket + " but onSuccess() data = " + data,
            new Exception("debug"));
        // Caller guarantees that data == returnBucket
        onFailure(
            new FetchException(FetchException.INTERNAL_ERROR, "Data != returnBucket"),
            null,
            container);
        return;
      }
    }
    boolean dontFree = false;
    // FIXME I don't think this is a problem in this case...? (Disk write while locked..)
    AllDataMessage adm = null;
    synchronized (this) {
      if (succeeded) {
        Logger.error(this, "onSuccess called twice for " + this + " (" + identifier + ')');
        return; // We might be called twice; ignore it if so.
      }
      started = true;
      if (!binaryBlob) this.foundDataMimeType = result.getMimeType();
      else this.foundDataMimeType = BinaryBlob.MIME_TYPE;

      if (returnType == ClientGetMessage.RETURN_TYPE_DIRECT) {
        // Send all the data at once
        // FIXME there should be other options
        // FIXME: CompletionTime is set on finish() : we need to give it current time here
        // but it means we won't always return the same value to clients... Does it matter ?
        adm =
            new AllDataMessage(
                returnBucket,
                identifier,
                global,
                startupTime,
                System.currentTimeMillis(),
                this.foundDataMimeType);
        if (persistenceType == PERSIST_CONNECTION) adm.setFreeOnSent();
        dontFree = true;
        /*
         * } else if(returnType == ClientGetMessage.RETURN_TYPE_NONE) {
        // Do nothing
         */
      } else if (returnType == ClientGetMessage.RETURN_TYPE_DISK) {
        // Write to temp file, then rename over filename
        if (!FileUtil.renameTo(tempFile, targetFile)) {
          postFetchProtocolErrorMessage =
              new ProtocolErrorMessage(
                  ProtocolErrorMessage.COULD_NOT_RENAME_FILE, false, null, identifier, global);
          // Don't delete temp file, user might want it.
        }
        returnBucket = new FileBucket(targetFile, false, true, false, false, false);
      }
      if (persistenceType == PERSIST_FOREVER && progressPending != null) {
        container.activate(progressPending, 1);
        progressPending.removeFrom(container);
      }
      progressPending = null;
      this.foundDataLength = returnBucket.size();
      this.succeeded = true;
      finished = true;
    }
    trySendDataFoundOrGetFailed(null, container);

    if (adm != null) trySendAllDataMessage(adm, null, container);
    if (!dontFree) {
      data.free();
    }
    if (persistenceType == PERSIST_FOREVER) {
      returnBucket.storeTo(container);
      container.store(this);
    }
    finish(container);
    if (client != null) client.notifySuccess(this, container);
  }