^1727576223128
@
sname
Contexts
slabel
Listeners
sgroup
actions
sdescritporForNewThing
xworker.message.MessageWithToolbar
Sdescription
#$@text#$@
<h1>动作监听器</h1>

<h2>1.简介</h2>

<p>&nbsp;&nbsp;&nbsp; 动作监听器用于监听动作的执行。主要监听以下事件：</p>

<ul>
	<li>动作执行前。</li>
	<li>动作执行后无异常。</li>
	<li>动作执行后有异常。</li>
	<li>模型执行行为时。</li>
</ul>

<h2>2.用途</h2>

<p>&nbsp;&nbsp;&nbsp; 常用于调试、监控和管理上下文。比如打印一个动作的执行信息，向上下文设置JDBC连接以及自动提交和关闭连接等。</p>

<h2>3.实现</h2>

<p>&nbsp;&nbsp;&nbsp; 动作监听器建议使用Java实现，模型提供创建Java对象的方法。</p>

<ul>
	<li><strong>org.xmeta.ActionListener</strong><br />
	动作监听器接口。</li>
	<li><strong>org.xmeta.ContextVarProvider</strong><br />
	抽象类，实现了ActionListener，用于管理上下文中的变量。</li>
	<li><strong>org.xmeta.ActionListenerProvider</strong><br />
	用于创建ActionListener实例。动作监听器模型需要实现createProvider()方法，createProvider()方法返回ActionListenerProvider。</li>
</ul>

<p>&nbsp;</p>
#$@text#$@
sdescriptors
xworker.lang.util.ThingIndex
sinheritDescription
false
sth_createIndex
true
sth_registThing
child|xworker.lang.util.ThingIndex
sth_registMyChilds
false
sth_registDisabled
false
sth_fileMonitor
false
Sen_description
#$@text#$@
<h1>Action Listener</h1>

<p>&nbsp;&nbsp;&nbsp; An action listener is a thing that can monitor the execution of an action. It can execute the corresponding init, suceess and exception methods before the action is executed, the execution is successful or the execution is abnormal, so that the execution of the action can be monitored. In addition, the onDoAction method is added to monitor the execution of things. </p>

<p>&nbsp;&nbsp;&nbsp; The action listener can be used to implement action monitoring, action debugging, database resource creation and release, and so on. </p>

<h2>1. Use the action listener</h2>

<p>&nbsp;&nbsp;&nbsp; Add contexts (action listeners or ActionListeners) sub-things under an action, and you can add action listeners for the action. </p>

<p>&nbsp;&nbsp;&nbsp; The action listener was originally called the action context, but was later renamed the action listener, so the contexts child thing was added, and the label was the action listener (Chinese) or ActionListener (English). </p>

<h2>2. Global action listener</h2>

<p>&nbsp;&nbsp;&nbsp; You can add a global action listener through the World.addGlobalActionListener(Thing listener, int index) method. </p>

<p>&nbsp;&nbsp;&nbsp;The global action listener will monitor the execution of every action in the system. If the execution of the action context takes too much time, it will slow down the overall speed of the system. </p>

<p>&nbsp;&nbsp;&nbsp; For example, the action debugging function of XWorker is realized through the global action listener. </p>

<h3>2.1. Avoid recursion</h3>

<p>&nbsp;&nbsp;&nbsp; To avoid recursion, actions in the global action context cannot be monitored by the global action context. </p>

<h2>4. How to implement an action listener</h2>

<p>&nbsp;&nbsp;&nbsp; Things that implement the init, success, exception and onDoAction methods can all be used as action listeners. The action listener should be registered under the thing xworker.lang.context.Contexts in a child manner. </p>

<h3>4.1. Get the monitored action and variable context</h3>

<p>&nbsp;&nbsp;&nbsp;&nbsp; The action listener uses an independent variable context, and the monitored action and action variable context can be obtained in the variable context of the action listener. </p>

<pre class="brush:java;">
//The variable context of the action being monitored
ActionContext acContext = (ActionContext) actionContext.get(Action.str_parentContext);
//Get the monitored action
List&lt;Action&gt; actions = acContext.getActions();
Action action = actions.get(actions.size()-1);</pre>

<p>&nbsp;&nbsp;&nbsp; The above is valid for init, sucess and exception methods. </p>

<h3>4.2. Get the name of the monitored thing and method</h3>

<p>&nbsp;&nbsp;&nbsp; does not use an independent variable context when monitoring things perform actions, so the current variable context is the variable context when things perform actions. </p>

<pre class="brush:java;">
//Get things and the name of the corresponding method to be executed
Thing thing = actionContext.getObject(&quot;thing&quot;);
String actionName = actionContext.getObject(&quot;actionName&quot;);</pre>

<p>&nbsp;</p>

<p>&nbsp;</p>
#$@text#$@
sth_mark
false
  @/@DataSouceActionContext
  sname
  DataSouceActionContext
  sdescriptors
  xworker.lang.MetaDescriptor3/@thing
  sextends
  xworker.lang.db.jdbc.DataSouceActionContext
  smany
  true
  seditCols
  2
  sinitialization
  false
  sgroup
  db
  smodifier
  public
  sinheritDescription
  true
  sth_createIndex
  false
  sid
  DataSouceActionContext
  @/@HibernateContext
  sname
  HibernateContext
  sdescriptors
  xworker.lang.MetaDescriptor3/@thing
  sextends
  xworker.core.context.HibernateContext
  smany
  true
  seditCols
  2
  sinitialization
  false
  sgroup
  db
  smodifier
  public
  sinheritDescription
  true
  sth_createIndex
  false
  sid
  HibernateContext
  @/@PerformanceContext
  sname
  PerformanceContext
  sdescriptors
  xworker.lang.MetaDescriptor3/@thing
  sextends
  xworker.lang.context.PerformanceContext
  smany
  true
  seditCols
  2
  sinitialization
  false
  sgroup
  debug
  smodifier
  public
  sinheritDescription
  true
  sth_createIndex
  false
  sid
  PerformanceContext
  @/@FileOutputStream
  sname
  FileOutputStream
  sdescriptors
  xworker.lang.MetaDescriptor3/@thing
  sextends
  xworker.core.actions.io.FileOutputStream
  smany
  true
  seditCols
  2
  sinitialization
  false
  sgroup
  io
  smodifier
  public
  sinheritDescription
  true
  sth_createIndex
  false
  sid
  FileOutputStream
  @/@FileInputStream
  sname
  FileInputStream
  sdescriptors
  xworker.lang.MetaDescriptor3/@thing
  sextends
  xworker.core.actions.io.FileInputStream
  smany
  true
  seditCols
  2
  sinitialization
  false
  sgroup
  io
  smodifier
  public
  sinheritDescription
  true
  sth_createIndex
  false
  sid
  FileInputStream
  @/@DebugContext
  sname
  DebugContext
  sdescriptors
  xworker.lang.MetaDescriptor3/@thing
  sextends
  xworker.lang.context.DebugContext
  smany
  true
  seditCols
  2
  sinitialization
  false
  sgroup
  debug
  smodifier
  public
  sinheritDescription
  true
  snotXmlAttribute
  false
  sjson_isArray
  false
  sth_createIndex
  false
  sth_registMyChilds
  false
  sth_registDisabled
  false
  sth_mark
  false
  sid
  DebugContext
  @/@ExecutorActionContext
  sname
  ExecutorActionContext
  sdescriptors
  xworker.lang.MetaDescriptor3/@thing
  sextends
  xworker.lang.executor.ExecutorActionContext
  smany
  true
  seditCols
  2
  sinitialization
  false
  sgroup
  executor
  smodifier
  public
  sinheritDescription
  true
  snotXmlAttribute
  false
  sjson_isArray
  false
  sth_createIndex
  false
  sth_registMyChilds
  false
  sth_registDisabled
  false
  sth_fileMonitor
  false
  sth_mark
  false
  sid
  ExecutorActionContext
  @/@AbstractActionListener
  sname
  AbstractActionListener
  sdescriptors
  xworker.lang.util.ThingIndex/@thing
  sextends
  xworker.lang.context.ActionListener
  smany
  true
  seditCols
  2
  sinitialization
  false
  smodifier
  public
  sinheritDescription
  true
  snotXmlAttribute
  false
  sjson_isArray
  false
  sjson_array_type
  children
  sjson_attribute
  false
  sth_createIndex
  false
  sth_registMyChilds
  false
  sth_registDisabled
  false
  sth_noThingRegistViewer
  false
  sth_fileMonitor
  false
  sth_mark
  false
  sth_registQueryOnlySelf
  false
  sid
  AbstractActionListener
