View Javadoc

1   // ========================================================================
2   // Copyright 2007-2008 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // Licensed under the Apache License, Version 2.0 (the "License");
5   // you may not use this file except in compliance with the License.
6   // You may obtain a copy of the License at 
7   // http://www.apache.org/licenses/LICENSE-2.0
8   // Unless required by applicable law or agreed to in writing, software
9   // distributed under the License is distributed on an "AS IS" BASIS,
10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  // See the License for the specific language governing permissions and
12  // limitations under the License.
13  //========================================================================
14  
15  package org.cometd.oort;
16  
17  
18  import java.io.IOException;
19  
20  import javax.servlet.Servlet;
21  import javax.servlet.ServletConfig;
22  import javax.servlet.ServletContextAttributeEvent;
23  import javax.servlet.ServletContextAttributeListener;
24  import javax.servlet.ServletException;
25  import javax.servlet.ServletRequest;
26  import javax.servlet.ServletResponse;
27  import javax.servlet.UnavailableException;
28  import javax.servlet.http.HttpServletResponse;
29  
30  import org.mortbay.log.Log;
31  
32  /* ------------------------------------------------------------ */
33  public class SetiServlet implements Servlet
34  {    
35      private ServletConfig _config;
36  
37      /* ------------------------------------------------------------ */
38      public void destroy()
39      {
40          try
41          {
42              Seti seti= (Seti)_config.getServletContext().getAttribute(Oort.OORT_ATTRIBUTE);
43              if (seti!=null)
44                  seti.stop();
45          }
46          catch(Exception e)
47          {
48              _config.getServletContext().log("destroy",e);
49          }
50      }
51  
52      /* ------------------------------------------------------------ */
53      public ServletConfig getServletConfig()
54      {
55          return _config;
56      }
57  
58      /* ------------------------------------------------------------ */
59      public String getServletInfo()
60      {
61          return SetiServlet.class.toString();
62      }
63  
64      /* ------------------------------------------------------------ */
65      public void init(ServletConfig config) throws ServletException
66      {
67          _config=config;
68          
69          Oort oort = (Oort)config.getServletContext().getAttribute(Oort.OORT_ATTRIBUTE);
70          if (oort==null)
71          {
72              _config.getServletContext().log("No "+Oort.OORT_ATTRIBUTE+" initialized");
73              throw new UnavailableException(Oort.OORT_ATTRIBUTE);
74          }
75  
76          String shard=_config.getInitParameter(Seti.SETI_SHARD);
77          
78          Seti seti= new Seti(oort,shard);
79          _config.getServletContext().setAttribute(Seti.SETI_ATTRIBUTE,seti);
80  
81          try
82          {
83              seti.start();
84          }
85          catch(Exception e)
86          {
87              throw new ServletException(e);
88          }
89          
90      }
91  
92      /* ------------------------------------------------------------ */
93      public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
94      {
95          HttpServletResponse response = (HttpServletResponse)res;
96          response.sendError(503);        
97      }
98  }