Skip to content

Commit 277880c

Browse files
committed
[Core] Start/stop HTTP service modules using internal methods
doStart()/doStop() but also set state in handleEvent. Reverts previous change. Fixes #308
1 parent 1731041 commit 277880c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

sensorhub-core/src/main/java/org/sensorhub/impl/service/AbstractHttpServiceModule.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,18 @@ public abstract class AbstractHttpServiceModule<ConfigType extends ModuleConfig>
4444
@Override
4545
public void start() throws SensorHubException
4646
{
47-
httpServer = getParentHub().getModuleRegistry().getModuleByType(IHttpServer.class);
48-
if (httpServer == null)
49-
throw new SensorHubException("HTTP server module is not loaded");
47+
if (canStart())
48+
{
49+
httpServer = getParentHub().getModuleRegistry().getModuleByType(IHttpServer.class);
50+
if (httpServer == null)
51+
throw new SensorHubException("HTTP server module is not loaded");
5052

51-
// subscribe to server lifecycle events
52-
httpServer.registerListener(this);
53+
// subscribe to server lifecycle events
54+
httpServer.registerListener(this);
5355

54-
// we actually start in the handleEvent() method when
55-
// a STARTED event is received from HTTP server
56+
// we actually start in the handleEvent() method when
57+
// a STARTED event is received from HTTP server
58+
}
5659
}
5760

5861

@@ -81,7 +84,8 @@ public void handleEvent(Event e)
8184
{
8285
try
8386
{
84-
super.start();
87+
doStart();
88+
setState(ModuleState.STARTED);
8589
}
8690
catch (Exception ex)
8791
{
@@ -94,7 +98,8 @@ else if (newState == ModuleState.STOPPED)
9498
{
9599
try
96100
{
97-
stop();
101+
doStop();
102+
setState(ModuleState.STOPPED);
98103
}
99104
catch (SensorHubException ex)
100105
{

0 commit comments

Comments
 (0)