View Javadoc

1   /*
2    * $Id: ComponentNotification.java 7976 2007-08-21 14:26:13Z 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.impl.MuleDescriptor;
14  import org.mule.umo.UMODescriptor;
15  import org.mule.umo.manager.UMOServerNotification;
16  
17  /**
18   * <code>ComponentNotification</code> is fired when an event such as the component
19   * starting occurs. The payload of this event will always be a reference to the
20   * component Descriptor.
21   * 
22   * @see org.mule.impl.MuleDescriptor
23   * @see org.mule.umo.UMODescriptor
24   */
25  public class ComponentNotification extends UMOServerNotification
26  {
27      /**
28       * Serial version
29       */
30      private static final long serialVersionUID = -8575741816897936674L;
31      public static final int COMPONENT_INITIALISED = COMPONENT_EVENT_ACTION_START_RANGE + 1;
32      public static final int COMPONENT_STARTED = COMPONENT_EVENT_ACTION_START_RANGE + 2;
33      public static final int COMPONENT_STOPPED = COMPONENT_EVENT_ACTION_START_RANGE + 3;
34      public static final int COMPONENT_PAUSED = COMPONENT_EVENT_ACTION_START_RANGE + 4;
35      public static final int COMPONENT_RESUMED = COMPONENT_EVENT_ACTION_START_RANGE + 5;
36      public static final int COMPONENT_DISPOSED = COMPONENT_EVENT_ACTION_START_RANGE + 6;
37      public static final int COMPONENT_STOPPING = COMPONENT_EVENT_ACTION_START_RANGE + 7;
38  
39      private static final transient String[] ACTIONS = new String[]{"initialised", "started", "stopped",
40          "paused", "resumed", "disposed", "stopping"};
41  
42      public ComponentNotification(UMODescriptor message, int action)
43      {
44          super(message, action);
45          resourceIdentifier = message.getName();
46      }
47  
48      protected String getPayloadToString()
49      {
50          return ((MuleDescriptor) source).getName();
51      }
52  
53      protected String getActionName(int action)
54      {
55          int i = action - COMPONENT_EVENT_ACTION_START_RANGE;
56          if (i - 1 > ACTIONS.length)
57          {
58              return String.valueOf(action);
59          }
60          return ACTIONS[i - 1];
61      }
62  }