예제 #1
0
 public void writeExternal(ObjectOutput out) throws IOException {
   out.writeObject(value);
   if (lockable) {
     try {
       if (!latch.await(1, TimeUnit.MINUTES)) throw new RuntimeException("Cannot serialize!!");
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
     latch.close();
   }
 }
예제 #2
0
  protected void waitForReplicationLatch(ReplicableCommand rpcCommand, Set<Class> filter) {
    Class cmdClass = getActualClass(rpcCommand);
    if (!filter.contains(cmdClass)) {
      return;
    }

    try {
      log.debugf("Replication trigger called, waiting for latch to open.");
      blockingLatch.open();
      replicationLatch.await();
      log.trace("Replication latch opened, continuing.");
    } catch (Exception e) {
      throw new RuntimeException("Unexpected exception!", e);
    }
  }
 @Override
 public void initializeReplicableCommand(ReplicableCommand command, boolean isRemote) {
   log.tracef("Received command %s", command);
   receivedCommands.add(command);
   if (isRemote) {
     remoteCommandsReceived.incrementAndGet();
     if (toBlock != null && command.getClass().isAssignableFrom(toBlock)) {
       blockTypeCommandsReceived.incrementAndGet();
       try {
         gate.await();
         log.tracef("gate is opened, processing the lock cleanup:  %s", command);
       } catch (InterruptedException e) {
         throw new RuntimeException(e);
       }
     }
   }
   actual.initializeReplicableCommand(command, isRemote);
 }
예제 #4
0
 public void allowSerialization() {
   if (lockable) latch.open();
 }
예제 #5
0
 public void waitForCommandToBlock() throws InterruptedException {
   blockingLatch.await();
 }
예제 #6
0
 public void stopBlocking() {
   blockBeforeFilter = Collections.emptySet();
   blockAfterFilter = Collections.emptySet();
   replicationLatch.open();
 }
예제 #7
0
 public void blockAfter(Class... filter) {
   this.blockAfterFilter = new HashSet<Class>(Arrays.asList(filter));
   replicationLatch.close();
   blockingLatch.close();
 }