Skip to content
Browse files

fixed missing OverallStatisticsUpdates when using cli: Refactored the…

… date from attribute to the according methods' local variable. Fixed some wrong ResourceBundle-calls. Added try-catch-blocks to statistics-methods for debugging, because Exceptions had been silently dropped by Jeff before. Added log.txt to .hgingnore
  • Loading branch information...
1 parent 907bfca commit 59c39d50e5dedcf011999c57162de2965453a8ff Tobi Stoeckel committed
Showing with 51 additions and 13 deletions.
  1. +1 −0 .hgignore
  2. +14 −2 nbactions.xml
  3. +36 −11 src/main/java/com/spam/mctool/view/CommandLineView.java
View
1 .hgignore
@@ -18,3 +18,4 @@ private.xml
^\.settings(/.*)?$
RecentProfiles.xml
testprofile
+log.txt
View
16 nbactions.xml
@@ -16,7 +16,7 @@
</goals>
<properties>
<exec.classpathScope>runtime</exec.classpathScope>
- <exec.args>-classpath %classpath com.spam.mctool.controller.Controller</exec.args>
+ <exec.args>-classpath %classpath com.spam.mctool.controller.Controller -cli</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
@@ -36,9 +36,21 @@
</goals>
<properties>
<exec.classpathScope>runtime</exec.classpathScope>
- <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath com.spam.mctool.controller.Controller</exec.args>
+ <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath com.spam.mctool.controller.Controller -cli</exec.args>
<jpda.listen>true</jpda.listen>
<exec.executable>java</exec.executable>
</properties>
</action>
+ <action>
+ <actionName>profile</actionName>
+ <goals>
+ <goal>process-classes</goal>
+ <goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
+ </goals>
+ <properties>
+ <exec.args>${profiler.args} -classpath %classpath com.spam.mctool.controller.Controller -cli</exec.args>
+ <profiler.action>profile</profiler.action>
+ <exec.executable>${profiler.java}</exec.executable>
+ </properties>
+ </action>
</actions>
View
47 src/main/java/com/spam/mctool/view/CommandLineView.java
@@ -33,7 +33,6 @@
private PrintStream out = System.out;
private BufferedWriter log;
private Controller c;
- private Date date;
private Date lastUpdate = null;
private java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("internationalization/Bundle");
@@ -63,40 +62,40 @@ public void init(Controller c) {
e.printStackTrace();
}
- logger.info(bundle.getString(("CommandLine.LoggerInitialized.text"))+" "+new Date());
+ logger.info(bundle.getString("CommandLine.LoggerInitialized.text")+" "+new Date());
}
public void profileChanged(ProfileChangeEvent e) {
out.println(bundle.getString("CommandLine.ProfileChanged.text"));
- logger.info(bundle.getString(("CommandLine.ProfileChanged.text")));
+ logger.info(bundle.getString("CommandLine.ProfileChanged.text"));
}
public void receiverGroupAdded(ReceiverAddedOrRemovedEvent e) {
out.println(bundle.getString("CommandLine.ReceiverGroupAdded.text") + e.getSource().getGroup().toString());
- logger.info(bundle.getString(("CommandLine.ReceiverGroupAdded.text") + e.getSource().getGroup().toString()));
+ logger.info(bundle.getString("CommandLine.ReceiverGroupAdded.text") + e.getSource().getGroup().toString());
}
public void receiverGroupRemoved(ReceiverAddedOrRemovedEvent e) {
out.println(bundle.getString("CommandLine.ReceiverGroupRemoved.text") + e.getSource().getGroup().toString());
- logger.info(bundle.getString(("CommandLine.ReceiverGroupRemoved.text") + e.getSource().getGroup().toString()));
+ logger.info(bundle.getString("CommandLine.ReceiverGroupRemoved.text") + e.getSource().getGroup().toString());
}
public void senderAdded(SenderAddedOrRemovedEvent e) {
out.println(bundle.getString("CommandLine.SenderAdded.text") + "ID:" + e.getSource().getSenderId());
- logger.info(bundle.getString(("CommandLine.SenderAdded.text") + "ID:" + e.getSource().getSenderId()));
+ logger.info(bundle.getString("CommandLine.SenderAdded.text") + "ID:" + e.getSource().getSenderId());
}
public void senderRemoved(SenderAddedOrRemovedEvent e) {
out.println(bundle.getString("CommandLine.SenderRemoved.text") + "ID:" + e.getSource().getSenderId());
- logger.info(bundle.getString(("CommandLine.SenderRemoved.text") + "ID:" + e.getSource().getSenderId()));
+ logger.info(bundle.getString("CommandLine.SenderRemoved.text") + "ID:" + e.getSource().getSenderId());
}
@@ -109,7 +108,7 @@ public void kill()
c.removeOverallReceiverStatisticsUpdatedListener(this);
c.removeOverallSenderStatisticsUpdatedListener(this);
- logger.info(bundle.getString(("CommandLine.Kill.text")) + new Date());
+ logger.info(bundle.getString("CommandLine.Kill.text") + new Date());
try {
log.close();
@@ -121,7 +120,7 @@ public void kill()
@Override
public void newErrorEvent(ErrorEvent e) {
- date = new Date();
+ Date date = new Date();
if(e.getErrorLevel() == ErrorEventManager.WARNING)
logger.info(date.toString() + " - " + bundle.getString("CommandLine.Warning.text") + e.getCompleteMessage());
@@ -130,14 +129,25 @@ public void newErrorEvent(ErrorEvent e) {
out.println(date.toString() + " - " + bundle.getString("CommandLine.Error.text") + e.getCompleteMessage());
}
+ /**
+ * {@inheritDoc }
+ *
+ * <p>This implementation will print all internal exceptions' stack traces.
+ * This is because this method will be called by the model's threading
+ * framework which conveniently "swallows" all exceptions.</p>
+ *
+ * @param e
+ */
@Override
public void overallSenderStatisticsUpdated(
OverallSenderStatisticsUpdatedEvent e) {
+ try {
if(lastUpdate == null){
lastUpdate = new Date();
}
if(lastUpdate.getTime() > 5.*60.*1000){
+ Date date = new Date();
out.println(bundle.getString("CommandLine.SenderStatistics.text") + date.toString() + ":\n" );
out.println(bundle.getString("CommandLine.SentPackets.text") + e.getSource().getOverallSentPackets() + "\n");
out.println(bundle.getString("CommandLine.SentPacketsPerSec.text") + e.getSource().getOverallSentPPS() + "\n");
@@ -147,18 +157,31 @@ public void overallSenderStatisticsUpdated(
logger.info(bundle.getString("CommandLine.SentPacketsPerSec.text") + e.getSource().getOverallSentPPS() + "\n");
}
-
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
+ /**
+ * {@inheritDoc }
+ *
+ * <p>This implementation will print all internal exceptions' stack traces.
+ * This is because this method will be called by the model's threading
+ * framework which conveniently "swallows" all exceptions.</p>
+ *
+ * @param e
+ */
@Override
public void overallReceiverStatisticsUpdated(
OverallReceiverStatisticsUpdatedEvent e) {
+ try {
if(lastUpdate == null){
lastUpdate = new Date();
}
if(lastUpdate.getTime() > 5.*60.*1000){
+ Date date = new Date();
out.println(bundle.getString("CommandLine.ReceiverStatistics.text") + date.toString() + ":\n" );
out.println(bundle.getString("CommandLine.ReceivedPackages.text") + e.getSource().getOverallReceivedPackets() + "\n");
out.println(bundle.getString("CommandLine.FaultyPackets.text") + e.getSource().getOverallFaultyPackets() + "\n");
@@ -171,7 +194,9 @@ public void overallReceiverStatisticsUpdated(
logger.info(bundle.getString("CommandLine.LostPackages.text") + e.getSource().getOverallLostPackets() + "\n");
logger.info(bundle.getString("CommandLine.ReceivedPaketsPerSec.text") + e.getSource().getOverallReceivedPPS() + "\n");
}
-
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
}
}

0 comments on commit 59c39d5

Please sign in to comment.
Something went wrong with that request. Please try again.