001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.jk.core;
019:
020: import java.util.Hashtable;
021: import javax.management.ObjectName;
022:
023: /**
024: * The controller object. It manages all other jk objects, acting as the root of
025: * the jk object model.
026: *
027: * @author Gal Shachor
028: * @author Henri Gomez [hgomez@apache.org]
029: * @author Dan Milstein [danmil@shore.net]
030: * @author Keith Wannamaker [Keith@Wannamaker.org]
031: * @author Kevin Seguin
032: * @author Costin Manolache
033: */
034: public class WorkerEnv {
035:
036: Hashtable properties;
037:
038: public static final int ENDPOINT_NOTE = 0;
039: public static final int REQUEST_NOTE = 1;
040: public static final int SSL_CERT_NOTE = 16;
041: int noteId[] = new int[4];
042: String noteName[][] = new String[4][];
043: private Object notes[] = new Object[32];
044:
045: Hashtable handlersMap = new Hashtable();
046: JkHandler handlersTable[] = new JkHandler[20];
047: int handlerCount = 0;
048:
049: // base dir for the jk webapp
050: String home;
051: int localId = 0;
052:
053: public WorkerEnv() {
054: for (int i = 0; i < noteId.length; i++) {
055: noteId[i] = 7;
056: noteName[i] = new String[20];
057: }
058: }
059:
060: public void setLocalId(int id) {
061: localId = id;
062: }
063:
064: public int getLocalId() {
065: return localId;
066: }
067:
068: public void setJkHome(String s) {
069: home = s;
070: }
071:
072: public String getJkHome() {
073: return home;
074: }
075:
076: public final Object getNote(int i) {
077: return notes[i];
078: }
079:
080: public final void setNote(int i, Object o) {
081: notes[i] = o;
082: }
083:
084: public int getNoteId(int type, String name) {
085: for (int i = 0; i < noteId[type]; i++) {
086: if (name.equals(noteName[type][i]))
087: return i;
088: }
089: int id = noteId[type]++;
090: noteName[type][id] = name;
091: return id;
092: }
093:
094: public void addHandler(String name, JkHandler w) {
095: JkHandler oldH = getHandler(name);
096: if (oldH == w) {
097: // Already added
098: return;
099: }
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,
106: handlersTable.length);
107: handlersTable = newT;
108: }
109: if (oldH == null) {
110: handlersTable[handlerCount] = w;
111: w.setId(handlerCount);
112: handlerCount++;
113: } else {
114: handlersTable[oldH.getId()] = w;
115: w.setId(oldH.getId());
116: }
117:
118: // Notify all other handlers of the new one
119: // XXX Could be a Coyote action ?
120: for (int i = 0; i < handlerCount; i++) {
121: handlersTable[i].addHandlerCallback(w);
122: }
123: }
124:
125: public final JkHandler getHandler(String name) {
126: return (JkHandler) handlersMap.get(name);
127: }
128:
129: public final JkHandler getHandler(int id) {
130: return handlersTable[id];
131: }
132:
133: public final int getHandlerCount() {
134: return handlerCount;
135: }
136:
137: public ObjectName[] getHandlersObjectName() {
138:
139: ObjectName onames[] = new ObjectName[handlerCount];
140: for (int i = 0; i < handlerCount; i++) {
141: onames[i] = handlersTable[i].getObjectName();
142: }
143: return onames;
144: }
145:
146: }
|