View Javadoc

1   // ========================================================================
2   // Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.server.handler;
15  
16  
17  import java.io.IOException;
18  
19  import org.eclipse.jetty.server.Handler;
20  import org.eclipse.jetty.server.Server;
21  import org.eclipse.jetty.util.TypeUtil;
22  import org.eclipse.jetty.util.component.AbstractLifeCycle;
23  import org.eclipse.jetty.util.component.AggregateLifeCycle;
24  import org.eclipse.jetty.util.log.Log;
25  
26  
27  /* ------------------------------------------------------------ */
28  /** AbstractHandler.
29   * 
30   *
31   */
32  public abstract class AbstractHandler extends AggregateLifeCycle implements Handler
33  {
34      private Server _server;
35      
36      /* ------------------------------------------------------------ */
37      /**
38       * 
39       */
40      public AbstractHandler()
41      {
42      }
43  
44      /* ------------------------------------------------------------ */
45      /* 
46       * @see org.eclipse.thread.LifeCycle#start()
47       */
48      @Override
49      protected void doStart() throws Exception
50      {
51          Log.debug("starting {}",this);
52          super.doStart();
53      }
54  
55      /* ------------------------------------------------------------ */
56      /* 
57       * @see org.eclipse.thread.LifeCycle#stop()
58       */
59      @Override
60      protected void doStop() throws Exception
61      {
62          Log.debug("stopping {}",this);
63          super.doStop();
64      }
65  
66      /* ------------------------------------------------------------ */
67      public void setServer(Server server)
68      {
69          Server old_server=_server;
70          if (old_server!=null && old_server!=server)
71              old_server.getContainer().removeBean(this);
72          _server=server;
73          if (_server!=null && _server!=old_server)
74              _server.getContainer().addBean(this);
75      }
76  
77      /* ------------------------------------------------------------ */
78      public Server getServer()
79      {
80          return _server;
81      }
82  
83      /* ------------------------------------------------------------ */
84      public void destroy()
85      {
86          if (!isStopped())
87              throw new IllegalStateException("!STOPPED");
88          super.destroy();
89          if (_server!=null)
90              _server.getContainer().removeBean(this);
91      }
92  
93      /* ------------------------------------------------------------ */
94      public void dumpThis(Appendable out) throws IOException
95      {
96          out.append(toString()).append(' ').append(getState()).append('\n');
97      }
98      
99  }