diff --git a/webui/src/main/java/com/muwire/webui/ConnectionCounter.java b/webui/src/main/java/com/muwire/webui/ConnectionCounter.java new file mode 100644 index 00000000..de9eb8f0 --- /dev/null +++ b/webui/src/main/java/com/muwire/webui/ConnectionCounter.java @@ -0,0 +1,24 @@ +package com.muwire.webui; + +import com.muwire.core.connection.ConnectionAttemptStatus; +import com.muwire.core.connection.ConnectionEvent; +import com.muwire.core.connection.DisconnectionEvent; + +public class ConnectionCounter { + + private volatile int connections; + + public int getConnections() { + return connections; + } + + public void onConnectionEvent(ConnectionEvent e) { + if (e.getStatus() == ConnectionAttemptStatus.SUCCESSFUL) + connections++; + } + + public void onDisconnectionEvent(DisconnectionEvent e) { + connections--; + } + +} diff --git a/webui/src/main/java/com/muwire/webui/MuWireClient.java b/webui/src/main/java/com/muwire/webui/MuWireClient.java index fa6a2a07..af85307f 100644 --- a/webui/src/main/java/com/muwire/webui/MuWireClient.java +++ b/webui/src/main/java/com/muwire/webui/MuWireClient.java @@ -18,6 +18,8 @@ import javax.servlet.ServletContext; import com.muwire.core.Core; import com.muwire.core.MuWireSettings; +import com.muwire.core.connection.ConnectionEvent; +import com.muwire.core.connection.DisconnectionEvent; import com.muwire.core.download.DownloadStartedEvent; import com.muwire.core.search.UIResultBatchEvent; @@ -116,8 +118,13 @@ public class MuWireClient { DownloadManager downloadManager = new DownloadManager(core); core.getEventBus().register(DownloadStartedEvent.class, downloadManager); + ConnectionCounter connectionCounter = new ConnectionCounter(); + core.getEventBus().register(ConnectionEvent.class, connectionCounter); + core.getEventBus().register(DisconnectionEvent.class, connectionCounter); + servletContext.setAttribute("searchManager", searchManager); servletContext.setAttribute("downloadManager", downloadManager); + servletContext.setAttribute("connectionCounter", connectionCounter); } public String getHome() { diff --git a/webui/src/main/webapp/Downloads.jsp b/webui/src/main/webapp/Downloads.jsp index 5890de9c..f1fa482d 100644 --- a/webui/src/main/webapp/Downloads.jsp +++ b/webui/src/main/webapp/Downloads.jsp @@ -11,6 +11,7 @@ <% MuWireClient client = (MuWireClient) session.getAttribute("mwClient"); + ConnectionCounter connectionCounter = (ConnectionCounter) client.getServletContext().getAttribute("connectionCounter"); %>
@@ -18,8 +19,24 @@ -Welcome to MuWire ${persona}
- +| + Welcome to MuWire ${persona} + | ++ Connections <%= connectionCounter.getConnections() %> + | +
| + Search + | +
Downloads:
diff --git a/webui/src/main/webapp/Home.jsp b/webui/src/main/webapp/Home.jsp index 5ff8febd..91e14866 100644 --- a/webui/src/main/webapp/Home.jsp +++ b/webui/src/main/webapp/Home.jsp @@ -11,6 +11,8 @@ <% MuWireClient client = (MuWireClient) session.getAttribute("mwClient"); + ConnectionCounter connectionCounter = (ConnectionCounter) client.getServletContext().getAttribute("connectionCounter"); + String persona = client.getCore().getMe().getHumanReadableName(); String version = client.getCore().getVersion(); @@ -24,12 +26,31 @@ -Welcome to MuWire ${persona}
+| + Welcome to MuWire ${persona} + | ++ Connections <%= connectionCounter.getConnections() %> + | +
| - + | ++ Downloads + | +