Wrapped FCP API requests into jSite requests.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 23 May 2009 15:35:51 +0000 (17:35 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 23 May 2009 15:35:51 +0000 (17:35 +0200)
src/net/pterodactylus/jsite/core/RequestManager.java

index cc381cf..23184b9 100644 (file)
@@ -23,13 +23,13 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import net.pterodactylus.fcp.highlevel.FcpClient;
 import net.pterodactylus.fcp.highlevel.FcpException;
-import net.pterodactylus.fcp.highlevel.Request;
 import net.pterodactylus.jsite.util.IdGenerator;
 import net.pterodactylus.util.number.Hex;
 
@@ -99,6 +99,23 @@ public class RequestManager implements NodeListener {
                return true;
        }
 
+       /**
+        * Wraps the requests of the FCP API into jSite requests.
+        *
+        * @param requests
+        *            The requests to wrap
+        * @return The wrapped requests
+        */
+       private Collection<Request> wrapRequests(Collection<net.pterodactylus.fcp.highlevel.Request> requests) {
+               Collection<Request> wrappedRequests = new HashSet<Request>();
+               for (net.pterodactylus.fcp.highlevel.Request request : requests) {
+                       Request wrappedRequest = new Request(request.getIdentifier());
+                       wrappedRequest.setClientToken(request.getClientToken());
+                       wrappedRequests.add(wrappedRequest);
+               }
+               return wrappedRequests;
+       }
+
        //
        // INTERFACE NodeListener
        //
@@ -120,7 +137,7 @@ public class RequestManager implements NodeListener {
                        return;
                }
                try {
-                       Collection<Request> requests = fcpClient.getRequests(true);
+                       Collection<Request> requests = wrapRequests(fcpClient.getRequests(true));
                        for (Request request : requests) {
                                String clientToken = request.getClientToken();
                                if ((clientToken == null) || (clientToken.trim().length() == 0)) {