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