Remove code based on old high-level client.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 22 May 2009 04:47:51 +0000 (06:47 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 22 May 2009 04:47:51 +0000 (06:47 +0200)
src/net/pterodactylus/jsite/core/RequestManager.java

index b4df6f2..ac9d588 100644 (file)
@@ -25,21 +25,8 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import net.pterodactylus.fcp.highlevel.GetRequestResult;
-import net.pterodactylus.fcp.highlevel.HighLevelCallback;
-import net.pterodactylus.fcp.highlevel.HighLevelCallbackListener;
-import net.pterodactylus.fcp.highlevel.HighLevelClient;
-import net.pterodactylus.fcp.highlevel.HighLevelException;
-import net.pterodactylus.fcp.highlevel.HighLevelProgress;
-import net.pterodactylus.fcp.highlevel.HighLevelProgressListener;
-import net.pterodactylus.fcp.highlevel.PutDirRequestResult;
-import net.pterodactylus.fcp.highlevel.PutRequestResult;
-import net.pterodactylus.fcp.highlevel.RequestListResult;
-import net.pterodactylus.fcp.highlevel.RequestResult;
-import net.pterodactylus.jsite.core.Request.Type;
 import net.pterodactylus.util.logging.Logging;
 
 /**
@@ -50,7 +37,7 @@ import net.pterodactylus.util.logging.Logging;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class RequestManager implements NodeListener, HighLevelProgressListener {
+public class RequestManager implements NodeListener {
 
        /** Logger. */
        private static final Logger logger = Logging.getLogger(RequestManager.class.getName());
@@ -186,54 +173,6 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
         *             if there is a problem with the node
         */
        private void getRequests(final Node node) throws IOException, JSiteException {
-               HighLevelClient highLevelClient = nodeManager.getHighLevelClient(node);
-               if (highLevelClient == null) {
-                       logger.log(Level.WARNING, "no client for node: " + node);
-                       return;
-               }
-               final Map<String, Request> identifierRequests = Collections.synchronizedMap(new HashMap<String, Request>());
-               nodeRequests.put(node, identifierRequests);
-               HighLevelCallback<RequestListResult> requestListCallback;
-               try {
-                       requestListCallback = highLevelClient.getRequests();
-                       requestListCallback.addHighLevelCallbackListener(new HighLevelCallbackListener<RequestListResult>() {
-
-                               @SuppressWarnings("synthetic-access")
-                               public void gotResult(HighLevelCallback<RequestListResult> highLevelCallback) {
-                                       RequestListResult requestListResult;
-                                       try {
-                                               requestListResult = highLevelCallback.getResult();
-                                       } catch (InterruptedException e) {
-                                               logger.log(Level.SEVERE, "getResult() blocked and was interrupted");
-                                               return;
-                                       }
-                                       for (RequestResult requestResult : requestListResult) {
-                                               String identifier = requestResult.getIdentifier();
-                                               logger.log(Level.FINER, "got identifier: " + identifier);
-                                               Request request = identifierRequests.get(identifier);
-                                               if (request == null) {
-                                                       request = new Request(node, identifier);
-                                               }
-                                               if (request.getType() == null) {
-                                                       if (requestResult instanceof GetRequestResult) {
-                                                               request.setType(Type.get);
-                                                       } else if (requestResult instanceof PutRequestResult) {
-                                                               request.setType(Type.put);
-                                                       } else if (requestResult instanceof PutDirRequestResult) {
-                                                               request.setType(Type.putDir);
-                                                       }
-                                               }
-                                               if (identifierRequests.containsKey(identifier)) {
-                                                       continue;
-                                               }
-                                               identifierRequests.put(requestResult.getIdentifier(), request);
-                                               fireRequestAdded(request);
-                                       }
-                               }
-                       });
-               } catch (HighLevelException hle1) {
-                       throw new BackendException(hle1);
-               }
        }
 
        //
@@ -244,45 +183,18 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
         * {@inheritDoc}
         */
        public void nodeAdded(Node node) {
-               HighLevelClient highLevelClient = nodeManager.getHighLevelClient(node);
-               if (highLevelClient == null) {
-                       logger.warning("got nodeAdded but no high-level client: " + node);
-                       return;
-               }
-               highLevelClient.addHighLevelProgressListener(this);
        }
 
        /**
         * {@inheritDoc}
         */
        public void nodeRemoved(Node node) {
-               HighLevelClient highLevelClient = nodeManager.getHighLevelClient(node);
-               if (highLevelClient == null) {
-                       logger.warning("got nodeRemoved but no high-level client: " + node);
-                       return;
-               }
-               highLevelClient.removeHighLevelProgressListener(this);
        }
 
        /**
         * {@inheritDoc}
         */
        public void nodeConnected(Node node) {
-               HighLevelClient highLevelClient = nodeManager.getHighLevelClient(node);
-               if (highLevelClient == null) {
-                       logger.log(Level.WARNING, "got no high-level client for node " + node);
-                       return;
-               }
-               try {
-                       highLevelClient.setWatchGlobal(true);
-                       getRequests(node);
-               } catch (HighLevelException hle1) {
-                       logger.log(Level.WARNING, "error in backend", hle1);
-               } catch (JSiteException jse1) {
-                       logger.log(Level.WARNING, "error in backend", jse1);
-               } catch (IOException e) {
-                       /* ignore exception, disconnects are handled elsewhere. */
-               }
        }
 
        /**
@@ -307,51 +219,4 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                identifierRequests.clear();
        }
 
-       //
-       // INTERFACE HighLevelProgressListener
-       //
-
-       /**
-        * @see net.pterodactylus.fcp.highlevel.HighLevelProgressListener#progressReceived(HighLevelClient,
-        *      String, HighLevelProgress)
-        */
-       public void progressReceived(HighLevelClient highLevelClient, String identifier, HighLevelProgress highLevelProgress) {
-               Node node = nodeManager.getNode(highLevelClient);
-               if (node == null) {
-                       logger.warning("got high-level client without node: " + highLevelClient);
-                       return;
-               }
-               Map<String, Request> identifierRequests = nodeRequests.get(node);
-               if (identifierRequests == null) {
-                       logger.warning("got node without request map: " + node);
-                       identifierRequests = Collections.synchronizedMap(new HashMap<String, Request>());
-                       nodeRequests.put(node, identifierRequests);
-               }
-               Request request = identifierRequests.get(identifier);
-               if (request == null) {
-                       logger.warning("got progress for unknown request: " + identifier);
-                       request = new Request(node, identifier);
-                       identifierRequests.put(identifier, request);
-                       fireRequestAdded(request);
-               }
-               if (highLevelProgress.isFinished()) {
-                       request.setFinished(true);
-                       request.setSuccessful(!highLevelProgress.isFailed());
-                       fireRequestFinished(request);
-               } else if (highLevelProgress.isFetchable()) {
-                       /* TODO - ignore? */
-               } else if (highLevelProgress.getURI() != null) {
-                       request.setURI(highLevelProgress.getURI());
-                       fireRequestGeneratedURI(request, highLevelProgress.getURI());
-               } else {
-                       request.setTotalBlocks(highLevelProgress.getTotalBlocks());
-                       request.setRequiredBlocks(highLevelProgress.getRequiredBlocks());
-                       request.setSuccessfulBlocks(highLevelProgress.getSuccessfulBlocks());
-                       request.setFailedBlocks(highLevelProgress.getFailedBlocks());
-                       request.setFatallyFailedBlocks(highLevelProgress.getFatallyFailedBlocks());
-                       request.setTotalFinalized(highLevelProgress.isTotalFinalized());
-                       fireRequestProgressed(request);
-               }
-       }
-
 }