Example #1
0
 public DistStageAck executeOnSlave() {
   DefaultDistStageAck ack = newDefaultStageAck();
   if (partitions == null) {
     ack.setError(true);
     ack.setErrorMessage("No partitions configured!");
     return ack;
   }
   int myPartitionIndex = -1;
   for (int i = 0; i < partitions.size(); ++i) {
     if (partitions.get(i).contains(getSlaveIndex())) {
       myPartitionIndex = i;
       break;
     }
   }
   if (myPartitionIndex < 0) {
     ack.setError(true);
     ack.setErrorMessage("Slave " + getSlaveIndex() + " is not contained in any partition!");
     return ack;
   }
   try {
     CacheWrapper cacheWrapper = slaveState.getCacheWrapper();
     if (cacheWrapper == null) {
       log.info("Cache wrapper not running, ignoring request to partition");
       return ack;
     }
     if (cacheWrapper instanceof Partitionable) {
       ((Partitionable) cacheWrapper)
           .setMembersInPartition(getSlaveIndex(), partitions.get(myPartitionIndex));
     } else {
       String message =
           "Cache wrapper " + cacheWrapper.getClass() + "does not allow to split partitions";
       ack.setError(true);
       ack.setErrorMessage(message);
       log.error(message);
     }
   } catch (Exception e) {
     ack.setError(true);
     ack.setErrorMessage(e.getMessage());
     log.error(e);
   }
   return ack;
 }