source: branches/supervisor/src/main/java/omq/common/message/Request.java @ 91

Last change on this file since 91 was 83, checked in by stoda, 11 years ago

J

File size: 3.7 KB
Line 
1package omq.common.message;
2
3import java.io.Serializable;
4
5/**
6 * Serializable request information. This class is used to send the information
7 * to the server. It has information about which method is wanted to invoke, its
8 * parameters, its correlation id and if a response is needed -asynchronous
9 * method-.
10 *
11 * @author Sergi Toda <sergi.toda@estudiants.urv.cat>
12 *
13 */
14public class Request implements Serializable {
15
16        /**
17         *
18         */
19        private static final long serialVersionUID = 6366255840200365083L;
20
21        private String method;
22        private Object[] params;
23        private String id;
24        private boolean async = false;
25
26        private transient boolean multi;
27        private transient int wait;
28        private transient long timeout;
29        private transient int retries;
30
31        // This constructor is used by kryo
32        public Request() {
33        }
34
35        public Request(String id, String method, boolean async, Object[] params) {
36                this.id = id;
37                this.method = method;
38                this.async = async;
39                this.params = params;
40        }
41
42        public Request(String id, String method, boolean async, Object[] params, boolean multi) {
43                this.id = id;
44                this.method = method;
45                this.async = async;
46                this.params = params;
47                this.multi = multi;
48        }
49
50        /**
51         * This method creates a new synchronous request
52         *
53         * @param id
54         *            - correlation id of this invocation
55         * @param method
56         *            - method name wanted to call
57         * @param params
58         *            - parameters of this method
59         * @return - new SyncRequest
60         */
61        public static Request newSyncRequest(String id, String method, Object[] params) {
62                return new Request(id, method, false, params);
63        }
64
65        /**
66         * This method creates a new synchronous request
67         *
68         * @param id
69         *            - correlation id of this invocation
70         * @param method
71         *            - method name wanted to call
72         * @param params
73         *            - parameters of this method
74         * @param retries
75         *            - How many retries will be done
76         * @param timeout
77         *            - Timeout for every retry
78         * @param multi
79         *            - If the method is multi
80         * @param wait
81         *            - If the method is multi how many responses will be listened
82         * @return - new SyncRequest
83         */
84        public static Request newSyncRequest(String id, String method, Object[] params, int retries, long timeout, boolean multi, int wait) {
85                Request req = new Request(id, method, false, params, multi);
86                req.setRetries(retries);
87                req.setTimeout(timeout);
88                req.setWait(wait);
89                return req;
90        }
91
92        /**
93         * This method creates a new asynchronous request
94         *
95         * @param id
96         *            - correlation id of this invocation
97         * @param method
98         *            - method name wanted to call
99         * @param params
100         *            - parameters of this method
101         * @param multi
102         *            - If the method is multi
103         * @return new AsyncRequest
104         */
105        public static Request newAsyncRequest(String id, String method, Object[] params, boolean multi) {
106                return new Request(id, method, true, params, multi);
107        }
108
109        public String getId() {
110                return id;
111        }
112
113        public void setId(String id) {
114                this.id = id;
115        }
116
117        public String getMethod() {
118                return method;
119        }
120
121        public void setMethod(String method) {
122                this.method = method;
123        }
124
125        public Object[] getParams() {
126                return params;
127        }
128
129        public void setParams(Object[] params) {
130                this.params = params;
131        }
132
133        public boolean isAsync() {
134                return async;
135        }
136
137        public void setAsync(boolean async) {
138                this.async = async;
139        }
140
141        public long getTimeout() {
142                return timeout;
143        }
144
145        public void setTimeout(long timeout) {
146                this.timeout = timeout;
147        }
148
149        public int getRetries() {
150                return retries;
151        }
152
153        public void setRetries(int retries) {
154                this.retries = retries;
155        }
156
157        public boolean isMulti() {
158                return multi;
159        }
160
161        public void setMulti(boolean multi) {
162                this.multi = multi;
163        }
164
165        public int getWait() {
166                return wait;
167        }
168
169        public void setWait(int wait) {
170                this.wait = wait;
171        }
172}
Note: See TracBrowser for help on using the repository browser.