+ //
+ // PRIVATE METHODS
+ //
+
+ /**
+ * Searches all callback collections for a callback with the given
+ * identifier and cancels it.
+ *
+ * @param identifier
+ * The identifier to search for, or <code>null</code> to
+ * cancel all pending requests
+ */
+ @SuppressWarnings("synthetic-access")
+ private void cancelIdentifier(String identifier) {
+ synchronized (syncObject) {
+ if (connectCallback != null) {
+ connectCallback.getIntermediaryResult().setFailed(true);
+ connectCallback.setDone();
+ connectCallback = null;
+ }
+ }
+ if (identifier == null) {
+ /* key generation callbacks */
+ for (Entry<String, HighLevelCallback<KeyGenerationResult>> keyGenerationEntry: keyGenerationCallbacks.entrySet()) {
+ keyGenerationEntry.getValue().getIntermediaryResult().setFailed(true);
+ keyGenerationEntry.getValue().setDone();
+ }
+ keyGenerationCallbacks.clear();
+ /* peer list callbacks. */
+ for (Entry<String, HighLevelCallback<PeerListResult>> peerListEntry: peerListCallbacks.entrySet()) {
+ peerListEntry.getValue().getIntermediaryResult().setFailed(true);
+ peerListEntry.getValue().setDone();
+ }
+ peerListCallbacks.clear();
+ /* peer callbacks. */
+ for (Entry<String, HighLevelCallback<PeerResult>> peerEntry: peerCallbacks.entrySet()) {
+ peerEntry.getValue().getIntermediaryResult().setFailed(true);
+ peerEntry.getValue().setDone();
+ }
+ peerCallbacks.clear();
+ /* direct disk access callbacks. */
+ for (Entry<String, HighLevelCallback<DirectDiskAccessResult>> directDiskAccessEntry: directDiskAccessCallbacks.entrySet()) {
+ directDiskAccessEntry.getValue().getIntermediaryResult().setFailed(true);
+ directDiskAccessEntry.getValue().setDone();
+ }
+ directDiskAccessCallbacks.clear();
+ } else {
+ HighLevelCallback<KeyGenerationResult> keyGenerationCallback = keyGenerationCallbacks.remove(identifier);
+ if (keyGenerationCallback != null) {
+ keyGenerationCallback.getIntermediaryResult().setFailed(true);
+ keyGenerationCallback.setDone();
+ return;
+ }
+ HighLevelCallback<PeerListResult> peerListCallback = peerListCallbacks.remove(identifier);
+ if (peerListCallback != null) {
+ peerListCallback.getIntermediaryResult().setFailed(true);
+ peerListCallback.setDone();
+ return;
+ }
+ HighLevelCallback<PeerResult> peerCallback = peerCallbacks.remove(identifier);
+ if (peerCallback != null) {
+ peerCallback.getIntermediaryResult().setFailed(true);
+ peerCallback.setDone();
+ return;
+ }
+ HighLevelCallback<DirectDiskAccessResult> directDiskAccessCallback = directDiskAccessCallbacks.remove(identifier);
+ if (directDiskAccessCallback != null) {
+ directDiskAccessCallback.getIntermediaryResult().setFailed(true);
+ directDiskAccessCallback.setDone();
+ return;
+ }
+ }
+ }
+
+ /**
+ * Reads the given file and returns the first line of the file.
+ *
+ * @param readFilename
+ * The name of the file to read
+ * @return The content of the file
+ */
+ private String readContent(String readFilename) {
+ FileReader fileReader = null;
+ BufferedReader bufferedFileReader = null;
+ try {
+ fileReader = new FileReader(readFilename);
+ bufferedFileReader = new BufferedReader(fileReader);
+ String content = bufferedFileReader.readLine();
+ return content;
+ } catch (IOException ioe1) {
+ /* swallow. */
+ } finally {
+ FcpUtils.close(bufferedFileReader);
+ FcpUtils.close(fileReader);
+ }
+ return null;
+ }
+
+ /**
+ * Writes the given content to the given file.
+ *
+ * @param directDiskAccessResult
+ * The DDA result
+ * @param writeFilename
+ * The name of the file to write to
+ * @param writeContent
+ * The content to write to the file
+ */
+ private void writeContent(DirectDiskAccessResult directDiskAccessResult, String writeFilename, String writeContent) {
+ if ((writeFilename == null) || (writeContent == null)) {
+ return;
+ }
+ writtenFiles.put(directDiskAccessResult, writeFilename);
+ FileWriter fileWriter = null;
+ try {
+ fileWriter = new FileWriter(writeFilename);
+ fileWriter.write(writeContent);
+ } catch (IOException ioe1) {
+ /* swallow. */
+ } finally {
+ FcpUtils.close(fileWriter);
+ }
+ }
+
+ /**
+ * Cleans up any files that written for the given result.
+ *
+ * @param directDiskAccessResult
+ * The direct disk access result
+ */
+ @SuppressWarnings("synthetic-access")
+ private void cleanFiles(DirectDiskAccessResult directDiskAccessResult) {
+ String writeFilename = writtenFiles.remove(directDiskAccessResult);
+ if (writeFilename != null) {
+ if (!new File(writeFilename).delete()) {
+ logger.warning("could not delete " + writeFilename);
+ }
+ }
+ }
+
+ //
+ // INTERFACE FcpListener
+ //
+