Fix ALL the logging!
[Sone.git] / src / main / java / net / pterodactylus / sone / core / SoneInsertListenerManager.java
1 /*
2  * Sone - SoneInsertListenerManager.java - Copyright © 2011 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.core;
19
20 import net.pterodactylus.sone.data.Sone;
21 import net.pterodactylus.util.event.AbstractListenerManager;
22
23 /**
24  * Manager for {@link SoneInsertListener}s.
25  *
26  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
27  */
28 public class SoneInsertListenerManager extends AbstractListenerManager<Sone, SoneInsertListener> {
29
30         /**
31          * Creates a new Sone insert listener manager.
32          *
33          * @param sone
34          *            The sone being inserted
35          */
36         public SoneInsertListenerManager(Sone sone) {
37                 super(sone);
38         }
39
40         //
41         // ACTIONS
42         //
43
44         /**
45          * Notifies all listeners that the insert of the Sone has started.
46          *
47          * @see SoneInsertListener#insertStarted(Sone)
48          */
49         void fireInsertStarted() {
50                 for (SoneInsertListener soneInsertListener : getListeners()) {
51                         soneInsertListener.insertStarted(getSource());
52                 }
53         }
54
55         /**
56          * Notifies all listeners that the insert of the Sone has finished
57          * successfully.
58          *
59          * @see SoneInsertListener#insertFinished(Sone, long)
60          * @param insertDuration
61          *            The insert duration (in milliseconds)
62          */
63         void fireInsertFinished(long insertDuration) {
64                 for (SoneInsertListener soneInsertListener : getListeners()) {
65                         soneInsertListener.insertFinished(getSource(), insertDuration);
66                 }
67         }
68
69         /**
70          * Notifies all listeners that the insert of the Sone was aborted.
71          *
72          * @see SoneInsertListener#insertAborted(Sone, Throwable)
73          * @param cause
74          *            The cause of the abortion (may be {@code null}
75          */
76         void fireInsertAborted(Throwable cause) {
77                 for (SoneInsertListener soneInsertListener : getListeners()) {
78                         soneInsertListener.insertAborted(getSource(), cause);
79                 }
80         }
81
82 }