Add: Added Coverage Screenshots And htlmReport.
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html id="htmlId">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>Coverage Report > RMIHeartbeat</title>
|
||||
<style type="text/css">
|
||||
@import "../../css/coverage.css";
|
||||
@import "../../css/idea.min.css";
|
||||
</style>
|
||||
<script type="text/javascript" src="../../js/highlight.min.js"></script>
|
||||
<script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="content">
|
||||
<div class="breadCrumbs">
|
||||
Current scope: <a href="../../index.html">all classes</a>
|
||||
<span class="separator">|</span>
|
||||
<a href="../index.html">it.polimi.ingsw.gc14.Network.RMI.Server</a>
|
||||
</div>
|
||||
|
||||
<h1>Coverage Summary for Class: RMIHeartbeat (it.polimi.ingsw.gc14.Network.RMI.Server)</h1>
|
||||
|
||||
<table class="coverageStats">
|
||||
<tr>
|
||||
<th class="name">Class</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Class, %
|
||||
</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Method, %
|
||||
</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Branch, %
|
||||
</th>
|
||||
<th class="coverageStat
|
||||
">
|
||||
Line, %
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name">RMIHeartbeat</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/1)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/6)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/4)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/25)
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<pre>
|
||||
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Network.RMI.Server;
|
||||
|
||||
import it.polimi.ingsw.gc14.LimitedMap;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.DisconnectedPlayer;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
* Server-side heartbeat watchdog for a single RMI client.
|
||||
*
|
||||
* <p>Mirrors {@code HeartbeatHandler} used in the TCP stack, but adapted for RMI:
|
||||
* instead of reading raw bytes from a dedicated socket, it relies on {@link #receivePing()}
|
||||
* being called by {@link RMIServer#ping(String)} every time the client sends a ping.
|
||||
*
|
||||
* <p>If no ping is received within {@value NetworkConfig#SILENCE_THRESHOLD_MS} ms, the player is
|
||||
* considered disconnected and {@link #disconnect()} is invoked, which:
|
||||
* <ul>
|
||||
* <li>stops the watchdog;</li>
|
||||
* <li>marks the player as offline in {@code playerList};</li>
|
||||
* <li>removes the callback from {@code clients};</li>
|
||||
* <li>adds a {@link DisconnectedPlayer} event to the action queue.</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class RMIHeartbeat {
|
||||
|
||||
<b class="nc"> private String username = "";</b>
|
||||
private final LimitedMap<String, Boolean> playerList;
|
||||
private final Map<String, IClientCallback> clients;
|
||||
private final BlockingQueue<NetworkEvent> actionQueue;
|
||||
|
||||
/** Last time a ping was received from this client. */
|
||||
<b class="nc"> private volatile long lastPingTime = System.currentTimeMillis();</b>
|
||||
<b class="nc"> private volatile boolean running = true;</b>
|
||||
|
||||
<b class="nc"> private final ScheduledExecutorService watchdog =</b>
|
||||
<b class="nc"> Executors.newSingleThreadScheduledExecutor(r -> {</b>
|
||||
<b class="nc"> Thread t = new Thread(r, "rmi-watchdog-" + username);</b>
|
||||
<b class="nc"> t.setDaemon(true);</b>
|
||||
<b class="nc"> return t;</b>
|
||||
});
|
||||
|
||||
/**
|
||||
* Constructs an RMI heartbeat handler for the specified client.
|
||||
*
|
||||
* @param username the username of the client monitored by the heartbeat.
|
||||
* @param playerList the map storing the connection status of the players.
|
||||
* @param clients the collection of currently registered RMI clients.
|
||||
* @param actionQueue the queue containing network events to be processed.
|
||||
*/
|
||||
public RMIHeartbeat(
|
||||
String username,
|
||||
LimitedMap<String, Boolean> playerList,
|
||||
Map<String, IClientCallback> clients,
|
||||
<b class="nc"> BlockingQueue<NetworkEvent> actionQueue) {</b>
|
||||
|
||||
<b class="nc"> this.username = username;</b>
|
||||
<b class="nc"> this.playerList = playerList;</b>
|
||||
<b class="nc"> this.clients = clients;</b>
|
||||
<b class="nc"> this.actionQueue = actionQueue;</b>
|
||||
}
|
||||
|
||||
/** Called by {@link RMIServer} whenever it starts tracking this player. */
|
||||
public void start() {
|
||||
<b class="nc"> watchdog.scheduleAtFixedRate(() -> {</b>
|
||||
<b class="nc"> if (System.currentTimeMillis() - lastPingTime > NetworkConfig.SILENCE_THRESHOLD_MS) {</b>
|
||||
<b class="nc"> System.out.println("RMI heartbeat timeout: " + username);</b>
|
||||
<b class="nc"> disconnect();</b>
|
||||
}
|
||||
}, 1, 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link RMIServer#ping(String)} each time the client pings.
|
||||
* Resets the silence timer — mirrors writing {@code lastReceivedTime} in
|
||||
* {@code HeartbeatHandler}.
|
||||
*/
|
||||
public void receivePing() {
|
||||
<b class="nc"> lastPingTime = System.currentTimeMillis();</b>
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the monitored RMI client.
|
||||
*
|
||||
* <p>The heartbeat handler is stopped, the player is marked as offline,
|
||||
* the associated RMI callback is removed, and a disconnection event is
|
||||
* added to the action queue for server-side processing.
|
||||
*/
|
||||
public void disconnect() {
|
||||
<b class="nc"> if (!running) return;</b>
|
||||
<b class="nc"> running = false;</b>
|
||||
<b class="nc"> watchdog.shutdownNow();</b>
|
||||
|
||||
<b class="nc"> playerList.put(username, false);</b>
|
||||
|
||||
<b class="nc"> clients.remove(username);</b>
|
||||
<b class="nc"> actionQueue.add(new DisconnectedPlayer(username));</b>
|
||||
<b class="nc"> System.out.println("RMI disconnected: " + username);</b>
|
||||
}
|
||||
}
|
||||
</code>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var msie = false, msie9 = false;
|
||||
/*@cc_on
|
||||
msie = true;
|
||||
@if (@_jscript_version >= 9)
|
||||
msie9 = true;
|
||||
@end
|
||||
@*/
|
||||
|
||||
if (!msie || msie && msie9) {
|
||||
hljs.highlightAll()
|
||||
hljs.initLineNumbersOnLoad();
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
|
||||
<div class="footer">
|
||||
|
||||
<div style="float:right;">generated on 2026-06-14 21:53</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user