Skip to content

Commit cc28338

Browse files
committed
it all works for milestone1
1 parent a2b1be5 commit cc28338

27 files changed

+272
-235
lines changed

code/Client/Client/Client.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
public abstract class Client {
1313
IResourceManager m_resourceManager = null;
1414

15-
public Client() {
16-
super();
17-
}
18-
1915
public abstract void connectServer();
2016

2117
public void start() {

code/Client/Client/TCPClient.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ public static void main(String args[]) {
2828
System.exit(1);
2929
}
3030

31-
// Set the security policy
32-
if (System.getSecurityManager() == null) {
33-
System.setSecurityManager(new SecurityManager());
34-
}
35-
3631
// Get a reference to the RMIRegister
3732
try {
3833
TCPClient client = new TCPClient();
@@ -57,18 +52,22 @@ public void connectServer() {
5752
public AbstractProxyObject getProxyResourceManager(String hostname, int port, String boundName) {
5853
Message messageToSend = new Message();
5954
messageToSend.proxyObjectBoundName = s_tcpPrefix + boundName;
55+
System.out.println("requesting proxy " + messageToSend.proxyObjectBoundName);
6056
while (true) {
6157
try {
6258
Socket socket = new Socket(hostname, port);
6359

6460
ObjectOutputStream osOut = new ObjectOutputStream(socket.getOutputStream());
65-
ObjectInputStream osIn = new ObjectInputStream(socket.getInputStream());
61+
ObjectInputStream osIn = new ObjectInputStream(socket.getInputStream());
6662

6763
osOut.writeObject(messageToSend);
6864

6965
try {
7066
Message messageReceived = (Message) osIn.readObject();
71-
return (AbstractProxyObject) messageReceived.requestedValue;
67+
AbstractProxyObject receivedObject = (AbstractProxyObject) messageReceived.requestedValue;
68+
if (receivedObject == null) throw new Exception("received proxy object was null");
69+
System.out.println("got requested " + messageToSend.proxyObjectBoundName);
70+
return receivedObject;
7271
} catch (Exception e) {
7372
Trace.info(s_serverName + ": expected customerRM to be AbstractProxyObject. Cast failed.");
7473
e.printStackTrace();

code/Client/Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
all: java.policy compile-client compile-client-tcp
1+
all: java.policy RMIClient TCPClient
22

33
java.policy: FORCE
44
@echo "Creating client java policy"
55
@echo "grant codebase \"file:`pwd`/\" {" > java.policy
66
@echo "permission java.security.AllPermission;" >> java.policy
77
@echo "};" >> java.policy
88

9-
compile-client: ../Server/RMIInterface.jar ../Server/Trace.jar ../Server/TCP.jar
9+
jar_deps = ../Server/RMIInterface.jar ../Server/Trace.jar ../Server/TCP.jar
10+
11+
RMIClient: $(jar_deps) Client/RMIClient.java
1012
javac -cp ../Server/RMIInterface.jar:../Server/Trace.jar:../Server/TCP.jar Client/*.java
1113

14+
TCPClient: $(jar_deps) Client/TCPClient.java
15+
javac -cp ../Server/TCP.jar:../Server/Trace.jar:../Server/RMIInterface.jar:. Client/TCPClient.java
16+
1217
../Server/RMIInterface.jar: ../Server/Server/Interface/IResourceManager.java
1318
make -C ../Server/ RMIInterface.jar
1419

15-
compile-client-tcp: ../Server/TCP.jar ../Server/Trace.jar
16-
javac -cp ../Server/TCP.jar:../Server/Trace.jar:../Server/RMIInterface.jar:. Client/TCPClient.java
17-
1820
../Server/TCP.jar: ../Server/Server/TCP/*.java
1921
make -C ../Server/ TCP.jar
2022

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Usage: ./run_client.sh [<server_hostname> [<server_rmiobject>]]
22

3-
java -Djava.security.policy=java.policy -cp ../Server/RMIInterface.jar:. Client.RMIClient $1 $2
3+
java -Djava.security.policy=java.policy -cp ../Server/RMIInterface.jar:../Server/TCP.jar:../Server.Trace.jar:. Client.RMIClient $1 $2

code/Client/run_tcp_client.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Usage: ./run_client.sh [<server_hostname> [<server_rmiobject>]]
2+
3+
java -Djava.security.policy=java.policy -cp ../Server/RMIInterface.jar:../Server/TCP.jar:../Server/Trace.jar:. Client.TCPClient $1 $2

code/Server/Server/TCP/AbstractProxyObject.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import java.io.ObjectOutputStream;
88
import java.io.IOException;
99

10-
11-
public abstract class AbstractProxyObject implements Serializable {
10+
public abstract class AbstractProxyObject implements Serializable
11+
{
1212
protected String hostname;
1313
protected int port;
1414
protected String boundName;
1515

16-
public AbstractProxyObject(String hostname, int port, String boundName) {
16+
public AbstractProxyObject(String hostname, int port, String boundName)
17+
{
1718
this.hostname = hostname;
1819
this.port = port;
1920
this.boundName = boundName;
@@ -23,7 +24,9 @@ public String getBoundName() {
2324
return this.boundName;
2425
}
2526

26-
protected Message sendAndReceiveMessage(Message messageToSend) throws UnknownHostException, IOException, ClassNotFoundException {
27+
protected Message sendAndReceiveMessage(Message messageToSend)
28+
throws UnknownHostException, IOException, ClassNotFoundException
29+
{
2730
messageToSend.proxyObjectBoundName = boundName;
2831

2932
Socket socket = new Socket(hostname, port);
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package Server.TCP;
22

3+
import java.rmi.RemoteException;
4+
35
public interface IProxiable {
4-
public AbstractProxyObject makeProxyObject(String hostname, int port, String boundName);
6+
public AbstractProxyObject makeProxyObject(String hostname, int port, String boundName)
7+
throws RemoteException;
58
}

code/Server/Server/TCP/ProxyCarResourceManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public boolean reserveCar(int id, int customerID, String location) throws Remote
2222
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
2323
message.proxyObjectBoundName = this.boundName;
2424
message.methodName = "reserveCar";
25-
message.methodArgs = new Object[]{new Integer(id), new Integer(customerID), location};
26-
message.methodArgTypes = new Class[]{Integer.class, Integer.class, String.class};
25+
message.methodArgs = new Object[]{id, customerID, location};
26+
message.methodArgTypes = new Class[]{int.class, int.class, String.class};
2727
Message recvMessage = null;
2828
try {
2929
recvMessage = sendAndReceiveMessage(message);
@@ -46,8 +46,8 @@ public boolean addCars(int id, String location, int numCars, int price) throws R
4646
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
4747
message.proxyObjectBoundName = this.boundName;
4848
message.methodName = "addCars";
49-
message.methodArgs = new Object[]{new Integer(id), location, new Integer(numCars), new Integer(price)};
50-
message.methodArgTypes = new Class[]{Integer.class, String.class, Integer.class, Integer.class};
49+
message.methodArgs = new Object[]{id, location, numCars, price};
50+
message.methodArgTypes = new Class[]{int.class, String.class, int.class, int.class};
5151

5252
Message recvMessage = null;
5353
try {
@@ -71,8 +71,8 @@ public boolean deleteCars(int id, String location) throws RemoteException {
7171
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
7272
message.proxyObjectBoundName = this.boundName;
7373
message.methodName = "deleteCars";
74-
message.methodArgs = new Object[]{new Integer(id), location};
75-
message.methodArgTypes = new Class[]{Integer.class, String.class};
74+
message.methodArgs = new Object[]{id, location};
75+
message.methodArgTypes = new Class[]{int.class, String.class};
7676

7777
Message recvMessage = null;
7878
try {
@@ -94,8 +94,8 @@ public int queryCars(int id, String location) throws RemoteException {
9494
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
9595
message.proxyObjectBoundName = this.boundName;
9696
message.methodName = "queryCars";
97-
message.methodArgs = new Object[]{new Integer(id), location};
98-
message.methodArgTypes = new Class[]{Integer.class, String.class};
97+
message.methodArgs = new Object[]{id, location};
98+
message.methodArgTypes = new Class[]{int.class, String.class};
9999

100100
Message recvMessage = null;
101101
try {
@@ -122,8 +122,8 @@ public int queryCarsPrice(int id, String location) throws RemoteException {
122122
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
123123
message.proxyObjectBoundName = this.boundName;
124124
message.methodName = "queryCarsPrice";
125-
message.methodArgs = new Object[]{new Integer(id), location};
126-
message.methodArgTypes = new Class[]{Integer.class, String.class};
125+
message.methodArgs = new Object[]{id, location};
126+
message.methodArgTypes = new Class[]{int.class, String.class};
127127

128128
Message recvMessage = null;
129129
try {

code/Server/Server/TCP/ProxyCustomer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public boolean setID(int id) {
1515
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
1616
message.proxyObjectBoundName = this.boundName;
1717
message.methodName = "setID";
18-
message.methodArgs = new Object[]{new Integer(id)};
19-
message.methodArgTypes = new Class[]{Integer.class};
18+
message.methodArgs = new Object[]{id};
19+
message.methodArgTypes = new Class[]{int.class};
2020
Message recvMessage = null;
2121
try {
2222
recvMessage = sendAndReceiveMessage(message);
@@ -30,8 +30,8 @@ public int getID() {
3030
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
3131
message.proxyObjectBoundName = this.boundName;
3232
message.methodName = "getID";
33-
// message.methodArgs = new Object[] {new Integer(id), location};
34-
// message.methodArgTypes = new Class[] {Integer.class, String.class};
33+
// message.methodArgs = new Object[] {id, location};
34+
// message.methodArgTypes = new Class[] {int.class, String.class};
3535

3636
Message recvMessage = null;
3737
try {
@@ -85,8 +85,8 @@ public String getBill() {
8585
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
8686
message.proxyObjectBoundName = this.boundName;
8787
message.methodName = "getBill";
88-
// message.methodArgs = new Object[] {new Integer(id), location};
89-
// message.methodArgTypes = new Class[] {Integer.class, String.class};
88+
// message.methodArgs = new Object[] {id, location};
89+
// message.methodArgTypes = new Class[] {int.class, String.class};
9090

9191
Message recvMessage = null;
9292
try {
@@ -106,8 +106,8 @@ public String getKey() {
106106
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
107107
message.proxyObjectBoundName = this.boundName;
108108
message.methodName = "getBill";
109-
// message.methodArgs = new Object[] {new Integer(id), location};
110-
// message.methodArgTypes = new Class[] {Integer.class, String.class};
109+
// message.methodArgs = new Object[] {id, location};
110+
// message.methodArgTypes = new Class[] {int.class, String.class};
111111

112112
Message recvMessage = null;
113113
try {
@@ -127,8 +127,8 @@ public RMHashMap getReservations() {
127127
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
128128
message.proxyObjectBoundName = this.boundName;
129129
message.methodName = "getBill";
130-
// message.methodArgs = new Object[] {new Integer(id), location};
131-
// message.methodArgTypes = new Class[] {Integer.class, String.class};
130+
// message.methodArgs = new Object[] {id, location};
131+
// message.methodArgTypes = new Class[] {int.class, String.class};
132132

133133
Message recvMessage = null;
134134
try {

code/Server/Server/TCP/ProxyCustomerResourceManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public int newCustomer(int id) throws RemoteException {
2121
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
2222
message.proxyObjectBoundName = this.boundName;
2323
message.methodName = "newCustomer";
24-
message.methodArgs = new Object[]{new Integer(id)};
25-
message.methodArgTypes = new Class[]{Integer.class};
24+
message.methodArgs = new Object[]{id};
25+
message.methodArgTypes = new Class[]{int.class};
2626
Message recvMessage = null;
2727
try {
2828
recvMessage = sendAndReceiveMessage(message);
@@ -47,8 +47,8 @@ public boolean newCustomer(int id, int customerID) throws RemoteException {
4747
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
4848
message.proxyObjectBoundName = this.boundName;
4949
message.methodName = "newCustomer";
50-
message.methodArgs = new Object[]{new Integer(id), new Integer(customerID)};
51-
message.methodArgTypes = new Class[]{Integer.class, Integer.class};
50+
message.methodArgs = new Object[]{id, customerID};
51+
message.methodArgTypes = new Class[]{int.class, int.class};
5252
Message recvMessage = null;
5353
try {
5454
recvMessage = sendAndReceiveMessage(message);
@@ -68,8 +68,8 @@ public boolean deleteCustomer(int id, int customerID) throws RemoteException {
6868
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
6969
message.proxyObjectBoundName = this.boundName;
7070
message.methodName = "deleteCustomer";
71-
message.methodArgs = new Object[]{new Integer(id), new Integer(customerID)};
72-
message.methodArgTypes = new Class[]{Integer.class, Integer.class};
71+
message.methodArgs = new Object[]{id, customerID};
72+
message.methodArgTypes = new Class[]{int.class, int.class};
7373

7474
Message recvMessage = null;
7575
try {
@@ -90,8 +90,8 @@ public String queryCustomerInfo(int id, int customerID) throws RemoteException {
9090
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
9191
message.proxyObjectBoundName = this.boundName;
9292
message.methodName = "queryCustomerInfo";
93-
message.methodArgs = new Object[]{new Integer(id), new Integer(customerID)};
94-
message.methodArgTypes = new Class[]{Integer.class, Integer.class};
93+
message.methodArgs = new Object[]{id, customerID};
94+
message.methodArgTypes = new Class[]{int.class, int.class};
9595

9696
Message recvMessage = null;
9797
try {
@@ -126,8 +126,8 @@ public Customer getCustomer(int xid, int customerID) throws RemoteException {
126126
ProxyMethodCallMessage message = new ProxyMethodCallMessage();
127127
message.proxyObjectBoundName = this.boundName;
128128
message.methodName = "getCustomer";
129-
message.methodArgs = new Object[]{new Integer(xid), new Integer(customerID)};
130-
message.methodArgTypes = new Class[]{Integer.class, Integer.class};
129+
message.methodArgs = new Object[]{xid, customerID};
130+
message.methodArgTypes = new Class[]{int.class, int.class};
131131

132132
Message recvMessage = null;
133133
try {

0 commit comments

Comments
 (0)