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

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

MultiMethod? without numWait -> it depends on the timeout

File size: 3.5 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 long timeout;
28        private transient int retries;
29
30        // This constructor is used by kryo
31        public Request() {
32        }
33
34        public Request(String id, String method, boolean async, Object[] params) {
35                this.id = id;
36                this.method = method;
37                this.async = async;
38                this.params = params;
39        }
40
41        public Request(String id, String method, boolean async, Object[] params, boolean multi) {
42                this.id = id;
43                this.method = method;
44                this.async = async;
45                this.params = params;
46                this.multi = multi;
47        }
48
49        /**
50         * This method creates a new synchronous request
51         *
52         * @param id
53         *            - correlation id of this invocation
54         * @param method
55         *            - method name wanted to call
56         * @param params
57         *            - parameters of this method
58         * @return - new SyncRequest
59         */
60        public static Request newSyncRequest(String id, String method, Object[] params) {
61                return new Request(id, method, false, params);
62        }
63
64        /**
65         * This method creates a new synchronous request
66         *
67         * @param id
68         *            - correlation id of this invocation
69         * @param method
70         *            - method name wanted to call
71         * @param params
72         *            - parameters of this method
73         * @param retries
74         *            - How many retries will be done
75         * @param timeout
76         *            - Timeout for every retry
77         * @param multi
78         *            - If the method is multi
79         * @return - new SyncRequest
80         */
81        public static Request newSyncRequest(String id, String method, Object[] params, int retries, long timeout, boolean multi) {
82                Request req = new Request(id, method, false, params, multi);
83                req.setRetries(retries);
84                req.setTimeout(timeout);
85                return req;
86        }
87
88        /**
89         * This method creates a new asynchronous request
90         *
91         * @param id
92         *            - correlation id of this invocation
93         * @param method
94         *            - method name wanted to call
95         * @param params
96         *            - parameters of this method
97         * @param multi
98         *            - If the method is multi
99         * @return new AsyncRequest
100         */
101        public static Request newAsyncRequest(String id, String method, Object[] params, boolean multi) {
102                return new Request(id, method, true, params, multi);
103        }
104
105        public String getId() {
106                return id;
107        }
108
109        public void setId(String id) {
110                this.id = id;
111        }
112
113        public String getMethod() {
114                return method;
115        }
116
117        public void setMethod(String method) {
118                this.method = method;
119        }
120
121        public Object[] getParams() {
122                return params;
123        }
124
125        public void setParams(Object[] params) {
126                this.params = params;
127        }
128
129        public boolean isAsync() {
130                return async;
131        }
132
133        public void setAsync(boolean async) {
134                this.async = async;
135        }
136
137        public long getTimeout() {
138                return timeout;
139        }
140
141        public void setTimeout(long timeout) {
142                this.timeout = timeout;
143        }
144
145        public int getRetries() {
146                return retries;
147        }
148
149        public void setRetries(int retries) {
150                this.retries = retries;
151        }
152
153        public boolean isMulti() {
154                return multi;
155        }
156
157        public void setMulti(boolean multi) {
158                this.multi = multi;
159        }
160
161}
Note: See TracBrowser for help on using the repository browser.