From: <sno...@us...> - 2013-09-23 23:21:53
|
Revision: 107 http://sourceforge.net/p/openrpg/svn/107 Author: snowdog_ Date: 2013-09-23 23:21:49 +0000 (Mon, 23 Sep 2013) Log Message: ----------- Fixes to connection stats timing methods Modified Paths: -------------- trunk/src/openrpg2/common/core/network/ConnectionStats.java Modified: trunk/src/openrpg2/common/core/network/ConnectionStats.java =================================================================== --- trunk/src/openrpg2/common/core/network/ConnectionStats.java 2013-09-23 18:34:21 UTC (rev 106) +++ trunk/src/openrpg2/common/core/network/ConnectionStats.java 2013-09-23 23:21:49 UTC (rev 107) @@ -29,7 +29,6 @@ */ -import java.util.Date; import java.util.Calendar; /** @@ -46,13 +45,11 @@ private long lastOut; private long inMessages; private long outMessages; - private Calendar cal; /** * Creates a new instance of ConnectionStats */ public ConnectionStats() { - cal = Calendar.getInstance(); clear(); } @@ -60,14 +57,14 @@ * Sets the time when the connection was established */ public void setConnectionTime(){ - connectionStart = cal.getTimeInMillis(); + connectionStart = Calendar.getInstance().getTimeInMillis(); } /** * Marks a moment in time for later calculations */ public void setTimeMark(){ - connectionMark = cal.getTimeInMillis(); + connectionMark = Calendar.getInstance().getTimeInMillis(); } /** @@ -82,7 +79,7 @@ public long getConnectionDuration(){ if (connectionStart == 0){ return 0L; } if (connectionMark > connectionStart ){ return connectionMark - connectionStart; } - return cal.getTimeInMillis() - connectionStart; + return Calendar.getInstance().getTimeInMillis() - connectionStart; } @@ -90,22 +87,24 @@ * Informs the ConnectionStats object of a socket message it should track. * Inbound socket message time is automatically updated internally on each * call to AddInbound. - * @param msgSize The number of bytes of an inbound message. Interal inbound byte counter is incremented by <CODE>msgSize</CODE> bytes. + * @param msgSize The number of bytes of an inbound message. Interval inbound + * byte counter is incremented by <CODE>msgSize</CODE> bytes. */ public void addInbound( long msgSize ){ inBytes += msgSize; - cal.setTime( new Date() ); - lastIn = cal.getTimeInMillis(); + lastIn = Calendar.getInstance().getTimeInMillis(); } /** - * Informs the ConnectionStats object of a socket message it should track. Outbound socket message time is automatically updated internally on each call to AddOutbound. - * @param msgSize The number of bytes of an outbound message. Interal outbound byte counter is incremented by <CODE>msgSize</CODE> bytes. + * Informs the ConnectionStats object of a socket message it should track. + * Outbound socket message time is automatically updated internally on each + * call to AddOutbound. + * @param msgSize The number of bytes of an outbound message. + * Interval outbound byte counter is incremented by <CODE>msgSize</CODE> bytes. */ public void addOutbound( long msgSize ){ outBytes += msgSize; - cal.setTime( new Date() ); - lastOut = cal.getTimeInMillis(); + lastOut = Calendar.getInstance().getTimeInMillis(); } /** @@ -116,9 +115,9 @@ outBytes = 0L; - cal.setTime(new Date() ); - lastIn = cal.getTimeInMillis(); - lastOut = cal.getTimeInMillis(); + long time = Calendar.getInstance().getTimeInMillis(); + lastIn = time; + lastOut = time; connectionMark = 0; connectionStart = 0; inMessages = 0; @@ -142,32 +141,35 @@ } /** - * This method can be used to test for timeout or delay conditions based on the ConnectionStats object's internal timers. The timers are automatically updated by calls to the AddInbound and AddOutbound methods and represent the last time when a socket message was reported to the object. + * This method can be used to test for timeout or delay conditions based on + * the ConnectionStats object's internal timers. The timers are automatically + * updated by calls to the AddInbound and AddOutbound methods and represent + * the last time when a socket message was reported to the object. * @param seconds The number of seconds of inactivity at which the method will return a <B>false</B> * @return <B>true</B> if network activity has been reported within the last X seconds. */ public boolean isActive(int seconds){ //convert seconds to milliseconds long ms = (long)seconds * 1000L; - if ( (lastIn+ms)<cal.getTimeInMillis() ) { return true; } + if ( (lastIn+ms)<Calendar.getInstance().getTimeInMillis() ) { return true; } return false; } /** - * Reports the time in seconds since the last inbound message was recorded in the object. + * Reports the time in milliseconds since the last inbound message was recorded in the object. * @return inbound message offset (milliseconds) */ public int getInboundMessageDelta(){ - int delta = (int)(cal.getTimeInMillis() - lastIn); + int delta = (int)(Calendar.getInstance().getTimeInMillis() - lastIn); return (int)delta; } /** - * Reports the time in seconds since the last outbound message was recorded in the object. + * Reports the time in milliseconds since the last outbound message was recorded in the object. * @return outbound message offset (milliseconds) */ public int getOutboundMessageDelta(){ - int delta =(int) (cal.getTimeInMillis() - lastOut); + int delta =(int) (Calendar.getInstance().getTimeInMillis() - lastOut); return delta; } @@ -203,8 +205,8 @@ } /** - * Retreives the total message count by summing both the inbound and outbound counters. - * @return total number of messages sent and recieved as a long integer + * Retrieves the total message count by summing both the inbound and outbound counters. + * @return total number of messages sent and received as a long integer */ public long getTotalMessageCount(){ return getInboundMessageCount()+getOutboundMessageCount(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |