change exception stuff a bit
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 May 2008 08:47:30 +0000 (08:47 +0000)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 19 May 2008 08:47:30 +0000 (08:47 +0000)
git-svn-id: http://trooper/svn/projects/jSite/trunk@918 c3eda9e8-030b-0410-8277-bc7414b0a119

src/net/pterodactylus/jsite/core/BackendException.java [new file with mode: 0644]
src/net/pterodactylus/jsite/core/Core.java
src/net/pterodactylus/jsite/core/CoreImpl.java
src/net/pterodactylus/jsite/core/NodeManager.java
src/net/pterodactylus/jsite/core/ProjectManager.java
src/net/pterodactylus/jsite/core/RequestManager.java
src/net/pterodactylus/jsite/gui/SwingInterface.java

diff --git a/src/net/pterodactylus/jsite/core/BackendException.java b/src/net/pterodactylus/jsite/core/BackendException.java
new file mode 100644 (file)
index 0000000..1c4d2a6
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * jSite2 - BackendException.java
+ * Copyright © 2008 David Roden
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package net.pterodactylus.jsite.core;
+
+/**
+ * Exception that is thrown when there is a problem with the FCP backend.
+ * 
+ * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
+ * @version $Id$
+ */
+public class BackendException extends JSiteException {
+
+       /**
+        * Creates a new backend exception.
+        */
+       public BackendException() {
+               super();
+       }
+
+       /**
+        * Creates a new backend exception with the given message.
+        * 
+        * @param message
+        *            The message of the exception
+        */
+       public BackendException(String message) {
+               super(message);
+       }
+
+       /**
+        * Creates a new backend exception with the given cause.
+        * 
+        * @param cause
+        *            The cause of the exception
+        */
+       public BackendException(Throwable cause) {
+               super(cause);
+       }
+
+       /**
+        * Creates a new backend exception with the given message and cause.
+        * 
+        * @param message
+        *            The message of the exception
+        * @param cause
+        *            The cause of the exception
+        */
+       public BackendException(String message, Throwable cause) {
+               super(message, cause);
+       }
+
+}
index 0599a76..ba0b452 100644 (file)
@@ -117,10 +117,10 @@ public interface Core {
         * @return A newly created project
         * @throws IOException
         *             if an I/O error occured communicating with the node
-        * @throws NoNodeException
-        *             if no node is configured
+        * @throws JSiteException
+        *             if there is a problem with the node
         */
-       public Project createProject() throws IOException, NoNodeException;
+       public Project createProject() throws IOException, JSiteException;
 
        /**
         * Returns a list of all projects.
index 5fc0e26..fdf008d 100644 (file)
@@ -448,7 +448,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener {
        /**
         * {@inheritDoc}
         */
-       public Project createProject() throws IOException, NoNodeException {
+       public Project createProject() throws IOException, JSiteException {
                return projectManager.createProject();
        }
 
index b9404c7..079e367 100644 (file)
@@ -40,6 +40,7 @@ import java.util.logging.Logger;
 
 import net.pterodactylus.fcp.highlevel.HighLevelClient;
 import net.pterodactylus.fcp.highlevel.HighLevelClientListener;
+import net.pterodactylus.fcp.highlevel.HighLevelException;
 import net.pterodactylus.fcp.highlevel.KeyGenerationResult;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
@@ -429,10 +430,10 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         *         public key at index <code>1</code>
         * @throws IOException
         *             if an I/O error occurs communicating with the node
-        * @throws NoNodeException
-        *             if no node is configured
+        * @throws JSiteException
+        *             if there is a problem with the node
         */
-       public String[] generateKeyPair() throws IOException, NoNodeException {
+       public String[] generateKeyPair() throws IOException, JSiteException {
                if (nodes.isEmpty()) {
                        throw new NoNodeException("no node configured");
                }
@@ -441,6 +442,8 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                try {
                        KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
                        return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
+               } catch (HighLevelException hle1) {
+                       throw new BackendException(hle1);
                } catch (InterruptedException e) {
                        /* ignore. */
                }
index 5bb4c75..ca07a4d 100644 (file)
@@ -180,10 +180,10 @@ public class ProjectManager {
         * @return A newly created project
         * @throws IOException
         *             if an I/O error occured communicating with the node
-        * @throws NoNodeException
-        *             if no node is configured
+        * @throws JSiteException
+        *             if there is a problem with the node
         */
-       public Project createProject() throws IOException, NoNodeException {
+       public Project createProject() throws IOException, JSiteException {
                Project project = new Project();
                String[] keyPair = nodeManager.generateKeyPair();
                project.setPrivateKey(keyPair[0]);
index d2b1bde..4e23d79 100644 (file)
@@ -32,6 +32,7 @@ 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;
@@ -155,8 +156,10 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
         *            The node to get all requests for
         * @throws IOException
         *             if an I/O error occurs while communicating with the node
+        * @throws JSiteException
+        *             if there is a problem with the node
         */
-       private void getRequests(final Node node) throws IOException {
+       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);
@@ -164,19 +167,21 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                }
                final Map<String, Request> identifierRequests = Collections.synchronizedMap(new HashMap<String, Request>());
                nodeRequests.put(node, identifierRequests);
-               HighLevelCallback<RequestListResult> requestListCallback = highLevelClient.getRequests();
-               requestListCallback.addHighLevelCallbackListener(new HighLevelCallbackListener<RequestListResult>() {
+               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) {
+                               @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);
@@ -197,9 +202,12 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                                                }
                                                identifierRequests.put(requestResult.getIdentifier(), request);
                                                fireRequestAdded(request);
+                                       }
                                }
-                       }
-               });
+                       });
+               } catch (HighLevelException hle1) {
+                       throw new BackendException(hle1);
+               }
        }
 
        //
@@ -242,6 +250,10 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                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. */
                }
@@ -290,12 +302,12 @@ public class RequestManager implements NodeListener, HighLevelProgressListener {
                        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 (request == null) {
+                       logger.warning("got progress for unknown request: " + identifier);
+                       request = new Request(node, identifier);
+                       identifierRequests.put(identifier, request);
+                       fireRequestAdded(request);
+               }
                request.setTotalBlocks(highLevelProgress.getTotalBlocks());
                request.setRequiredBlocks(highLevelProgress.getRequiredBlocks());
                request.setSuccessfulBlocks(highLevelProgress.getSuccessfulBlocks());
index 49913ce..4381ea8 100644 (file)
@@ -46,7 +46,7 @@ import javax.swing.UnsupportedLookAndFeelException;
 
 import net.pterodactylus.jsite.core.Core;
 import net.pterodactylus.jsite.core.CoreListener;
-import net.pterodactylus.jsite.core.NoNodeException;
+import net.pterodactylus.jsite.core.JSiteException;
 import net.pterodactylus.jsite.core.Node;
 import net.pterodactylus.jsite.core.Project;
 import net.pterodactylus.jsite.core.Request;
@@ -823,7 +823,7 @@ public class SwingInterface implements CoreListener, LoggingListener {
                        mainWindow.addProject(project);
                        project.setName(I18n.get("general.newProject.name"));
                        project.setDescription(I18n.get("general.newProject.description", new Date()));
-               } catch (NoNodeException nne1) {
+               } catch (JSiteException nne1) {
                        /* TODO - add i18n */
                        JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
                } catch (IOException e) {