see how that looks

(shendaras)
This commit is contained in:
shendaras
2004-04-10 10:01:17 +00:00
committed by zzz
parent 9a0a527b2b
commit 4fb3d34786

View File

@@ -14,16 +14,27 @@ import net.i2p.util.Log;
*
*/
public class ClientConfig {
private static final Log _log = new Log(ClientConfig.class);
private Destination _peer;
private Destination _us;
private String _statFile;
private int _statDuration;
private int _statFrequency;
private int _sendFrequency;
private int _sendSize;
private int _numHops;
private String _comment;
private int _averagePeriods[];
/**
@@ -88,17 +99,28 @@ public class ClientConfig {
}
/**
* @param peer who we will test against
* @param us who we are
* @param duration how many minutes to keep events for
* @param statFreq how often to write out stats
* @param sendFreq how often to send pings
* @param sendSize how large the pings should be
* @param numHops how many hops is the current Heartbeat app using
* @param comment describe this test
* @param averagePeriods list of minutes to summarize over
* @param peer
* who we will test against
* @param us
* who we are
* @param duration
* how many minutes to keep events for
* @param statFreq
* how often to write out stats
* @param sendFreq
* how often to send pings
* @param sendSize
* how large the pings should be
* @param numHops
* how many hops is the current Heartbeat app using
* @param comment
* describe this test
* @param averagePeriods
* list of minutes to summarize over
*/
public ClientConfig(Destination peer, Destination us, String statFile, int duration, int statFreq, int sendFreq, int sendSize, int numHops, String comment, int averagePeriods[]) {
public ClientConfig(Destination peer, Destination us, String statFile,
int duration, int statFreq, int sendFreq, int sendSize,
int numHops, String comment, int averagePeriods[]) {
_peer = peer;
_us = us;
_statFile = statFile;
@@ -111,167 +133,258 @@ public class ClientConfig {
_averagePeriods = averagePeriods;
}
/** Retrieves the peer to test against
/**
* Retrieves the peer to test against
*
* @return the Destination (peer)
*/
public Destination getPeer() { return _peer; }
public Destination getPeer() {
return _peer;
}
/**
* Sets the peer to test against
* @param peer the Destination (peer)
*
* @param peer
* the Destination (peer)
*/
public void setPeer(Destination peer) { _peer = peer; }
public void setPeer(Destination peer) {
_peer = peer;
}
/**
* Retrieves who we are when we test
*
* @return the Destination (us)
*/
public Destination getUs() { return _us; }
public Destination getUs() {
return _us;
}
/**
* Sets who we are when we test
* @param us the Destination (us)
*
* @param us
* the Destination (us)
*/
public void setUs(Destination us) { _us = us; }
public void setUs(Destination us) {
_us = us;
}
/**
* Retrieves the location to write the current stats to
*
* @return the name of the file
*/
public String getStatFile() { return _statFile; }
public String getStatFile() {
return _statFile;
}
/**
* Sets the name of the location we write the current stats to
* @param statFile the name of the file
*
* @param statFile
* the name of the file
*/
public void setStatFile(String statFile) { _statFile = statFile; }
public void setStatFile(String statFile) {
_statFile = statFile;
}
/**
* Retrieves how many minutes of statistics should be maintained within the window for this client
* Retrieves how many minutes of statistics should be maintained within the
* window for this client
*
* @return the number of minutes
*/
public int getStatDuration() { return _statDuration; }
public int getStatDuration() {
return _statDuration;
}
/**
* Sets how many minutes of statistics should be maintained within the window for this client
* @param durationMinutes the number of minutes
* Sets how many minutes of statistics should be maintained within the
* window for this client
*
* @param durationMinutes
* the number of minutes
*/
public void setStatDuration(int durationMinutes) { _statDuration = durationMinutes; }
public void setStatDuration(int durationMinutes) {
_statDuration = durationMinutes;
}
/**
* Retrieves how frequently the stats are written out (in seconds)
*
* @return the frequency in seconds
*/
public int getStatFrequency() { return _statFrequency; }
public int getStatFrequency() {
return _statFrequency;
}
/**
* Sets how frequently the stats are written out (in seconds)
* @param freqSeconds the frequency in seconds
*
* @param freqSeconds
* the frequency in seconds
*/
public void setStatFrequency(int freqSeconds) { _statFrequency = freqSeconds; }
public void setStatFrequency(int freqSeconds) {
_statFrequency = freqSeconds;
}
/**
* Retrieves how frequenty we send messages to the peer (in seconds)
*
* @return the frequency in seconds
*/
public int getSendFrequency() { return _sendFrequency; }
public int getSendFrequency() {
return _sendFrequency;
}
/**
* Sets how frequenty we send messages to the peer (in seconds)
* @param freqSeconds the frequency in seconds
*
* @param freqSeconds
* the frequency in seconds
*/
public void setSendFrequency(int freqSeconds) { _sendFrequency = freqSeconds; }
public void setSendFrequency(int freqSeconds) {
_sendFrequency = freqSeconds;
}
/**
* Retrieves how many bytes the ping messages should be
* (min values ~700, max ~32KB)
* Retrieves how many bytes the ping messages should be (min values ~700,
* max ~32KB)
*
* @return the size in bytes
*/
public int getSendSize() { return _sendSize; }
public int getSendSize() {
return _sendSize;
}
/**
* Sets how many bytes the ping messages should be
* (min values ~700, max ~32KB)
* @param numBytes the size in bytes
* Sets how many bytes the ping messages should be (min values ~700, max
* ~32KB)
*
* @param numBytes
* the size in bytes
*/
public void setSendSize(int numBytes) { _sendSize = numBytes; }
public void setSendSize(int numBytes) {
_sendSize = numBytes;
}
/**
* Retrieves the brief, 1 line description of the test.
* Useful comments are along the lines of "The peer is located on a fast router and connection with 2 hop tunnels".
* Retrieves the brief, 1 line description of the test. Useful comments are
* along the lines of "The peer is located on a fast router and connection
* with 2 hop tunnels".
*
* @return the brief comment
*/
public String getComment() { return _comment; }
public String getComment() {
return _comment;
}
/**
* Sets a brief, 1 line description (comment) of the test.
* @param comment the brief comment
*
* @param comment
* the brief comment
*/
public void setComment(String comment) { _comment = comment; }
public void setComment(String comment) {
_comment = comment;
}
/**
* Retrieves the periods that the client's tests should be averaged over.
* @return list of periods (in minutes) that the data should be averaged over, or null
*
* @return list of periods (in minutes) that the data should be averaged
* over, or null
*/
public int[] getAveragePeriods() { return _averagePeriods; }
public int[] getAveragePeriods() {
return _averagePeriods;
}
/**
* Sets the periods that the client's tests should be averaged over.
* @param periods the list of periods (in minutes) that the data should be averaged over, or null
*
* @param periods
* the list of periods (in minutes) that the data should be
* averaged over, or null
*/
public void setAveragePeriods(int periods[]) { _averagePeriods = periods; }
public void setAveragePeriods(int periods[]) {
_averagePeriods = periods;
}
/**
* Retrieves how many hops this test engine is configured to use for its outbound and inbound tunnels
* Retrieves how many hops this test engine is configured to use for its
* outbound and inbound tunnels
*
* @return the number of hops
*/
public int getNumHops() { return _numHops; }
public int getNumHops() {
return _numHops;
}
/**
* Sets how many hops this test engine is configured to use for its outbound and inbound tunnels
* @param numHops the number of hops
*/
public void setNumHops(int numHops) { _numHops = numHops; }
/**
* Load the client config from the properties specified, deriving the current
* config entry from the peer number.
* Sets how many hops this test engine is configured to use for its outbound
* and inbound tunnels
*
* @param clientConfig the properties to load from
* @param peerNum the number associated with the peer
* @param numHops
* the number of hops
*/
public void setNumHops(int numHops) {
_numHops = numHops;
}
/**
* Load the client config from the properties specified, deriving the
* current config entry from the peer number.
*
* @param clientConfig
* the properties to load from
* @param peerNum
* the number associated with the peer
* @return true if it was loaded correctly, false if there were errors
*/
public boolean load(Properties clientConfig, int peerNum) {
if ((clientConfig == null) || (peerNum < 0)) return false;
String peerVal = clientConfig.getProperty(PROP_PREFIX + peerNum + PROP_PEER);
String statFileVal = clientConfig.getProperty(PROP_PREFIX + peerNum + PROP_STATFILE);
String statDurationVal = clientConfig.getProperty(PROP_PREFIX + peerNum + PROP_STATDURATION);
String statFrequencyVal = clientConfig.getProperty(PROP_PREFIX + peerNum + PROP_STATFREQUENCY);
String sendFrequencyVal = clientConfig.getProperty(PROP_PREFIX + peerNum + PROP_SENDFREQUENCY);
String sendSizeVal = clientConfig.getProperty(PROP_PREFIX + peerNum + PROP_SENDSIZE);
String commentVal = clientConfig.getProperty(PROP_PREFIX + peerNum + PROP_COMMENT);
String periodsVal = clientConfig.getProperty(PROP_PREFIX + peerNum + PROP_AVERAGEPERIODS);
String peerVal = clientConfig.getProperty(PROP_PREFIX + peerNum
+ PROP_PEER);
String statFileVal = clientConfig.getProperty(PROP_PREFIX + peerNum
+ PROP_STATFILE);
String statDurationVal = clientConfig.getProperty(PROP_PREFIX + peerNum
+ PROP_STATDURATION);
String statFrequencyVal = clientConfig.getProperty(PROP_PREFIX
+ peerNum + PROP_STATFREQUENCY);
String sendFrequencyVal = clientConfig.getProperty(PROP_PREFIX
+ peerNum + PROP_SENDFREQUENCY);
String sendSizeVal = clientConfig.getProperty(PROP_PREFIX + peerNum
+ PROP_SENDSIZE);
String commentVal = clientConfig.getProperty(PROP_PREFIX + peerNum
+ PROP_COMMENT);
String periodsVal = clientConfig.getProperty(PROP_PREFIX + peerNum
+ PROP_AVERAGEPERIODS);
if ( (peerVal == null) || (statFileVal == null) || (statDurationVal == null) ||
(statFrequencyVal == null) || (sendFrequencyVal == null) || (sendSizeVal == null) ) {
if ((peerVal == null) || (statFileVal == null)
|| (statDurationVal == null) || (statFrequencyVal == null)
|| (sendFrequencyVal == null) || (sendSizeVal == null)) {
if (_log.shouldLog(Log.DEBUG)) {
_log.debug("Peer number " + peerNum + " does not exist");
}
return false;
}
try {
int duration = getInt(statDurationVal);
int statFreq = getInt(statFrequencyVal);
int sendFreq = getInt(sendFrequencyVal);
int sendSize = getInt(sendSizeVal);
if ( (duration <= 0) || (statFreq <= 0) || (sendFreq <= 0) || (sendSize <= 0) ) {
if ((duration <= 0) || (statFreq <= 0) || (sendFreq <= 0)
|| (sendSize <= 0)) {
if (_log.shouldLog(Log.WARN)) {
_log.warn("Invalid client config: duration [" + statDurationVal + "] stat frequency [" + statFrequencyVal +
"] send frequency [" + sendFrequencyVal + "] send size [" + sendSizeVal + "]");
_log.warn("Invalid client config: duration ["
+ statDurationVal + "] stat frequency ["
+ statFrequencyVal + "] send frequency ["
+ sendFrequencyVal + "] send size [" + sendSizeVal
+ "]");
}
return false;
}
@@ -320,7 +433,8 @@ public class ClientConfig {
_averagePeriods = avgPeriods;
return true;
} catch (DataFormatException dfe) {
_log.error("Peer destination for " + peerNum + " was invalid: " + peerVal);
_log.error("Peer destination for " + peerNum + " was invalid: "
+ peerVal);
return false;
}
}
@@ -329,15 +443,16 @@ public class ClientConfig {
* Store the client config to the properties specified, deriving the current
* config entry from the peer number.
*
* @param clientConfig the properties to store to
* @param peerNum the number associated with the peer
* @param clientConfig
* the properties to store to
* @param peerNum
* the number associated with the peer
* @return true if it was stored correctly, false if there were errors
*/
public boolean store(Properties clientConfig, int peerNum) {
if ( (_peer == null) || (_sendFrequency <= 0) || (_sendSize <= 0) ||
(_statDuration <= 0) || (_statFrequency <= 0) || (_statFile == null) ) {
return false;
}
if ((_peer == null) || (_sendFrequency <= 0) || (_sendSize <= 0)
|| (_statDuration <= 0) || (_statFrequency <= 0)
|| (_statFile == null)) { return false; }
String comment = _comment;
if (comment == null) {
@@ -354,14 +469,21 @@ public class ClientConfig {
}
}
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_PEER, _peer.toBase64());
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_STATFILE, _statFile);
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_STATDURATION, _statDuration + "");
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_STATFREQUENCY, _statFrequency + "");
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_SENDFREQUENCY, _sendFrequency + "");
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_SENDSIZE, _sendSize + "");
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_PEER, _peer
.toBase64());
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_STATFILE,
_statFile);
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_STATDURATION,
_statDuration + "");
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_STATFREQUENCY,
_statFrequency + "");
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_SENDFREQUENCY,
_sendFrequency + "");
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_SENDSIZE,
_sendSize + "");
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_COMMENT, comment);
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_AVERAGEPERIODS, buf.toString());
clientConfig.setProperty(PROP_PREFIX + peerNum + PROP_AVERAGEPERIODS,
buf.toString());
return true;
}