2 * Copyright 2007 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.system.core;
18 import javax.sql.DataSource;
20 import org.wamblee.system.core.AbstractComponent;
21 import org.wamblee.system.core.DefaultProvidedInterface;
22 import org.wamblee.system.core.ProvidedInterface;
23 import org.wamblee.system.core.RequiredInterface;
24 import org.wamblee.test.EventTracker;
26 public class IntegerComponent extends AbstractComponent<Object> {
28 private static final ProvidedInterface[] provided(String aPrefix) {
29 return new ProvidedInterface[] {
30 new DefaultProvidedInterface(aPrefix + "integer", Integer.class) };
33 private EventTracker<String> _tracker;
34 private double _random;
36 public IntegerComponent() {
40 public IntegerComponent(String aName) {
44 public IntegerComponent(String aName, String aPrefix) {
45 super(aName, provided(aPrefix), new RequiredInterface[0]);
46 _random = Math.random();
51 public IntegerComponent(EventTracker aTracker) {
56 public Integer getInteger() {
61 protected Object doStart(Scope aScope) {
62 addInterface(getProvidedInterfaces().get(1), getInteger(), aScope);
63 track("start." + getName());
68 protected void doStop(Object aRuntime) {
69 track("stop." + getName());
70 if (_random != (Double) aRuntime) {
71 throw new IllegalArgumentException("Wrong runtime: expected "
72 + _random + " but got " + aRuntime);
76 private void track(String aString) {
77 if (_tracker == null) {
80 _tracker.eventOccurred(aString);