View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.context.notification;
8   
9   import org.mule.api.MuleContext;
10  import org.mule.api.context.notification.BlockingServerEvent;
11  import org.mule.api.context.notification.ServerNotification;
12  
13  /**
14   * <code>MuleContextNotification</code> is fired when an event such as the mule
15   * context starting occurs. The payload of this event will always be a reference to
16   * the muleContext.
17   */
18  public class MuleContextNotification extends ServerNotification implements BlockingServerEvent
19  {
20      /**
21       * Serial version
22       */
23      private static final long serialVersionUID = -3246036188011581121L;
24      
25      public static final int CONTEXT_INITIALISING = CONTEXT_EVENT_ACTION_START_RANGE + 1;
26      public static final int CONTEXT_INITIALISED = CONTEXT_EVENT_ACTION_START_RANGE + 2;
27      public static final int CONTEXT_STARTING = CONTEXT_EVENT_ACTION_START_RANGE + 3;
28      public static final int CONTEXT_STARTED = CONTEXT_EVENT_ACTION_START_RANGE + 4;
29      public static final int CONTEXT_STOPPING = CONTEXT_EVENT_ACTION_START_RANGE + 5;
30      public static final int CONTEXT_STOPPED = CONTEXT_EVENT_ACTION_START_RANGE + 6;
31      public static final int CONTEXT_DISPOSING = CONTEXT_EVENT_ACTION_START_RANGE + 7;
32      public static final int CONTEXT_DISPOSED = CONTEXT_EVENT_ACTION_START_RANGE + 8;
33      
34      static {
35          registerAction("mule context initialising", CONTEXT_INITIALISING);
36          registerAction("mule context initialised", CONTEXT_INITIALISED);
37          registerAction("mule context starting", CONTEXT_STARTING);
38          registerAction("mule context started", CONTEXT_STARTED);
39          registerAction("mule context stopping", CONTEXT_STOPPING);
40          registerAction("mule context stopped", CONTEXT_STOPPED);
41          registerAction("mule context disposing", CONTEXT_DISPOSING);
42          registerAction("mule context disposed", CONTEXT_DISPOSED);
43      }
44  
45      private String clusterId;
46      private String domain;
47      private transient MuleContext muleContext;
48  
49      public MuleContextNotification(MuleContext context, String action)
50      {
51          this(context, getActionId(action));
52      }
53  
54      public MuleContextNotification(MuleContext context, int action)
55      {
56          super(generateId(context), action);
57          this.muleContext = context;
58          this.resourceIdentifier = context.getConfiguration().getId();
59          this.clusterId = context.getConfiguration().getClusterId();
60          this.domain = context.getConfiguration().getDomainId();
61      }
62  
63      public String getClusterId()
64      {
65          return clusterId;
66      }
67  
68      public String getDomain()
69      {
70          return domain;
71      }
72  
73      public MuleContext getMuleContext()
74      {
75          return this.muleContext;
76      }
77  
78      @Override
79      protected String getPayloadToString()
80      {
81          return ((MuleContext) source).getConfiguration().getId();
82      }
83  
84      @Override
85      public String toString()
86      {
87          return EVENT_NAME + "{" + "action=" + getActionName(action) + ", resourceId=" + resourceIdentifier
88                  + ", timestamp=" + timestamp + "}";
89      }
90      
91  }