From 9030b0e6266f4962aee282fa3ec689547775b925 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 19 May 2008 08:47:30 +0000 Subject: [PATCH] change exception stuff a bit git-svn-id: http://trooper/svn/projects/jSite/trunk@918 c3eda9e8-030b-0410-8277-bc7414b0a119 --- .../pterodactylus/jsite/core/BackendException.java | 69 ++++++++++++++++++++++ src/net/pterodactylus/jsite/core/Core.java | 6 +- src/net/pterodactylus/jsite/core/CoreImpl.java | 2 +- src/net/pterodactylus/jsite/core/NodeManager.java | 9 ++- .../pterodactylus/jsite/core/ProjectManager.java | 6 +- .../pterodactylus/jsite/core/RequestManager.java | 54 ++++++++++------- .../pterodactylus/jsite/gui/SwingInterface.java | 4 +- 7 files changed, 117 insertions(+), 33 deletions(-) create mode 100644 src/net/pterodactylus/jsite/core/BackendException.java diff --git a/src/net/pterodactylus/jsite/core/BackendException.java b/src/net/pterodactylus/jsite/core/BackendException.java new file mode 100644 index 0000000..1c4d2a6 --- /dev/null +++ b/src/net/pterodactylus/jsite/core/BackendException.java @@ -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 <bombe@freenetproject.org> + * @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); + } + +} diff --git a/src/net/pterodactylus/jsite/core/Core.java b/src/net/pterodactylus/jsite/core/Core.java index 0599a76..ba0b452 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -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. diff --git a/src/net/pterodactylus/jsite/core/CoreImpl.java b/src/net/pterodactylus/jsite/core/CoreImpl.java index 5fc0e26..fdf008d 100644 --- a/src/net/pterodactylus/jsite/core/CoreImpl.java +++ b/src/net/pterodactylus/jsite/core/CoreImpl.java @@ -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(); } diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index b9404c7..079e367 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -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, PropertyChangeListener, High * public key at index 1 * @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, 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. */ } diff --git a/src/net/pterodactylus/jsite/core/ProjectManager.java b/src/net/pterodactylus/jsite/core/ProjectManager.java index 5bb4c75..ca07a4d 100644 --- a/src/net/pterodactylus/jsite/core/ProjectManager.java +++ b/src/net/pterodactylus/jsite/core/ProjectManager.java @@ -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]); diff --git a/src/net/pterodactylus/jsite/core/RequestManager.java b/src/net/pterodactylus/jsite/core/RequestManager.java index d2b1bde..4e23d79 100644 --- a/src/net/pterodactylus/jsite/core/RequestManager.java +++ b/src/net/pterodactylus/jsite/core/RequestManager.java @@ -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 identifierRequests = Collections.synchronizedMap(new HashMap()); nodeRequests.put(node, identifierRequests); - HighLevelCallback requestListCallback = highLevelClient.getRequests(); - requestListCallback.addHighLevelCallbackListener(new HighLevelCallbackListener() { + HighLevelCallback requestListCallback; + try { + requestListCallback = highLevelClient.getRequests(); + requestListCallback.addHighLevelCallbackListener(new HighLevelCallbackListener() { - @SuppressWarnings("synthetic-access") - public void gotResult(HighLevelCallback 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 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()); diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index 49913ce..4381ea8 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -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) { -- 2.7.4