Re: @OnStart/OnStop vs ModuleInstall and also force exit during starup
Ernest C Lötter <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Jean-Marc
How about having both annotated subclasses embedded in the same parent,
as such:
public class StartupAndShutdown {
private static final Logger LOGGER = LogUtils.getLogger();
private static MyContainer container;
private static Thread containerThread;
@OnStart
public static class Starter implements Runnable {
@Override
public void run() {
try {
File f = new File("some path");
container = new NbNimbusContainer(f, "some title",
15555, 0);
containerThread = new Thread(new Runnable() {
@Override
public void run() {
try {
container.run();
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, "Exception during
container run. Exiting...", ex);
LifecycleManager.getDefault().exit(-1);
}
}
});
containerThread.start();
} catch (Exception ex) {
// must be posted on another thread otherwise deadlock
Runnable r = new Runnable() {
@Override
public void run() {
LifecycleManager.getDefault().exit(-1);
}
};
SwingUtilities.invokeLater(r);
}
}
}
@OnStop
public static class Stopper implements Runnable {
@Override
public void run() {
if (container != null) {
container.requestShutdown();
}
// wait for container to exit
if (containerThread != null) {
try {
containerThread.join(30000);
} catch (InterruptedException ex) {
LOGGER.log(Level.WARNING, "Container join
interrupted.", ex);
}
}
}
}
}
Best regards,
Ernest
On 29/09/16 22:44, Jean-Marc Borer wrote:
> public class Installer extends ModuleInstall {
>
> private static final Logger LOGGER = LogUtils.getLogger();
>
> private MyContainer container;
> private Thread containerThread;
>
> @Override
> public void restored() {
> try {
> File f = new File("some path");
> container = new NbNimbusContainer(f, "some title", 15555, 0);
> containerThread = new Thread(new Runnable() {
>
> @Override
> public void run() {
> try {
> container.run();
> } catch (Exception ex) {
> LOGGER.log(Level.SEVERE, "Exception during
> container run. Exiting...", ex);
> LifecycleManager.getDefault().exit(-1);
> }
> }
> });
> containerThread.start();
> } catch (Exception ex) {
> // must be posted on another thread otherwise deadlock
> Runnable r = new Runnable() {
>
> @Override
> public void run() {
> LifecycleManager.getDefault().exit(-1);
> }
> };
> SwingUtilities.invokeLater(r);
> }
> }
>
> @Override
> public void close() {
> if (container != null) {
> container.requestShutdown();
> }
>
> // wait for container to exit
> if (containerThread != null) {
> try {
> containerThread.join(30000);
> } catch (InterruptedException ex) {
> LOGGER.log(Level.WARNING, "Container join
> interrupted.", ex);
> }
> }
> }
> }