Browse Source

added getters for server fields; changd executor run method signature

develop
Robin Thoni 8 years ago
parent
commit
825230f84d

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

2
 
2
 
3
 import com.uqac.rthoni.java_rmi.server.executors.AbstractCommandExecutor;
3
 import com.uqac.rthoni.java_rmi.server.executors.AbstractCommandExecutor;
4
 import com.uqac.rthoni.java_rmi.common.Command;
4
 import com.uqac.rthoni.java_rmi.common.Command;
5
+import javafx.beans.binding.ObjectExpression;
5
 
6
 
6
 import java.io.BufferedReader;
7
 import java.io.BufferedReader;
7
 import java.io.IOException;
8
 import java.io.IOException;
9
 import java.net.InetAddress;
10
 import java.net.InetAddress;
10
 import java.net.ServerSocket;
11
 import java.net.ServerSocket;
11
 import java.net.Socket;
12
 import java.net.Socket;
13
+import java.util.HashMap;
12
 import java.util.Vector;
14
 import java.util.Vector;
13
 
15
 
14
 /**
16
 /**
18
 
20
 
19
     private Vector<AbstractCommandExecutor> _executors = null;
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
     public static String ipToString(InetAddress ip) {
31
     public static String ipToString(InetAddress ip) {
22
         String ipString = ip.toString();
32
         String ipString = ip.toString();
23
         if (!ipString.isEmpty() && ipString.startsWith("/")) {
33
         if (!ipString.isEmpty() && ipString.startsWith("/")) {
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
     public void run(int port, String sourceDir, String classDir, String logFile)
71
     public void run(int port, String sourceDir, String classDir, String logFile)
40
     {
72
     {
73
+        _sourceDir = sourceDir;
74
+        _classDir = classDir;
75
+        _logFile = logFile;
41
         try {
76
         try {
42
             loadExecutors();
77
             loadExecutors();
43
         } catch (ClassNotFoundException e) {
78
         } catch (ClassNotFoundException e) {
150
         }
185
         }
151
         else {
186
         else {
152
             try {
187
             try {
153
-                data = executor.run(command);
188
+                data = executor.run(command, this);
154
             } catch (Exception e) {
189
             } catch (Exception e) {
155
                 data = String.format("Error when handling command: %s", e.getMessage());
190
                 data = String.format("Error when handling command: %s", e.getMessage());
156
                 System.err.println(data);
191
                 System.err.println(data);

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

2
 
2
 
3
 import com.uqac.rthoni.java_rmi.common.Command;
3
 import com.uqac.rthoni.java_rmi.common.Command;
4
 import com.uqac.rthoni.java_rmi.common.ReflectionUtil;
4
 import com.uqac.rthoni.java_rmi.common.ReflectionUtil;
5
+import com.uqac.rthoni.java_rmi.server.ServerApplication;
5
 
6
 
6
 import java.util.Vector;
7
 import java.util.Vector;
7
 
8
 
17
 
18
 
18
     public abstract String getCommandName();
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
 package com.uqac.rthoni.java_rmi.server.executors;
1
 package com.uqac.rthoni.java_rmi.server.executors;
2
 
2
 
3
 import com.uqac.rthoni.java_rmi.common.Command;
3
 import com.uqac.rthoni.java_rmi.common.Command;
4
+import com.uqac.rthoni.java_rmi.server.ServerApplication;
4
 
5
 
5
 /**
6
 /**
6
  * Created by robin on 9/16/16.
7
  * Created by robin on 9/16/16.
12
     }
13
     }
13
 
14
 
14
     @Override
15
     @Override
15
-    public String run(Command command) throws Exception {
16
+    public String run(Command command, ServerApplication server) throws Exception {
16
         return "Test. succeeded";
17
         return "Test. succeeded";
17
     }
18
     }
18
 }
19
 }

Loading…
Cancel
Save