[44] | 1 | package omq.common.message; |
---|
| 2 | |
---|
| 3 | import java.io.Serializable; |
---|
| 4 | |
---|
[83] | 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 | */ |
---|
[44] | 14 | public 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 | |
---|
[54] | 26 | private transient boolean multi; |
---|
[44] | 27 | private transient long timeout; |
---|
| 28 | private transient int retries; |
---|
| 29 | |
---|
[83] | 30 | // This constructor is used by kryo |
---|
[44] | 31 | public Request() { |
---|
| 32 | } |
---|
| 33 | |
---|
[75] | 34 | public Request(String id, String method, boolean async, Object[] params) { |
---|
[44] | 35 | this.id = id; |
---|
| 36 | this.method = method; |
---|
| 37 | this.async = async; |
---|
| 38 | this.params = params; |
---|
| 39 | } |
---|
| 40 | |
---|
[75] | 41 | public Request(String id, String method, boolean async, Object[] params, boolean multi) { |
---|
[55] | 42 | this.id = id; |
---|
| 43 | this.method = method; |
---|
| 44 | this.async = async; |
---|
| 45 | this.params = params; |
---|
| 46 | this.multi = multi; |
---|
[54] | 47 | } |
---|
| 48 | |
---|
[83] | 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 | */ |
---|
[44] | 60 | public static Request newSyncRequest(String id, String method, Object[] params) { |
---|
| 61 | return new Request(id, method, false, params); |
---|
| 62 | } |
---|
| 63 | |
---|
[83] | 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 | */ |
---|
[104] | 81 | public static Request newSyncRequest(String id, String method, Object[] params, int retries, long timeout, boolean multi) { |
---|
[55] | 82 | Request req = new Request(id, method, false, params, multi); |
---|
[44] | 83 | req.setRetries(retries); |
---|
| 84 | req.setTimeout(timeout); |
---|
| 85 | return req; |
---|
| 86 | } |
---|
| 87 | |
---|
[83] | 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 | */ |
---|
[54] | 101 | public static Request newAsyncRequest(String id, String method, Object[] params, boolean multi) { |
---|
| 102 | return new Request(id, method, true, params, multi); |
---|
[44] | 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 | |
---|
[54] | 153 | public boolean isMulti() { |
---|
| 154 | return multi; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | public void setMulti(boolean multi) { |
---|
| 158 | this.multi = multi; |
---|
| 159 | } |
---|
[58] | 160 | |
---|
[44] | 161 | } |
---|