Browse Source

added getters for server fields; changd executor run method signature

develop
Robin Thoni 7 years ago
parent
commit
825230f84d

+ 36
- 1
server/src/main/java/com/uqac/rthoni/java_rmi/server/ServerApplication.java View File

@@ -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);

+ 2
- 1
server/src/main/java/com/uqac/rthoni/java_rmi/server/executors/AbstractCommandExecutor.java View File

@@ -2,6 +2,7 @@ package com.uqac.rthoni.java_rmi.server.executors;
2 2
 
3 3
 import com.uqac.rthoni.java_rmi.common.Command;
4 4
 import com.uqac.rthoni.java_rmi.common.ReflectionUtil;
5
+import com.uqac.rthoni.java_rmi.server.ServerApplication;
5 6
 
6 7
 import java.util.Vector;
7 8
 
@@ -17,5 +18,5 @@ public abstract class AbstractCommandExecutor {
17 18
 
18 19
     public abstract String getCommandName();
19 20
 
20
-    public abstract String run(Command command) throws Exception;
21
+    public abstract String run(Command command, ServerApplication server) throws Exception;
21 22
 }

+ 2
- 1
server/src/main/java/com/uqac/rthoni/java_rmi/server/executors/TestExecutor.java View File

@@ -1,6 +1,7 @@
1 1
 package com.uqac.rthoni.java_rmi.server.executors;
2 2
 
3 3
 import com.uqac.rthoni.java_rmi.common.Command;
4
+import com.uqac.rthoni.java_rmi.server.ServerApplication;
4 5
 
5 6
 /**
6 7
  * Created by robin on 9/16/16.
@@ -12,7 +13,7 @@ public class TestExecutor extends AbstractCommandExecutor {
12 13
     }
13 14
 
14 15
     @Override
15
-    public String run(Command command) throws Exception {
16
+    public String run(Command command, ServerApplication server) throws Exception {
16 17
         return "Test. succeeded";
17 18
     }
18 19
 }

Loading…
Cancel
Save