1246 |
21 Oct 10 |
nicklas |
1 |
/** |
1246 |
21 Oct 10 |
nicklas |
$Id$ |
1246 |
21 Oct 10 |
nicklas |
3 |
|
1246 |
21 Oct 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
1246 |
21 Oct 10 |
nicklas |
5 |
|
1246 |
21 Oct 10 |
nicklas |
This file is part of Bittorent download service for BASE. |
1246 |
21 Oct 10 |
nicklas |
Available at http://baseplugins.thep.lu.se/ |
1246 |
21 Oct 10 |
nicklas |
8 |
|
1246 |
21 Oct 10 |
nicklas |
BASE is free software; you can redistribute it and/or |
1246 |
21 Oct 10 |
nicklas |
modify it under the terms of the GNU General Public License |
1246 |
21 Oct 10 |
nicklas |
as published by the Free Software Foundation; either version 2 |
1246 |
21 Oct 10 |
nicklas |
of the License, or (at your option) any later version. |
1246 |
21 Oct 10 |
nicklas |
13 |
|
1246 |
21 Oct 10 |
nicklas |
BASE is distributed in the hope that it will be useful, |
1246 |
21 Oct 10 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1246 |
21 Oct 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1246 |
21 Oct 10 |
nicklas |
GNU General Public License for more details. |
1246 |
21 Oct 10 |
nicklas |
18 |
|
1246 |
21 Oct 10 |
nicklas |
You should have received a copy of the GNU General Public License |
1246 |
21 Oct 10 |
nicklas |
along with this program; if not, write to the Free Software |
1246 |
21 Oct 10 |
nicklas |
Foundation, Inc., 59 Temple Place - Suite 330, |
1246 |
21 Oct 10 |
nicklas |
Boston, MA 02111-1307, USA. |
1246 |
21 Oct 10 |
nicklas |
23 |
*/ |
1246 |
21 Oct 10 |
nicklas |
24 |
package net.sf.basedb.clients.torrent.service; |
1246 |
21 Oct 10 |
nicklas |
25 |
|
1246 |
21 Oct 10 |
nicklas |
26 |
import org.slf4j.Logger; |
1246 |
21 Oct 10 |
nicklas |
27 |
import org.slf4j.LoggerFactory; |
1246 |
21 Oct 10 |
nicklas |
28 |
|
1246 |
21 Oct 10 |
nicklas |
29 |
import net.sf.basedb.clients.web.extensions.service.ServiceControllerAction; |
1246 |
21 Oct 10 |
nicklas |
30 |
import net.sf.basedb.util.extensions.ActionFactory; |
1246 |
21 Oct 10 |
nicklas |
31 |
import net.sf.basedb.util.extensions.InvokationContext; |
1246 |
21 Oct 10 |
nicklas |
32 |
|
1246 |
21 Oct 10 |
nicklas |
33 |
/** |
1246 |
21 Oct 10 |
nicklas |
An action factory for creating {@link TorrentServiceController} actions. |
1246 |
21 Oct 10 |
nicklas |
A single factory is tied to a single {@link TorrentService}, which is |
1246 |
21 Oct 10 |
nicklas |
created lazily when it is first needed. This usually happens when |
1246 |
21 Oct 10 |
nicklas |
the {@link #getActions(InvokationContext)} method is called. |
1246 |
21 Oct 10 |
nicklas |
<p> |
1246 |
21 Oct 10 |
nicklas |
The action factory accepts the following parameters: |
1246 |
21 Oct 10 |
nicklas |
<ul> |
1246 |
21 Oct 10 |
nicklas |
<li>{@link #setConfig(String)}: The path to the configuration file. The |
1246 |
21 Oct 10 |
nicklas |
default is: <code>/torrent.properties</code> |
1246 |
21 Oct 10 |
nicklas |
</ul> |
1246 |
21 Oct 10 |
nicklas |
44 |
|
1246 |
21 Oct 10 |
nicklas |
@author Nicklas |
1246 |
21 Oct 10 |
nicklas |
@since 1.0 |
1246 |
21 Oct 10 |
nicklas |
47 |
*/ |
1246 |
21 Oct 10 |
nicklas |
48 |
public class TorrentServiceControllerFactory |
1246 |
21 Oct 10 |
nicklas |
49 |
implements ActionFactory<ServiceControllerAction> |
1246 |
21 Oct 10 |
nicklas |
50 |
{ |
1246 |
21 Oct 10 |
nicklas |
51 |
private static final Logger log = LoggerFactory.getLogger(TorrentServiceControllerFactory.class); |
1246 |
21 Oct 10 |
nicklas |
52 |
|
1246 |
21 Oct 10 |
nicklas |
53 |
private TorrentServiceController controller; |
1246 |
21 Oct 10 |
nicklas |
54 |
private String config; |
1246 |
21 Oct 10 |
nicklas |
55 |
|
1246 |
21 Oct 10 |
nicklas |
56 |
/** |
1246 |
21 Oct 10 |
nicklas |
Creates a new factory instance. |
1246 |
21 Oct 10 |
nicklas |
58 |
*/ |
1246 |
21 Oct 10 |
nicklas |
59 |
public TorrentServiceControllerFactory() |
1246 |
21 Oct 10 |
nicklas |
60 |
{} |
1246 |
21 Oct 10 |
nicklas |
61 |
|
1246 |
21 Oct 10 |
nicklas |
62 |
/* |
1246 |
21 Oct 10 |
nicklas |
From the ActionFactory interface |
1246 |
21 Oct 10 |
nicklas |
64 |
------------------------------------------- |
1246 |
21 Oct 10 |
nicklas |
65 |
*/ |
1246 |
21 Oct 10 |
nicklas |
66 |
@Override |
1246 |
21 Oct 10 |
nicklas |
67 |
public ServiceControllerAction[] getActions(InvokationContext context) |
1246 |
21 Oct 10 |
nicklas |
68 |
{ |
1246 |
21 Oct 10 |
nicklas |
69 |
return new ServiceControllerAction[] { getController() }; |
1246 |
21 Oct 10 |
nicklas |
70 |
} |
1246 |
21 Oct 10 |
nicklas |
71 |
|
1246 |
21 Oct 10 |
nicklas |
72 |
/** |
1246 |
21 Oct 10 |
nicklas |
Always TRUE. |
1246 |
21 Oct 10 |
nicklas |
74 |
*/ |
1246 |
21 Oct 10 |
nicklas |
75 |
@Override |
1246 |
21 Oct 10 |
nicklas |
76 |
public boolean prepareContext(InvokationContext context) |
1246 |
21 Oct 10 |
nicklas |
77 |
{ |
1246 |
21 Oct 10 |
nicklas |
78 |
return true; |
1246 |
21 Oct 10 |
nicklas |
79 |
} |
1246 |
21 Oct 10 |
nicklas |
80 |
// ----------------------------------------------- |
1246 |
21 Oct 10 |
nicklas |
81 |
|
1246 |
21 Oct 10 |
nicklas |
82 |
/** |
1246 |
21 Oct 10 |
nicklas |
Set the path to the configuration file to use. The path |
1246 |
21 Oct 10 |
nicklas |
should be a path on the CLASSPATH. |
1246 |
21 Oct 10 |
nicklas |
@param config The path, or null to use the default path (/torrent.properties) |
1246 |
21 Oct 10 |
nicklas |
86 |
*/ |
1246 |
21 Oct 10 |
nicklas |
87 |
public void setConfig(String config) |
1246 |
21 Oct 10 |
nicklas |
88 |
{ |
1246 |
21 Oct 10 |
nicklas |
89 |
this.config = config; |
1246 |
21 Oct 10 |
nicklas |
90 |
} |
1246 |
21 Oct 10 |
nicklas |
91 |
|
1246 |
21 Oct 10 |
nicklas |
92 |
private synchronized TorrentServiceController getController() |
1246 |
21 Oct 10 |
nicklas |
93 |
{ |
1246 |
21 Oct 10 |
nicklas |
94 |
if (controller == null) |
1246 |
21 Oct 10 |
nicklas |
95 |
{ |
1246 |
21 Oct 10 |
nicklas |
96 |
controller = new TorrentServiceController(config); |
1246 |
21 Oct 10 |
nicklas |
97 |
} |
1246 |
21 Oct 10 |
nicklas |
98 |
return controller; |
1246 |
21 Oct 10 |
nicklas |
99 |
} |
1246 |
21 Oct 10 |
nicklas |
100 |
|
1246 |
21 Oct 10 |
nicklas |
101 |
} |