In test.jsp i am showing following information
Node Name
Node Location
Current Status
To show above information showStatus method of action class TestAction.java is called, this method is retrieving status by following block of code.
TestDTO.getInstance("NODE1").getCurrentStatus()
After executing showStatus method control will go to 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";
}
}
After executing showStatus method control will go to 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>
Some other application is updating the status by following block of code
TestDTO.getInstance("NODE1").setCurrentStatus("RUNNING");
My problem is that I want to dynamically update the current status of node on gui without any user intervention. Once user click on the link, i am calling showStatus method,and able to show the staus of node on gui,but after that if it changes,then to know the current status user is again accesing the link,i want to avoid this. I want gui behaviour something like that 1. user access the link and can see the status. 2. After some second if it changes then automatically current status should be updated.
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;
}
}
}