Launching a Java daemon with a GWT interface served by the embedded Jetty

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);

    // Create and start the daemon
    Daemon daemon = new Daemon();
    Thread thread = new Thread(daemon);
    thread.start();

    // war handler
    WebAppContext waContext = new WebAppContext();
    waContext.setContextPath("/webapp");
    waContext.setWar("./apps/DefaultApp.war");
    waContext.addEventListener(new DaemonLoader(daemon));

    // Add it to the server
    EmbJetTest.server.setHandler(waContext);

    EmbJetTest.server.setThreadPool(new QueuedThreadPool(10));

    // Start the server; join() blocks until we shut down
    EmbJetTest.server.start();
    EmbJetTest.server.join();

    // Stop the daemon thread
    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 - ?
  • , ?

.

+3
2

- GWT? , ( , .war ).

( .war) / .

+3

, , - , classload - Daemon.class WEB-INF/classes GWT app. , , GWT Daemon EmbJetTest.

, , .:)

0

Source: https://habr.com/ru/post/1738875/


All Articles