|
11 | 11 | import java.util.List; |
12 | 12 |
|
13 | 13 | import multichain.command.builders.QueryBuilderStream; |
| 14 | +import multichain.object.Stream; |
| 15 | +import multichain.object.StreamKey; |
14 | 16 | import multichain.object.StreamKeyItem; |
15 | 17 | import multichain.object.formatters.StreamFormatter; |
16 | 18 |
|
@@ -80,6 +82,217 @@ public String create(String streamName) throws MultichainException { |
80 | 82 | return create(streamName, false); |
81 | 83 | } |
82 | 84 |
|
| 85 | + /** |
| 86 | + * liststreams (stream-identifier(s) verbose count start ) |
| 87 | + * 1. "stream-identifier(s)" (string, optional, default=*, all streams) Stream identifier - one of the following: |
| 88 | + * issue txid, stream reference, stream name. |
| 89 | + * or |
| 90 | + * 1. stream-identifier(s) (array, optional) A json array of stream identifiers |
| 91 | + * 2. verbose (boolean, optional, default=false) If true, returns stream list of creators |
| 92 | + * 3. count (number, optional, default=INT_MAX - all) The number of streams to display |
| 93 | + * 4. start (number, optional, default=-count - last) Start from specific stream, 0 based, if negative - from the |
| 94 | + * end |
| 95 | + * |
| 96 | + * Returns list of defined streams |
| 97 | + * |
| 98 | + * @param streamName |
| 99 | + * @param verbose |
| 100 | + * @param count |
| 101 | + * @param start |
| 102 | + * @return |
| 103 | + * @throws MultichainException |
| 104 | + */ |
| 105 | + @SuppressWarnings("unchecked") |
| 106 | + public List<Stream> listStreams(String streamName, boolean verbose, int count, int start) |
| 107 | + throws MultichainException { |
| 108 | + List<Stream> streams = new ArrayList<Stream>(); |
| 109 | + |
| 110 | + Object objectStreams = executeListStreams(streamName, verbose, count, start); |
| 111 | + if (verifyInstance(objectStreams, ArrayList.class) |
| 112 | + && verifyInstanceofList((ArrayList<Object>) objectStreams, Stream.class)) { |
| 113 | + streams = StreamFormatter.formatStreams((ArrayList<Object>) objectStreams); |
| 114 | + } |
| 115 | + |
| 116 | + return streams; |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * {@link #listStreams(String, boolean, int, int)} without start |
| 121 | + * |
| 122 | + * @param streamName |
| 123 | + * @param verbose |
| 124 | + * @param count |
| 125 | + * @return |
| 126 | + * @throws MultichainException |
| 127 | + */ |
| 128 | + @SuppressWarnings("unchecked") |
| 129 | + public List<Stream> listStreams(String streamName, boolean verbose, int count) throws MultichainException { |
| 130 | + List<Stream> streams = new ArrayList<Stream>(); |
| 131 | + |
| 132 | + Object objectStreams = executeListStreams(streamName, verbose, count); |
| 133 | + if (verifyInstance(objectStreams, ArrayList.class) |
| 134 | + && verifyInstanceofList((ArrayList<Object>) objectStreams, Stream.class)) { |
| 135 | + streams = StreamFormatter.formatStreams((ArrayList<Object>) objectStreams); |
| 136 | + } |
| 137 | + |
| 138 | + return streams; |
| 139 | + |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * {@link #listStreams(String, boolean, int, int)} without start and default count = 10 |
| 144 | + * |
| 145 | + * @param streamName |
| 146 | + * @param verbose |
| 147 | + * @return |
| 148 | + * @throws MultichainException |
| 149 | + */ |
| 150 | + @SuppressWarnings("unchecked") |
| 151 | + public List<Stream> listStreams(String streamName, boolean verbose) throws MultichainException { |
| 152 | + List<Stream> streams = new ArrayList<Stream>(); |
| 153 | + |
| 154 | + Object objectStreams = executeListStreams(streamName, verbose, 10); |
| 155 | + if (verifyInstance(objectStreams, ArrayList.class) |
| 156 | + && verifyInstanceofList((ArrayList<Object>) objectStreams, Stream.class)) { |
| 157 | + streams = StreamFormatter.formatStreams((ArrayList<Object>) objectStreams); |
| 158 | + } |
| 159 | + |
| 160 | + return streams; |
| 161 | + |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * {@link #listStreams(String, boolean, int, int)} without start and default count = 10 and defautl verbose = false |
| 166 | + * |
| 167 | + * @param streamName |
| 168 | + * @return |
| 169 | + * @throws MultichainException |
| 170 | + */ |
| 171 | + @SuppressWarnings("unchecked") |
| 172 | + public List<Stream> listStreams(String streamName) throws MultichainException { |
| 173 | + List<Stream> streams = new ArrayList<Stream>(); |
| 174 | + |
| 175 | + Object objectStreams = executeListStreams(streamName, false, 10); |
| 176 | + if (verifyInstance(objectStreams, ArrayList.class) |
| 177 | + && verifyInstanceofList((ArrayList<Object>) objectStreams, Stream.class)) { |
| 178 | + streams = StreamFormatter.formatStreams((ArrayList<Object>) objectStreams); |
| 179 | + } |
| 180 | + |
| 181 | + return streams; |
| 182 | + |
| 183 | + } |
| 184 | + |
| 185 | + /** |
| 186 | + * liststreamkeys "stream-identifier" ( key(s) verbose count start local-ordering ) |
| 187 | + * |
| 188 | + * Returns stream keys. |
| 189 | + * |
| 190 | + * Arguments: |
| 191 | + * 1. "stream-identifier"(string, required) Stream identifier - one of the following: stream txid, stream reference, |
| 192 | + * stream name. |
| 193 | + * 2. "key" (string, optional, default=*) Stream key |
| 194 | + * or |
| 195 | + * 2. key(s) (array, optional) A json array of stream keys |
| 196 | + * 3. verbose (boolean, optional, default=false) If true, returns extended information about key |
| 197 | + * 4. count (number, optional, default=INT_MAX - all) The number of items to display |
| 198 | + * 5. start (number, optional, default=-count - last) Start from specific item, 0 based, if negative - from the end |
| 199 | + * 6. local-ordering (boolean, optional, default=false) If true, items appear in the order they were processed by |
| 200 | + * the wallet, if false - in the order they apppear in blockchain |
| 201 | + * |
| 202 | + * Result: |
| 203 | + * "stream-keys" (array) List of stream keys. |
| 204 | + * |
| 205 | + * @param streamName |
| 206 | + * @param key |
| 207 | + * @param verbose |
| 208 | + * @param count |
| 209 | + * @param start |
| 210 | + * @return |
| 211 | + * @throws MultichainException |
| 212 | + */ |
| 213 | + @SuppressWarnings("unchecked") |
| 214 | + public List<StreamKey> listStreamKeys(String streamName, String key, boolean verbose, int count, int start) |
| 215 | + throws MultichainException { |
| 216 | + List<StreamKey> streamKeys = new ArrayList<StreamKey>(); |
| 217 | + |
| 218 | + Object objectStreamKeys = executeListStreamKeys(streamName, key, verbose, count, start); |
| 219 | + if (verifyInstance(objectStreamKeys, ArrayList.class) |
| 220 | + && verifyInstanceofList((ArrayList<Object>) objectStreamKeys, StreamKey.class)) { |
| 221 | + streamKeys = StreamFormatter.formatStreamKeys((ArrayList<Object>) objectStreamKeys); |
| 222 | + } |
| 223 | + |
| 224 | + return streamKeys; |
| 225 | + } |
| 226 | + |
| 227 | + /** |
| 228 | + * {@link listStreamKeys(String streamName, String key, boolean verbose, int count, int start)} without start |
| 229 | + * |
| 230 | + * @param streamName |
| 231 | + * @param key |
| 232 | + * @param verbose |
| 233 | + * @param count |
| 234 | + * @return |
| 235 | + * @throws MultichainException |
| 236 | + */ |
| 237 | + @SuppressWarnings("unchecked") |
| 238 | + public List<StreamKey> listStreamKeys(String streamName, String key, boolean verbose, int count) |
| 239 | + throws MultichainException { |
| 240 | + List<StreamKey> streamKeys = new ArrayList<StreamKey>(); |
| 241 | + |
| 242 | + Object objectStreamKeys = executeListStreamKeys(streamName, key, verbose, count); |
| 243 | + if (verifyInstance(objectStreamKeys, ArrayList.class) |
| 244 | + && verifyInstanceofList((ArrayList<Object>) objectStreamKeys, StreamKey.class)) { |
| 245 | + streamKeys = StreamFormatter.formatStreamKeys((ArrayList<Object>) objectStreamKeys); |
| 246 | + } |
| 247 | + |
| 248 | + return streamKeys; |
| 249 | + } |
| 250 | + |
| 251 | + /** |
| 252 | + * {@link listStreamKeys(String streamName, String key, boolean verbose, int count, int start)} without start, with |
| 253 | + * count = 10 |
| 254 | + * |
| 255 | + * @param streamName |
| 256 | + * @param key |
| 257 | + * @param verbose |
| 258 | + * @param count |
| 259 | + * @return |
| 260 | + * @throws MultichainException |
| 261 | + */ |
| 262 | + public List<StreamKey> listStreamKeys(String streamName, String key, boolean verbose) throws MultichainException { |
| 263 | + return listStreamKeys(streamName, key, verbose, 10); |
| 264 | + } |
| 265 | + |
| 266 | + /** |
| 267 | + * {@link listStreamKeys(String streamName, String key, boolean verbose, int count, int start)} without start, with |
| 268 | + * count = 10, verbse = false |
| 269 | + * |
| 270 | + * @param streamName |
| 271 | + * @param key |
| 272 | + * @param verbose |
| 273 | + * @param count |
| 274 | + * @return |
| 275 | + * @throws MultichainException |
| 276 | + */ |
| 277 | + public List<StreamKey> listStreamKeys(String streamName, String key) throws MultichainException { |
| 278 | + return listStreamKeys(streamName, key, false, 10); |
| 279 | + } |
| 280 | + |
| 281 | + /** |
| 282 | + * {@link listStreamKeys(String streamName, String key, boolean verbose, int count, int start)} without start, with |
| 283 | + * count = 10, verbse = false, keys = "*" |
| 284 | + * |
| 285 | + * @param streamName |
| 286 | + * @param key |
| 287 | + * @param verbose |
| 288 | + * @param count |
| 289 | + * @return |
| 290 | + * @throws MultichainException |
| 291 | + */ |
| 292 | + public List<StreamKey> listStreamKeys(String streamName) throws MultichainException { |
| 293 | + return listStreamKeys(streamName, "*", false, 10); |
| 294 | + } |
| 295 | + |
83 | 296 | /** |
84 | 297 | * liststreamkeyitems "stream-identifier" "key" ( verbose count start |
85 | 298 | * local-ordering ) |
@@ -272,4 +485,25 @@ public void subscribe(String streamName) throws MultichainException { |
272 | 485 | executeSubscribe(streamName); |
273 | 486 | } |
274 | 487 |
|
| 488 | + /** |
| 489 | + * unsubscribe entity-identifier(s) |
| 490 | + * |
| 491 | + * Unsubscribes from the stream. |
| 492 | + * |
| 493 | + * Arguments: |
| 494 | + * 1. "stream-identifier" (string, required) Stream identifier - one of the following: stream txid, stream |
| 495 | + * reference, stream name. |
| 496 | + * or |
| 497 | + * 1. "asset-identifier" (string, required) Asset identifier - one of the following: asset txid, asset reference, |
| 498 | + * asset name. |
| 499 | + * or |
| 500 | + * 1. entity-identifier(s) (array, optional) A json array of stream or asset identifiers |
| 501 | + * |
| 502 | + * @param streamName |
| 503 | + * @throws MultichainException |
| 504 | + */ |
| 505 | + public void unsubscribe(String streamName) throws MultichainException { |
| 506 | + executeUnsubscribe(streamName); |
| 507 | + } |
| 508 | + |
275 | 509 | } |
0 commit comments