[dwr-users] ScheduledThreadPoolExecutor won't run after intialized
I took the PeopleTable method and built my own runner method. It works
perfectly fine with a direct call. However, after seeing that
ScheduledThreadPoolExecutor gets initialized, the
ScheduledThreadPoolExecutor run method is never called. Can anyone tell me
what I'm doing wrong?
Here is my runnable class:
public class AlertRunner implements Runnable
{
// Create default logging
static Logger log = Logger.getLogger(AlertRunner.class);
ScheduledThreadPoolExecutor executor = null;
/**
* Constructor - Creates a thread pool that runs every minute.
*/
public AlertRunner()
{
System.out.println("Initialize ScheduledThreadPoolExecutor");
executor = new
ScheduledThreadPoolExecutor(1, new DaemonThreadFactory());
executor.scheduleAtFixedRate(this, 1, 10, TimeUnit.SECONDS);
int queued = executor.getQueue().size();
int active = executor.getActiveCount();
int notCompleted = queued + active; // approximate
System.out.println(String.format("\nBeginning Executor Statistics:\nqueued
%1$d\nactive %2$d\nnotCompleted %3$d", queued, active, notCompleted));
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run()
{
updateTableDisplay();
}
public void stop()
{
log.info("stopping executor...");
executor.shutdownNow();
}
public void updateTableDisplay()
{
int queued = executor.getQueue().size();
int active = executor.getActiveCount();
int notCompleted = queued + active; // approximate
System.out.println(String.format("\nBeginning Executor Statistics:\nqueued
%1$d\nactive %2$d\nnotCompleted %3$d", queued, active, notCompleted));
// Get the current page.
String page = ServerContextFactory.get().getContextPath() +
"/html/LandingPage.jsp";
ScriptSessionFilter attributeFilter = new
AttributeScriptSessionFilter(SCRIPT_SESSION_ATTR);
log.info("Check for page filter...");
ScriptSession session = WebContextFactory.get().getScriptSession();
String customSessionAttr =
(String)session.getAttribute(SCRIPT_SESSION_ATTR);
log.info("<Before Page> SCRIPT_SESSION_ATTR: " + customSessionAttr);
Browser.withPageFiltered(page, attributeFilter, new Runnable(){
@Override
public void run() {
try {
Util.setValue("errorDiv1", "");
log.info("updating table....");
ScriptSession session = WebContextFactory.get().getScriptSession();
if (session.isInvalidated()) {
return;
}
String jfsEndpoint = (String) session.getAttribute("jfsEndpoint");
Object jfsinfoObj = session.getAttribute("jfsinfo");
JFSInfo jfsinfo = (JFSInfo)jfsinfoObj;
if (jfsEndpoint == null || jfsinfo == null) {
Util.setValue("errorDiv1", "Error: missing session information");
return;
}
String alertXML = JFSWSClient.getAlertHistory(jfsEndpoint, jfsinfo);
Util.setValue("alertXML", alertXML);
ScriptSessions.addFunctionCall("eg.ahpkg.loadForm");
log.info("table updated.");
} catch (AxisFault e) {
Util.setValue("errorDiv1", "Error: " + e.getMessage());
}
}
});
}
/**
* Called from the client to add an attribute on the ScriptSession. This
* attribute will be used so that only pages (ScriptSessions) that have
* set this attribute will be updated.
*/
public void addAttributeToScriptSession(String val) {
log.info("Setting filter of " + val + " to " + SCRIPT_SESSION_ATTR);
ScriptSession scriptSession =
WebContextFactory.get().getScriptSession();
scriptSession.setAttribute(SCRIPT_SESSION_ATTR, val);
}
/**
* Called from the client to remove an attribute from the ScriptSession.
* When called from a client that client will no longer receive updates
(unless addAttributeToScriptSession)
* is called again.
*/
public void removeAttributeToScriptSession(String val) {
ScriptSession scriptSession =
WebContextFactory.get().getScriptSession();
scriptSession.removeAttribute(SCRIPT_SESSION_ATTR);
}
/**
* This is the ScriptSessionFilter that will be used to filter out
allScriptSessions
* unless the SCRIPT_SESSION_ATTR attribute exists and is the same as the
user's username.
*/
protected class AttributeScriptSessionFilter implements
ScriptSessionFilter
{
public AttributeScriptSessionFilter(String attributeName)
{
this.attributeName = attributeName;
}
/* (non-Javadoc)
* @see
org.directwebremoting.ScriptSessionFilter#match(org.directwebremoting.ScriptSession)
*/
@Override
public boolean match(ScriptSession session)
{
Object jfsinfoObj = session.getAttribute("jfsinfo");
if (jfsinfoObj == null)
return false;
JFSInfo jfsinfo = (JFSInfo)jfsinfoObj;
String userName = (String)session.getAttribute(attributeName);
if (userName == null || "".equals(userName))
return false;
return (userName.equals(jfsinfo.getUserName()));
}
private final String attributeName;
}
private final static String SCRIPT_SESSION_ATTR = "SCRIPT_SESSION_ATTR";
}
And just in case you need it,
my dwr.xml:
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN"
"http://getahead.org/dwr//dwr30.dtd">
<dwr>
<allow>
<create creator="new" scope="application">
</create>
<create creator="new" scope="application">
</create>
<convert converter="bean" match="com.jfs.util.JFSInfo" />
<create creator="new" scope="application">
</create>
<convert match="java.lang.Exception" converter="exception">
</convert>
</allow>
</dwr>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID">
<display-name>JFSSETSInteractive</display-name>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<display-name>DWR Servlet</display-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>LoginHelper</servlet-name>
<servlet-class>com.jfs.servlets.LoginHelper</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>DataEntryHelper</servlet-name>
<servlet-class>com.jfs.servlets.DataEntryHelper</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>DataSubmitter</servlet-name>
<servlet-class>com.jfs.servlets.DataSubmitter</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet>
<servlet-name>DocumentHelper</servlet-name>
<servlet-class>com.jfs.servlets.DocumentHelper</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LoginHelper</servlet-name>
<url-pattern>/html/LoginHelper</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DataEntryHelper</servlet-name>
<url-pattern>/html/DataEntryHelper</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DataSubmitter</servlet-name>
<url-pattern>/html/DataSubmitter</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DocumentHelper</servlet-name>
<url-pattern>/html/DocumentHelper</url-pattern>
</servlet-mapping>
<welcome-file-list id="WelcomeFileList_1">
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
The relevent javascript code:
this is the load function:
ahpkg.tableLoaded = function() {
AlertRunner.addAttributeToScriptSession(dwr.util.getValue("userName"),
function() {dwr.engine.setActiveReverseAjax(true);});
AlertRunner.updateTableDisplay();
}
And some global javascript:
dwr.engine.setErrorHandler(errh);
dwr.engine.setNotifyServerOnPageUnload(true);
Thanks.
--
View this message in context: http://dwr.2114559.n2.nabble.com/ScheduledThreadPoolExecutor-won-t-run-after-intialized-tp7525522.html
Sent from the DWR - Users mailing list archive at Nabble.com.