Add: Added Coverage Screenshots And htlmReport.
This commit is contained in:
@@ -0,0 +1,380 @@
|
||||
|
||||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html id="htmlId">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||
<title>Coverage Report > RMIClient</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.Client</a>
|
||||
</div>
|
||||
|
||||
<h1>Coverage Summary for Class: RMIClient (it.polimi.ingsw.gc14.Network.RMI.Client)</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">RMIClient</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/15)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/12)
|
||||
</span>
|
||||
</td>
|
||||
<td class="coverageStat">
|
||||
<span class="percent">
|
||||
0%
|
||||
</span>
|
||||
<span class="absValue">
|
||||
(0/60)
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<pre>
|
||||
<code class="sourceCode" id="sourceCode"> package it.polimi.ingsw.gc14.Network.RMI.Client;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.ErrorType;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkConfig;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
|
||||
|
||||
/**
|
||||
* Client RMI. Uses the methods exposed by the server RMI.
|
||||
*/
|
||||
public class RMIClient implements IClient {
|
||||
|
||||
private final String host;
|
||||
private final int port;
|
||||
private IGameServer stub;
|
||||
private ClientController controller;
|
||||
private String myIp;
|
||||
private String username;
|
||||
|
||||
<b class="nc"> private volatile boolean running = false;</b>
|
||||
|
||||
/** Scheduler that fires ping() every {@value NetworkConfig#KEEPALIVE_INTERVAL_MS} ms. */
|
||||
private ScheduledExecutorService pingSender;
|
||||
private ExecutorService executor;
|
||||
|
||||
/**
|
||||
* Constructs an RMI client and initializes its connection parameters.
|
||||
*
|
||||
* @param controller the client controller associated with this RMI client.
|
||||
* @param host the hostname or IP address of the RMI server.
|
||||
* @param port the port used to connect to the RMI registry.
|
||||
* @param myIp the IP address of the client.
|
||||
*/
|
||||
<b class="nc"> public RMIClient(ClientController controller, String host, int port, String myIp) {</b>
|
||||
<b class="nc"> this.controller = controller;</b>
|
||||
<b class="nc"> this.host = host;</b>
|
||||
<b class="nc"> this.port = port;</b>
|
||||
<b class="nc"> this.myIp = myIp;</b>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Connects to the RMI server and starts the heartbeat loop.
|
||||
*
|
||||
* <p>Mirrors {@code TCPClient.connect()}: after a successful join the
|
||||
* heartbeat channel is opened (here: a scheduler is started instead of
|
||||
* opening a second socket).
|
||||
*/
|
||||
@Override
|
||||
public ErrorType connect(String username, int proposedNPlayers) {
|
||||
try {
|
||||
<b class="nc"> System.setProperty("java.rmi.server.hostname", this.myIp);</b>
|
||||
<b class="nc"> Registry registry = LocateRegistry.getRegistry(host, port);</b>
|
||||
<b class="nc"> this.stub = (IGameServer) registry.lookup("RMIGameServer");</b>
|
||||
<b class="nc"> this.username = username;</b>
|
||||
|
||||
<b class="nc"> ClientCallbackImpl callback = new ClientCallbackImpl(controller);</b>
|
||||
<b class="nc"> ErrorType status = stub.joinGame(username, proposedNPlayers, callback);</b>
|
||||
<b class="nc"> if(status==null)</b>
|
||||
{
|
||||
<b class="nc"> running = true;</b>
|
||||
<b class="nc"> startHeartbeat();</b>
|
||||
<b class="nc"> return null;</b>
|
||||
}
|
||||
<b class="nc"> return status;</b>
|
||||
} catch (Exception e) {
|
||||
<b class="nc"> e.printStackTrace();</b>
|
||||
<b class="nc"> return ErrorType.GENERIC_ERROR;</b>
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Heartbeat — mirrors TCPClient.heartbeatLoop()
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Starts sending periodic pings to the server.
|
||||
*
|
||||
* <p>Mirrors the {@code ScheduledExecutorService} in
|
||||
* {@code TCPClient.heartbeatLoop()} that writes {@code PING} every 3 s.
|
||||
* On {@link RemoteException} the server is considered gone and
|
||||
* {@link #disconnect()} is called — mirrors the behaviour on
|
||||
* {@code SocketTimeoutException} / {@code IOException} in the TCP version.
|
||||
*/
|
||||
private void startHeartbeat() {
|
||||
<b class="nc"> pingSender = Executors.newSingleThreadScheduledExecutor(r -> {</b>
|
||||
<b class="nc"> Thread t = new Thread(r, "rmi-heartbeat");</b>
|
||||
<b class="nc"> t.setDaemon(true);</b>
|
||||
<b class="nc"> return t;</b>
|
||||
});
|
||||
|
||||
<b class="nc"> executor = Executors.newSingleThreadExecutor();</b>
|
||||
<b class="nc"> pingSender.scheduleAtFixedRate(() -> {</b>
|
||||
<b class="nc"> Future<?> future = executor.submit(() -> {</b>
|
||||
try {
|
||||
<b class="nc"> stub.ping(username);</b>
|
||||
} catch (RemoteException e) {
|
||||
<b class="nc"> disconnect();</b>
|
||||
<b class="nc"> controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());</b>
|
||||
}
|
||||
});
|
||||
try {
|
||||
<b class="nc"> future.get(NetworkConfig.SILENCE_THRESHOLD_MS, TimeUnit.MILLISECONDS);</b>
|
||||
} catch (TimeoutException e) {
|
||||
<b class="nc"> future.cancel(true);</b>
|
||||
<b class="nc"> controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());</b>
|
||||
<b class="nc"> disconnect();</b>
|
||||
} catch (Exception e) {
|
||||
<b class="nc"> disconnect();</b>
|
||||
<b class="nc"> controller.getView().showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());</b>
|
||||
}
|
||||
}, 0, NetworkConfig.KEEPALIVE_INTERVAL_MS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the connection.
|
||||
* Mirrors {@code TCPClient.disconnect()}: stops the heartbeat and notifies
|
||||
* the view.
|
||||
*/
|
||||
private void disconnect() {
|
||||
<b class="nc"> if (!running) return;</b>
|
||||
<b class="nc"> running = false;</b>
|
||||
<b class="nc"> if (pingSender != null) pingSender.shutdownNow();</b>
|
||||
<b class="nc"> if (executor != null) executor.shutdownNow();</b>
|
||||
<b class="nc"> controller.setModel(null);</b>
|
||||
<b class="nc"> controller.setClient(null);</b>
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Requests to draw a tribe card from the upper list.
|
||||
* Creates a NetworkEvent and sends it through the network client.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public void drawUpperTribeCard(String playerUsername, int pos) {
|
||||
try{
|
||||
<b class="nc"> stub.drawUpperTribeCard(playerUsername,pos);</b>
|
||||
}
|
||||
catch (RemoteException e){
|
||||
<b class="nc"> System.out.println("Error during remote draw upper tribe card");</b>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests to draw a tribe card from the lower list.
|
||||
* Creates a NetworkEvent and sends it through the network client.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public void drawLowerTribeCard(String playerUsername,int pos) {
|
||||
try{
|
||||
<b class="nc"> stub.drawLowerTribeCard(playerUsername,pos);</b>
|
||||
}
|
||||
catch (RemoteException e){
|
||||
<b class="nc"> System.out.println("Error during remote draw lower tribe card");</b>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests to draw a building card from the upper list.
|
||||
* Creates a NetworkEvent and sends it through the network client.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public void drawUpperBuildingCard(String playerUsername,int pos) {
|
||||
try{
|
||||
<b class="nc"> stub.drawUpperBuildingCard(playerUsername,pos);</b>
|
||||
}
|
||||
catch (RemoteException e){
|
||||
<b class="nc"> System.out.println("Error during remote draw upper building card");</b>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests to draw a building card from the lower list.
|
||||
* Creates a NetworkEvent and sends it through the network client.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public void drawLowerBuildingCard(String playerUsername,int pos) {
|
||||
try{
|
||||
<b class="nc"> stub.drawLowerBuildingCard(playerUsername,pos);</b>
|
||||
}
|
||||
catch (RemoteException e){
|
||||
<b class="nc"> System.out.println("Error during remote draw lower building card");</b>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Requests to skip the turn.
|
||||
* This action is available only when the player cannot draw any tribe card, but still can buy some buildings.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
*/
|
||||
public void skipTurn(String playerUsername) {
|
||||
try{
|
||||
<b class="nc"> stub.skipTurn(playerUsername);</b>
|
||||
}
|
||||
catch (RemoteException e){
|
||||
<b class="nc"> System.out.println("Error during remote skip turn");</b>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Used to perform the slot choice action for the specified player at the specified position.
|
||||
* @param playerUsername the name of the player performing the action
|
||||
* @param pos the index of the selected slot
|
||||
*/
|
||||
public void slotChoice(String playerUsername,int pos) {
|
||||
try{
|
||||
<b class="nc"> stub.slotChoice(playerUsername,pos);</b>
|
||||
}
|
||||
catch (RemoteException e){
|
||||
<b class="nc"> System.out.println("Error during remote slot choice");</b>
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sends a totem choice to the server for the specified player via RMI.
|
||||
*
|
||||
* @param playerUsername the username of the player choosing the totem.
|
||||
* @param totem the name of the chosen totem.
|
||||
*/
|
||||
public void totemChoice(String playerUsername,String totem) {
|
||||
try{
|
||||
<b class="nc"> stub.totemChoice(playerUsername,totem);</b>
|
||||
}
|
||||
catch (RemoteException e){
|
||||
<b class="nc"> System.out.println("Error during remote totem choice");</b>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies the server of a voluntary disconnection via RMI, then stops
|
||||
* the keep-alive scheduler.
|
||||
*/
|
||||
public void notifyDisconnection() {
|
||||
<b class="nc"> running = false;</b>
|
||||
<b class="nc"> if (pingSender != null) pingSender.shutdownNow();</b>
|
||||
<b class="nc"> if (executor != null) executor.shutdownNow();</b>
|
||||
try {
|
||||
<b class="nc"> stub.disconnectPlayer(username);</b>
|
||||
} catch (RemoteException e) {
|
||||
<b class="nc"> System.out.println("Error during remote disconnection");</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