View Javadoc

1   /*
2    * $Id: TransientRegistryDisposePhase.java 11181 2008-03-05 17:31:34Z dfeist $
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  package org.mule.lifecycle.phases;
11  
12  import org.mule.api.MuleContext;
13  import org.mule.api.agent.Agent;
14  import org.mule.api.lifecycle.Disposable;
15  import org.mule.api.lifecycle.Initialisable;
16  import org.mule.api.lifecycle.LifecyclePhase;
17  import org.mule.api.model.Model;
18  import org.mule.api.registry.Registry;
19  import org.mule.api.transport.Connector;
20  import org.mule.context.notification.MuleContextNotification;
21  import org.mule.lifecycle.DefaultLifecyclePhase;
22  import org.mule.lifecycle.NotificationLifecycleObject;
23  
24  import java.util.LinkedHashSet;
25  import java.util.Set;
26  
27  /**
28   * The Dispose phase for the TransientRegistry LifecycleManager. Calling {@link org.mule.registry.TransientRegistry#dispose()}
29   * with initiate this phase via the {@link org.mule.api.lifecycle.LifecycleManager}.
30   * This phase controls the order in which objects should be disposed.
31   *
32   * @see org.mule.api.MuleContext
33   * @see org.mule.api.lifecycle.LifecycleManager
34   * @see org.mule.registry.TransientRegistry
35   * @see org.mule.api.lifecycle.Disposable
36   */
37  public class TransientRegistryDisposePhase extends DefaultLifecyclePhase
38  {
39      public TransientRegistryDisposePhase()
40      {
41          this(new Class[]{Registry.class});
42      }
43  
44      public TransientRegistryDisposePhase(Class[] ignorredObjects)
45      {
46          super(Disposable.PHASE_NAME, Disposable.class, Initialisable.PHASE_NAME);
47  
48          Set disposeOrderedObjects = new LinkedHashSet();
49  //        disposeOrderedObjects.add(new NotificationLifecycleObject(MuleContext.class, MuleContextNotification.class,
50  //                MuleContextNotification.getActionName(MuleContextNotification.CONTEXT_DISPOSING),
51  //                MuleContextNotification.getActionName(MuleContextNotification.CONTEXT_DISPOSED)));
52          disposeOrderedObjects.add(new NotificationLifecycleObject(MuleContext.class));
53          disposeOrderedObjects.add(new NotificationLifecycleObject(Connector.class, MuleContextNotification.class,
54                  MuleContextNotification.CONTEXT_DISPOSING_CONNECTORS,MuleContextNotification.CONTEXT_DISPOSED_CONNECTORS));
55          disposeOrderedObjects.add(new NotificationLifecycleObject(Agent.class));
56          disposeOrderedObjects.add(new NotificationLifecycleObject(Model.class));
57          disposeOrderedObjects.add(new NotificationLifecycleObject(Disposable.class));
58  
59          setIgnoredObjectTypes(ignorredObjects);
60          setOrderedLifecycleObjects(disposeOrderedObjects);
61          registerSupportedPhase(LifecyclePhase.ALL_PHASES);
62      }
63  }