test.jsp では、次の情報を表示しています
ノード名
ノードの場所
現在のステータス
上記の情報を表示するには、アクション クラス TestAction.java の showStatus メソッドが呼び出されます。このメソッドは、次のコード ブロックによってステータスを取得しています。
TestDTO.getInstance("NODE1").getCurrentStatus()
showStatus メソッドの実行後、コントロールは test.jsp に移動します。
TestAction.java
import java.util.ArrayList;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport
{
public TestAction()
{super();
try{}
catch (Exception e){e.printStackTrace();}
}
public String showStatus() throws Exception
{
ArrayList testList=new ArrayList();
Map session = (Map)ActionContext.getContext().getSession();
TestDTO tdto=new TestDTO();
tdto.setNodeName("NODE1");
tdto.setNodeLocation("location1");
tdto.setCurrentStatus(TestDTO.getInstance("NODE1").getCurrentStatus());
testList.add(tdto);
session.put("SHOWLIST",tdto);
return "input";
}
}
showStatus メソッドの実行後、コントロールは test.jsp に移動します。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.opensymphony.xwork2.ActionContext"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>NODE STATUS</title>
</head><body><center><s:form><br>
<s:if test="%{#session.SHOWLIST}">
<table width="80%" border="1" bgcolor="#FFFFFF" bordercolor="grey" align="center">
<tr><th><font size="4">NODE NAME</font></th><th><font size="4">NODE LOCATION</font></th>
<th ><font size="4">Status</font></th></tr>
<s:iterator value="%{#session.SHOWLIST}" var="mylist">
<tr><td bgcolor="#E6FAFB" align="center"><s:property value="nodeName" /></td>
<td bgcolor="#E6FAFB" align="center"><s:property value="nodeLocation"/></td>
<td bgcolor="#E6FAFB" align="center"><s:property value="currentStatus" /></td></tr>
</s:iterator></table></s:if></s:form></center>
</body></html>
他のアプリケーションは、次のコード ブロックによってステータスを更新しています
TestDTO.getInstance("NODE1").setCurrentStatus("RUNNING");
私の問題は、ユーザーの介入なしに GUI 上のノードの現在のステータスを動的に更新したいということです。ユーザーがリンクをクリックすると、showStatus メソッドを呼び出して、GUI でノードのステータスを表示できますが、その後変更された場合、現在のステータス ユーザーが再びリンクにアクセスしていることを知るために、これを回避したいと考えています。1.ユーザーがリンクにアクセスしてステータスを確認できるようなGUIの動作が必要です。2. 数秒後に変更された場合、自動的に現在のステータスが更新されます。
TestDTO.java
import java.util.HashMap;
public class TestDTO
{
String nodeName;String nodeLocation;String currentStatus="STOPPED";
private static HashMap instance=new HashMap();
public String getNodeName() {
return nodeName;
}
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
public String getNodeLocation() {
return nodeLocation;
}
public void setNodeLocation(String nodeLocation) {
this.nodeLocation = nodeLocation;
}
public String getCurrentStatus() {
return currentStatus;
}
public void setCurrentStatus(String currentStatus) {
this.currentStatus = currentStatus;
}
public static synchronized TestDTO getInstance(String nodeName)
{
TestDTO a;
if(instance.containsKey(nodeName))
{
return (TestDTO) instance.get(nodeName);
}
else
{
a = new TestDTO();
if(nodeName!=null && nodeName.length()>0)
instance.put(nodeName,a);
return a;
}
}
}