1 /**
2  * Copyright (C) Azureus Software, Inc, All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  */
17 
18 package org.gudy.azureus2.core3.util;
19 
20 /**
21  * A Runnable that calls the AECallback function when it's done running the
22  * code the implementer supplied
23  *
24  * @author TuxPaper
25  * @created Mar 22, 2007
26  *
27  */
28 public abstract class AERunnableWithCallback
29 	implements Runnable
30 {
31 	private final AECallback callback;
32 
AERunnableWithCallback(AECallback callback)33 	public AERunnableWithCallback(AECallback callback) {
34 		this.callback = callback;
35 	}
36 
run()37 	public final void run() {
38 		try {
39 			Object o = runSupport();
40 			if (callback != null) {
41 				callback.callbackSuccess(o);
42 			}
43 		} catch (Throwable e) {
44 			Debug.out(e);
45 			if (callback != null) {
46 				callback.callbackFailure(e);
47 			}
48 		}
49 	}
50 
runSupport()51 	public abstract Object runSupport();
52 }
53