Save This Page
Home » apache-tomcat-6.0.16-src » org.apache.jk » core » [javadoc | source]
    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.jk.core;
   19   
   20   import java.io.IOException;
   21   import java.util.Properties;
   22   
   23   import javax.management.MBeanRegistration;
   24   import javax.management.MBeanServer;
   25   import javax.management.Notification;
   26   import javax.management.NotificationListener;
   27   import javax.management.ObjectName;
   28   
   29   import org.apache.tomcat.util.modeler.Registry;
   30   
   31   /**
   32    *
   33    * @author Costin Manolache
   34    */
   35   public class JkHandler implements MBeanRegistration, NotificationListener {
   36       public static final int OK=0;
   37       public static final int LAST=1;
   38       public static final int ERROR=2;
   39   
   40       protected Properties properties=new Properties();
   41       protected WorkerEnv wEnv;
   42       protected JkHandler next;
   43       protected String nextName=null;
   44       protected String name;
   45       protected int id;
   46   
   47       // XXX Will be replaced with notes and (configurable) ids
   48       // Each represents a 'chain' - similar with ActionCode in Coyote ( the concepts
   49       // will be merged ).    
   50       public static final int HANDLE_RECEIVE_PACKET   = 10;
   51       public static final int HANDLE_SEND_PACKET      = 11;
   52       public static final int HANDLE_FLUSH            = 12;
   53       public static final int HANDLE_THREAD_END       = 13;
   54       
   55       public void setWorkerEnv( WorkerEnv we ) {
   56           this.wEnv=we;
   57       }
   58   
   59       /** Set the name of the handler. Will allways be called by
   60        *  worker env after creating the worker.
   61        */
   62       public void setName(String s ) {
   63           name=s;
   64       }
   65   
   66       public String getName() {
   67           return name;
   68       }
   69   
   70       /** Set the id of the worker. We use an id for faster dispatch.
   71        *  Since we expect a decent number of handler in system, the
   72        *  id is unique - that means we may have to allocate bigger
   73        *  dispatch tables. ( easy to fix if needed )
   74        */
   75       public void setId( int id ) {
   76           this.id=id;
   77       }
   78   
   79       public int getId() {
   80           return id;
   81       }
   82       
   83       /** Catalina-style "recursive" invocation.
   84        *  A chain is used for Apache/3.3 style iterative invocation.
   85        */
   86       public void setNext( JkHandler h ) {
   87           next=h;
   88       }
   89   
   90       public void setNext( String s ) {
   91           nextName=s;
   92       }
   93   
   94       public String getNext() {
   95           if( nextName==null ) {
   96               if( next!=null)
   97                   nextName=next.getName();
   98           }
   99           return nextName;
  100       }
  101   
  102       /** Should register the request types it can handle,
  103        *   same style as apache2.
  104        */
  105       public void init() throws IOException {
  106       }
  107   
  108       /** Clean up and stop the handler
  109        */
  110       public void destroy() throws IOException {
  111       }
  112   
  113       public MsgContext createMsgContext() {
  114           return new MsgContext(8*1024);
  115       }
  116       
  117       public MsgContext createMsgContext(int bsize) {
  118           return new MsgContext(bsize);
  119       }
  120   
  121       public int invoke(Msg msg, MsgContext mc )  throws IOException {
  122           return OK;
  123       }
  124       
  125       public void setProperty( String name, String value ) {
  126           properties.put( name, value );
  127       }
  128   
  129       public String getProperty( String name ) {
  130           return properties.getProperty(name) ;
  131       }
  132   
  133       /** Experimental, will be replaced. This allows handlers to be
  134        *  notified when other handlers are added.
  135        */
  136       public void addHandlerCallback( JkHandler w ) {
  137   
  138       }
  139   
  140       public void handleNotification(Notification notification, Object handback)
  141       {
  142   //        BaseNotification bNot=(BaseNotification)notification;
  143   //        int code=bNot.getCode();
  144   //
  145   //        MsgContext ctx=(MsgContext)bNot.getSource();
  146   
  147   
  148       }
  149   
  150       protected String domain;
  151       protected ObjectName oname;
  152       protected MBeanServer mserver;
  153   
  154       public ObjectName getObjectName() {
  155           return oname;
  156       }
  157   
  158       public String getDomain() {
  159           return domain;
  160       }
  161   
  162       public ObjectName preRegister(MBeanServer server,
  163                                     ObjectName oname) throws Exception {
  164           this.oname=oname;
  165           mserver=server;
  166           domain=oname.getDomain();
  167           if( name==null ) {
  168               name=oname.getKeyProperty("name");
  169           }
  170           
  171           // we need to create a workerEnv or set one.
  172           ObjectName wEnvName=new ObjectName(domain + ":type=JkWorkerEnv");
  173           if ( wEnv == null ) {
  174               wEnv=new WorkerEnv();
  175           }
  176           if( ! mserver.isRegistered(wEnvName )) {
  177               Registry.getRegistry(null, null).registerComponent(wEnv, wEnvName, null);
  178           }
  179           mserver.invoke( wEnvName, "addHandler", 
  180                   new Object[] {name, this}, 
  181                   new String[] {"java.lang.String", 
  182                                 "org.apache.jk.core.JkHandler"});
  183           return oname;
  184       }
  185       
  186       public void postRegister(Boolean registrationDone) {
  187       }
  188   
  189       public void preDeregister() throws Exception {
  190       }
  191   
  192       public void postDeregister() {
  193       }
  194   
  195       public void pause() throws Exception {
  196       }
  197   
  198       public void resume() throws Exception {
  199       }
  200   
  201   }

Save This Page
Home » apache-tomcat-6.0.16-src » org.apache.jk » core » [javadoc | source]