Permalink
Browse files

Adding status service

  • Loading branch information...
1 parent 9db1252 commit 9c9652b7dc5872c3ff71b5afdb8d205ee3872e32 @chamerling chamerling committed Apr 11, 2012
@@ -42,6 +42,7 @@
<component definition="org.petalslink.dsb.kernel.ws.RESTServiceBinderServiceImpl" name="RESTServiceBinderImpl"/>
<component definition="org.petalslink.dsb.kernel.ws.SOAPServiceBinderServiceImpl" name="SOAPServiceBinderImpl"/>
+ <component definition="org.petalslink.dsb.kernel.ws.StatusServiceImpl" name="StatusServiceImpl"/>
<!-- DSB/JBI stuff -->
<component definition="org.petalslink.dsb.kernel.ws.jbi.ServiceArtefactsInformationServiceImpl" name="ServiceUnitInformationServiceImpl"/>
@@ -0,0 +1,30 @@
+/**
+ *
+ */
+package org.petalslink.dsb.ws.api;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+/**
+ * Test if the current DSB node is starting, started, stopping, etc...
+ *
+ * @author chamerling
+ *
+ */
+@WebService
+public interface StatusService {
+
+ @WebMethod
+ boolean isStarting();
+
+ @WebMethod
+ boolean isStarted();
+
+ @WebMethod
+ boolean isStopping();
+
+ @WebMethod
+ long getStartedAt();
+
+}
@@ -0,0 +1,108 @@
+/**
+ *
+ */
+package org.petalslink.dsb.kernel.ws;
+
+import org.objectweb.fractal.fraclet.annotation.annotations.FractalComponent;
+import org.objectweb.fractal.fraclet.annotation.annotations.Interface;
+import org.objectweb.fractal.fraclet.annotation.annotations.LifeCycle;
+import org.objectweb.fractal.fraclet.annotation.annotations.Monolog;
+import org.objectweb.fractal.fraclet.annotation.annotations.Provides;
+import org.objectweb.fractal.fraclet.annotation.annotations.type.LifeCycleType;
+import org.objectweb.util.monolog.api.Logger;
+import org.ow2.petals.util.oldies.LoggingUtil;
+import org.petalslink.dsb.annotations.LifeCycleListener;
+import org.petalslink.dsb.annotations.Phase;
+import org.petalslink.dsb.ws.api.StatusService;
+
+/**
+ * @author chamerling
+ *
+ */
+@FractalComponent
+@Provides(interfaces = { @Interface(name = "service", signature = StatusService.class) })
+public class StatusServiceImpl implements StatusService {
+
+ @Monolog(name = "logger")
+ private Logger logger;
+
+ private LoggingUtil log;
+
+ private boolean starting;
+
+ private boolean started;
+
+ private boolean stopping;
+
+ private long startedAt = -1L;
+
+ @LifeCycle(on = LifeCycleType.START)
+ protected void start() {
+ this.log = new LoggingUtil(this.logger);
+ starting = true;
+
+ }
+
+ @LifeCycle(on = LifeCycleType.STOP)
+ protected void stop() {
+ started = false;
+ stopping = true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.petalslink.dsb.ws.api.StatusService#isStarting()
+ */
+ public boolean isStarting() {
+ return starting;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.petalslink.dsb.ws.api.StatusService#isStarted()
+ */
+ public boolean isStarted() {
+ return started;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.petalslink.dsb.ws.api.StatusService#isStopping()
+ */
+ public boolean isStopping() {
+ return stopping;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.petalslink.dsb.ws.api.StatusService#getStartedAt()
+ */
+ public long getStartedAt() {
+ return this.startedAt;
+ }
+
+ /**
+ * Let's change the flag with the help of the lifecycle listener...
+ */
+ @LifeCycleListener(phase = Phase.START, priority = 0)
+ public void started() {
+ starting = false;
+ started = true;
+ stopping = false;
+ startedAt = System.currentTimeMillis();
+ }
+
+ /**
+ * High priority means that this component is called first when the
+ * container starts to stop...
+ */
+ @LifeCycleListener(phase = Phase.STOP, priority = 10000)
+ public void stopping() {
+ starting = false;
+ started = false;
+ stopping = true;
+ }
+}

0 comments on commit 9c9652b

Please sign in to comment.