Add: Added Coverage Screenshots And htlmReport.

This commit is contained in:
GabrieleRadice
2026-06-19 21:50:38 +02:00
parent 6aca188aa3
commit d78b8bbd93
316 changed files with 86329 additions and 0 deletions
@@ -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">&nbsp;package it.polimi.ingsw.gc14.Network.RMI.Server;
&nbsp;
&nbsp;import it.polimi.ingsw.gc14.LimitedMap;
&nbsp;import it.polimi.ingsw.gc14.Network.NetworkEvent;
&nbsp;import it.polimi.ingsw.gc14.Network.NetworkConfig;
&nbsp;import it.polimi.ingsw.gc14.Network.NetworkEvents.DisconnectedPlayer;
&nbsp;import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
&nbsp;
&nbsp;import java.util.Map;
&nbsp;import java.util.concurrent.*;
&nbsp;
&nbsp;/**
&nbsp; * Server-side heartbeat watchdog for a single RMI client.
&nbsp; *
&nbsp; * &lt;p&gt;Mirrors {@code HeartbeatHandler} used in the TCP stack, but adapted for RMI:
&nbsp; * instead of reading raw bytes from a dedicated socket, it relies on {@link #receivePing()}
&nbsp; * being called by {@link RMIServer#ping(String)} every time the client sends a ping.
&nbsp; *
&nbsp; * &lt;p&gt;If no ping is received within {@value NetworkConfig#SILENCE_THRESHOLD_MS} ms, the player is
&nbsp; * considered disconnected and {@link #disconnect()} is invoked, which:
&nbsp; * &lt;ul&gt;
&nbsp; * &lt;li&gt;stops the watchdog;&lt;/li&gt;
&nbsp; * &lt;li&gt;marks the player as offline in {@code playerList};&lt;/li&gt;
&nbsp; * &lt;li&gt;removes the callback from {@code clients};&lt;/li&gt;
&nbsp; * &lt;li&gt;adds a {@link DisconnectedPlayer} event to the action queue.&lt;/li&gt;
&nbsp; * &lt;/ul&gt;
&nbsp; */
&nbsp;public class RMIHeartbeat {
&nbsp;
<b class="nc">&nbsp; private String username = &quot;&quot;;</b>
&nbsp; private final LimitedMap&lt;String, Boolean&gt; playerList;
&nbsp; private final Map&lt;String, IClientCallback&gt; clients;
&nbsp; private final BlockingQueue&lt;NetworkEvent&gt; actionQueue;
&nbsp;
&nbsp; /** Last time a ping was received from this client. */
<b class="nc">&nbsp; private volatile long lastPingTime = System.currentTimeMillis();</b>
<b class="nc">&nbsp; private volatile boolean running = true;</b>
&nbsp;
<b class="nc">&nbsp; private final ScheduledExecutorService watchdog =</b>
<b class="nc">&nbsp; Executors.newSingleThreadScheduledExecutor(r -&gt; {</b>
<b class="nc">&nbsp; Thread t = new Thread(r, &quot;rmi-watchdog-&quot; + username);</b>
<b class="nc">&nbsp; t.setDaemon(true);</b>
<b class="nc">&nbsp; return t;</b>
&nbsp; });
&nbsp;
&nbsp; /**
&nbsp; * Constructs an RMI heartbeat handler for the specified client.
&nbsp; *
&nbsp; * @param username the username of the client monitored by the heartbeat.
&nbsp; * @param playerList the map storing the connection status of the players.
&nbsp; * @param clients the collection of currently registered RMI clients.
&nbsp; * @param actionQueue the queue containing network events to be processed.
&nbsp; */
&nbsp; public RMIHeartbeat(
&nbsp; String username,
&nbsp; LimitedMap&lt;String, Boolean&gt; playerList,
&nbsp; Map&lt;String, IClientCallback&gt; clients,
<b class="nc">&nbsp; BlockingQueue&lt;NetworkEvent&gt; actionQueue) {</b>
&nbsp;
<b class="nc">&nbsp; this.username = username;</b>
<b class="nc">&nbsp; this.playerList = playerList;</b>
<b class="nc">&nbsp; this.clients = clients;</b>
<b class="nc">&nbsp; this.actionQueue = actionQueue;</b>
&nbsp; }
&nbsp;
&nbsp; /** Called by {@link RMIServer} whenever it starts tracking this player. */
&nbsp; public void start() {
<b class="nc">&nbsp; watchdog.scheduleAtFixedRate(() -&gt; {</b>
<b class="nc">&nbsp; if (System.currentTimeMillis() - lastPingTime &gt; NetworkConfig.SILENCE_THRESHOLD_MS) {</b>
<b class="nc">&nbsp; System.out.println(&quot;RMI heartbeat timeout: &quot; + username);</b>
<b class="nc">&nbsp; disconnect();</b>
&nbsp; }
&nbsp; }, 1, 1, TimeUnit.SECONDS);
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Called by {@link RMIServer#ping(String)} each time the client pings.
&nbsp; * Resets the silence timer — mirrors writing {@code lastReceivedTime} in
&nbsp; * {@code HeartbeatHandler}.
&nbsp; */
&nbsp; public void receivePing() {
<b class="nc">&nbsp; lastPingTime = System.currentTimeMillis();</b>
&nbsp; }
&nbsp;
&nbsp; /**
&nbsp; * Disconnects the monitored RMI client.
&nbsp; *
&nbsp; * &lt;p&gt;The heartbeat handler is stopped, the player is marked as offline,
&nbsp; * the associated RMI callback is removed, and a disconnection event is
&nbsp; * added to the action queue for server-side processing.
&nbsp; */
&nbsp; public void disconnect() {
<b class="nc">&nbsp; if (!running) return;</b>
<b class="nc">&nbsp; running = false;</b>
<b class="nc">&nbsp; watchdog.shutdownNow();</b>
&nbsp;
<b class="nc">&nbsp; playerList.put(username, false);</b>
&nbsp;
<b class="nc">&nbsp; clients.remove(username);</b>
<b class="nc">&nbsp; actionQueue.add(new DisconnectedPlayer(username));</b>
<b class="nc">&nbsp; System.out.println(&quot;RMI disconnected: &quot; + username);</b>
&nbsp; }
&nbsp;}
</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>