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.ServletException;
23  import javax.servlet.ServletRequest;
24  import javax.servlet.ServletResponse;
25  import javax.servlet.UnavailableException;
26  import javax.servlet.http.HttpServletResponse;
27  
28  /* ------------------------------------------------------------ */
29  public class SetiServlet implements Servlet
30  {    
31      private ServletConfig _config;
32  
33      /* ------------------------------------------------------------ */
34      public void destroy()
35      {
36          try
37          {
38              Seti seti= (Seti)_config.getServletContext().getAttribute(Oort.OORT_ATTRIBUTE);
39              if (seti!=null)
40                  seti.stop();
41          }
42          catch(Exception e)
43          {
44              _config.getServletContext().log("destroy",e);
45          }
46      }
47  
48      /* ------------------------------------------------------------ */
49      public ServletConfig getServletConfig()
50      {
51          return _config;
52      }
53  
54      /* ------------------------------------------------------------ */
55      public String getServletInfo()
56      {
57          return SetiServlet.class.toString();
58      }
59  
60      /* ------------------------------------------------------------ */
61      public void init(ServletConfig config) throws ServletException
62      {
63          _config=config;
64          
65          Oort oort = (Oort)config.getServletContext().getAttribute(Oort.OORT_ATTRIBUTE);
66          if (oort==null)
67          {
68              _config.getServletContext().log("No "+Oort.OORT_ATTRIBUTE+" initialized");
69              throw new UnavailableException(Oort.OORT_ATTRIBUTE);
70          }
71  
72          String shard=_config.getInitParameter(Seti.SETI_SHARD);
73          
74          Seti seti= new Seti(oort,shard);
75          _config.getServletContext().setAttribute(Seti.SETI_ATTRIBUTE,seti);
76  
77          try
78          {
79              seti.start();
80          }
81          catch(Exception e)
82          {
83              throw new ServletException(e);
84          }
85          
86      }
87  
88      /* ------------------------------------------------------------ */
89      public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException
90      {
91          HttpServletResponse response = (HttpServletResponse)res;
92          response.sendError(503);        
93      }
94  }