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  * @author TuxPaper
22  * @created Mar 22, 2007
23  *
24  */
25 public abstract class AERunnableObject
26 	implements Runnable
27 {
28 	private Object[] returnValueObject;
29 
30 	private AESemaphore sem;
31 
32 	private String id = "AEReturningRunnable";
33 
run()34 	public void run() {
35 		try {
36 			Object o = runSupport();
37 			if (returnValueObject != null && returnValueObject.length > 0) {
38 				returnValueObject[0] = o;
39 			}
40 		} catch (Throwable e) {
41 			Debug.out(id, e);
42 		} finally {
43 			if (sem != null) {
44 				sem.releaseForever();
45 			}
46 		}
47 	}
48 
setupReturn(String ID, Object[] returnValueObject, AESemaphore sem)49 	public void setupReturn(String ID, Object[] returnValueObject, AESemaphore sem) {
50 		id = ID;
51 		this.returnValueObject = returnValueObject;
52 		this.sem = sem;
53 	}
54 
runSupport()55 	public abstract Object runSupport();
56 }
57