View Javadoc

1   /*
2    * $Id: MuleContextNotification.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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      static {
39          registerAction("mule context initialising", CONTEXT_INITIALISING);
40          registerAction("mule context initialised", CONTEXT_INITIALISED);
41          registerAction("mule context starting", CONTEXT_STARTING);
42          registerAction("mule context started", CONTEXT_STARTED);
43          registerAction("mule context stopping", CONTEXT_STOPPING);
44          registerAction("mule context stopped", CONTEXT_STOPPED);
45          registerAction("mule context disposing", CONTEXT_DISPOSING);
46          registerAction("mule context disposed", CONTEXT_DISPOSED);
47      }
48  
49      private String clusterId;
50      private String domain;
51      private transient MuleContext muleContext;
52  
53      public MuleContextNotification(MuleContext context, String action)
54      {
55          this(context, getActionId(action));
56      }
57  
58      public MuleContextNotification(MuleContext context, int action)
59      {
60          super(generateId(context), action);
61          this.muleContext = context;
62          this.resourceIdentifier = context.getConfiguration().getId();
63          this.clusterId = context.getConfiguration().getClusterId();
64          this.domain = context.getConfiguration().getDomainId();
65      }
66  
67      public String getClusterId()
68      {
69          return clusterId;
70      }
71  
72      public String getDomain()
73      {
74          return domain;
75      }
76  
77      public MuleContext getMuleContext()
78      {
79          return this.muleContext;
80      }
81  
82      @Override
83      protected String getPayloadToString()
84      {
85          return ((MuleContext) source).getConfiguration().getId();
86      }
87  
88      @Override
89      public String toString()
90      {
91          return EVENT_NAME + "{" + "action=" + getActionName(action) + ", resourceId=" + resourceIdentifier
92                  + ", timestamp=" + timestamp + "}";
93      }
94      
95  }