Don't require that ConnectionManager be a Reporter
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6377 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -49,7 +49,7 @@ import com.threerings.io.UnreliableObjectOutputStream;
|
||||
|
||||
import com.threerings.presents.annotation.AuthInvoker;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.data.ConMgrStats;
|
||||
import com.threerings.presents.data.PresentsConMgrStats;
|
||||
import com.threerings.presents.net.Message;
|
||||
import com.threerings.presents.net.PongResponse;
|
||||
import com.threerings.presents.net.Transport;
|
||||
@@ -69,20 +69,68 @@ import static com.threerings.presents.Log.log;
|
||||
|
||||
@Singleton
|
||||
public class PresentsConnectionManager extends ConnectionManager
|
||||
implements ReportManager.Reporter
|
||||
{
|
||||
|
||||
@Inject
|
||||
public PresentsConnectionManager (Lifecycle cycle, ReportManager repmgr)
|
||||
throws IOException
|
||||
{
|
||||
super(cycle, repmgr);
|
||||
super(cycle);
|
||||
repmgr.registerReporter(this);
|
||||
_stats = new PresentsConMgrStats();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized ConMgrStats getStats ()
|
||||
public synchronized PresentsConMgrStats getStats ()
|
||||
{
|
||||
_stats.authQueueSize = _authq.size();
|
||||
return super.getStats();
|
||||
((PresentsConMgrStats)_stats).authQueueSize = _authq.size();
|
||||
return ((PresentsConMgrStats)super.getStats());
|
||||
}
|
||||
|
||||
// from interface ReportManager.Reporter
|
||||
public void appendReport (StringBuilder report, long now, long sinceLast, boolean reset)
|
||||
{
|
||||
PresentsConMgrStats stats = getStats();
|
||||
long eventCount = stats.eventCount - _lastStats.eventCount;
|
||||
int connects = stats.connects - _lastStats.connects;
|
||||
int disconnects = stats.disconnects - _lastStats.disconnects;
|
||||
int closes = stats.closes - _lastStats.closes;
|
||||
long bytesIn = stats.bytesIn - _lastStats.bytesIn;
|
||||
long bytesOut = stats.bytesOut - _lastStats.bytesOut;
|
||||
long msgsIn = stats.msgsIn - _lastStats.msgsIn;
|
||||
long msgsOut = stats.msgsOut - _lastStats.msgsOut;
|
||||
if (reset) {
|
||||
_lastStats = stats;
|
||||
}
|
||||
|
||||
// make sure we don't div0 if this method somehow gets called twice in
|
||||
// the same millisecond
|
||||
sinceLast = Math.max(sinceLast, 1L);
|
||||
|
||||
report.append("* presents.net.ConnectionManager:\n");
|
||||
report.append("- Network connections: ");
|
||||
report.append(stats.connectionCount).append(" connections, ");
|
||||
report.append(stats.handlerCount).append(" handlers\n");
|
||||
report.append("- Network activity: ");
|
||||
report.append(eventCount).append(" events, ");
|
||||
report.append(connects).append(" connects, ");
|
||||
report.append(disconnects).append(" disconnects, ");
|
||||
report.append(closes).append(" closes\n");
|
||||
report.append("- Network input: ");
|
||||
report.append(bytesIn).append(" bytes, ");
|
||||
report.append(msgsIn).append(" msgs, ");
|
||||
report.append(msgsIn*1000/sinceLast).append(" mps, ");
|
||||
long avgIn = (msgsIn == 0) ? 0 : (bytesIn/msgsIn);
|
||||
report.append(avgIn).append(" avg size, ");
|
||||
report.append(bytesIn*1000/sinceLast).append(" bps\n");
|
||||
report.append("- Network output: ");
|
||||
report.append(bytesOut).append(" bytes, ");
|
||||
report.append(msgsOut).append(" msgs, ");
|
||||
report.append(msgsOut*1000/sinceLast).append(" mps, ");
|
||||
long avgOut = (msgsOut == 0) ? 0 : (bytesOut/msgsOut);
|
||||
report.append(avgOut).append(" avg size, ");
|
||||
report.append(bytesOut*1000/sinceLast).append(" bps\n");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -485,6 +533,9 @@ public class PresentsConnectionManager extends ConnectionManager
|
||||
@Inject protected ClientManager _clmgr;
|
||||
@Inject protected PresentsDObjectMgr _omgr;
|
||||
|
||||
/** A snapshot of our runtime stats as of our last report. */
|
||||
protected PresentsConMgrStats _lastStats = new PresentsConMgrStats();
|
||||
|
||||
protected Queue<Tuple<PresentsConnection, byte[]>> _dataq = Queue.newQueue();
|
||||
protected ByteBuffer _databuf = ByteBuffer.allocateDirect(Client.MAX_DATAGRAM_SIZE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user