Class ExecutionComponentFeature

    • Field Detail

      • DEBUG

        public static boolean DEBUG
        Debug flag.
      • TYPE_STEP

        public static final java.lang.String TYPE_STEP
        Constant for step event.
        See Also:
        Constant Field Values
      • stepcnt

        protected int stepcnt
        The stepcnt - used to keep insertion order of same priority elements in the queue.
      • bpstepid

        protected int bpstepid
        The id of the step at which the execution was stopped because of a breakpoint.
      • endstepcnt

        protected int endstepcnt
        The step at which the endstate begins.
      • timers

        protected java.util.List<ITimer> timers
        The current timer.
      • executing

        protected volatile boolean executing
        Flag for testing double execution.
      • stacktrace

        protected volatile java.lang.Throwable stacktrace
        Exception for debugging double execution.
      • componentthread

        protected java.lang.Thread componentthread
        The thread currently executing the component (null for none).
      • blocked

        protected java.util.Map<java.lang.Object,​jadex.commons.concurrent.Executor> blocked
        The blocked threads by monitor.
      • stepinfo

        protected java.lang.String stepinfo
        The flag for a requested step (true when a step is allowed in stepwise execution).
      • stepfuture

        protected jadex.commons.future.Future<java.lang.Void> stepfuture
        The future to be informed, when the requested step is finished.
      • subcomponents

        protected java.util.Set<IInternalExecutionFeature> subcomponents
        The synchronous subcomponents that want to be executed (if any).
      • endagenda

        protected jadex.commons.future.Future<java.lang.Void> endagenda
        Future for signalling that end of agenda execution has been reached.
      • termfuture

        protected jadex.commons.future.Future<java.util.Map<java.lang.String,​java.lang.Object>> termfuture
        The termination future (used in noplatform case).
      • debug

        protected boolean debug
        Heisenbug debug flag cached for speed.
      • stepadditions

        protected java.util.Map<IComponentStep<?>,​java.lang.Exception> stepadditions
      • manual

        protected volatile boolean manual
        Flag to indicate bootstrapping execution of main thread (only for platform, hack???).
      • switchtorescue

        protected boolean switchtorescue
        Should switch to rescue thread after next step?
      • isonrescue

        protected boolean isonrescue
        Running on rescue thread?
      • rescuethread

        protected java.lang.Thread rescuethread
        Is the current thread the rescue thread?
    • Method Detail

      • hasUserBody

        public boolean hasUserBody()
        Check if the feature potentially executed user code in body. Allows blocking operations in user bodies by using separate steps for each feature. Non-user-body-features are directly executed for speed. If unsure just return true. ;-)
        Specified by:
        hasUserBody in interface IComponentFeature
        Overrides:
        hasUserBody in class AbstractComponentFeature
      • kill

        public void kill()
        Kill is only invoked, when shutdown of some (e.g. other) feature does not return due to timeout. The feature should do any kind of possible cleanup, but no asynchronous operations.
        Specified by:
        kill in interface IComponentFeature
        Overrides:
        kill in class AbstractComponentFeature
      • doCleanup

        protected void doCleanup​(java.lang.Error e)
        Shared cleanup code for shutdown and kill.
      • getType

        public java.lang.Class<?> getType()
        Get the user interface type of the feature.
      • scheduleDecoupledStep

        public jadex.commons.future.IFuture<java.lang.Void> scheduleDecoupledStep​(IComponentStep<?> step)
        Schedule a component step but don't wait for its execution. Scheduling a decoupled step is useful to indicate that exceptions in the step are not handled by the caller, e.g., to have them printed to the console instead of discarded.
        Specified by:
        scheduleDecoupledStep in interface IExternalExecutionFeature
        Parameters:
        step - The component step.
        Returns:
        A future indicating that the step has been scheduled (but maybe not yet executed).
      • scheduleStep

        public <T> jadex.commons.future.IFuture<T> scheduleStep​(IComponentStep<T> step)
        Execute a component step.
        Specified by:
        scheduleStep in interface IExternalExecutionFeature
        Parameters:
        step - The component step.
        Returns:
        the future result of the step execution.
      • scheduleStep

        public <T> jadex.commons.future.IFuture<T> scheduleStep​(int priority,
                                                                boolean inherit,
                                                                IComponentStep<T> step)
        Execute a component step.
        Specified by:
        scheduleStep in interface IExternalExecutionFeature
        Parameters:
        step - The component step.
        priority - The step priority (0 is default).
      • repeatStep

        public <T> jadex.commons.future.ISubscriptionIntermediateFuture<T> repeatStep​(long initialdelay,
                                                                                      long delay,
                                                                                      IComponentStep<T> step)
        Repeats a ComponentStep periodically, until terminate() is called on result future or a failure occurs in a step.
        Specified by:
        repeatStep in interface IExternalExecutionFeature
        Parameters:
        initialdelay - delay before first execution in milliseconds
        delay - delay between scheduled executions of the step in milliseconds
        step - The component step
        Returns:
        The intermediate results
      • repeatStep

        public <T> jadex.commons.future.ISubscriptionIntermediateFuture<T> repeatStep​(long initialdelay,
                                                                                      long delay,
                                                                                      IComponentStep<T> step,
                                                                                      boolean ignorefailures)
        Repeats a ComponentStep periodically, until terminate() is called on result future. Warning: In order to avoid memory leaks, the returned subscription future does NOT store values, requiring the addition of a listener within the same step the repeat step was schedule.
        Specified by:
        repeatStep in interface IExternalExecutionFeature
        Parameters:
        initialdelay - delay before first execution in milliseconds
        delay - delay between scheduled executions of the step in milliseconds
        step - The component step
        ignorefailures - Don't terminate repeating after a failed step.
        Returns:
        The intermediate results
      • waitForDelay

        public <T> jadex.commons.future.IFuture<T> waitForDelay​(long delay,
                                                                IComponentStep<T> step,
                                                                boolean realtime)
        Wait for some time and execute a component step afterwards.
        Specified by:
        waitForDelay in interface IExternalExecutionFeature
      • waitForDelay

        public jadex.commons.future.IFuture<java.lang.Void> waitForDelay​(long delay)
        Wait for some time.
        Specified by:
        waitForDelay in interface IExternalExecutionFeature
      • waitForDelay

        public jadex.commons.future.IFuture<java.lang.Void> waitForDelay​(long delay,
                                                                         boolean realtime)
        Wait for some time.
        Specified by:
        waitForDelay in interface IExternalExecutionFeature
      • waitForTick

        public jadex.commons.future.IFuture<java.lang.Void> waitForTick()
        Wait for the next tick.
        Specified by:
        waitForTick in interface IExternalExecutionFeature
        Parameters:
        time - The time.
      • waitForTermination

        public jadex.commons.future.IFuture<java.util.Map<java.lang.String,​java.lang.Object>> waitForTermination()
        Waits for the components to finish.
        Specified by:
        waitForTermination in interface IExternalExecutionFeature
        Returns:
        Component results.
      • setManual

        public void setManual​(boolean manual)
        Set manual execution mode, e.g. for bootstrapping at platform startup.
        Specified by:
        setManual in interface IInternalExecutionFeature
        Parameters:
        manual - Ignore wake up calls, if true.
      • switchToRescueThread

        protected void switchToRescueThread()
        Switch to rescue thread when execution service is gone.
      • doStep

        public jadex.commons.future.IFuture<java.lang.Void> doStep​(java.lang.String stepinfo)
        Do a step of a suspended component.
        Specified by:
        doStep in interface IInternalExecutionFeature
      • isComponentThread

        public boolean isComponentThread()
        Test if current thread is the component thread.
        Specified by:
        isComponentThread in interface IExecutionFeature
        Returns:
        True if the current thread is the component thread.
      • createResultListener

        public <T> jadex.commons.future.IResultListener<T> createResultListener​(jadex.commons.future.IResultListener<T> listener)
        Create a result listener that is executed on the component thread.
        Specified by:
        createResultListener in interface IExecutionFeature
      • createResultListener

        public <T> jadex.commons.future.IIntermediateResultListener<T> createResultListener​(jadex.commons.future.IIntermediateResultListener<T> listener)
        Create a result listener that is executed on the component thread.
        Specified by:
        createResultListener in interface IExecutionFeature
      • block

        public void block​(java.lang.Object monitor,
                          long timeout,
                          boolean realtime)
        Block the current thread and allow execution on other threads.
        Specified by:
        block in interface IInternalExecutionFeature
        Parameters:
        monitor - The monitor to wait for.
        realtime - Flag if timeout is realtime (in contrast to simulation time).
      • unblock

        public void unblock​(java.lang.Object monitor,
                            java.lang.Throwable exception)
        Unblock the thread waiting for the given monitor and cease execution on the current thread.
        Specified by:
        unblock in interface IInternalExecutionFeature
        Parameters:
        monitor - The monitor to notify.
      • beforeBlock

        protected void beforeBlock()
        Called before blocking the component thread.
      • afterBlock

        protected void afterBlock()
        Called after unblocking the component thread.
      • execute

        public boolean execute()
        Execute the executable.
        Specified by:
        execute in interface jadex.commons.concurrent.IExecutable
        Specified by:
        execute in interface IInternalExecutionFeature
        Returns:
        True, if the object wants to be executed again.
      • getComponentThread

        public java.lang.Thread getComponentThread()
        Get the component thread.
        Returns:
        The component thread.
      • setComponentThread

        public void setComponentThread​(java.lang.Thread componentthread)
        Set the component thread.
        Parameters:
        componentthread - The component thread.
      • setExecutionState

        protected java.lang.ClassLoader setExecutionState()
        Set flags when entering thread.
        Returns:
        The previous context class loader.
      • resetExecutionState

        protected void resetExecutionState​(java.lang.ClassLoader cl)
        Reset flags when exiting thread.
        Parameters:
        cl - The previous context class loader.
      • executeCycle

        protected boolean executeCycle()
        Components with autonomous behavior may override this method to implement a recurring execution cycle.
        Returns:
        true, if the execution should continue, false, if the component may become idle.
      • createStepFuture

        protected <T> jadex.commons.future.Future<T> createStepFuture​(IComponentStep<T> step)
        Create intermediate of direct future.
      • getCurrentStateEvents

        public java.util.List<IMonitoringEvent> getCurrentStateEvents()
        Get the current state as events.
      • isAtBreakpoint

        public boolean isAtBreakpoint​(java.lang.String[] breakpoints)
        Test if the agent's execution is currently at one of the given breakpoints. If yes, the agent will be suspended by the platform. Available breakpoints can be specified in the micro agent meta info.
        Parameters:
        breakpoints - An array of breakpoints.
        Returns:
        True, when some breakpoint is triggered.
      • testIfBreakpoint

        public boolean testIfBreakpoint​(java.lang.String[] breakpoints)
        Kernel specific test if the step is a breakpoint.
      • listenToComponent

        public jadex.commons.future.ISubscriptionIntermediateFuture<CMSStatusEvent> listenToComponent()
        Add a component listener for a specific component. The listener is registered for component changes.
        Specified by:
        listenToComponent in interface IExternalExecutionFeature
        Parameters:
        cid - The component to be listened.
      • listenToAll

        public jadex.commons.future.ISubscriptionIntermediateFuture<CMSStatusEvent> listenToAll()
        Add a component listener for all components of a platform. The listener is registered for component changes.
        Specified by:
        listenToAll in interface IExternalExecutionFeature
      • stepComponent

        public jadex.commons.future.IFuture<java.lang.Void> stepComponent​(java.lang.String stepinfo)
        Execute a step of a suspended component.
        Specified by:
        stepComponent in interface IExternalExecutionFeature
        Parameters:
        componentid - The component identifier.
      • setComponentBreakpoints

        public jadex.commons.future.IFuture<java.lang.Void> setComponentBreakpoints​(java.lang.String[] breakpoints)
        Set breakpoints for a component. Replaces existing breakpoints. To add/remove breakpoints, use current breakpoints from component description as a base.
        Specified by:
        setComponentBreakpoints in interface IExternalExecutionFeature
        Parameters:
        componentid - The component identifier.
        breakpoints - The new breakpoints (if any).
      • suspendComponent

        public jadex.commons.future.IFuture<java.lang.Void> suspendComponent()
        Suspend the execution of an component.
        Specified by:
        suspendComponent in interface IExternalExecutionFeature
        Parameters:
        componentid - The component identifier.
      • resumeComponent

        public jadex.commons.future.IFuture<java.lang.Void> resumeComponent()
        Resume the execution of an component.
        Specified by:
        resumeComponent in interface IExternalExecutionFeature
        Parameters:
        componentid - The component identifier.
      • isStepped

        public boolean isStepped()
        Check if component is in stepped execution.
        Specified by:
        isStepped in interface IExecutionFeature
        Returns:
        True, if is in stepped execution.
      • isSemanticStepped

        public boolean isSemanticStepped()
        Check if the execution kernel supports semantic steps.
        Returns:
        True, if semantic steps are supported and the kernel uses events to setSemanticEffect on current steps.
      • killComponent

        public jadex.commons.future.IFuture<java.util.Map<java.lang.String,​java.lang.Object>> killComponent()
        Kill the component.
        Specified by:
        killComponent in interface IExternalExecutionFeature
      • killComponent

        public jadex.commons.future.IFuture<java.util.Map<java.lang.String,​java.lang.Object>> killComponent​(java.lang.Exception e)
        Kill the component.
        Specified by:
        killComponent in interface IExternalExecutionFeature
        Parameters:
        e - The failure reason, if any.
      • toString

        public java.lang.String toString()
        Get the string representation.
        Overrides:
        toString in class java.lang.Object