01: package org.drftpd.slaveselection;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.net.URL;
06: import java.net.URLClassLoader;
07: import java.util.Collection;
08:
09: import net.sf.drftpd.NoAvailableSlaveException;
10: import net.sf.drftpd.master.BaseFtpConnection;
11: import net.sf.drftpd.mirroring.Job;
12:
13: import org.apache.log4j.Logger;
14: import org.drftpd.GlobalContext;
15: import org.drftpd.master.RemoteSlave;
16: import org.drftpd.remotefile.LinkedRemoteFileInterface;
17:
18: /**
19: * @author mog
20: * @version $Id$
21: */
22: public class DelegatingSlaveSelectionManager implements
23: SlaveSelectionManagerInterface {
24:
25: private static final String CLASSNAME = "se.mog.javaslaveselection.JavaSlaveSelectionManager";
26:
27: private static final Logger logger = Logger
28: .getLogger(DelegatingSlaveSelectionManager.class);
29:
30: private URLClassLoader _cl;
31:
32: private SlaveSelectionManagerInterface _delegate;
33:
34: private Object _gctx;
35:
36: public DelegatingSlaveSelectionManager(GlobalContext gctx) {
37: _gctx = gctx;
38: init2();
39: }
40:
41: public RemoteSlave getASlave(Collection<RemoteSlave> arg0,
42: char arg1, BaseFtpConnection arg2,
43: LinkedRemoteFileInterface arg3)
44: throws NoAvailableSlaveException {
45: return _delegate.getASlave(arg0, arg1, arg2, arg3);
46: }
47:
48: public RemoteSlave getASlaveForJobDownload(Job job)
49: throws NoAvailableSlaveException {
50: return _delegate.getASlaveForJobDownload(job);
51: }
52:
53: public RemoteSlave getASlaveForJobUpload(Job job,
54: RemoteSlave sourceSlave) throws NoAvailableSlaveException {
55: return getASlaveForJobUpload(job, sourceSlave);
56: }
57:
58: public GlobalContext getGlobalContext() {
59: //this is problably never called
60: return _delegate.getGlobalContext();
61: }
62:
63: public void reload() throws IOException {
64: init2();
65: }
66:
67: private void init2() {
68: try {
69: Class.forName(CLASSNAME);
70: logger
71: .warn("Was able to load slaveselection class with current classloader!");
72: } catch (ClassNotFoundException e) {
73: }
74: try {
75: _cl = new URLClassLoader(new URL[] { new File(
76: "classes-slaveselection").toURL() });
77: _delegate = (SlaveSelectionManagerInterface) _cl.loadClass(
78: CLASSNAME).getConstructor(
79: new Class[] { GlobalContext.class }).newInstance(
80: new Object[] { _gctx });
81:
82: } catch (Exception e) {
83: throw new RuntimeException(e);
84: }
85: }
86:
87: }
|