public final Config config() { return core.config(); }
/** * Negative. * * @param portType the port type * * @return the negative < p> */ protected final <P extends PortType> Negative<P> negative(Class<P> portType) { return core.createNegativePort(portType); }
/** * Positive. * * @param portType the port type * * @return the positive < p> */ protected final <P extends PortType> Positive<P> positive(Class<P> portType) { return core.createPositivePort(portType); }
protected void doDestroy(Component component) { ComponentCore child = (ComponentCore) component; child.cleanPorts(); if ((child.state != State.PASSIVE) && (child.state != State.FAULTY)) { logger().warn("Destroying a component before it has been stopped is not a good idea: {}", child.getComponent()); } child.state = State.DESTROYED; try { childrenLock.writeLock().lock(); children.remove(child); } finally { childrenLock.writeLock().unlock(); } }
protected void destroyTree(ComponentCore child) { try { childrenLock.writeLock().lock(); child.childrenLock.writeLock().lock(); for (ComponentCore grandchild : child.children) { child.destroyTree(grandchild); } child.getComponent().tearDown(); doDestroy(child); } finally { child.childrenLock.writeLock().unlock(); childrenLock.writeLock().unlock(); } }
/** * Instantiates a new component definition. */ protected ComponentDefinition() { core = new JavaComponent(this); control = core.createControlPort(); loopback = core.createNegativePort(LoopbackPort.class); onSelf = loopback.getPair(); loggingCtxInit(); }
if (mainCore != null) { if (mainCore.state == State.ACTIVE) { mainCore.control().doTrigger(Kill.event, mainCore.wid, mainCore); mainCore.cleanPorts(); mainCore.cleanPorts();
@Override public void run() { ResolveAction ra = fh.handle(f); switch (ra) { case RESOLVED: Kompics.logger.info("Fault {} was resolved by user.", f); break; case IGNORE: Kompics.logger.info("Fault {} was declared to be ignored by user. Resuming component...", f); f.source.markSubtreeAs(Component.State.PASSIVE); f.source.control().doTrigger(Start.event, 0, mainCore); break; case DESTROY: Kompics.logger.info("User declared that Fault {} should quit Kompics...", f); Kompics.forceShutdown(); { try { Kompics.waitForTermination(); } catch (InterruptedException ex) { Kompics.logger.error("Interrupted while waiting for Kompics termination..."); System.exit(1); } } Kompics.logger.info("finished quitting Kompics."); break; default: Kompics.logger.info("User declared that Fault {} should quit JVM...", f); System.exit(1); } }
/** * Creates the. * * @param definition the definition * @param initEvent init event to be passed to constructor * * @return the component */ protected final <T extends ComponentDefinition> Component create( Class<T> definition, Init<T> initEvent) { return core.doCreate(definition, Optional.of(initEvent)); }
@Override public void escalateFault(Fault fault) { if (parent != null) { parent.control().doTrigger(fault, wid, this); } else { // StackTraceElement[] stackTrace = throwable.getStackTrace(); // System.err.println("Kompics isolated fault: " // + throwable.getMessage()); // do { // for (int i = 0; i < stackTrace.length; i++) { // System.err.println(" " + stackTrace[i]); // } // throwable = throwable.getCause(); // if (throwable != null) { // stackTrace = throwable.getStackTrace(); // System.err.println("Caused by: " + throwable + ": " // + throwable.getMessage()); // } // } while (throwable != null); logger().error("A fault was escalated to the root component: \n{} \n\n", fault); Kompics.handleFault(fault); // System.exit(1); } }
protected final void destroy(Component component) { core.doDestroy(component); }
protected void destroyTreeAtParentOf(ComponentCore source) { source.parent.destroyTree(source); }
public final void updateConfig(ConfigUpdate update) { core.doConfigUpdate(update); }
protected ComponentDefinition(Class<? extends ComponentCore> coreClass) { try { Constructor[] constrs = coreClass.getConstructors(); for (Constructor constr : constrs) { Class[] paramTypes = constr.getParameterTypes(); if ((paramTypes.length) == 1 && paramTypes[0].isInstance(this)) { core = (ComponentCore) constr.newInstance(this); } } if (core == null) { core = coreClass.newInstance(); } } catch (Exception e) { //e.printStackTrace(); //System.out.println(e + ": " + e.getMessage()); throw new ConfigurationException(e); } control = core.createControlPort(); loopback = core.createNegativePort(LoopbackPort.class); onSelf = loopback.getPair(); loggingCtxInit(); } }
/** * Creates the. * * @param definition the definition * @param initEvent none * * @return the component */ protected final <T extends ComponentDefinition> Component create( Class<T> definition, Init.None initEvent) { Optional<Init<T>> init = Optional.absent(); return core.doCreate(definition, init); }
@Override public void handle(Fault event) { ResolveAction ra = component.handleFault(event); switch (ra) { case RESOLVED: logger().info("Fault {} was resolved by user.", event); break; case IGNORE: logger().info("Fault {} was declared to be ignored by user. Resuming component...", event); markSubtreeAtAs(event.source, State.PASSIVE); event.source.control().doTrigger(Start.event, wid, JavaComponent.this); break; case DESTROY: logger().info("User declared that Fault {} should destroy component tree...", event); destroyTreeAtParentOf(event.source); logger().info("finished destroying the subtree."); break; default: escalateFault(event); } } };
/** * Creates the. * * @param definition the definition * @param initEvent init event to be passed to constructor * * @return the component */ protected final <T extends ComponentDefinition> Component create( Class<T> definition, Init<T> initEvent, ConfigUpdate update) { return core.doCreate(definition, Optional.of(initEvent), Optional.of(update)); }
/** * specifies that this component requires a port of type * <code>portType</code>. * * @param <P> * @param portType * @return */ protected final <P extends PortType> Positive<P> requires(Class<P> portType) { return core.createPositivePort(portType); }
protected final <P extends PortType> Negative<P> provides(Class<P> portType) { return core.createNegativePort(portType); }
/** * Creates the. * * @param definition the definition * @param initEvent none * * @return the component */ protected final <T extends ComponentDefinition> Component create( Class<T> definition, Init.None initEvent, ConfigUpdate update) { Optional<Init<T>> init = Optional.absent(); return core.doCreate(definition, init, Optional.of(update)); }