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