Exemplo n.º 1
0
 @Override
 public void incomingDataFromServer(TransportMessage transportMessage) {
   if (!mix.isLastMix())
     throw new RuntimeException(
         "ERROR: BasicSynchronousBatch only supports NoneMixMessages as reply from distant proxy!");
   clientReplyWaitingQueues
       .get(transportMessage.getOwner().getIdentifier())
       .add(transportMessage);
 }
Exemplo n.º 2
0
 private void createReplyBatchFromUserData() {
   Vector<MixMessage> batch = new Vector<MixMessage>(simulator.getClients().size());
   for (AbstractClient client : simulator.getClients().values()) {
     Vector<TransportMessage> replyWaitingQueue =
         clientReplyWaitingQueues.get(client.getIdentifier());
     boolean isDummy = replyWaitingQueue.size() == 0 ? true : false;
     MixMessage mixMessage = createDummyMessage(client);
     if (isDummy) {
       batch.add(mixMessage);
     } else {
       for (int i = 0; i < replyWaitingQueue.size(); i++) {
         TransportMessage noneMixMessage = replyWaitingQueue.get(i);
         if (mixMessage.getFreeSpace() >= noneMixMessage.getLength()
             && !noneMixMessage.isFragmented()) { // noneMixMessage fits in mixMessage completely
           replyWaitingQueue.remove(noneMixMessage);
           i--;
           mixMessage.addPayloadObject(noneMixMessage);
         } else { // add Fragment
           if (noneMixMessage.hasNextFragment()) {
             MessageFragment messageFragment =
                 noneMixMessage.getFragment(mixMessage.getFreeSpace());
             mixMessage.addPayloadObject(messageFragment);
           }
           if (!noneMixMessage.hasNextFragment()) {
             replyWaitingQueue.remove(i);
             i--;
           }
         }
         if (mixMessage.getFreeSpace() == 0) break;
       }
       batch.add(mixMessage);
     }
   }
   Collections.shuffle(batch);
   for (MixMessage mixMessage : batch) mix.putOutRequest(mixMessage);
 }