Skip to content
Snippets Groups Projects
Commit 54bee9ce authored by BIGARET Sebastien's avatar BIGARET Sebastien
Browse files

Application.exiting() indicates whether exit() has been called

parent b689c7d9
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,10 @@ import java.util.EventListener; ...@@ -8,6 +8,10 @@ import java.util.EventListener;
*/ */
public interface ApplicationListener extends EventListener public interface ApplicationListener extends EventListener
{ {
/** Invoked when the application exits. At this point there is no way to interrupt the process. */ /**
* Invoked when the application exits. At this point there is no way to interrupt the process.
* Code needing to know whether this event has already been fired will check
* {@link eu.telecom_bretagne.praxis.common.Application.Application#exiting()}.
*/
public void applicationExiting(); public void applicationExiting();
} }
...@@ -16,6 +16,13 @@ public class Application ...@@ -16,6 +16,13 @@ public class Application
protected ArrayList<ApplicationListener> appListeners = new ArrayList<ApplicationListener>(); protected ArrayList<ApplicationListener> appListeners = new ArrayList<ApplicationListener>();
/**
* Indicates whether {@link #exit()} has been called. The value only change once (from false to true) in the
* object's lifetime.
* @see #exiting()
*/
private boolean exiting = false;
/** /**
* The console attached to the application. Note that it is run only if configuration key "console" is true. * The console attached to the application. Note that it is run only if configuration key "console" is true.
*/ */
...@@ -56,6 +63,7 @@ public class Application ...@@ -56,6 +63,7 @@ public class Application
public void exit() public void exit()
{ {
exiting = true;
ArrayList<ApplicationListener> _listeners; ArrayList<ApplicationListener> _listeners;
synchronized(appListeners) synchronized(appListeners)
{ {
...@@ -66,6 +74,17 @@ public class Application ...@@ -66,6 +74,17 @@ public class Application
System.exit(0); System.exit(0);
} }
/**
* Tells whether the application is exiting, i.e. if exit() has been called.
* This is specially useful for code that may be indirectly triggered by
* {@link ApplicationListener#applicationExiting()}.
* @return {@code true} if {@link #exit()} has been called.
*/
public boolean exiting()
{
return exiting;
}
public void addListener(ApplicationListener listener) public void addListener(ApplicationListener listener)
{ {
synchronized(appListeners) synchronized(appListeners)
......
...@@ -8,6 +8,7 @@ import java.util.logging.Level; ...@@ -8,6 +8,7 @@ import java.util.logging.Level;
import org.jdom.Document; import org.jdom.Document;
import eu.telecom_bretagne.praxis.common.Application;
import eu.telecom_bretagne.praxis.common.Configuration; import eu.telecom_bretagne.praxis.common.Configuration;
import eu.telecom_bretagne.praxis.common.Log; import eu.telecom_bretagne.praxis.common.Log;
import eu.telecom_bretagne.praxis.common.ReleaseInfo; import eu.telecom_bretagne.praxis.common.ReleaseInfo;
...@@ -209,7 +210,7 @@ implements PlatformToServerEventListener, ClientToServerEventListener ...@@ -209,7 +210,7 @@ implements PlatformToServerEventListener, ClientToServerEventListener
{ {
Serveur.removePlatform(this); Serveur.removePlatform(this);
cnx.disconnect(); cnx.disconnect();
if (!Application.getApplication().exiting())
eu.telecom_bretagne.praxis.common.Utile.unimplemented("The running jobs should be rescheduled"); eu.telecom_bretagne.praxis.common.Utile.unimplemented("The running jobs should be rescheduled");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment