View Javadoc

1   /*
2    * $Id: ModelNotification.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.impl.internal.notifications;
12  
13  import org.mule.umo.manager.UMOServerNotification;
14  import org.mule.umo.model.UMOModel;
15  
16  /**
17   * <code>ModelNotification</code> is fired when an event such as the model starting
18   * occurs. The payload of this event will always be a reference to the model.
19   * 
20   * @see org.mule.umo.model.UMOModel
21   */
22  public class ModelNotification extends UMOServerNotification implements BlockingServerEvent
23  {
24      /**
25       * Serial version
26       */
27      private static final long serialVersionUID = -1954880336427554435L;
28  
29      public static final int MODEL_INITIALISING = MODEL_EVENT_ACTION_START_RANGE + 1;
30      public static final int MODEL_INITIALISED = MODEL_EVENT_ACTION_START_RANGE + 2;
31      public static final int MODEL_INITIALISING_LISTENERS = MODEL_EVENT_ACTION_START_RANGE + 3;
32      public static final int MODEL_INITIALISED_LISTENERS = MODEL_EVENT_ACTION_START_RANGE + 4;
33      public static final int MODEL_STARTING = MODEL_EVENT_ACTION_START_RANGE + 5;
34      public static final int MODEL_STARTED = MODEL_EVENT_ACTION_START_RANGE + 6;
35      public static final int MODEL_STOPPING = MODEL_EVENT_ACTION_START_RANGE + 7;
36      public static final int MODEL_STOPPED = MODEL_EVENT_ACTION_START_RANGE + 8;
37      public static final int MODEL_DISPOSING = MODEL_EVENT_ACTION_START_RANGE + 9;
38      public static final int MODEL_DISPOSED = MODEL_EVENT_ACTION_START_RANGE + 10;
39  
40      private static final transient String[] ACTIONS = new String[]{"initialising", "initialised",
41          "initialising listeners", "initialised listeners", "starting", "started", "stopping", "stopped",
42          "disposing", "disposed"};
43  
44      public ModelNotification(UMOModel model, int action)
45      {
46          super(model, action);
47          resourceIdentifier = model.getName();
48      }
49  
50      protected String getPayloadToString()
51      {
52          return ((UMOModel) source).getName();
53      }
54  
55      protected String getActionName(int action)
56      {
57          int i = action - MODEL_EVENT_ACTION_START_RANGE;
58          if (i - 1 > ACTIONS.length)
59          {
60              return String.valueOf(action);
61          }
62          return ACTIONS[i - 1];
63      }
64  }