private static final Log LOG = LogFactory.getLog(AbstractComponent.class);
- private Status _status;
private String _context;
private String _name;
private List<ProvidedInterface> _provided;
*/
protected AbstractComponent(String aName, ProvidedInterface[] aProvided,
RequiredInterface[] aRequired) {
- _status = Status.NOT_STARTED;
_context = null;
_name = aName;
_provided = new ArrayList<ProvidedInterface>();
_required.addAll(Arrays.asList(aRequired));
_running = new HashSet<ProvidedInterface>();
}
-
- @Override
- public Status getStatus() {
- return _status;
- }
@Override
public final String getName() {
public final void start() {
LOG.info("Initializing '" + getQualifiedName() + "'");
doStart();
- _status = Status.RUNNING;
if ( _running.size() != _provided.size()) {
List<ProvidedInterface> remaining =
new ArrayList<ProvidedInterface>(_provided);
// programming error.
throw new RuntimeException(getQualifiedName() + ": still services running after the stop call.");
}
- _status = Status.STOPPED;
}
protected abstract void doStop();
package org.wamblee.system.core;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Arrays;
+import junit.framework.TestCase;
+
import org.easymock.classextension.ConstructorArgs;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
-import org.wamblee.system.core.Component;
-import org.wamblee.system.core.Container;
-import org.wamblee.system.core.DefaultProvidedInterface;
-import org.wamblee.system.core.DefaultRequiredInterface;
-import org.wamblee.system.core.ProvidedInterface;
-import org.wamblee.system.core.RequiredInterface;
-import org.wamblee.system.core.SystemAssemblyException;
-import org.wamblee.system.core.Component.Status;
import org.wamblee.test.AssertionUtils;
import org.wamblee.test.EventTracker;
-import junit.framework.TestCase;
-
public class ContainerTest extends TestCase {
private EventTracker<String> _tracker;
Component environment = new Environment(_tracker);
Component application = new Application(_tracker);
assertEquals(0, _tracker.getEventCount());
- assertEquals(Status.NOT_STARTED, environment.getStatus());
- assertEquals(Status.NOT_STARTED, application.getStatus());
Container system = new Container("all", new Component[] { environment,
application }, new ProvidedInterface[0],
new RequiredInterface[0]);
- assertEquals(Status.NOT_STARTED, system.getStatus());
system.start();
RequiredInterface[] required = system.getRequiredInterfaces();
assertEquals(0, required.length);
ProvidedInterface[] provided = system.getProvidedInterfaces();
assertEquals(0, provided.length);
- assertEquals(Status.RUNNING, environment.getStatus());
- assertEquals(Status.RUNNING, application.getStatus());
- assertEquals(Status.RUNNING, system.getStatus());
AssertionUtils.assertEquals(new String[] { "start.environment",
"start.application" }, _tracker.getEvents(
_tracker.clear();
system.stop();
- assertEquals(Status.STOPPED, environment.getStatus());
- assertEquals(Status.STOPPED, application.getStatus());
- assertEquals(Status.STOPPED, system.getStatus());
-
AssertionUtils.assertEquals(new String[] { "stop.application",
"stop.environment" }, _tracker
.getEvents(Thread.currentThread()).toArray(new String[0]));