+ * Adds the peer whose noderef is stored in the given file.
+ *
+ * @param nodeRefFile
+ * The name of the file the peer’s noderef is stored in
+ * @return A peer callback
+ * @throws IOException
+ * if an I/O error occurs communicating with the node
+ */
+ public HighLevelCallback<PeerResult> addPeer(String nodeRefFile) throws IOException {
+ String identifier = generateIdentifier("addPeer");
+ AddPeer addPeer = new AddPeer(nodeRefFile);
+ HighLevelCallback<PeerResult> peerCallback = new HighLevelCallback<PeerResult>(new PeerResult(identifier));
+ peerCallbacks.put(identifier, peerCallback);
+ fcpConnection.sendMessage(addPeer);
+ return peerCallback;
+ }
+
+ /**
+ * Adds the peer whose noderef is stored in the given file.
+ *
+ * @param nodeRefURL
+ * The URL where the peer’s noderef is stored
+ * @return A peer callback
+ * @throws IOException
+ * if an I/O error occurs communicating with the node
+ */
+ public HighLevelCallback<PeerResult> addPeer(URL nodeRefURL) throws IOException {
+ String identifier = generateIdentifier("addPeer");
+ AddPeer addPeer = new AddPeer(nodeRefURL);
+ HighLevelCallback<PeerResult> peerCallback = new HighLevelCallback<PeerResult>(new PeerResult(identifier));
+ peerCallbacks.put(identifier, peerCallback);
+ fcpConnection.sendMessage(addPeer);
+ return peerCallback;
+ }
+
+ /**
+ * Adds the peer whose noderef is stored in the given file.
+ *
+ * @param nodeRef
+ * The peer’s noderef
+ * @return A peer callback
+ * @throws IOException
+ * if an I/O error occurs communicating with the node
+ */
+ public HighLevelCallback<PeerResult> addPeer(NodeRef nodeRef) throws IOException {
+ String identifier = generateIdentifier("addPeer");
+ AddPeer addPeer = new AddPeer(nodeRef);
+ HighLevelCallback<PeerResult> peerCallback = new HighLevelCallback<PeerResult>(new PeerResult(identifier));
+ peerCallbacks.put(identifier, peerCallback);
+ fcpConnection.sendMessage(addPeer);
+ return peerCallback;
+ }
+
+ /**
+ * Checks whether direct disk access for the given directory is possible.
+ * You have to perform this check before you can upload or download anything
+ * from or the disk directly!
+ *
+ * @param directory
+ * The directory to check
+ * @param wantRead
+ * Whether you want to read the given directory
+ * @param wantWrite
+ * Whether you want to write to the given directory
+ * @return A direct disk access callback
+ * @throws IOException
+ */
+ public HighLevelCallback<DirectDiskAccessResult> checkDirectDiskAccess(String directory, boolean wantRead, boolean wantWrite) throws IOException {
+ TestDDARequest testDDARequest = new TestDDARequest(directory, wantRead, wantWrite);
+ HighLevelCallback<DirectDiskAccessResult> directDiskAccessCallback = new HighLevelCallback<DirectDiskAccessResult>(new DirectDiskAccessResult(directory));
+ directDiskAccessCallbacks.put(directory, directDiskAccessCallback);
+ fcpConnection.sendMessage(testDDARequest);
+ return directDiskAccessCallback;
+ }
+
+ /**
+ * Starts a download. Files can either be download to disk or streamed from
+ * the node. When downloading to disk you have to perform a direct disk
+ * access check for the directory you want to put the downloaded file in!
+ *
+ * @see #checkDirectDiskAccess(String, boolean, boolean)
+ * @param uri
+ * The URI to get
+ * @param filename
+ * The filename to save the data to, or <code>null</code> to
+ * retrieve the data as InputStream from the
+ * {@link DownloadResult}
+ * @param global
+ * Whether to put the download on the global queue
+ * @return A download result
+ * @throws IOException
+ * if an I/O error occurs communicating with the node
+ */
+ public HighLevelProgressCallback<DownloadResult> download(String uri, String filename, boolean global) throws IOException {
+ String identifier = generateIdentifier("download");
+ ClientGet clientGet = new ClientGet(uri, identifier, (filename == null) ? ReturnType.direct : ReturnType.disk);
+ clientGet.setGlobal(global);
+ HighLevelProgressCallback<DownloadResult> downloadCallback = new HighLevelProgressCallback<DownloadResult>(new DownloadResult(identifier));
+ downloadCallbacks.put(identifier, downloadCallback);
+ fcpConnection.sendMessage(clientGet);
+ return downloadCallback;
+ }
+
+ /**
+ * Requests a list of all running requests from the node.
+ *
+ * @return The request list result
+ * @throws IOException
+ * if an I/O errors communicating with the node
+ */
+ public HighLevelCallback<RequestListResult> getRequests() throws IOException {
+ String identifier = generateIdentifier("list-persistent-requests");
+ ListPersistentRequests listPersistentRequests = new ListPersistentRequests();
+ synchronized (syncObject) {
+ if (requestListCallback != null) {
+ logger.log(Level.SEVERE, "getRequests() called with request still running!");
+ }
+ requestListCallback = new HighLevelCallback<RequestListResult>(new RequestListResult(identifier));
+ }
+ fcpConnection.sendMessage(listPersistentRequests);
+ return requestListCallback;
+ }
+
+ //
+ // PRIVATE METHODS
+ //
+
+ /**