e2d49466f3fc7c5134a1092e4dd8a0bd4869884e
[jSite2.git] / src / net / pterodactylus / jsite / core / CoreListener.java
1 /*
2  * jSite2 - UserInterface.java -
3  * Copyright © 2008 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package net.pterodactylus.jsite.core;
21
22 import net.pterodactylus.jsite.project.Project;
23
24 /**
25  * Interface definition for user interfaces.
26  * 
27  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
28  * @version $Id$
29  */
30 public interface CoreListener {
31
32         //
33         // project configuration
34         //
35
36         /**
37          * Notifies a listener that loading the projects finished successfully.
38          * 
39          * @param directory
40          *            The directory the nodes were loaded from
41          */
42         public void loadingProjectsDone(String directory);
43
44         /**
45          * Notifies all listeners that loading the projects has failed.
46          * 
47          * @param directory
48          *            The directory the projects were tried to load from
49          * @param throwable
50          *            The exception that occured while saving, if any
51          */
52         public void loadingProjectsFailed(String directory, Throwable throwable);
53
54         /**
55          * Notifies a listener that the projects were successfully saved to the
56          * given directory.
57          * 
58          * @param directory
59          *            The directory the projects were saved to
60          */
61         public void savingProjectsDone(String directory);
62
63         /**
64          * Notifies a listener that saving the projects has failed.
65          * 
66          * @param directory
67          *            The directory the projects were to be saved to
68          * @param throwable
69          *            The exception that occured when saving the projects, if any
70          */
71         public void savingProjectsFailed(String directory, Throwable throwable);
72
73         //
74         // node configuration
75         //
76
77         /**
78          * Notifies a listener that the nodes were successfully loaded.
79          * 
80          * @param directory
81          *            The directory the nodes were loaded from
82          */
83         public void loadingNodesDone(String directory);
84
85         /**
86          * Notifies a listener that loading the nodes has failed.
87          * 
88          * @param directory
89          *            The directory the nodes were loaded from
90          * @param throwable
91          *            The exception that occured while loading the nodes
92          */
93         public void loadingNodesFailed(String directory, Throwable throwable);
94
95         /**
96          * Notifies a listener that the nodes were successfully saved.
97          * 
98          * @param directory
99          *            The directory the nodes were saved to
100          */
101         public void savingNodesDone(String directory);
102
103         /**
104          * Notifies a listener that saving the nodes has failed.
105          * 
106          * @param directory
107          *            The directory the nodes were saved to
108          * @param throwable
109          *            The exception that occured while saving the nodes
110          */
111         public void savingNodesFailed(String directory, Throwable throwable);
112
113         //
114         // basic core functionality
115         //
116
117         /**
118          * Notifies all listeners that the core has loaded.
119          */
120         public void coreLoaded();
121
122         /**
123          * Notifies a listener that the core was stopped.
124          */
125         public void coreStopped();
126
127         //
128         // node stuff
129         //
130
131         /**
132          * Notifies a listener that a node was added to the core.
133          * 
134          * @param node
135          *            The node that was added.
136          */
137         public void nodeAdded(Node node);
138
139         /**
140          * Notifies a listener that a node was removed from the core. Before a node
141          * is removed, it will be disconnected (and
142          * {@link #nodeDisconnected(Node, Throwable)} will be called).
143          * 
144          * @param node
145          *            The node that was removed
146          */
147         public void nodeRemoved(Node node);
148
149         /**
150          * Notifies all listeners that the core started connecting to the given
151          * node. Before a node is connected, it will be added (and
152          * {@link #nodeAdded(Node)} will be called).
153          * 
154          * @param node
155          *            The node that is being connected
156          */
157         public void nodeConnecting(Node node);
158
159         /**
160          * Notifies all listeners that the core connected to the given node.
161          * 
162          * @param node
163          *            The node that is connected
164          */
165         public void nodeConnected(Node node);
166
167         /**
168          * Notifies a listener that a connection to a node has failed.
169          * 
170          * @param node
171          *            The node that could not be connected
172          * @param cause
173          *            The cause of the failure
174          */
175         public void nodeConnectionFailed(Node node, Throwable cause);
176
177         /**
178          * Notifies all listeners that the core disconnected from the given node.
179          * 
180          * @param node
181          *            The node that was diconnected
182          * @param throwable
183          *            The exception that caused the disconnect, or <code>null</code>
184          *            if there was no exception
185          */
186         public void nodeDisconnected(Node node, Throwable throwable);
187
188         //
189         // project insertion stuff
190         //
191
192         /**
193          * Notifies a listener that a project insert started.
194          * 
195          * @param project
196          *            The project that is now inserting
197          */
198         public void projectInsertStarted(Project project);
199
200         /**
201          * Notifies a listener that a project insert made progress.
202          * 
203          * @param project
204          *            The project that made progress
205          * @param totalBlocks
206          *            The number of total blocks
207          * @param requiredBlocks
208          *            The number of required blocks
209          * @param successfulBlocks
210          *            The number of successfully inserted blocks
211          * @param failedBlocks
212          *            The number of blocks that could not be inserted
213          * @param fatallyFailedBlocks
214          *            The number of blocks that can not be inserted even with
215          *            retries
216          * @param finalizedTotal
217          *            <code>true</code> if the number of total blocks is already
218          *            finalized, <code>false</code> otherwise
219          */
220         public void projectInsertProgressed(Project project, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean finalizedTotal);
221
222         /**
223          * Notifies a listener that a project insert has generated a URI.
224          * 
225          * @param project
226          *            The project that generated a URI
227          * @param uri
228          *            The URI that was generated
229          */
230         public void projectInsertGeneratedURI(Project project, String uri);
231
232         /**
233          * Notifies a listener that a project insert has finished.
234          * 
235          * @param project
236          *            The project that has finished
237          * @param success
238          *            <code>true</code> if the project was inserted successfully,
239          *            <code>false</code> otherwise
240          */
241         public void projectInsertFinished(Project project, boolean success);
242
243 }