--- /dev/null
+/*
+ * 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);
+ }
+
+}
* @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.
/**
* {@inheritDoc}
*/
- public Project createProject() throws IOException, NoNodeException {
+ public Project createProject() throws IOException, JSiteException {
return projectManager.createProject();
}
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;
* 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");
}
try {
KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
+ } catch (HighLevelException hle1) {
+ throw new BackendException(hle1);
} catch (InterruptedException e) {
/* ignore. */
}
* @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]);
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;
* 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);
}
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);
}
identifierRequests.put(requestResult.getIdentifier(), request);
fireRequestAdded(request);
+ }
}
- }
- });
+ });
+ } catch (HighLevelException hle1) {
+ throw new BackendException(hle1);
+ }
}
//
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. */
}
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());
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;
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) {