@Override public void executeEvent(Event e) { if (e.getEventType() == OutputStrategyEvent.TIMEOUT) { MixMessage mixMessage = (MixMessage) e.getAttachment(); if (mixMessage.isRequest()) mix.putOutRequest(mixMessage); else mix.putOutReply(mixMessage); } else throw new RuntimeException("ERROR: StopAndGo received unknown Event: " + e); }
public void addMessage(MixMessage mixMessage) { if (isFirstMessage) { isFirstMessage = false; scheduleNextOutput(); } int index = mixMessage.getOwner().getClientId(); boolean drop; if (batch[index] == null) { // user has no message in current batch -> add his message batch[index] = mixMessage; drop = true; } else { // user has message in current batch -> drop message drop = false; statistics.addValue(drop, StatisticsType.DLPA_REQUEST_MESSAGE_DROP_PERCENTAGE_INCL_DUMMIES); statistics.addValue(drop, StatisticsType.DLPA_MESSAGE_DROP_PERCENTAGE_INCL_DUMMIES); } // record statistics if (isRequestBatch) { statistics.addValue(drop, StatisticsType.DLPA_REQUEST_MESSAGE_DROP_PERCENTAGE); statistics.addValue(drop, StatisticsType.DLPA_MESSAGE_DROP_PERCENTAGE); } else { statistics.addValue(drop, StatisticsType.DLPA_REPLY_MESSAGE_DROP_PERCENTAGE); statistics.addValue(drop, StatisticsType.DLPA_MESSAGE_DROP_PERCENTAGE); } }
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); }
private MixMessage createDummyMessage(AbstractClient owner) { NetworkNode source = isRequestBatch ? owner : mix; NetworkNode destination = isRequestBatch ? simulator.getDistantProxy() : owner; return MixMessage.getInstance( isRequestBatch, source, destination, owner, Simulator.getNow(), true); }