+ }
+
+ }
+
+ }
+
+ @Override
+ public ClientGetCommand clientGet() {
+ return new ClientGetCommandImpl();
+ }
+
+ private class ClientGetCommandImpl implements ClientGetCommand {
+
+ private String identifier;
+ private boolean ignoreDataStore;
+ private boolean dataStoreOnly;
+ private Long maxSize;
+ private Priority priority;
+ private boolean realTime;
+ private boolean global;
+
+ @Override
+ public ClientGetCommand identifier(String identifier) {
+ this.identifier = identifier;
+ return this;
+ }
+
+ @Override
+ public ClientGetCommand ignoreDataStore() {
+ ignoreDataStore = true;
+ return this;
+ }
+
+ @Override
+ public ClientGetCommand dataStoreOnly() {
+ dataStoreOnly = true;
+ return this;
+ }
+
+ @Override
+ public ClientGetCommand maxSize(long maxSize) {
+ this.maxSize = maxSize;
+ return this;
+ }
+
+ @Override
+ public ClientGetCommand priority(Priority priority) {
+ this.priority = priority;
+ return this;
+ }
+
+ @Override
+ public ClientGetCommand realTime() {
+ realTime = true;
+ return this;
+ }
+
+ @Override
+ public ClientGetCommand global() {
+ global = true;
+ return this;
+ }
+
+ @Override
+ public Future<Optional<Data>> uri(String uri) {
+ return threadPool.submit(new Callable<Optional<Data>>() {
+ @Override
+ public Optional<Data> call() throws Exception {
+ DefaultFcpClient.this.connect();
+ ClientGet clientGet = new ClientGet(uri, identifier, ReturnType.direct);
+ if (ignoreDataStore) {
+ clientGet.setIgnoreDataStore(true);
+ }
+ if (dataStoreOnly) {
+ clientGet.setDataStoreOnly(true);
+ }
+ if (maxSize != null) {
+ clientGet.setMaxSize(maxSize);
+ }
+ if (priority != null) {
+ clientGet.setPriority(priority);
+ }
+ if (realTime) {
+ clientGet.setRealTimeFlag(true);
+ }
+ if (global) {
+ clientGet.setGlobal(true);
+ }
+ try (FcpReplySequence replySequence = new FcpReplySequence(threadPool, fcpConnection.get())) {
+ Sequence sequence = new Sequence(identifier);
+ replySequence.handle(AllData.class).with(sequence::allData);
+ replySequence.handle(GetFailed.class).with(sequence::getFailed);
+ replySequence.handleClose().with(sequence::disconnect);
+ replySequence.waitFor(sequence::isFinished);
+ replySequence.send(clientGet).get();
+ return sequence.isSuccessful() ? Optional.of(sequence.getData()) : Optional.empty();
+ }
+ }