Issue #443 better logging of traffic

Change-Id: Ia968b79a9d6ee1e5224678ac63684fb9c7aa5b81

Former-commit-id: a4b0addeee [formerly a4b0addeee [formerly 4a7faa743900edada4ecf8b42aa3315515617e71]]
Former-commit-id: 39ebbc3913
Former-commit-id: 8130c22b64
This commit is contained in:
Nate Jensen 2012-04-23 11:23:22 -05:00
parent 160a359b30
commit 776ef738f7
17 changed files with 155 additions and 108 deletions

View file

@ -683,16 +683,8 @@ public class CollaborationDataManager implements IRosterEventSubscriber {
@Subscribe
public void handleModifiedPresence(IRosterEntry entry) {
final IRosterEntry rosterEntry = entry;
System.out.println("CollaborationDataManager.handleModifiedPresence: "
+ rosterEntry.getUser().getFQName() + " mode "
+ rosterEntry.getPresence().getMode() + "/"
+ rosterEntry.getPresence().getType() + ": \""
+ rosterEntry.getPresence().getStatusMessage() + "\" groups "
+ rosterEntry.getGroups());
String userId = CollaborationUtils.makeUserId(rosterEntry);
DataUser user = usersMap.get(userId);
System.out.println("\tuserId: " + userId + " DataUser: " + user);
System.out.println(usersMap.keySet());
if (user != null) {
user.setPresence(rosterEntry.getPresence());
// Assumes only UI updates will be registered.

View file

@ -232,10 +232,6 @@ public class SessionView extends AbstractSessionView {
@Subscribe
public void handleModifiedPresence(IRosterEntry rosterEntry) {
System.out.println("session view roster entry for:"
+ rosterEntry.getUser().getFQName() + " "
+ rosterEntry.getPresence().getMode() + "/"
+ rosterEntry.getPresence().getType());
usersTable.refresh();
}
@ -615,7 +611,6 @@ public class SessionView extends AbstractSessionView {
@Subscribe
public void participantHandler(IVenueParticipantEvent event)
throws Exception {
System.out.println("++ ParticipantHander type " + event.getEventType());
final ParticipantEventType type = event.getEventType();
final UserId participant = event.getParticipant();
final IPresence presence = event.getPresence();
@ -634,9 +629,7 @@ public class SessionView extends AbstractSessionView {
participantPresenceUpdated(participant, presence);
break;
case UPDATED:
System.out.println("---- handle update here: "
+ participant.getName() + ", "
+ participant.getFQName());
// TODO ?
break;
default:
System.err.println("Unknown Event type");
@ -664,8 +657,6 @@ public class SessionView extends AbstractSessionView {
@SuppressWarnings("unchecked")
private void participantDeparted(UserId participant) {
System.out.println("++++ handle departed here: "
+ participant.getName() + ", " + participant.getFQName());
String userId = CollaborationUtils.makeUserId(participant);
List<CollaborationUser> users = (List<CollaborationUser>) usersTable
.getInput();
@ -692,7 +683,5 @@ public class SessionView extends AbstractSessionView {
.getInput();
String name = participant.getFQName();
String userId = CollaborationUtils.makeUserId(participant);
System.out.println("++++ handle presence's role updated here name: "
+ name + ", userId: " + userId);
}
}

View file

@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.core.runtime,
com.raytheon.uf.common.serialization;bundle-version="1.12.1174",
com.raytheon.uf.viz.core;bundle-version="1.12.1174",
org.jivesoftware.smack;bundle-version="3.1.100",
org.eclipse.swt;bundle-version="3.6.1"
org.eclipse.swt;bundle-version="3.6.1",
com.raytheon.uf.common.comm
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: com.raytheon.uf.viz.collaboration,

View file

@ -22,6 +22,9 @@ package com.raytheon.uf.viz.collaboration;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import com.raytheon.uf.common.comm.NetworkStatistics;
import com.raytheon.uf.viz.core.jobs.StatsJob;
/**
* TODO Add Description
*
@ -40,9 +43,20 @@ import org.osgi.framework.BundleContext;
*/
public class Activator implements BundleActivator {
private static BundleContext context;
public static final String PEER_TO_PEER = "PeerToPeerMsg";
static BundleContext getContext() {
public static final String VENUE = "VenueMsg";
private static Activator plugin;
private BundleContext context;
private NetworkStatistics networkStats = new NetworkStatistics();
private StatsJob statsJob = new StatsJob("XMPP Network Statistics",
networkStats);
public BundleContext getContext() {
return context;
}
@ -50,14 +64,26 @@ public class Activator implements BundleActivator {
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
this.context = bundleContext;
plugin = this;
statsJob.schedule();
}
/**
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
plugin = null;
context = null;
statsJob.shutdown();
}
public NetworkStatistics getNetworkStats() {
return networkStats;
}
public static Activator getDefault() {
return plugin;
}
}

View file

@ -62,10 +62,6 @@ import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
public abstract class Tools {
public static final String PROP_DATA_PROVIDER = "DATA_PROVIDER";
public static final String PROP_SESSION_LEADER = "SESSION_LEADER";
public static final String TAG_INVITE = "[[INVITEID#";
public static final String TAG_INVITE_ID = TAG_INVITE + "%s]]%s";
@ -107,8 +103,10 @@ public abstract class Tools {
public static CompressionType COMPRESSION_TYPE = CompressionType.ZLIB;
private static boolean log_compression = false;
private enum CompressionType {
ZLIB, GZIP, SNAPPY;
ZLIB, GZIP;
public byte toByte() {
return (byte) ordinal();
@ -430,7 +428,8 @@ public abstract class Tools {
break;
}
case NONE: {
break;
throw new CollaborationException("Serialization of "
+ data.getClass().getName() + " not supported");
}
case ISNULL: {
break;
@ -524,10 +523,12 @@ public abstract class Tools {
compressionStrm.flush();
compressionStrm.close();
byte[] result = out.toByteArray();
System.out.println(cType + " Compression time(milliseconds) "
+ (System.currentTimeMillis() - start) / 1000F
+ " to compress " + bytes.length + " bytes to "
+ result.length + " bytes.");
if (log_compression) {
System.out.println(cType + " Compression time(milliseconds) "
+ (System.currentTimeMillis() - start) / 1000F
+ " to compress " + bytes.length + " bytes to "
+ result.length + " bytes.");
}
return result;
} catch (IOException e) {
throw new CollaborationException("Unable to compress data.", e);
@ -536,13 +537,17 @@ public abstract class Tools {
private static OutputStream createCompressionOutputStream(OutputStream out)
throws IOException {
OutputStream stream = null;
switch (COMPRESSION_TYPE) {
case GZIP:
return new GZIPOutputStream(out);
stream = new GZIPOutputStream(out);
break;
case ZLIB:
default:
return new DeflaterOutputStream(out);
stream = new DeflaterOutputStream(out);
break;
}
return stream;
}
private static byte[] uncompress(byte[] bytes)
@ -574,10 +579,13 @@ public abstract class Tools {
}
dest.close();
byte[] resultBuffer = out.toByteArray();
System.out.println(cType + " Uncompression time(milliseconds): "
+ ((System.currentTimeMillis() - start) / 1000F)
+ " to uncompress " + bytes.length + " bytes to "
+ resultBuffer.length + " bytes.");
if (log_compression) {
System.out.println(cType
+ " Uncompression time(milliseconds): "
+ ((System.currentTimeMillis() - start) / 1000F)
+ " to uncompress " + bytes.length + " bytes to "
+ resultBuffer.length + " bytes.");
}
return resultBuffer;
} catch (IOException e) {
throw new CollaborationException("Unable to uncompress data.", e);
@ -586,13 +594,17 @@ public abstract class Tools {
private static InputStream createCompressionInputStream(
CompressionType cType, InputStream in) throws IOException {
InputStream stream = null;
switch (cType) {
case GZIP:
return new GZIPInputStream(in);
stream = new GZIPInputStream(in);
break;
case ZLIB:
default:
return new InflaterInputStream(in);
stream = new InflaterInputStream(in);
break;
}
return stream;
}
}

View file

@ -203,8 +203,8 @@ public class CollaborationConnection implements IEventPublisher {
eventBus.register(rosterEventSubscriber);
}
// Debug -- event viewer ----------------
rosterEventHandler = new RosterEventHandler();
eventBus.register(rosterEventHandler);
// rosterEventHandler = new RosterEventHandler();
// eventBus.register(rosterEventHandler);
// Debug -- event viewer ----------------
sessions = new HashMap<String, ISession>();
@ -217,10 +217,9 @@ public class CollaborationConnection implements IEventPublisher {
@Override
public void handleEvent(IContainerEvent event) {
// TODO?
System.out.println("ContainerEvent.Type = "
+ event.getClass().getName());
}
});
}

View file

@ -30,6 +30,7 @@ import org.eclipse.ecf.presence.im.IChatMessage;
import org.eclipse.ecf.presence.im.IChatMessageSender;
import com.google.common.eventbus.EventBus;
import com.raytheon.uf.viz.collaboration.Activator;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
import com.raytheon.uf.viz.collaboration.comm.identity.IPeerToPeer;
@ -93,6 +94,11 @@ public class PeerToPeerChat extends BaseSession implements IPeerToPeer {
}
}
try {
Activator
.getDefault()
.getNetworkStats()
.log(Activator.PEER_TO_PEER,
message.getBody().length(), 0);
chatSender.sendChatMessage(toID, null, IChatMessage.Type.CHAT,
subject, body, props);
} catch (ECFException e) {

View file

@ -26,6 +26,10 @@ import org.eclipse.ecf.presence.IIMMessageListener;
import org.eclipse.ecf.presence.im.IChatMessage;
import org.eclipse.ecf.presence.im.IChatMessageEvent;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.collaboration.Activator;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.ISession;
import com.raytheon.uf.viz.collaboration.comm.identity.event.ITextMessageEvent;
@ -54,6 +58,9 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
public class PeerToPeerCommHelper implements IIMMessageListener {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(PeerToPeerCommHelper.class);
private CollaborationConnection manager;
/**
@ -61,7 +68,7 @@ public class PeerToPeerCommHelper implements IIMMessageListener {
* @param manager
* @param presenceAdapter
*/
PeerToPeerCommHelper(CollaborationConnection manager) {
protected PeerToPeerCommHelper(CollaborationConnection manager) {
this.manager = manager;
}
@ -70,18 +77,16 @@ public class PeerToPeerCommHelper implements IIMMessageListener {
*/
@Override
public void handleMessageEvent(IIMMessageEvent messageEvent) {
if (messageEvent instanceof IChatMessageEvent) {
IChatMessageEvent event = (IChatMessageEvent) messageEvent;
System.out.println(" message event.body "
+ event.getChatMessage().getBody());
IChatMessage msg = event.getChatMessage();
String body = msg.getBody();
Activator.getDefault().getNetworkStats()
.log(Activator.PEER_TO_PEER, 0, body.length());
if (body != null) {
if (body.startsWith(Tools.CMD_PREAMBLE)) {
routeData(msg);
} else {
// anything else pass to the normal text
routeMessage(msg);
@ -99,7 +104,8 @@ public class PeerToPeerCommHelper implements IIMMessageListener {
try {
object = Tools.unMarshallData(message.getBody());
} catch (CollaborationException e) {
System.out.println("Error unmarshalling PeerToPeer data");
statusHandler.handle(Priority.PROBLEM,
"Error unmarshalling PeerToPeer data", e);
}
if (object != null) {
String sessionId = (String) message.getProperties().get(
@ -112,8 +118,8 @@ public class PeerToPeerCommHelper implements IIMMessageListener {
if (session != null) {
session.getEventPublisher().post(object);
} else {
System.out.println("ERROR: Unknown sessionid [" + sessionId
+ "]");
statusHandler.handle(Priority.PROBLEM,
"ERROR: Unknown sessionid [" + sessionId + "]");
}
}
manager.getEventPublisher().post(object);

View file

@ -82,10 +82,8 @@ public class SharedDisplaySession extends VenueSession implements
if (session != null) {
String message = Tools.marshallData(obj);
if (message != null) {
TextMessage msg = new TextMessage(participant, message);
msg.setProperty(Tools.PROP_SESSION_ID, getSessionId());
session.sendPeerToPeer(msg);
}
}

View file

@ -43,6 +43,7 @@ import org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID;
import com.google.common.eventbus.EventBus;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.viz.collaboration.Activator;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
@ -284,6 +285,8 @@ public class VenueSession extends BaseSession implements IVenueSession {
throws CollaborationException {
// Assume success
if ((venueContainer != null) && (message != null)) {
Activator.getDefault().getNetworkStats()
.log(Activator.VENUE, message.length(), 0);
IChatRoomMessageSender sender = venueContainer
.getChatRoomMessageSender();
try {
@ -408,7 +411,11 @@ public class VenueSession extends BaseSession implements IVenueSession {
if (messageEvent instanceof IChatRoomMessageEvent) {
IChatRoomMessage m = ((IChatRoomMessageEvent) messageEvent)
.getChatRoomMessage();
Activator
.getDefault()
.getNetworkStats()
.log(Activator.VENUE, 0,
m.getMessage().length());
if (accept(m)) {
distributeMessage(convertMessage(m));
}

View file

@ -17,7 +17,7 @@
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.uf.viz.thinclient;
package com.raytheon.uf.viz.core.jobs;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@ -46,7 +46,7 @@ import com.raytheon.uf.common.comm.NetworkStatistics.NetworkTraffic;
public class StatsJob extends Job {
private NetworkStatistics stats = NetworkStatistics.getInstance();
private NetworkStatistics stats;
private long lastSent = 0, lastReceived = 0, lastRequestCount = 0;
@ -57,9 +57,10 @@ public class StatsJob extends Job {
/**
* @param name
*/
public StatsJob() {
super("Network Statistics Job");
public StatsJob(String name, NetworkStatistics stats) {
super(name);
setSystem(true);
this.stats = stats;
}
/*
@ -81,14 +82,14 @@ public class StatsJob extends Job {
- lastRequestCount;
System.out.println("Last minute sent " + requestCountInLastMinute
+ " http requests for a total of "
+ (sentInLastMinute / 1000) + " kB sent and "
+ (receivedInLastMinute / 1000) + " kB received");
+ " messages for a total of " + (sentInLastMinute / 1000)
+ " kB sent and " + (receivedInLastMinute / 1000)
+ " kB received");
lastSent = total.getBytesSent();
lastReceived = total.getBytesReceived();
lastRequestCount = total.getRequestCount();
System.out.println("Total sent " + total.getRequestCount()
+ " http requests for a total of " + (lastSent / 1000)
+ " messages for a total of " + (lastSent / 1000)
+ " kB sent and " + (lastReceived / 1000) + " kB received");
NetworkTraffic[] mapped = stats.getMappedTrafficStats();
for (NetworkTraffic nt : mapped) {

View file

@ -122,7 +122,8 @@ public class ThriftClient {
private static INotAuthHandler defaultHandler = UserController
.getNotAuthHandler();
private static NetworkStatistics stats = NetworkStatistics.getInstance();
private static NetworkStatistics stats = HttpClient.getInstance()
.getStats();
/**
* Construct a thrift web service object that sends method calls to the http

View file

@ -13,6 +13,7 @@ Require-Bundle: com.raytheon.uf.viz.core,
com.raytheon.uf.viz.product.alertviz;bundle-version="1.12.1174",
com.raytheon.uf.viz.alertviz.ui;bundle-version="1.12.1174",
com.raytheon.uf.viz.alertviz;bundle-version="1.12.1174",
com.raytheon.uf.common.message;bundle-version="1.12.1174"
com.raytheon.uf.common.message;bundle-version="1.12.1174",
com.raytheon.uf.common.comm
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy

View file

@ -26,11 +26,12 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import com.raytheon.uf.common.comm.HttpClient;
import com.raytheon.uf.viz.alertviz.ui.dialogs.AlertVisualization;
import com.raytheon.uf.viz.core.jobs.StatsJob;
import com.raytheon.uf.viz.product.alertviz.AlertVizApplication;
import com.raytheon.uf.viz.thinclient.Activator;
import com.raytheon.uf.viz.thinclient.IThinClientComponent;
import com.raytheon.uf.viz.thinclient.StatsJob;
import com.raytheon.uf.viz.thinclient.ThinClientNotificationManagerJob;
import com.raytheon.uf.viz.thinclient.cache.ThinClientCacheManager;
import com.raytheon.uf.viz.thinclient.localization.LocalizationCachePersistence;
@ -63,9 +64,10 @@ public class ThinAlertVizComponent extends AlertVizApplication implements
@Override
public Object startComponent(String componentName) throws Exception {
Activator.getDefault().setComponent(this);
// Start network statistics
statsJob = new StatsJob();
Activator.getDefault().setComponent(this);
// Start network statistics
statsJob = new StatsJob("HTTP Network Statistics", HttpClient
.getInstance().getStats());
statsJob.schedule();
return super.startComponent(componentName);
}
@ -94,30 +96,30 @@ public class ThinAlertVizComponent extends AlertVizApplication implements
}
protected AlertVisualization createAlertVisualization(
boolean runningStandalone, final Display display) {
return new AlertVisualization(runningStandalone, display) {
boolean runningStandalone, final Display display) {
return new AlertVisualization(runningStandalone, display) {
@Override
protected void createTrayMenuItems() {
super.createTrayMenuItems();
if (!runningStandalone) {
new MenuItem(trayItemMenu, SWT.SEPARATOR);
}
MenuItem exitMI = new MenuItem(trayItemMenu, SWT.NONE);
exitMI.setText("Exit...");
exitMI.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION
| SWT.YES | SWT.NO);
mb.setText("Confirm Exit");
mb.setMessage("Any unsaved changes will be lost.\n Are you sure you want to exit?");
if (mb.open() == SWT.YES) {
display.dispose();
}
}
});
}
};
@Override
protected void createTrayMenuItems() {
super.createTrayMenuItems();
if (!runningStandalone) {
new MenuItem(trayItemMenu, SWT.SEPARATOR);
}
MenuItem exitMI = new MenuItem(trayItemMenu, SWT.NONE);
exitMI.setText("Exit...");
exitMI.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION
| SWT.YES | SWT.NO);
mb.setText("Confirm Exit");
mb.setMessage("Any unsaved changes will be lost.\n Are you sure you want to exit?");
if (mb.open() == SWT.YES) {
display.dispose();
}
}
});
}
};
}
}

View file

@ -31,16 +31,17 @@ import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.application.WorkbenchAdvisor;
import org.osgi.framework.Bundle;
import com.raytheon.uf.common.comm.HttpClient;
import com.raytheon.uf.common.datastorage.DataStoreFactory;
import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.jobs.StatsJob;
import com.raytheon.uf.viz.core.localization.BundleScanner;
import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.uf.viz.thinclient.Activator;
import com.raytheon.uf.viz.thinclient.IThinClientComponent;
import com.raytheon.uf.viz.thinclient.StatsJob;
import com.raytheon.uf.viz.thinclient.ThinClientNotificationManagerJob;
import com.raytheon.uf.viz.thinclient.cache.ThinClientCacheManager;
import com.raytheon.uf.viz.thinclient.cave.cache.CachingDataStoreFactory;
@ -106,7 +107,8 @@ public class ThinClientComponent extends CAVE implements IThinClientComponent {
ThinClientPreferenceConstants.P_MENU_TIME_REFRESH_INTERVAL));
// Start network statistics
statsJob = new StatsJob();
statsJob = new StatsJob("HTTP Network Statistics", HttpClient
.getInstance().getStats());
statsJob.schedule();
// Set ourselves as the activators component

View file

@ -89,7 +89,7 @@ public class HttpClient {
private ThreadSafeClientConnManager connManager = null;
private NetworkStatistics stats = NetworkStatistics.getInstance();
private NetworkStatistics stats = new NetworkStatistics();
private HttpClient() {
connManager = new ThreadSafeClientConnManager();
@ -633,6 +633,15 @@ public class HttpClient {
this.retryCount = retryCount;
}
/**
* Gets the network statistics for http traffic.
*
* @return
*/
public NetworkStatistics getStats() {
return stats;
}
/**
* Provides a safe interface callback for implementing stream behavior with
* http

View file

@ -109,7 +109,7 @@ public class NetworkStatistics {
String sentString = toString(bytesSent), receivedString = toString(bytesReceived);
return "Network Traffic Stats for '" + identifier + "' : "
+ requestCount + " requests, sent " + sentString
+ requestCount + " messages, sent " + sentString
+ ", received " + receivedString;
}
@ -134,17 +134,11 @@ public class NetworkStatistics {
}
}
private static final NetworkStatistics instance = new NetworkStatistics();
private NetworkTraffic totalTraffic = new NetworkTraffic(null);
private Map<String, NetworkTraffic> mappedTraffic = new LinkedHashMap<String, NetworkTraffic>();
public static NetworkStatistics getInstance() {
return instance;
}
private NetworkStatistics() {
public NetworkStatistics() {
}
@ -185,6 +179,7 @@ public class NetworkStatistics {
traffic.addBytesSent(bytesSent);
traffic.addBytesReceived(bytesReceived);
traffic.incrementRequestCount();
this.log(bytesSent, bytesReceived);
}
/**