|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
java.lang.Objectjp.co.fujitsu.reffi.client.android.model.BaseModel
jp.co.fujitsu.reffi.client.android.model.TimerProcessCore
public class TimerProcessCore
[概 要]
設定されたタイマー契機で任意のコード、Actionを実行する機能モデルです。[詳 細]
タイマーが実行されるとModelProcessEvent.SUCCESSイベントが発行されます。
intervalActionフィールドが設定されていると、ModelProcessEvent.SUCCESSイベントの発行の代わりに
intervalActionの実行をコントローラに委譲します。
繰り返し実行されるのはアクションのsuccessForwardでは無く、intervalActionになります。
intervalActionの指定有無に関わらず、TimerProcessCoreをリザーブしたアクションのcompleteが コールされるのは、TimerProcessCoreが停止したタイミングです。
[備 考]
使用例)
package demo.jfreechart.action;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.util.List;
import jp.co.fujitsu.reffi.client.swing.action.BaseAction;
import jp.co.fujitsu.reffi.client.swing.controller.ParameterMapping;
import jp.co.fujitsu.reffi.client.swing.event.ModelProcessEvent;
import jp.co.fujitsu.reffi.client.swing.model.Model;
import jp.co.fujitsu.reffi.client.swing.model.TimerProcessCore;
import org.jfree.data.time.Millisecond;
import demo.jfreechart.TimeSeriesChartIFrame;
public class TimeSeriesChartInitAction extends BaseAction {
MemoryPoolMXBean eden;
MemoryPoolMXBean survivor;
MemoryPoolMXBean tenured;
MemoryPoolMXBean perm;
@Override
protected boolean prepare(ParameterMapping parameterMapping) throws Exception {
// 世代別メモリのMXBeanを取得してフィールドに保存します。
List memoryPoolMXBeans = ManagementFactory
.getMemoryPoolMXBeans();
for (MemoryPoolMXBean mpbean : memoryPoolMXBeans) {
if("Eden Space".equals(mpbean.getName())) {
this.eden = mpbean;
}else if("Survivor Space".equals(mpbean.getName())) {
this.survivor = mpbean;
}else if("Tenured Gen".equals(mpbean.getName())) {
this.tenured = mpbean;
}else if("Perm Gen".equals(mpbean.getName())) {
this.perm = mpbean;
}
}
return true;
}
@Override
protected void reserveModels(List> models) {
// タイマー実行機能モデルをリザーブ
models.add(TimerProcessCore.class);
}
@Override
public boolean nextModel(int index, ModelProcessEvent prev, Model next) throws Exception {
if(index == 0) {
// 1秒毎にタイマー実行され、successForwardが定期実行されるよう設定します。
// タイマーをストップさせる為に必要なtimerIdは、画面クラスのハッシュコードにしています。
Object eventSource = getParameterMapping().getEventSource();
((TimerProcessCore)next).setTimerId(String.valueOf(eventSource.hashCode()));
((TimerProcessCore)next).setPeriod(1000);
}
return true;
}
@Override
public void successForward(int index, Model model, Object result) throws Exception {
// 1秒毎にコントローラからコールバックされます。
// JFreeChartの描画データを追加しています。
TimeSeriesChartIFrame iframe = (TimeSeriesChartIFrame) getParameterMapping().getEventSource();
iframe.edenSeries.add(new Millisecond(), eden.getUsage().getUsed());
iframe.survivorSeries.add(new Millisecond(), survivor.getUsage().getUsed());
iframe.tenuredSeries.add(new Millisecond(), tenured.getUsage().getUsed());
iframe.permSeries.add(new Millisecond(), perm.getUsage().getUsed());
}
}
・サーバ時刻を取得するアクションを定期的に実行する。
package demo.timeraction.action;
import java.util.List;
import javax.swing.JLabel;
import jp.co.fujitsu.reffi.client.swing.action.BaseAction;
import jp.co.fujitsu.reffi.client.swing.controller.ParameterMapping;
import jp.co.fujitsu.reffi.client.swing.event.ModelProcessEvent;
import jp.co.fujitsu.reffi.client.swing.model.HTTPRequestCore;
import jp.co.fujitsu.reffi.client.swing.model.Model;
// タイマーで定期実行されるアクションです。
public class PeriodicAction extends BaseAction {
@Override
protected boolean prepare(ParameterMapping parameterMapping) throws Exception {
System.out.println("PeriodicAction#prepare");
return true;
}
@Override
protected void reserveModels(List> models) {
// サーバに時刻を問い合わせる為のHTTPリクエスト機能モデルをリザーブ
models.add(HTTPRequestCore.class);
}
@Override
public boolean nextModel(int index, ModelProcessEvent prev, Model next) throws Exception {
if(index == 0) {
// サーバロジックは任意です(Struts等でも可)。
// PeriodicAccessModelはサーバ側でnew Date()をシリアライズして返却します。
String serverSleepMs = getComponentValueAsString("timerActionFrame.jtfServerSleepMs");
((HTTPRequestCore)next).setRequestUrl("/webcontroller");
((HTTPRequestCore)next).addUrlParamteters("model.fqcn", "demo.server.model.PeriodicAccessModel");
((HTTPRequestCore)next).addUrlParamteters("sleepMs", serverSleepMs);
}
return true;
}
@Override
public void successForward(int index, Model model, Object result) throws Exception {
// 画面にサーバ時刻を表示します。
JLabel jlResult = (JLabel)getComponentByName("timerActionFrame.jlResult");
jlResult.setText(result.toString());
System.out.println("PeriodicAction#successForward");
}
@Override
public Exception failureForward(int index, Model model, Exception e) {
System.out.println("PeriodicAction#failureForward");
return e;
}
@Override
public void complete() {
System.out.println("PeriodicAction#complete");
}
}
package demo.timeraction.action;
import java.util.List;
import javax.swing.JButton;
import jp.co.fujitsu.reffi.client.swing.action.BaseAction;
import jp.co.fujitsu.reffi.client.swing.controller.ParameterMapping;
import jp.co.fujitsu.reffi.client.swing.event.ModelProcessEvent;
import jp.co.fujitsu.reffi.client.swing.model.Model;
import jp.co.fujitsu.reffi.client.swing.model.TimerProcessCore;
// タイマー開始ボタン押下アクションです。
public class TimerActionStartAction extends BaseAction {
@Override
protected boolean prepare(ParameterMapping parameterMapping) throws Exception {
// 開始、停止ボタンの有無効を切り替えます。
JButton jbStart = (JButton)getComponentByName("timerActionFrame.jbStart");
JButton jbStop = (JButton)getComponentByName("timerActionFrame.jbStop");
jbStart.setEnabled(false);
jbStop.setEnabled(true);
return true;
}
@Override
protected void reserveModels(List> models) {
// タイマー開始用機能モデルをリザーブ
models.add(TimerProcessCore.class);
}
@Override
public boolean nextModel(int index, ModelProcessEvent prev, Model next) throws Exception {
if(index == 0) {
// 画面から初期遅延、間隔、自動終了ミリ秒数を取ります。(ここでは自動終了ミリ秒数は0です)
int timerInitDelayMs =
Integer.parseInt(getComponentValueAsString("timerActionFrame.jtfTimerInitDelayMs"));
int timerPeriodMs =
Integer.parseInt(getComponentValueAsString("timerActionFrame.jtfTimerPeriodMs"));
int timerStopLaterMs =
Integer.parseInt(getComponentValueAsString("timerActionFrame.jtfTimerStopLaterMs"));
((TimerProcessCore)next).setTimerId(String.valueOf(getOwnWindow().hashCode()));
((TimerProcessCore)next).setInitialDelay(timerInitDelayMs);
((TimerProcessCore)next).setPeriod(timerPeriodMs);
((TimerProcessCore)next).setStopLater(timerStopLaterMs);
((TimerProcessCore)next).setIntervalAction(PeriodicAction.class);
}
return true;
}
@Override
public void successForward(int index, Model model, Object result) throws Exception {
System.out.println("TimerActionExecuteAction#successForward");
}
@Override
public Exception failureForward(int index, Model model, Exception e) {
System.out.println("TimerActionExecuteAction#failureForward");
return e;
}
@Override
public void complete() {
System.out.println("TimerActionExecuteAction#complete");
JButton jbStart = (JButton)getComponentByName("timerActionFrame.jbStart");
JButton jbStop = (JButton)getComponentByName("timerActionFrame.jbStop");
jbStart.setEnabled(true);
jbStop.setEnabled(false);
}
}
package demo.timeraction.action;
import java.util.List;
import jp.co.fujitsu.reffi.client.swing.action.BaseAction;
import jp.co.fujitsu.reffi.client.swing.event.ModelProcessEvent;
import jp.co.fujitsu.reffi.client.swing.model.Model;
import jp.co.fujitsu.reffi.client.swing.model.TimerProcessCore;
// タイマー停止ボタン押下アクションです。
public class TimerActionStopAction extends BaseAction {
@Override
protected void reserveModels(List> models) {
// タイマー停止用にリザーブ
models.add(TimerProcessCore.class);
}
@Override
public boolean nextModel(int index, ModelProcessEvent prev, Model next) throws Exception {
if(index == 0) {
// タイマーを開始したtimerIdに対してタイマーストップを依頼します。
((TimerProcessCore)next).setTimerId(String.valueOf(getOwnWindow().hashCode()));
((TimerProcessCore)next).setStop(true);
}
return true;
}
@Override
public void successForward(int index, Model model, Object result) throws Exception {
System.out.println("TimerActionStopAction#successForward");
}
@Override
public Exception failureForward(int index, Model model, Exception e) {
System.out.println("TimerActionStopAction#failureForward");
return e;
}
@Override
public void complete() {
System.out.println("TimerActionStopAction#complete");
}
}
・開始ボタンを押下して数秒後に停止ボタンを押下した実行結果
PeriodicAction#prepare
PeriodicAction#successForward
PeriodicAction#complete
:
:
PeriodicAction#prepare
PeriodicAction#successForward
PeriodicAction#complete
TimerActionExecuteAction#complete
TimerActionStopAction#successForward
TimerActionStopAction#complete
[環 境] JDK 6.0 Update 11
Copyright (c) 2008-2009 FUJITSU Japan All rights reserved.
| コンストラクタの概要 | |
|---|---|
TimerProcessCore()
|
|
| メソッドの概要 | |
|---|---|
java.util.concurrent.ScheduledExecutorService |
getExecutorService()
[概 要] タイマー実行するスケジューラサービスを返却します。 |
java.util.concurrent.ScheduledFuture<?> |
getFuture()
[概 要] タイマー実行中のタスクを返却します。 |
long |
getInitialDelay()
[概 要] 初期遅延ミリ秒数を返却します。 |
java.lang.Class<? extends AbstractAction> |
getIntervalAction()
[概 要] 定期実行するアクションクラスを返却します。 |
long |
getPeriod()
[概 要] タイマー実行する間隔ミリ秒数を返却します。 |
long |
getStopLater()
[概 要] タイマーを終了させるミリ秒数を返却します。 |
java.lang.String |
getTimerId()
[概 要] タイマーの識別子を返却します。 |
boolean |
isStop()
[概 要] タイマーを停止するかどうかのフラグを返却します。 |
protected void |
mainproc()
[概 要] TimerProcessCoreManagerにタイマーの開始、停止を委譲します。 |
protected void |
postTick()
[概 要] タイマーハンドラ拡張用メソッドです。 |
void |
setExecutorService(java.util.concurrent.ScheduledExecutorService executorService)
[概 要] タイマー実行するスケジューラサービスを設定します。 |
void |
setFuture(java.util.concurrent.ScheduledFuture<?> future)
[概 要] タイマー実行中のタスクを設定します。 |
void |
setInitialDelay(long initialDelay)
[概 要] 初期遅延ミリ秒数を設定します。 |
void |
setIntervalAction(java.lang.Class<? extends AbstractAction> intervalAction)
[概 要] 定期実行するアクションクラスを設定します。 |
void |
setPeriod(long period)
[概 要] タイマー実行する間隔ミリ秒数を設定します。 |
void |
setStop(boolean stop)
[概 要] タイマーを停止するかどうかのフラグを設定します。 |
void |
setStopLater(long stopLater)
[概 要] タイマーを終了させるミリ秒数を設定します。 |
void |
setTimerId(java.lang.String timerId)
[概 要] タイマーの識別子を設定します。 |
void |
timerCompleted()
[概 要] 指定したタイマー間隔でコールされるメソッドです。 |
| クラス jp.co.fujitsu.reffi.client.android.model.BaseModel から継承されたメソッド |
|---|
addModelProcessListener, call, done, finalproc, fireModelFailure, fireModelFinished, fireModelSuccess, getController, getExecuteIndex, getHandler, getListenerList, getParameterMapping, getResult, getSuccessCount, incrementSuccessCount, init, isAsync, isSkip, postproc, preproc, removeModelProcessListener, run, setAsync, setController, setExecuteIndex, setHandler, setListenerList, setParameterMapping, setResult, setSkip, trap |
| クラス java.lang.Object から継承されたメソッド |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| コンストラクタの詳細 |
|---|
public TimerProcessCore()
| メソッドの詳細 |
|---|
public java.lang.String getTimerId()
[概 要]
タイマーの識別子を返却します。[詳 細]
timerIdフィールドを返却します。[備 考]
public void setTimerId(java.lang.String timerId)
[概 要]
タイマーの識別子を設定します。[詳 細]
timerIdフィールドを引数timerIdで設定します。[備 考]
timerId - タイマーの識別子public long getInitialDelay()
[概 要]
初期遅延ミリ秒数を返却します。[詳 細]
initialDelayフィールドを返却します。[備 考]
public void setInitialDelay(long initialDelay)
[概 要]
初期遅延ミリ秒数を設定します。[詳 細]
initialDelayフィールドを引数initialDelayで設定します。[備 考]
initialDelay - 初期遅延ミリ秒数public long getPeriod()
[概 要]
タイマー実行する間隔ミリ秒数を返却します。[詳 細]
periodフィールドを返却します。[備 考]
public void setPeriod(long period)
[概 要]
タイマー実行する間隔ミリ秒数を設定します。[詳 細]
periodフィールドを引数periodで設定します。[備 考]
period - タイマー実行する間隔ミリ秒数public long getStopLater()
[概 要]
タイマーを終了させるミリ秒数を返却します。[詳 細]
stopLaterフィールドを返却します。[備 考]
public void setStopLater(long stopLater)
[概 要]
タイマーを終了させるミリ秒数を設定します。[詳 細]
stopLaterフィールドを引数stopLaterで設定します。[備 考]
stopLater - タイマーを終了させるミリ秒数public java.util.concurrent.ScheduledExecutorService getExecutorService()
[概 要]
タイマー実行するスケジューラサービスを返却します。[詳 細]
executorServiceフィールドを返却します。[備 考]
public void setExecutorService(java.util.concurrent.ScheduledExecutorService executorService)
[概 要]
タイマー実行するスケジューラサービスを設定します。[詳 細]
executorServiceフィールドを引数executorServiceで設定します。[備 考]
executorService - タイマー実行するスケジューラサービスpublic java.util.concurrent.ScheduledFuture<?> getFuture()
[概 要]
タイマー実行中のタスクを返却します。[詳 細]
futureフィールドを返却します。[備 考]
public void setFuture(java.util.concurrent.ScheduledFuture<?> future)
[概 要]
タイマー実行中のタスクを設定します。[詳 細]
futureフィールドを引数futureで設定します。[備 考]
future - タイマー実行中のタスクpublic boolean isStop()
[概 要]
タイマーを停止するかどうかのフラグを返却します。[詳 細]
stopフィールドを返却します。[備 考]
public void setStop(boolean stop)
[概 要]
タイマーを停止するかどうかのフラグを設定します。[詳 細]
stopフィールドを引数stopで設定します。[備 考]
stop - タイマーを停止するかどうかのフラグpublic java.lang.Class<? extends AbstractAction> getIntervalAction()
[概 要]
定期実行するアクションクラスを返却します。[詳 細]
intervalActionフィールドを返却します。[備 考]
public void setIntervalAction(java.lang.Class<? extends AbstractAction> intervalAction)
[概 要]
定期実行するアクションクラスを設定します。[詳 細]
intervalActionフィールドを引数intervalActionで設定します。[備 考]
intervalAction - 定期実行するアクションクラス
protected void mainproc()
throws java.lang.Exception
[概 要]
TimerProcessCoreManagerにタイマーの開始、停止を委譲します。[詳 細]
isStop()を判定して開始、停止をManagerに依頼します。isStopがtrueの場合は、TimerProcessCoreManager#stopが正常に行われた後、 ModelProcessEvent.SUCCESS、ModelProcessEvent.FINISHEDイベントが発行されます。
[備 考]
BaseModel 内の mainprocjava.lang.Exception - オーバーライド先で発生する可能性が有る例外public final void timerCompleted()
[概 要]
指定したタイマー間隔でコールされるメソッドです。[詳 細]
ModelProcessEvent.SUCCESSイベントを発行します。[備 考]
protected void postTick()
[概 要]
タイマーハンドラ拡張用メソッドです。[詳 細]
timerCompleted()によってテンプレートコールされます。[備 考]
|
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||