public abstract class AbstractMockedModule implements Module {
protected final AutoCloseable instance;
+ private final ModuleIdentifier id;
- public AbstractMockedModule() throws Exception {
- instance = prepareMockedInstance();
+ protected abstract AutoCloseable prepareMockedInstance() throws Exception;
+
+ public AbstractMockedModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {
+ if(old!=null)
+ instance = old.getInstance();
+ else
+ try {
+ instance = prepareMockedInstance();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ this.id = id==null ? new ModuleIdentifier(getClass().getCanonicalName(), "mock") : id;
}
- protected abstract AutoCloseable prepareMockedInstance() throws Exception;
- public AbstractMockedModule(DynamicMBeanWithInstance old) {
- instance = old.getInstance();
+ @Override
+ public boolean canReuse(Module oldModule) {
+ return instance!=null;
}
@Override
}
@Override
- public ModuleIdentifier getName() {
- return new ModuleIdentifier(getClass().getCanonicalName(), "mock");
+ public ModuleIdentifier getIdentifier() {
+ return id;
}
}