Public void destroy() does not get called

Hello,



I am currently implementing/testing some basic network functionality.

Following the spidermonkey tutorial i wanted to override the destroy function.

Here is the code i am using:

[java]

/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.

    */

    package Runnables;



    import ConfigFiles.ConfigNetworkMasterServer;

    import Network.Messages.Universe2MasterServer.RegisterUniverse.req_RegisterUniverse;

    import Network.Messages.Universe2MasterServer.RegisterUniverse.req_UnregisterUniverse;

    import Network.Messages.Universe2MasterServer.Universe2MasterMessageRegister;

    import Network.NetworkClient;

    import Network.NetworkServer;

    import com.jme3.app.SimpleApplication;

    import com.jme3.system.JmeContext;

    import java.io.IOException;

    import java.util.logging.Level;

    import java.util.logging.Logger;



    /**

    *
  • @author Michael

    */

    public class DeepUniverseUniverseServer extends SimpleApplication {



    private NetworkServer server;

    private static int universePort;

    private static int universeId;

    private NetworkClient client;



    public static void main(String args[]) {

    SimpleApplication app = new DeepUniverseUniverseServer();

    universePort = 1222;

    universeId = 1;

    app.start(JmeContext.Type.Headless);



    }



    @Override

    public void simpleInitApp() {

    try {



    Universe2MasterMessageRegister.registerMessages();

    server = new NetworkServer(universePort);

    client = new NetworkClient(ConfigNetworkMasterServer.masterServerIP, ConfigNetworkMasterServer.masterServerPort);

    client.sendMessage(new req_RegisterUniverse(universeId, universePort));



    } catch (IOException ex) {

    Logger.getLogger(DeepUniverseUniverseServer.class.getName()).log(Level.SEVERE, null, ex);

    }

    }



    @Override

    public void destroy() {

    client.sendMessage(new req_UnregisterUniverse(universeId, universePort));

    super.destroy();

    }

    }

    [/java]



    The problem is that the destory does not get called when i shutdown the program.

    I have already tested the message pipeline, it works wenn sending the message from another function.



    What have i missed here?

I use destroy just like you but not in a headless application, your implementation looks fine to me.

I think that headless applications don’t call destroy in all situations, have you tried to call close on your SimpleApplication class when you want to quit?

@dansion said:
I use destroy just like you but not in a headless application, your implementation looks fine to me.
I think that headless applications don't call destroy in all situations, have you tried to call close on your SimpleApplication class when you want to quit?


Handeling a regular shutdown is not an issue. I hoped that the @destory function would act as a fall back for unexpected shutdown, like CONTROL+C on the server.
@zzuegg Handeling a regular shutdown is not an issue. I hoped that the @destory function would act as a fall back for unexpected shutdown, like CONTROL+C on the server.


Then I don't know if there are any JMonkey solutions but there are java alternatives,and I suggest you study those, I don't use them myself so no examples :P :
how-to-capture-system-exit-event
java signalhandling

There is no reliable way to detect a shutdown in every case.

on every os ther are ways to kill a process directly, (they will never know what hit them).



(makes sense, if you do like a Thread.intterupt() in the shutdown hook, you could hang a os thread else)

Just build an “esc” function into your console app instead of having to Ctrl-C it?

I posted on another thread how to use a simple command loop instead of running a JME headless app on the server. Between that and a shutdown hook you could catch most cases.



You don’t really get any benefit from a JME SimpleApplication on the server and so I don’t really see the point of going that route.

@pspeed said:
You don't really get any benefit from a JME SimpleApplication on the server and so I don't really see the point of going that route.

Depends on how your server is set up. E.g. MonkeyZone basically mirrors everything happening on clients and server and all of that happens in AppStates, so why would I not use the existing infrastructure when I need an update loop and some jME API anyway.
@pspeed said:
I posted on another thread how to use a simple command loop instead of running a JME headless app on the server. Between that and a shutdown hook you could catch most cases.


That is true, i use the command loop also for the passive server.

In this case, the server should also simulate the physics for which i need the SimpleApp. I want all actions to be executed on the server side. The client only shows the visual representation and manages the playerinput.