Ejemplo n.º 1
0
 public void schedule(ObjectContainer container, ClientContext context) throws InsertException {
   synchronized (this) {
     if (finished) {
       if (logMINOR) Logger.minor(this, "Finished already: " + this);
       return;
     }
   }
   if (getCHKOnly) {
     boolean deactivateCB = false;
     if (persistent) {
       deactivateCB = !container.ext().isActive(cb);
       if (deactivateCB) container.activate(cb, 1);
       container.activate(parent, 1);
     }
     ClientKeyBlock block = encode(container, context, true);
     cb.onEncode(block.getClientKey(), this, container, context);
     parent.completedBlock(false, container, context);
     cb.onSuccess(this, container, context);
     finished = true;
     if (persistent) {
       container.store(this);
       if (deactivateCB) container.deactivate(cb, 1);
     }
   } else {
     getScheduler(context).registerInsert(this, persistent, true, container);
   }
 }
Ejemplo n.º 2
0
 protected ClientKeyBlock encode(
     ObjectContainer container, ClientContext context, boolean calledByCB) throws InsertException {
   if (persistent) {
     container.activate(sourceData, 1);
     container.activate(cb, 1);
   }
   ClientKeyBlock block;
   boolean shouldSend;
   synchronized (this) {
     if (finished) return null;
     if (sourceData == null) {
       Logger.error(this, "Source data is null on " + this + " but not finished!");
       return null;
     }
     block = innerEncode(context.random, container);
     shouldSend = (resultingURI == null);
     resultingURI = block.getClientKey().getURI();
   }
   if (logMINOR)
     Logger.minor(
         this,
         "Encoded "
             + resultingURI
             + " for "
             + this
             + " shouldSend="
             + shouldSend
             + " dontSendEncoded="
             + dontSendEncoded);
   if (shouldSend && !dontSendEncoded) cb.onEncode(block.getClientKey(), this, container, context);
   if (shouldSend && persistent) container.store(this);
   if (persistent && !calledByCB) container.deactivate(cb, 1);
   return block;
 }
Ejemplo n.º 3
0
 public ClientKeyBlock getBlock(
     ObjectContainer container, ClientContext context, boolean calledByCB) {
   try {
     synchronized (this) {
       if (finished) return null;
     }
     if (persistent) container.store(this);
     return encode(container, context, calledByCB);
   } catch (InsertException e) {
     if (persistent) container.activate(cb, 1);
     cb.onFailure(e, this, container, context);
     if (persistent && !calledByCB) container.deactivate(cb, 1);
     return null;
   } catch (Throwable t) {
     if (persistent) container.activate(cb, 1);
     Logger.error(this, "Caught " + t, t);
     cb.onFailure(
         new InsertException(InsertException.INTERNAL_ERROR, t, null), this, container, context);
     if (persistent && !calledByCB) container.deactivate(cb, 1);
     return null;
   }
 }
Ejemplo n.º 4
0
 protected void onEncode(ClientKey key, ObjectContainer container, ClientContext context) {
   synchronized (this) {
     if (finished) return;
     if (resultingURI != null) return;
     resultingURI = key.getURI();
   }
   if (persistent) {
     container.store(this);
     container.activate(cb, 1);
   }
   cb.onEncode(key, this, container, context);
   if (persistent) container.deactivate(cb, 1);
 }
Ejemplo n.º 5
0
 @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);
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 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);
 }