Cheers, coders,
Background information and code
I am trying to create a program like a daemon (for example, it runs constantly, polling for work), which is controlled by the GWT application (servlets in WAR), which, in turn, is served by the built-in Jetty server (using WebAppContext). I'm having problems with what the GWT application knows about the daemon object.
For testing things, I currently have two projects: a daemon and an embedded Jetty server in one ( EmbJetTest) and a GWT application in the other ( DefaultApp). This is the current state of the code:
First, it EmbJetTestcreates an embedded Jetty server, for example, using the ServletContextListenerdaemon to enter the context of a web application to enter:
EmbJetTest.server = new Server(8080);
Daemon daemon = new Daemon();
Thread thread = new Thread(daemon);
thread.start();
WebAppContext waContext = new WebAppContext();
waContext.setContextPath("/webapp");
waContext.setWar("./apps/DefaultApp.war");
waContext.addEventListener(new DaemonLoader(daemon));
EmbJetTest.server.setHandler(waContext);
EmbJetTest.server.setThreadPool(new QueuedThreadPool(10));
EmbJetTest.server.start();
EmbJetTest.server.join();
daemon.stopLoop();
Daemon - . DaemonLoader ServletContextListener:
private Daemon daemon;
public DaemonLoader(Daemon daemon)
{
this.daemon = daemon;
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
arg0.getServletContext().setAttribute("daemon", this.daemon);
}
GWT :
Daemon daemon = (Daemon) this.getServletContext().getAttribute("daemon");
, localhost: 8080/webapp/* , ClassCastException, . qaru.site/questions/137514/... , , .
.
- ? ? - , . GWT? GWT - ? , GWT - ?
- , ?
.