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;
8   
9   import org.mule.api.MuleContext;
10  import org.mule.api.MuleException;
11  import org.mule.api.agent.Agent;
12  import org.mule.api.context.MuleContextAware;
13  
14  /**
15   * Implements common methods for all Agents. Importantly, the MuleContext is made available to Agents that
16   * extend this.
17   */
18  public abstract class AbstractAgent implements Agent, MuleContextAware
19  {
20  
21      protected MuleContext muleContext;
22  
23      protected String name;
24  
25      protected AbstractAgent(String name)
26      {
27          this.name = name;
28      }
29  
30      public final String getName()
31      {
32          return name;
33      }
34  
35      public final void setName(String name)
36      {
37          this.name = name;
38      }
39  
40      public String getDescription()
41      {
42          return name;
43      }
44  
45      public void setMuleContext(MuleContext context)
46      {
47          this.muleContext = context;
48      }
49  
50      /**
51       * Quietly unregister ourselves.
52       */
53      protected void unregisterMeQuietly()
54      {
55          try
56          {
57              // remove the agent from the list, it's not functional
58              muleContext.getRegistry().unregisterAgent(this.getName());
59          }
60          catch (MuleException e)
61          {
62              // not interested, really
63          }
64      }
65  }