summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/Replica4pkg/RemoteServer.java
blob: 6bc74114aadc5367181d5e028192ee9dd20dadac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//RemoteServer.java
package derms.Replica4pkg;

import javax.xml.ws.Endpoint;
import java.util.*;

public class RemoteServer {
    private static List<Endpoint> endpoints = new ArrayList<>();
    
        public static void main(String[] args) {
            try {
                Map<String, Integer> UDPPorts = new HashMap<>();
                UDPPorts.put("MTL", 4000);
                UDPPorts.put("QUE", 5000);
                UDPPorts.put("SHE", 6000);
    
                String[] serverNames = {"MTL", "QUE", "SHE"};
                int i = 0;
                for (String serverName : serverNames) {
                    int UDPPort = UDPPorts.get(serverName);
                    Server server = new Server();
                    server.initServer(serverName, UDPPort, UDPPorts);
                    int port = 8080 + i;
                    String url = "http://localhost:" + port + "/DERMS/" + serverName;
                    Endpoint endpoint = Endpoint.publish(url, server);
                    endpoints.add(endpoint);  // Keep track of the Endpoint
                i++;
                System.out.println(serverName + " Server ready and waiting ...");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // Method to stop all servers
    public void stopServers() {
        for (Endpoint endpoint : endpoints) {
            endpoint.stop();
        }
        System.out.println("All servers have been stopped.");
    }
}