View Javadoc

1   /*
2    * $Id: MuleContextNotification.java 11343 2008-03-13 10:58:26Z tcarlson $
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.context.notification;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.context.notification.BlockingServerEvent;
15  import org.mule.api.context.notification.ServerNotification;
16  
17  /**
18   * <code>MuleContextNotification</code> is fired when an event such as the mule
19   * context starting occurs. The payload of this event will always be a reference to
20   * the muleContext.
21   */
22  public class MuleContextNotification extends ServerNotification implements BlockingServerEvent
23  {
24      /**
25       * Serial version
26       */
27      private static final long serialVersionUID = -3246036188011581121L;
28      
29      public static final int CONTEXT_INITIALISING = CONTEXT_EVENT_ACTION_START_RANGE + 1;
30      public static final int CONTEXT_INITIALISED = CONTEXT_EVENT_ACTION_START_RANGE + 2;
31      public static final int CONTEXT_STARTING = CONTEXT_EVENT_ACTION_START_RANGE + 3;
32      public static final int CONTEXT_STARTED = CONTEXT_EVENT_ACTION_START_RANGE + 4;
33      public static final int CONTEXT_STOPPING = CONTEXT_EVENT_ACTION_START_RANGE + 5;
34      public static final int CONTEXT_STOPPED = CONTEXT_EVENT_ACTION_START_RANGE + 6;
35      public static final int CONTEXT_DISPOSING = CONTEXT_EVENT_ACTION_START_RANGE + 7;
36      public static final int CONTEXT_DISPOSED = CONTEXT_EVENT_ACTION_START_RANGE + 8;
37      
38      // The following events are not context events, but rather more general global
39      // mule events.
40      public static final int CONTEXT_DISPOSING_CONNECTORS = CONTEXT_EVENT_ACTION_START_RANGE + 9;
41      public static final int CONTEXT_DISPOSED_CONNECTORS = CONTEXT_EVENT_ACTION_START_RANGE + 10;
42      public static final int CONTEXT_STARTING_MODELS = CONTEXT_EVENT_ACTION_START_RANGE + 11;
43      public static final int CONTEXT_STARTED_MODELS = CONTEXT_EVENT_ACTION_START_RANGE + 12;
44      public static final int CONTEXT_STOPPING_MODELS = CONTEXT_EVENT_ACTION_START_RANGE + 13;
45      public static final int CONTEXT_STOPPED_MODELS = CONTEXT_EVENT_ACTION_START_RANGE + 14;
46  
47      static {
48          registerAction("mule context initialising", CONTEXT_INITIALISING);
49          registerAction("mule context initialised", CONTEXT_INITIALISED);
50          registerAction("mule context starting", CONTEXT_STARTING);
51          registerAction("mule context started", CONTEXT_STARTED);
52          registerAction("mule context stopping", CONTEXT_STOPPING);
53          registerAction("mule context stopped", CONTEXT_STOPPED);
54          registerAction("mule context disposing", CONTEXT_DISPOSING);
55          registerAction("mule context disposed", CONTEXT_DISPOSED);
56          registerAction("disposing connectors", CONTEXT_DISPOSING_CONNECTORS);
57          registerAction("disposed connectors", CONTEXT_DISPOSED_CONNECTORS);
58          registerAction("starting models", CONTEXT_STARTING_MODELS);
59          registerAction("started models", CONTEXT_STARTED_MODELS);
60          registerAction("stopping models", CONTEXT_STOPPING_MODELS);
61          registerAction("stopped models", CONTEXT_STOPPED_MODELS);
62      }
63  
64      private String clusterId;
65      private String domain;
66  
67  
68      public MuleContextNotification(MuleContext context, String action)
69      {
70          this(context, getActionId(action));
71      }
72  
73      public MuleContextNotification(MuleContext context, int action)
74      {
75          super(getId(context), action);
76          resourceIdentifier = getId(context);
77          this.clusterId = context.getConfiguration().getClusterId();
78          this.domain = context.getConfiguration().getDomainId();
79      }
80  
81      private static String getId(MuleContext context)
82      {
83          return context.getConfiguration().getDomainId() + "." + context.getConfiguration().getClusterId() + "." + context.getConfiguration().getId();
84      }
85  
86      public String getClusterId()
87      {
88          return clusterId;
89      }
90  
91      public String getDomain()
92      {
93          return domain;
94      }
95  
96      protected String getPayloadToString()
97      {
98          return ((MuleContext) source).getConfiguration().getId();
99      }
100 
101     public String toString()
102     {
103         return EVENT_NAME + "{" + "action=" + getActionName(action) + ", resourceId=" + resourceIdentifier
104                 + ", timestamp=" + timestamp + "}";
105     }
106     
107 }