show number of connections

pull/34/head
Zlatin Balevsky 2019-12-01 02:51:00 +00:00
parent 95dd5c4a7c
commit 3871170e44
4 changed files with 73 additions and 4 deletions

View File

@ -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--;
}
}

View File

@ -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() {

View File

@ -11,6 +11,7 @@
<%
MuWireClient client = (MuWireClient) session.getAttribute("mwClient");
ConnectionCounter connectionCounter = (ConnectionCounter) client.getServletContext().getAttribute("connectionCounter");
%>
<html>
<head>
@ -18,8 +19,24 @@
</head>
<body>
<p>Welcome to MuWire ${persona}</p>
<p><a href="/MuWire/Home.jsp">Back to search</a></p>
<table width="100%">
<tr>
<td>
Welcome to MuWire ${persona}
</td>
<td>
Connections <%= connectionCounter.getConnections() %>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td>
<a href="/MuWire/Home.jsp">Search</a>
</td>
</tr>
</table>
<hr/>
<p>Downloads:</p>

View File

@ -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 @@
</head>
<body>
<p>Welcome to MuWire ${persona}</p>
<table width="100%">
<tr>
<td>
Welcome to MuWire ${persona}
</td>
<td>
Connections <%= connectionCounter.getConnections() %>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td>
<form action="/MuWire/Search" method="post">
<input type="text", name="search" />
<input type="submit", value="Search" />
</form>
</td>
<td>
<a href="/MuWire/Downloads.jsp">Downloads</a>
</td>
</tr>
</table>
<hr/>
<%
SearchManager searchManager = (SearchManager) client.getServletContext().getAttribute("searchManager");