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.util.Hashtable;
21 import javax.management.ObjectName;
22
23 /**
24 * The controller object. It manages all other jk objects, acting as the root of
25 * the jk object model.
26 *
27 * @author Gal Shachor
28 * @author Henri Gomez [hgomez@apache.org]
29 * @author Dan Milstein [danmil@shore.net]
30 * @author Keith Wannamaker [Keith@Wannamaker.org]
31 * @author Kevin Seguin
32 * @author Costin Manolache
33 */
34 public class WorkerEnv {
35
36 Hashtable properties;
37
38 public static final int ENDPOINT_NOTE=0;
39 public static final int REQUEST_NOTE=1;
40 public static final int SSL_CERT_NOTE=16;
41 int noteId[]=new int[4];
42 String noteName[][]=new String[4][];
43 private Object notes[]=new Object[32];
44
45 Hashtable handlersMap=new Hashtable();
46 JkHandler handlersTable[]=new JkHandler[20];
47 int handlerCount=0;
48
49 // base dir for the jk webapp
50 String home;
51 int localId=0;
52
53 public WorkerEnv() {
54 for( int i=0; i<noteId.length; i++ ) {
55 noteId[i]=7;
56 noteName[i]=new String[20];
57 }
58 }
59
60 public void setLocalId(int id) {
61 localId=id;
62 }
63
64 public int getLocalId() {
65 return localId;
66 }
67
68 public void setJkHome( String s ) {
69 home=s;
70 }
71
72 public String getJkHome() {
73 return home;
74 }
75
76 public final Object getNote(int i ) {
77 return notes[i];
78 }
79
80 public final void setNote(int i, Object o ) {
81 notes[i]=o;
82 }
83
84 public int getNoteId( int type, String name ) {
85 for( int i=0; i<noteId[type]; i++ ) {
86 if( name.equals( noteName[type][i] ))
87 return i;
88 }
89 int id=noteId[type]++;
90 noteName[type][id]=name;
91 return id;
92 }
93
94 public void addHandler( String name, JkHandler w ) {
95 JkHandler oldH = getHandler(name);
96 if(oldH == w) {
97 // Already added
98 return;
99 }
100 w.setWorkerEnv( this );
101 w.setName( name );
102 handlersMap.put( name, w );
103 if( handlerCount > handlersTable.length ) {
104 JkHandler newT[]=new JkHandler[ 2 * handlersTable.length ];
105 System.arraycopy( handlersTable, 0, newT, 0, handlersTable.length );
106 handlersTable=newT;
107 }
108 if(oldH == null) {
109 handlersTable[handlerCount]=w;
110 w.setId( handlerCount );
111 handlerCount++;
112 } else {
113 handlersTable[oldH.getId()]=w;
114 w.setId(oldH.getId());
115 }
116
117 // Notify all other handlers of the new one
118 // XXX Could be a Coyote action ?
119 for( int i=0; i< handlerCount ; i++ ) {
120 handlersTable[i].addHandlerCallback( w );
121 }
122 }
123
124 public final JkHandler getHandler( String name ) {
125 return (JkHandler)handlersMap.get(name);
126 }
127
128 public final JkHandler getHandler( int id ) {
129 return handlersTable[id];
130 }
131
132 public final int getHandlerCount() {
133 return handlerCount;
134 }
135
136 public ObjectName[] getHandlersObjectName() {
137
138 ObjectName onames[]=new ObjectName[ handlerCount ];
139 for( int i=0; i<handlerCount; i++ ) {
140 onames[i]=handlersTable[i].getObjectName();
141 }
142 return onames;
143 }
144
145 }