Commits

John Eriksson committed 8eab1c8 Merge

Merge

Comments (0)

Files changed (6)

SimaMessageDescriptor.obj

Binary file added.

SimaQueueObjectDescriptor.obj

Binary file added.

src/SimaMessage.java

-
-public class SimaMessage extends se.kth.csc.sima.SimaMessage {
-
-    private static final long serialVersionUID = 6908363843809658154L;
-
-    @SuppressWarnings("unused")
-    private Object messageData;
-    @SuppressWarnings("unused")
-    private int messageType;
-
-    public SimaMessage(int type) {
-        super(type, null);
-    }
-
-    public SimaMessage(int type, Object data) {
-        super(type, data);
-    }
-}

src/SimaQueueObject.java

-
-public class SimaQueueObject extends se.kth.csc.sima.SimaQueueObject {
-
-    private static final long serialVersionUID = 1959276901940605978L;
-    
-    @SuppressWarnings("unused")
-    private String userID;
-    @SuppressWarnings("unused")
-    private String name;
-    @SuppressWarnings("unused")
-    private String host;
-    @SuppressWarnings("unused")
-    private long time;
-    @SuppressWarnings("unused")
-    private int type;
-    @SuppressWarnings("unused")
-    private String message;
-    @SuppressWarnings("unused")
-    private String sqoID;
-    @SuppressWarnings("unused")
-    private long portalID;
-
-    public SimaQueueObject(String name, int type) {
-        super(name, type, "");
-    }
-
-    public SimaQueueObject(String name, int type, String message) {
-        super(name, type, message);
-    }
-    
-    public SimaQueueObject(String name, int type, String host, String message) {
-        super(name, type, host, message);
-    }
-}

src/se/kth/csc/sima/SimaConnection.java

 package se.kth.csc.sima;
 
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
     private String joinedCourseName = "";
     private ArrayList<SimaQueueObject> joinedCourseQueue;
     private SimaQueueObject ownQueueObject;
+    
+    private ObjectStreamClass simaMessageDescriptor;
+    private ObjectStreamClass simaQueueObjectDescriptor;
 
     private Map<Integer, SimaConnectionListener> messageListeners = new HashMap<Integer, SimaConnectionListener>();
 
-    public SimaConnection(String host, int port) throws UnknownHostException, IOException {
+    public SimaConnection(String host, int port) throws UnknownHostException, IOException, ClassNotFoundException {
+        ObjectInputStream fileIn = new ObjectInputStream(new FileInputStream("SimaMessageDescriptor.obj"));
+        this.simaMessageDescriptor = (ObjectStreamClass)fileIn.readObject();
+        fileIn.close();
+        fileIn = new ObjectInputStream(new FileInputStream("SimaQueueObjectDescriptor.obj"));
+        this.simaQueueObjectDescriptor = (ObjectStreamClass)fileIn.readObject();
+        fileIn.close();
+        
         Socket soc = new Socket(host, port);
         this.in = new ObjectInputStream(soc.getInputStream()) {
             @Override
         this.out = new ObjectOutputStream(soc.getOutputStream()) {
             @Override
             protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
-                try {
-                    if (desc.getName().equals(SimaMessage.class.getName())) {
-                        super.writeClassDescriptor(ObjectStreamClass.lookup(ClassLoader.getSystemClassLoader()
-                                .loadClass("SimaMessage")));
-                    } else if (desc.getName().equals(SimaQueueObject.class.getName())) {
-                        super.writeClassDescriptor(ObjectStreamClass.lookup(ClassLoader.getSystemClassLoader()
-                                .loadClass("SimaQueueObject")));
-                    } else {
-                        super.writeClassDescriptor(desc);
-                    }
-                } catch (ClassNotFoundException e) {
+                if (desc.getName().equals(SimaMessage.class.getName())) {
+                    super.writeClassDescriptor(SimaConnection.this.simaMessageDescriptor);
+                } else if (desc.getName().equals(SimaQueueObject.class.getName())) {
+                    super.writeClassDescriptor(SimaConnection.this.simaQueueObjectDescriptor);
+                } else {
                     super.writeClassDescriptor(desc);
-                    e.printStackTrace();
                 }
             }
         };

src/se/kth/csc/sima/SimaManager.java

 public class SimaManager {
 
     public static void main(String[] args) {
-
+        
         String server;
         if ((server = System.getProperty("sima_server")) == null) {
             System.err.println("Run as: java -Dsima_server=<server_address> [-Ddebug] SimaManager");