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.component.AggregateLifeCycle;
22 import org.eclipse.jetty.util.log.Log;
23
24
25 /* ------------------------------------------------------------ */
26 /** AbstractHandler.
27 *
28 *
29 */
30 public abstract class AbstractHandler extends AggregateLifeCycle implements Handler
31 {
32 private Server _server;
33
34 /* ------------------------------------------------------------ */
35 /**
36 *
37 */
38 public AbstractHandler()
39 {
40 }
41
42 /* ------------------------------------------------------------ */
43 /*
44 * @see org.eclipse.thread.LifeCycle#start()
45 */
46 @Override
47 protected void doStart() throws Exception
48 {
49 Log.debug("starting {}",this);
50 super.doStart();
51 }
52
53 /* ------------------------------------------------------------ */
54 /*
55 * @see org.eclipse.thread.LifeCycle#stop()
56 */
57 @Override
58 protected void doStop() throws Exception
59 {
60 Log.debug("stopping {}",this);
61 super.doStop();
62 }
63
64 /* ------------------------------------------------------------ */
65 public void setServer(Server server)
66 {
67 Server old_server=_server;
68 if (old_server!=null && old_server!=server)
69 old_server.getContainer().removeBean(this);
70 _server=server;
71 if (_server!=null && _server!=old_server)
72 _server.getContainer().addBean(this);
73 }
74
75 /* ------------------------------------------------------------ */
76 public Server getServer()
77 {
78 return _server;
79 }
80
81 /* ------------------------------------------------------------ */
82 public void destroy()
83 {
84 if (!isStopped())
85 throw new IllegalStateException("!STOPPED");
86 super.destroy();
87 if (_server!=null)
88 _server.getContainer().removeBean(this);
89 }
90
91 /* ------------------------------------------------------------ */
92 public void dumpThis(Appendable out) throws IOException
93 {
94 out.append(toString()).append(' ').append(getState()).append('\n');
95 }
96
97 }