@OnStart & @OnStop

In applications based on NetBeans Platform 7.2, you'll be able to replace all your ModuleInstall classes with this code:

import org.openide.modules.OnStart;
import org.openide.modules.OnStop;

@OnStart
public final class Installer implements Runnable {

    @Override
    public void run() {
        System.out.println("enable something...");
    }

    @OnStop
    public static final class Down implements Runnable {
        @Override
        public void run() {
            System.out.println("disable something...");
        }
    }
    
}

Build the module and the annotations result in named services, thanks to @NamedServiceDefinition:

Aside from no longer needing to register the ModuleInstall class in the manifest, performance of startup will be enhanced, if you use the above approach:

https://netbeans.org/bugzilla/show_bug.cgi?id=200636

Comments:

It is unclear to me how to "enable something" across modules. For example, if you used the onStart for a login similarly to what you did here: https://blogs.oracle.com/geertjan/entry/simple_security_mechanism_for_the, but I'm not sure how to make sure the login occurs before the other modules are enabled.

Posted by Bertha Truble on March 15, 2014 at 03:03 PM PDT #

I created several @OnStart annotation runnable classes within the same module. Each class implements an independent initialization code. I observed that several threads are created to run @OnStart annotated runnables in parallel, which may cause race conditions.

Posted by Daniel Felix Ferber on August 01, 2014 at 05:16 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« August 2015
SunMonTueWedThuFriSat
      
8
9
19
22
23
29
31     
Today