View Javadoc

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