View Javadoc

1   /*
2    * $Id: AbstractConnectorHolder.java 20320 2010-11-24 15:03:31Z dfeist $
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.transport.servlet.jetty;
11  
12  import org.mule.api.MuleException;
13  import org.mule.api.lifecycle.LifecycleException;
14  import org.mule.api.transport.MessageReceiver;
15  
16  import javax.servlet.Servlet;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  import org.mortbay.jetty.Connector;
21  
22  /**
23   * TODO
24   */
25  public abstract class AbstractConnectorHolder<S extends Servlet, R extends MessageReceiver> implements ConnectorHolder<S, R>
26  {
27      /**
28       * logger used by this class
29       */
30      protected transient final Log logger = LogFactory.getLog(AbstractConnectorHolder.class);
31      protected Connector connector;
32      protected S servlet;
33      protected boolean started = false;
34  
35      @SuppressWarnings("unused")
36      public AbstractConnectorHolder(Connector connector, S servlet, R receiver)
37      {
38          this.connector = connector;
39          this.servlet = servlet;
40      }
41  
42      public S getServlet()
43      {
44          return servlet;
45      }
46  
47      public Connector getConnector()
48      {
49          return connector;
50      }
51  
52  
53      public void start() throws MuleException
54      {
55          try
56          {
57              connector.start();
58              started = true;
59          }
60          catch (Exception e)
61          {
62              throw new LifecycleException(e, this);
63          }
64      }
65  
66      public void stop() throws MuleException
67      {
68          try
69          {
70              connector.stop();
71              started = false;
72          }
73          catch (Exception e)
74          {
75              logger.warn("Jetty connector did not close cleanly: " + e.getMessage());
76          }
77  
78      }
79  
80  }