make connections work
[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 /**
23  * Interface definition for user interfaces.
24  * 
25  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
26  * @version $Id$
27  */
28 public interface CoreListener {
29
30         //
31         // project configuration
32         //
33
34         /**
35          * Notifies a listener that loading the projects finished successfully.
36          * 
37          * @param directory
38          *            The directory the nodes were loaded from
39          */
40         public void loadingProjectsDone(String directory);
41
42         /**
43          * Notifies all listeners that loading the projects has failed.
44          * 
45          * @param directory
46          *            The directory the projects were tried to load from
47          * @param throwable
48          *            The exception that occured while saving, if any
49          */
50         public void loadingProjectsFailed(String directory, Throwable throwable);
51
52         /**
53          * Notifies a listener that the projects were successfully saved to the
54          * given directory.
55          * 
56          * @param directory
57          *            The directory the projects were saved to
58          */
59         public void savingProjectsDone(String directory);
60
61         /**
62          * Notifies a listener that saving the projects has failed.
63          * 
64          * @param directory
65          *            The directory the projects were to be saved to
66          * @param throwable
67          *            The exception that occured when saving the projects, if any
68          */
69         public void savingProjectsFailed(String directory, Throwable throwable);
70
71         //
72         // node configuration
73         //
74
75         /**
76          * Notifies a listener that the nodes were successfully loaded.
77          * 
78          * @param directory
79          *            The directory the nodes were loaded from
80          */
81         public void loadingNodesDone(String directory);
82
83         /**
84          * Notifies a listener that loading the nodes has failed.
85          * 
86          * @param directory
87          *            The directory the nodes were loaded from
88          * @param throwable
89          *            The exception that occured while loading the nodes
90          */
91         public void loadingNodesFailed(String directory, Throwable throwable);
92
93         /**
94          * Notifies a listener that the nodes were successfully saved.
95          * 
96          * @param directory
97          *            The directory the nodes were saved to
98          */
99         public void savingNodesDone(String directory);
100
101         /**
102          * Notifies a listener that saving the nodes has failed.
103          * 
104          * @param directory
105          *            The directory the nodes were saved to
106          * @param throwable
107          *            The exception that occured while saving the nodes
108          */
109         public void savingNodesFailed(String directory, Throwable throwable);
110
111         //
112         // basic core functionality
113         //
114
115         /**
116          * Notifies all listeners that the core has loaded.
117          */
118         public void coreLoaded();
119
120         /**
121          * Notifies a listener that the core was stopped.
122          */
123         public void coreStopped();
124
125         //
126         // node stuff
127         //
128
129         /**
130          * Notifies a listener that a node was added to the core.
131          * 
132          * @param node
133          *            The node that was added.
134          */
135         public void nodeAdded(Node node);
136
137         /**
138          * Notifies a listener that a node was removed from the core. Before a node
139          * is removed, it will be disconnected (and
140          * {@link #nodeDisconnected(Node, Throwable)} will be called).
141          * 
142          * @param node
143          *            The node that was removed
144          */
145         public void nodeRemoved(Node node);
146
147         /**
148          * Notifies all listeners that the core started connecting to the given
149          * node. Before a node is connected, it will be added (and
150          * {@link #nodeAdded(Node)} will be called).
151          * 
152          * @param node
153          *            The node that is being connected
154          */
155         public void nodeConnecting(Node node);
156
157         /**
158          * Notifies all listeners that the core connected to the given node.
159          * 
160          * @param node
161          *            The node that is connected
162          */
163         public void nodeConnected(Node node);
164
165         /**
166          * Notifies a listener that a connection to a node has failed.
167          * 
168          * @param node
169          *            The node that could not be connected
170          * @param cause
171          *            The cause of the failure
172          */
173         public void nodeConnectionFailed(Node node, Throwable cause);
174
175         /**
176          * Notifies all listeners that the core disconnected from the given node.
177          * 
178          * @param node
179          *            The node that was diconnected
180          * @param throwable
181          *            The exception that caused the disconnect, or <code>null</code>
182          *            if there was no exception
183          */
184         public void nodeDisconnected(Node node, Throwable throwable);
185
186         //
187         // request stuff
188         //
189
190         /**
191          * Notifies a listener that a request was added to a node.
192          * 
193          * @param node
194          *            The node the request was added to
195          * @param request
196          *            The request that was added
197          */
198         public void requestAdded(Node node, Request request);
199
200         /**
201          * Notifies a listener that a request made some progress.
202          * 
203          * @param request
204          *            The request that made the progress
205          * @param totalBlocks
206          *            The total number of blocks
207          * @param requiredBlocks
208          *            The number of required blocks
209          * @param successfulBlocks
210          *            The number of successful blocks
211          * @param failedBlocks
212          *            The number of failed blocks
213          * @param fatallyFailedBlocks
214          *            The number of fatally failed blocks
215          * @param finalizedTotal
216          *            <code>true</code> if the number of total blocks is
217          *            finalized, <code>false</code> if it is not
218          */
219         public void requestProgressed(Request request, int totalBlocks, int requiredBlocks, int successfulBlocks, int failedBlocks, int fatallyFailedBlocks, boolean finalizedTotal);
220
221 }