001: /*
002: * $Id: MuleContextNotification.java 11343 2008-03-13 10:58:26Z tcarlson $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.context.notification;
012:
013: import org.mule.api.MuleContext;
014: import org.mule.api.context.notification.BlockingServerEvent;
015: import org.mule.api.context.notification.ServerNotification;
016:
017: /**
018: * <code>MuleContextNotification</code> is fired when an event such as the mule
019: * context starting occurs. The payload of this event will always be a reference to
020: * the muleContext.
021: */
022: public class MuleContextNotification extends ServerNotification
023: implements BlockingServerEvent {
024: /**
025: * Serial version
026: */
027: private static final long serialVersionUID = -3246036188011581121L;
028:
029: public static final int CONTEXT_INITIALISING = CONTEXT_EVENT_ACTION_START_RANGE + 1;
030: public static final int CONTEXT_INITIALISED = CONTEXT_EVENT_ACTION_START_RANGE + 2;
031: public static final int CONTEXT_STARTING = CONTEXT_EVENT_ACTION_START_RANGE + 3;
032: public static final int CONTEXT_STARTED = CONTEXT_EVENT_ACTION_START_RANGE + 4;
033: public static final int CONTEXT_STOPPING = CONTEXT_EVENT_ACTION_START_RANGE + 5;
034: public static final int CONTEXT_STOPPED = CONTEXT_EVENT_ACTION_START_RANGE + 6;
035: public static final int CONTEXT_DISPOSING = CONTEXT_EVENT_ACTION_START_RANGE + 7;
036: public static final int CONTEXT_DISPOSED = CONTEXT_EVENT_ACTION_START_RANGE + 8;
037:
038: // The following events are not context events, but rather more general global
039: // mule events.
040: public static final int CONTEXT_DISPOSING_CONNECTORS = CONTEXT_EVENT_ACTION_START_RANGE + 9;
041: public static final int CONTEXT_DISPOSED_CONNECTORS = CONTEXT_EVENT_ACTION_START_RANGE + 10;
042: public static final int CONTEXT_STARTING_MODELS = CONTEXT_EVENT_ACTION_START_RANGE + 11;
043: public static final int CONTEXT_STARTED_MODELS = CONTEXT_EVENT_ACTION_START_RANGE + 12;
044: public static final int CONTEXT_STOPPING_MODELS = CONTEXT_EVENT_ACTION_START_RANGE + 13;
045: public static final int CONTEXT_STOPPED_MODELS = CONTEXT_EVENT_ACTION_START_RANGE + 14;
046:
047: static {
048: registerAction("mule context initialising",
049: CONTEXT_INITIALISING);
050: registerAction("mule context initialised", CONTEXT_INITIALISED);
051: registerAction("mule context starting", CONTEXT_STARTING);
052: registerAction("mule context started", CONTEXT_STARTED);
053: registerAction("mule context stopping", CONTEXT_STOPPING);
054: registerAction("mule context stopped", CONTEXT_STOPPED);
055: registerAction("mule context disposing", CONTEXT_DISPOSING);
056: registerAction("mule context disposed", CONTEXT_DISPOSED);
057: registerAction("disposing connectors",
058: CONTEXT_DISPOSING_CONNECTORS);
059: registerAction("disposed connectors",
060: CONTEXT_DISPOSED_CONNECTORS);
061: registerAction("starting models", CONTEXT_STARTING_MODELS);
062: registerAction("started models", CONTEXT_STARTED_MODELS);
063: registerAction("stopping models", CONTEXT_STOPPING_MODELS);
064: registerAction("stopped models", CONTEXT_STOPPED_MODELS);
065: }
066:
067: private String clusterId;
068: private String domain;
069:
070: public MuleContextNotification(MuleContext context, String action) {
071: this (context, getActionId(action));
072: }
073:
074: public MuleContextNotification(MuleContext context, int action) {
075: super (getId(context), action);
076: resourceIdentifier = getId(context);
077: this .clusterId = context.getConfiguration().getClusterId();
078: this .domain = context.getConfiguration().getDomainId();
079: }
080:
081: private static String getId(MuleContext context) {
082: return context.getConfiguration().getDomainId() + "."
083: + context.getConfiguration().getClusterId() + "."
084: + context.getConfiguration().getId();
085: }
086:
087: public String getClusterId() {
088: return clusterId;
089: }
090:
091: public String getDomain() {
092: return domain;
093: }
094:
095: protected String getPayloadToString() {
096: return ((MuleContext) source).getConfiguration().getId();
097: }
098:
099: public String toString() {
100: return EVENT_NAME + "{" + "action=" + getActionName(action)
101: + ", resourceId=" + resourceIdentifier + ", timestamp="
102: + timestamp + "}";
103: }
104:
105: }
|