|
@@ -2,6 +2,7 @@ package com.uqac.rthoni.java_rmi.server;
|
2
|
2
|
|
3
|
3
|
import com.uqac.rthoni.java_rmi.server.executors.AbstractCommandExecutor;
|
4
|
4
|
import com.uqac.rthoni.java_rmi.common.Command;
|
|
5
|
+import javafx.beans.binding.ObjectExpression;
|
5
|
6
|
|
6
|
7
|
import java.io.BufferedReader;
|
7
|
8
|
import java.io.IOException;
|
|
@@ -9,6 +10,7 @@ import java.io.InputStreamReader;
|
9
|
10
|
import java.net.InetAddress;
|
10
|
11
|
import java.net.ServerSocket;
|
11
|
12
|
import java.net.Socket;
|
|
13
|
+import java.util.HashMap;
|
12
|
14
|
import java.util.Vector;
|
13
|
15
|
|
14
|
16
|
/**
|
|
@@ -18,6 +20,14 @@ public class ServerApplication {
|
18
|
20
|
|
19
|
21
|
private Vector<AbstractCommandExecutor> _executors = null;
|
20
|
22
|
|
|
23
|
+ private HashMap<String, Object> _objects = new HashMap<>();
|
|
24
|
+
|
|
25
|
+ private String _sourceDir;
|
|
26
|
+
|
|
27
|
+ private String _classDir;
|
|
28
|
+
|
|
29
|
+ private String _logFile;
|
|
30
|
+
|
21
|
31
|
public static String ipToString(InetAddress ip) {
|
22
|
32
|
String ipString = ip.toString();
|
23
|
33
|
if (!ipString.isEmpty() && ipString.startsWith("/")) {
|
|
@@ -36,8 +46,33 @@ public class ServerApplication {
|
36
|
46
|
}
|
37
|
47
|
}
|
38
|
48
|
|
|
49
|
+ public void addObject(String id, Object obj)
|
|
50
|
+ {
|
|
51
|
+ _objects.put(id, obj);
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ public Object getObject(String id)
|
|
55
|
+ {
|
|
56
|
+ return _objects.get(id);
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ public String getSourceDir() {
|
|
60
|
+ return _sourceDir;
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ public String getClassDir() {
|
|
64
|
+ return _classDir;
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ public String getLogFile() {
|
|
68
|
+ return _logFile;
|
|
69
|
+ }
|
|
70
|
+
|
39
|
71
|
public void run(int port, String sourceDir, String classDir, String logFile)
|
40
|
72
|
{
|
|
73
|
+ _sourceDir = sourceDir;
|
|
74
|
+ _classDir = classDir;
|
|
75
|
+ _logFile = logFile;
|
41
|
76
|
try {
|
42
|
77
|
loadExecutors();
|
43
|
78
|
} catch (ClassNotFoundException e) {
|
|
@@ -150,7 +185,7 @@ public class ServerApplication {
|
150
|
185
|
}
|
151
|
186
|
else {
|
152
|
187
|
try {
|
153
|
|
- data = executor.run(command);
|
|
188
|
+ data = executor.run(command, this);
|
154
|
189
|
} catch (Exception e) {
|
155
|
190
|
data = String.format("Error when handling command: %s", e.getMessage());
|
156
|
191
|
System.err.println(data);
|