mirror of https://github.com/zlatinb/muwire
show number of connections
parent
95dd5c4a7c
commit
3871170e44
|
@ -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--;
|
||||
}
|
||||
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue