From 5b50abee94e410586ae92f81e41e4afd5a6fc71c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 26 May 2008 18:45:39 +0000 Subject: Berkely Protocol now uses the integer vector. --- .../implementations/BerkelyTimeProtocol.java | 43 +++++++++++++++------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'sources/protocols/implementations/BerkelyTimeProtocol.java') diff --git a/sources/protocols/implementations/BerkelyTimeProtocol.java b/sources/protocols/implementations/BerkelyTimeProtocol.java index c4ce772..176b2d7 100644 --- a/sources/protocols/implementations/BerkelyTimeProtocol.java +++ b/sources/protocols/implementations/BerkelyTimeProtocol.java @@ -7,9 +7,10 @@ package protocols.implementations; import protocols.VSProtocol; import core.VSMessage; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Vector; -// TODO: Auto-generated Javadoc /** * The Class BerkelyTimeProtocol. */ @@ -18,17 +19,18 @@ public class BerkelyTimeProtocol extends VSProtocol { /* Berkely Server variables */ - /* Integer: Process ID, Long: Local time of the process */ - /** The process times. */ + /** Integer: Process ID, Long: Local time of the process */ private HashMap processTimes = new HashMap(); - /* Integer: Process ID, Long: Time of receiving the response from the process */ - /** The recv times. */ + + /** Integer: Process ID, Long: Time of receiving the response from the process */ private HashMap recvTimes = new HashMap(); - /* Integer: Process ID, Long: Calculated process times (using the RTT) */ - /** The real times rtt. */ + + /** Integer: Process ID, Long: Calculated process times (using the RTT) */ private HashMap realTimesRTT = new HashMap(); - /* Time the request/response has started */ - /** The request time. */ + + /** Contains all process IDs of processes which want to justify their time */ + private ArrayList peers; + /** Time the request/response has started */ private long requestTime; /** @@ -37,8 +39,11 @@ public class BerkelyTimeProtocol extends VSProtocol { public BerkelyTimeProtocol() { setClassname(getClass().toString()); - /* Those prefs are editable through the VSProtocol VSEditor GUI. t_min and t_max in milliseconds */ - initLong("numProcesses", 0, "Anzahl beteilitger Prozesse"); + /* Those prefs are editable through the VSProtocol VSEditor GUI. */ + Vector vec = new Vector(); + vec.add(2); + vec.add(3); + initVector("processPIDs", vec, "PIDs beteiliger Prozesse"); } /* (non-Javadoc) @@ -54,12 +59,16 @@ public class BerkelyTimeProtocol extends VSProtocol { processTimes.clear(); recvTimes.clear(); realTimesRTT.clear(); + peers.clear(); + peers.addAll(getVector("processPIDs")); } /* (non-Javadoc) * @see protocols.VSProtocol#onClientStart() */ protected void onClientStart() { + peers = new ArrayList(); + peers.addAll(getVector("processPIDs")); requestTime = process.getTime(); VSMessage message = new VSMessage(getClassname()); message.setBoolean("isRequest", true); @@ -75,13 +84,19 @@ public class BerkelyTimeProtocol extends VSProtocol { return; Integer processID = new Integer(recvMessage.getInteger("processID")); + + if (peers.contains(processID)) + peers.remove(processID); + else + return; /* Process has been handled already or is not listed */ + Long time = new Long(recvMessage.getLong("time")); processTimes.put(processID, time); recvTimes.put(processID, new Long(process.getTime())); - /* All processes have comitted the response */ - if (processTimes.size() == getInteger("numProcesses")) { + /* All peers have told their times */ + if (peers.size() == 0) { long avgTime = calculateAverageTime(); /* Set the local's process time to the new avg reference time */ process.setTime(avgTime); @@ -109,7 +124,7 @@ public class BerkelyTimeProtocol extends VSProtocol { } /* Include the time of the local process */ sum += process.getTime(); - return (long) sum / (1 + getInteger("numProcesses")); + return (long) sum / (getVector("processPIDs").size() + 1); } /** -- cgit v1.2.3