javacommons/utils/javasrc/com/nokia/mj/impl/rt/support/ApplicationUtils.java
changeset 78 71ad690e91f5
parent 49 35baca0e7a2e
child 80 d6dafc5d983f
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
    43  * Example how to register a shutdown listener.
    43  * Example how to register a shutdown listener.
    44  * <pre>
    44  * <pre>
    45  * package com.nokia.mj.impl.mypackage;
    45  * package com.nokia.mj.impl.mypackage;
    46  *
    46  *
    47  * import com.nokia.mj.impl.rt.support.ApplicationUtils;
    47  * import com.nokia.mj.impl.rt.support.ApplicationUtils;
    48  *      public void myClass()
    48  * import com.nokia.mj.impl.rt.support.ShutdownListener;
       
    49  *      public MyClass
    49  *      {
    50  *      {
    50  *          public void myMethod()
    51  *          public void myMethod()
    51  *          {
    52  *          {
    52  *              // Get the insatnce of ApplicationUtils.
    53  *              // Get the instance of ApplicationUtils.
    53  *              ApplicationUtils appUtils = ApplicationUtils.getInstance();
    54  *              ApplicationUtils appUtils = ApplicationUtils.getInstance();
    54  *
    55  *
    55  *              // Get the name of the application.
    56  *              // Get the name of the application.
    56  *              appUtils.addShutdownListener(new ShutdownListener()
    57  *              appUtils.addShutdownListener(new ShutdownListener()
    57  *              {
    58  *              {
   234      * will send a notification to all registered listeners by calling
   235      * will send a notification to all registered listeners by calling
   235      * {@link ShutdownListener#shuttingDown() shuttingDown} method. All the
   236      * {@link ShutdownListener#shuttingDown() shuttingDown} method. All the
   236      * calls are made in a loop in one thread, so if some listener blocks the
   237      * calls are made in a loop in one thread, so if some listener blocks the
   237      * call the rest of the listeners don't get the notification.
   238      * call the rest of the listeners don't get the notification.
   238      * <p>
   239      * <p>
   239      * There can be more than one listener.
   240      * There can be more than one listener, but it is recommended that there
       
   241      * is only one listener per component.
       
   242      * <p>
       
   243      * The implementation stores a strong reference to object which prevents
       
   244      * garbage collection of the listener unless the listener is removed.
   240      *
   245      *
   241      * @param listener the new listener.
   246      * @param listener the new listener.
   242      */
   247      */
   243     public void addShutdownListener(ShutdownListener listener)
   248     public void addShutdownListener(ShutdownListener listener)
   244     {
   249     {
   247             mListeners = new Vector();
   252             mListeners = new Vector();
   248         }
   253         }
   249         mListeners.addElement(listener);
   254         mListeners.addElement(listener);
   250     }
   255     }
   251 
   256 
       
   257     /**
       
   258      * Removes the registered shutdown listener.
       
   259      *
       
   260      * @param listener the listener to be removed. If the listener is not
       
   261      *                 found nothing happens. If the key is null, a 
       
   262      * @throws NullPointerException if the listener is null.
       
   263      */
       
   264     public void removeShutdownListener(ShutdownListener listener)
       
   265     {
       
   266         if (listener == null)
       
   267         {
       
   268             throw new 
       
   269               NullPointerException("Listener was null when trying to remove");
       
   270         }
       
   271         if (mListeners != null)
       
   272         {
       
   273             mListeners.removeElement(listener);
       
   274         }
       
   275     }
   252 
   276 
   253     /**
   277     /**
   254      * Waits (if needed) until the application to be started is known.
   278      * Waits (if needed) until the application to be started is known.
   255      * This method can be used for pre-warming features. If the runtime is in
   279      * This method can be used for pre-warming features. If the runtime is in
   256      * pre-warmed state where the application to be launched is not yet known,
   280      * pre-warmed state where the application to be launched is not yet known,