View Javadoc

1   /*
2    * $Id: AbstractConnectorHolder.java 22409 2011-07-14 05:14:27Z dirk.olmes $
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      public AbstractConnectorHolder(Connector connector, S servlet, R receiver)
36      {
37          this.connector = connector;
38          this.servlet = servlet;
39      }
40  
41      @Override
42      public S getServlet()
43      {
44          return servlet;
45      }
46  
47      @Override
48      public Connector getConnector()
49      {
50          return connector;
51      }
52  
53  
54      @Override
55      public void start() throws MuleException
56      {
57          try
58          {
59              connector.start();
60              started = true;
61          }
62          catch (Exception e)
63          {
64              throw new LifecycleException(e, this);
65          }
66      }
67  
68      @Override
69      public void stop() throws MuleException
70      {
71          try
72          {
73              connector.stop();
74              started = false;
75          }
76          catch (Exception e)
77          {
78              logger.warn("Jetty connector did not close cleanly: " + e.getMessage());
79          }
80      }
81  
82  }