2313 |
04 Apr 14 |
olle |
1 |
/** |
2313 |
04 Apr 14 |
olle |
$Id: LabEnvService.java 4512 2014-03-13 08:06:50Z olle $ |
2313 |
04 Apr 14 |
olle |
3 |
|
2313 |
04 Apr 14 |
olle |
Copyright (C) 2014 Olle MÃ¥nsson |
2313 |
04 Apr 14 |
olle |
5 |
|
2313 |
04 Apr 14 |
olle |
This file is part of BASE - BioArray Software Environment. |
2313 |
04 Apr 14 |
olle |
Available at http://base.thep.lu.se/ |
2313 |
04 Apr 14 |
olle |
8 |
|
2313 |
04 Apr 14 |
olle |
BASE is free software; you can redistribute it and/or |
2313 |
04 Apr 14 |
olle |
modify it under the terms of the GNU General Public License |
2313 |
04 Apr 14 |
olle |
as published by the Free Software Foundation; either version 3 |
2313 |
04 Apr 14 |
olle |
of the License, or (at your option) any later version. |
2313 |
04 Apr 14 |
olle |
13 |
|
2313 |
04 Apr 14 |
olle |
BASE is distributed in the hope that it will be useful, |
2313 |
04 Apr 14 |
olle |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
2313 |
04 Apr 14 |
olle |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2313 |
04 Apr 14 |
olle |
GNU General Public License for more details. |
2313 |
04 Apr 14 |
olle |
18 |
|
2313 |
04 Apr 14 |
olle |
You should have received a copy of the GNU General Public License |
2313 |
04 Apr 14 |
olle |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
2313 |
04 Apr 14 |
olle |
21 |
*/ |
2313 |
04 Apr 14 |
olle |
22 |
package net.sf.basedb.labenv.service; |
2313 |
04 Apr 14 |
olle |
23 |
|
2313 |
04 Apr 14 |
olle |
24 |
|
2328 |
08 Apr 14 |
olle |
25 |
import org.slf4j.Logger; |
2328 |
08 Apr 14 |
olle |
26 |
import org.slf4j.LoggerFactory; |
2313 |
04 Apr 14 |
olle |
27 |
|
2313 |
04 Apr 14 |
olle |
28 |
import net.sf.basedb.clients.web.extensions.service.ServiceControllerAction; |
3014 |
05 Dec 14 |
nicklas |
29 |
import net.sf.basedb.core.SessionControl; |
2313 |
04 Apr 14 |
olle |
30 |
import net.sf.basedb.util.extensions.ActionFactory; |
3014 |
05 Dec 14 |
nicklas |
31 |
import net.sf.basedb.util.extensions.Extension; |
2313 |
04 Apr 14 |
olle |
32 |
import net.sf.basedb.util.extensions.InvokationContext; |
2313 |
04 Apr 14 |
olle |
33 |
import net.sf.basedb.labenv.LabEnvironment; |
2313 |
04 Apr 14 |
olle |
34 |
|
2313 |
04 Apr 14 |
olle |
35 |
/** |
2313 |
04 Apr 14 |
olle |
A service implementation that measure lab environments at |
2313 |
04 Apr 14 |
olle |
specified time intervals (default is 1 minute) and store data |
2313 |
04 Apr 14 |
olle |
in a database when the service is running. It will also print |
2313 |
04 Apr 14 |
olle |
out messages when the service is started and stopped. |
2313 |
04 Apr 14 |
olle |
<p> |
2313 |
04 Apr 14 |
olle |
The service is it's own action factory and controller. |
2313 |
04 Apr 14 |
olle |
This service is based on DummyAction in BASE. |
2313 |
04 Apr 14 |
olle |
43 |
|
2313 |
04 Apr 14 |
olle |
@author Olle |
2313 |
04 Apr 14 |
olle |
@version 1.0 |
2313 |
04 Apr 14 |
olle |
46 |
*/ |
2313 |
04 Apr 14 |
olle |
47 |
public class LabEnvService |
3014 |
05 Dec 14 |
nicklas |
48 |
implements ActionFactory<ServiceControllerAction> |
2313 |
04 Apr 14 |
olle |
49 |
{ |
2328 |
08 Apr 14 |
olle |
50 |
private static final Logger log = LoggerFactory.getLogger(LabEnvService.class); |
2313 |
04 Apr 14 |
olle |
51 |
|
2313 |
04 Apr 14 |
olle |
52 |
|
2313 |
04 Apr 14 |
olle |
53 |
public LabEnvService() |
3014 |
05 Dec 14 |
nicklas |
54 |
{} |
2313 |
04 Apr 14 |
olle |
55 |
|
2313 |
04 Apr 14 |
olle |
56 |
/* |
2313 |
04 Apr 14 |
olle |
From the ActionFactory interface |
2313 |
04 Apr 14 |
olle |
58 |
-------------------------------- |
2313 |
04 Apr 14 |
olle |
59 |
*/ |
2313 |
04 Apr 14 |
olle |
60 |
@Override |
5513 |
19 Jun 19 |
nicklas |
61 |
public ServiceControllerAction[] getActions(InvokationContext<? super ServiceControllerAction> context) |
2313 |
04 Apr 14 |
olle |
62 |
{ |
3014 |
05 Dec 14 |
nicklas |
63 |
SessionControl sc = context.getClientContext().getSessionControl(); |
3014 |
05 Dec 14 |
nicklas |
64 |
return new ServiceControllerAction[] { new LabEnvServiceControllerAction(sc, context.getExtension()) }; |
2313 |
04 Apr 14 |
olle |
65 |
} |
2313 |
04 Apr 14 |
olle |
66 |
|
2313 |
04 Apr 14 |
olle |
67 |
@Override |
5513 |
19 Jun 19 |
nicklas |
68 |
public boolean prepareContext(InvokationContext<? super ServiceControllerAction> context) |
2313 |
04 Apr 14 |
olle |
69 |
{ |
2313 |
04 Apr 14 |
olle |
70 |
return true; |
2313 |
04 Apr 14 |
olle |
71 |
} |
2338 |
09 Apr 14 |
olle |
72 |
|
2313 |
04 Apr 14 |
olle |
73 |
// --------------------------------------------- |
2313 |
04 Apr 14 |
olle |
74 |
|
3014 |
05 Dec 14 |
nicklas |
75 |
static class LabEnvServiceControllerAction |
3014 |
05 Dec 14 |
nicklas |
76 |
implements ServiceControllerAction |
2313 |
04 Apr 14 |
olle |
77 |
{ |
3014 |
05 Dec 14 |
nicklas |
78 |
private final SessionControl sc; |
5513 |
19 Jun 19 |
nicklas |
79 |
private final Extension<ServiceControllerAction> ext; |
3014 |
05 Dec 14 |
nicklas |
80 |
|
5513 |
19 Jun 19 |
nicklas |
81 |
@SuppressWarnings({ "rawtypes", "unchecked" }) |
3014 |
05 Dec 14 |
nicklas |
82 |
public LabEnvServiceControllerAction(SessionControl sc, Extension ext) |
2313 |
04 Apr 14 |
olle |
83 |
{ |
3014 |
05 Dec 14 |
nicklas |
84 |
this.sc = sc; |
3014 |
05 Dec 14 |
nicklas |
85 |
this.ext = ext; |
2313 |
04 Apr 14 |
olle |
86 |
} |
3014 |
05 Dec 14 |
nicklas |
87 |
|
3014 |
05 Dec 14 |
nicklas |
88 |
/* |
3014 |
05 Dec 14 |
nicklas |
From the ServiceControllerAction interface |
3014 |
05 Dec 14 |
nicklas |
90 |
------------------------------------------ |
3014 |
05 Dec 14 |
nicklas |
91 |
*/ |
3014 |
05 Dec 14 |
nicklas |
92 |
@Override |
3014 |
05 Dec 14 |
nicklas |
93 |
public boolean isRunning() |
2313 |
04 Apr 14 |
olle |
94 |
{ |
3014 |
05 Dec 14 |
nicklas |
95 |
return LabEnvironment.getInstance().isRunning(); |
2313 |
04 Apr 14 |
olle |
96 |
} |
3014 |
05 Dec 14 |
nicklas |
97 |
|
3014 |
05 Dec 14 |
nicklas |
98 |
@Override |
3014 |
05 Dec 14 |
nicklas |
99 |
public void start() |
2313 |
04 Apr 14 |
olle |
100 |
{ |
3017 |
08 Dec 14 |
nicklas |
101 |
LabEnvironment.getInstance().start(sc); |
2313 |
04 Apr 14 |
olle |
102 |
} |
3014 |
05 Dec 14 |
nicklas |
103 |
|
3014 |
05 Dec 14 |
nicklas |
104 |
@Override |
3014 |
05 Dec 14 |
nicklas |
105 |
public void stop() |
3014 |
05 Dec 14 |
nicklas |
106 |
{ |
3014 |
05 Dec 14 |
nicklas |
107 |
LabEnvironment.getInstance().stop(); |
3014 |
05 Dec 14 |
nicklas |
108 |
} |
3014 |
05 Dec 14 |
nicklas |
109 |
|
3014 |
05 Dec 14 |
nicklas |
110 |
@Override |
3014 |
05 Dec 14 |
nicklas |
111 |
public String toString() |
3014 |
05 Dec 14 |
nicklas |
112 |
{ |
3014 |
05 Dec 14 |
nicklas |
113 |
return "LabEnv Server extension"; |
3014 |
05 Dec 14 |
nicklas |
114 |
} |
3014 |
05 Dec 14 |
nicklas |
115 |
// --------------------------------------------- |
2313 |
04 Apr 14 |
olle |
116 |
} |
2313 |
04 Apr 14 |
olle |
117 |
|
3014 |
05 Dec 14 |
nicklas |
118 |
|
2313 |
04 Apr 14 |
olle |
119 |
} |