]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/Message.java
added support for opensrf-serializable objects and JSON output of those objects....
[OpenSRF.git] / src / java / org / opensrf / Message.java
1 package org.opensrf;
2 import org.opensrf.util.*;
3
4
5 public class Message implements OSRFSerializable {
6
7     /** Message types */
8     public enum Type {
9         REQUEST,
10         STATUS,
11         RESULT,
12         CONNECT,
13         DISCONNECT,
14     };
15
16     /** Message ID.  This number is used to relate requests to responses */
17     private int id;
18     /** Type of message. */
19     private Type type;
20     /** message payload */
21     private Object payload;
22
23     /** Go ahead and register the Message object */
24     private static OSRFRegistry registry = 
25         OSRFRegistry.registerObject(
26             "osrfMessage", 
27             OSRFRegistry.WireProtocol.HASH, 
28             new String[] {"threadTrace", "type", "payload"});
29
30     /**
31      * @param id This message's ID
32      * @param type The type of message
33      */
34     public Message(int id, Type type) {
35         setId(id);
36         setType(type);
37     }
38
39     public int getId() {
40         return id;
41     }   
42     public Type getType() {
43         return type;
44     }
45     public Object getPayload() {
46         return payload;
47     }
48     public void setId(int id) {
49         this.id = id;
50     }
51     public void setType(Type type) {
52         this.type = type;
53     }
54     public void setPayload(Object p) {
55         payload = p;
56     }
57
58     /**
59      * Implements the generic get() API required by OSRFSerializable
60      */
61     public Object get(String field) {
62         if("threadTrace".equals(field))
63             return getId();
64         if("type".equals(field))
65             return getType().toString();
66         if("payload".equals(field))
67             return getPayload();
68         return null;
69     }
70
71     public OSRFRegistry getRegistry() {
72         return registry;
73     }
74 }
75
76