jadex.application.runtime.impl
Class ApplicationInterpreter

java.lang.Object
  extended by jadex.application.runtime.impl.ApplicationInterpreter
All Implemented Interfaces:
IApplication, IComponentInstance, IInternalAccess

public class ApplicationInterpreter
extends Object
implements IApplication, IComponentInstance, IInternalAccess

The application interpreter provides a closed environment for components. If components spawn other components, these will automatically be added to the context. When the context is deleted all components will be destroyed. An component must only be in one application context.


Field Summary
protected  IComponentAdapter adapter
          The component adapter.
protected  Map arguments
          The arguments.
protected  List componentlisteners
          The component listeners.
protected  MApplicationInstance config
          The application configuration.
protected  IServiceContainer container
          The service container.
protected  Map ctypes
          Component type mapping (cid -> modelname) and (modelname->application component type).
protected  IValueFetcher fetcher
          The value fetcher.
protected  MultiCollection instances
           
protected  MApplicationType model
          The application type.
protected  IExternalAccess parent
          The parent component.
protected  Map properties
          The properties.
protected  Map results
          The arguments.
protected  Map spaces
          The contained spaces.
protected static String STATE_INITFUTURES
          Application state, while waiting for initial futures.
protected static String STATE_INITREADY
          Application state, when ready to init.
protected static String STATE_STARTED
          Application state, when already started.
protected  List steps
          The scheduled steps of the component.
protected  boolean terminating
          Flag to indicate that the context is about to be deleted (no more components can be added).
protected  boolean willdostep
          Flag indicating an added step will be executed without the need for calling wakeup().
 
Constructor Summary
ApplicationInterpreter(IComponentDescription desc, MApplicationType model, MApplicationInstance config, IComponentAdapterFactory factory, IExternalAccess parent, Map arguments, Future inited)
          Create a new context.
 
Method Summary
 void addComponentListener(IComponentListener listener)
          Add an component listener.
 void addSpace(String name, ISpace space)
          Add a space to the context.
 IFuture cleanupComponent()
          Can be called concurrently (also during executeAction()).
 IFuture componentCreated(IComponentDescription desc, IModelInfo model)
          Called when a component has been created as a subcomponent of this component.
 IFuture componentDestroyed(IComponentDescription desc)
          Called when a subcomponent of this component has been destroyed.
protected  void createComponent(List components, IComponentManagementService ces, int i, Future inited)
          Create subcomponents.
 IResultListener createResultListener(IResultListener listener)
          Create a result listener which is executed as an component step.
 void deleteContext()
          Delete a context.
 boolean executeStep()
          Can be called on the component thread only.
protected  void findComponentType(int i, List componenttypes, ILibraryService ls, Class servicetype, Future ret)
          Find component type that provided a specific service.
 String[] getAllImports()
          Get the imports.
 MApplicationType getApplicationType()
          Get the application type.
 Map getArguments()
          Get the arguments.
 Map getArguments(MComponentInstance component)
          Get the arguments.
 IFuture getChildren()
          Get the children (if any).
 Collection getChildren(String type)
          Get the children (if any).
 ClassLoader getClassLoader()
          Get the class loader of the component.
 IComponentAdapter getComponentAdapter()
          Get the component adapter.
 String getComponentFilename(String type)
          Get the file name for a logical type name of a subcomponent of this application.
 IComponentIdentifier getComponentIdentifier()
          Get the component identifier.
 String getComponentType(IComponentIdentifier cid)
          Get the logical component type for a given component id.
 IExternalAccess getExternalAccess()
          Can be called concurrently (also during executeAction()).
 String getFileName(String ctype)
          Get the file name of a component type.
 Logger getLogger()
          Get the logger.
 IModelInfo getModel()
          Get the model.
 String getName()
          Get the name.
 int getNumber(MComponentInstance component)
          Get the number of components to start.
 IExternalAccess getParent()
          Get the parent.
 Map getResults()
          Get the results of the component (considering it as a functionality).
 IServiceContainer getServiceContainer()
          Create the service container.
 IServiceProvider getServiceProvider()
          Get the service provider.
 ISpace getSpace(String name)
          Get a space by name.
 boolean isAtBreakpoint(String[] breakpoints)
          Test if the component's execution is currently at one of the given breakpoints.
 boolean isTerminating()
          Get the flag indicating if the context is about to be deleted (no more components can be added).
 IFuture killComponent()
          Kill the component.
 void messageArrived(IMessageAdapter message)
          Can be called concurrently (also during executeAction()).
 void removeComponentListener(IComponentListener listener)
          Remove a component listener.
 void removeSpace(String name)
          Add a space to the context.
 IFuture scheduleStep(IComponentStep step)
          Schedule a step of the component.
 void setResultValue(String name, Object value)
          Set a result value.
protected  void setTerminating(boolean terminating)
          Set the flag indicating if the context is about to be deleted (no more components can be added).
 String toString()
          Get a string representation of the context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATE_INITFUTURES

protected static final String STATE_INITFUTURES
Application state, while waiting for initial futures.

See Also:
Constant Field Values

STATE_INITREADY

protected static final String STATE_INITREADY
Application state, when ready to init.

See Also:
Constant Field Values

STATE_STARTED

protected static final String STATE_STARTED
Application state, when already started.

See Also:
Constant Field Values

config

protected MApplicationInstance config
The application configuration.


spaces

protected Map spaces
The contained spaces.


properties

protected Map properties
The properties.


adapter

protected IComponentAdapter adapter
The component adapter.


model

protected MApplicationType model
The application type.


parent

protected IExternalAccess parent
The parent component.


terminating

protected boolean terminating
Flag to indicate that the context is about to be deleted (no more components can be added).


ctypes

protected Map ctypes
Component type mapping (cid -> modelname) and (modelname->application component type).


instances

protected MultiCollection instances

arguments

protected Map arguments
The arguments.


results

protected Map results
The arguments.


fetcher

protected IValueFetcher fetcher
The value fetcher.


container

protected IServiceContainer container
The service container.


steps

protected List steps
The scheduled steps of the component.


willdostep

protected boolean willdostep
Flag indicating an added step will be executed without the need for calling wakeup().


componentlisteners

protected List componentlisteners
The component listeners.

Constructor Detail

ApplicationInterpreter

public ApplicationInterpreter(IComponentDescription desc,
                              MApplicationType model,
                              MApplicationInstance config,
                              IComponentAdapterFactory factory,
                              IExternalAccess parent,
                              Map arguments,
                              Future inited)
Create a new context.

Method Detail

findComponentType

protected void findComponentType(int i,
                                 List componenttypes,
                                 ILibraryService ls,
                                 Class servicetype,
                                 Future ret)
Find component type that provided a specific service.


scheduleStep

public IFuture scheduleStep(IComponentStep step)
Schedule a step of the component. May safely be called from external threads.

Specified by:
scheduleStep in interface IApplication
Parameters:
step - Code to be executed as a step of the component.

addSpace

public void addSpace(String name,
                     ISpace space)
Add a space to the context.

Parameters:
space - The space.

removeSpace

public void removeSpace(String name)
Add a space to the context.

Parameters:
name - The space name.

getSpace

public ISpace getSpace(String name)
Get a space by name.

Parameters:
name - The name.
Returns:
The space.

getLogger

public Logger getLogger()
Get the logger.

Returns:
The logger.

deleteContext

public void deleteContext()
Delete a context. Called from context service before a context is removed from the platform. Default context behavior is to do nothing.

Parameters:
application - The context to be deleted.
listener - The listener to be notified when deletion is finished (if any).

componentCreated

public IFuture componentCreated(IComponentDescription desc,
                                IModelInfo model)
Called when a component has been created as a subcomponent of this component. This event may be ignored, if no special reaction to new or destroyed components is required. The current subcomponents can be accessed by IComponentAdapter.getSubcomponents().

Specified by:
componentCreated in interface IComponentInstance
Parameters:
comp - The newly created component.

componentDestroyed

public IFuture componentDestroyed(IComponentDescription desc)
Called when a subcomponent of this component has been destroyed. This event may be ignored, if no special reaction to new or destroyed components is required. The current subcomponents can be accessed by IComponentAdapter.getSubcomponents().

Specified by:
componentDestroyed in interface IComponentInstance
Parameters:
comp - The destroyed component.

getComponentAdapter

public IComponentAdapter getComponentAdapter()
Get the component adapter.

Returns:
The component adapter.

getName

public String getName()
Get the name.


toString

public String toString()
Get a string representation of the context.

Overrides:
toString in class Object

getModel

public IModelInfo getModel()
Get the model.

Specified by:
getModel in interface IInternalAccess
Returns:
The model.

getComponentIdentifier

public IComponentIdentifier getComponentIdentifier()
Get the component identifier.

Specified by:
getComponentIdentifier in interface IApplication
Specified by:
getComponentIdentifier in interface IInternalAccess
Returns:
The component id of the application.

getApplicationType

public MApplicationType getApplicationType()
Get the application type.

Specified by:
getApplicationType in interface IApplication

isTerminating

public boolean isTerminating()
Get the flag indicating if the context is about to be deleted (no more components can be added).


setTerminating

protected void setTerminating(boolean terminating)
Set the flag indicating if the context is about to be deleted (no more components can be added).


getAllImports

public String[] getAllImports()
Get the imports.

Specified by:
getAllImports in interface IApplication
Returns:
The imports.

executeStep

public boolean executeStep()
Can be called on the component thread only. Main method to perform component execution. Whenever this method is called, the component performs one of its scheduled actions. The platform can provide different execution models for components (e.g. thread based, or synchronous). To avoid idle waiting, the return value can be checked. The platform guarantees that executeAction() will not be called in parallel.

Specified by:
executeStep in interface IComponentInstance
Returns:
True, when there are more actions waiting to be executed.

messageArrived

public void messageArrived(IMessageAdapter message)
Can be called concurrently (also during executeAction()). Inform the component that a message has arrived. Can be called concurrently (also during executeAction()).

Specified by:
messageArrived in interface IComponentInstance
Parameters:
message - The message that arrived.

cleanupComponent

public IFuture cleanupComponent()
Can be called concurrently (also during executeAction()). Request component to kill itself. The component might perform arbitrary cleanup activities during which executeAction() will still be called as usual. Can be called concurrently (also during executeAction()).

Specified by:
cleanupComponent in interface IComponentInstance
Parameters:
listener - When cleanup of the component is finished, the listener must be notified.

killComponent

public IFuture killComponent()
Kill the component.

Specified by:
killComponent in interface IInternalAccess

getExternalAccess

public IExternalAccess getExternalAccess()
Can be called concurrently (also during executeAction()). Get the external access for this component. The specific external access interface is kernel specific and has to be casted to its corresponding incarnation.

Specified by:
getExternalAccess in interface IComponentInstance
Specified by:
getExternalAccess in interface IInternalAccess
Parameters:
listener - External access is delivered via result listener.

getClassLoader

public ClassLoader getClassLoader()
Get the class loader of the component. The component class loader is required to avoid incompatible class issues, when changing the platform class loader while components are running. This may occur e.g. when decoding messages and instantiating parameter values.

Specified by:
getClassLoader in interface IComponentInstance
Returns:
The component class loader.

isAtBreakpoint

public boolean isAtBreakpoint(String[] breakpoints)
Test if the component's execution is currently at one of the given breakpoints. If yes, the component will be suspended by the platform.

Specified by:
isAtBreakpoint in interface IComponentInstance
Parameters:
breakpoints - An array of breakpoints.
Returns:
True, when some breakpoint is triggered.

getArguments

public Map getArguments()
Get the arguments.

Specified by:
getArguments in interface IApplication
Returns:
The arguments.

setResultValue

public void setResultValue(String name,
                           Object value)
Set a result value.

Parameters:
name - The result name.
value - The result value.

getResults

public Map getResults()
Get the results of the component (considering it as a functionality). Note: The method cannot make use of the asynchrnonous result listener mechanism, because the it is called when the component is already terminated (i.e. no invokerLater can be used).

Specified by:
getResults in interface IApplication
Specified by:
getResults in interface IComponentInstance
Returns:
The results map (name -> value).

getComponentType

public String getComponentType(IComponentIdentifier cid)
Get the logical component type for a given component id.

Specified by:
getComponentType in interface IApplication
Parameters:
cid - The component id.
Returns:
The logical type name of the component as defined in the application descriptor.

getComponentFilename

public String getComponentFilename(String type)
Get the file name for a logical type name of a subcomponent of this application.

Specified by:
getComponentFilename in interface IApplication
Parameters:
type - The logical type name of the component as defined in the application descriptor.
Returns:
The file name.

getParent

public IExternalAccess getParent()
Get the parent.

Specified by:
getParent in interface IInternalAccess

createResultListener

public IResultListener createResultListener(IResultListener listener)
Create a result listener which is executed as an component step.

Specified by:
createResultListener in interface IInternalAccess
Parameters:
The - original listener to be called.
Returns:
The listener.

createComponent

protected void createComponent(List components,
                               IComponentManagementService ces,
                               int i,
                               Future inited)
Create subcomponents. NOTE: parent cannot declare itself initing while subcomponents are created because they need the external access of the parent, which is available only after init is finished (otherwise there is a cyclic init dependency between parent and subcomps).


getFileName

public String getFileName(String ctype)
Get the file name of a component type.

Parameters:
ctype - The component type.
Returns:
The file name of this component type.

getArguments

public Map getArguments(MComponentInstance component)
Get the arguments.

Returns:
The arguments as a map of name-value pairs.

getNumber

public int getNumber(MComponentInstance component)
Get the number of components to start.

Returns:
The number.

getServiceProvider

public IServiceProvider getServiceProvider()
Get the service provider.

Specified by:
getServiceProvider in interface IApplication
Specified by:
getServiceProvider in interface IInternalAccess
Returns:
The service container.

getServiceContainer

public IServiceContainer getServiceContainer()
Create the service container.

Specified by:
getServiceContainer in interface IComponentInstance
Returns:
The service container.

getChildren

public Collection getChildren(String type)
Get the children (if any).

Returns:
The children.

getChildren

public IFuture getChildren()
Get the children (if any).

Specified by:
getChildren in interface IInternalAccess
Returns:
The children.

addComponentListener

public void addComponentListener(IComponentListener listener)
Add an component listener.

Specified by:
addComponentListener in interface IInternalAccess
Parameters:
listener - The listener.

removeComponentListener

public void removeComponentListener(IComponentListener listener)
Remove a component listener.

Specified by:
removeComponentListener in interface IInternalAccess
Parameters:
listener - The listener.


Copyright © 2010. All Rights Reserved.