001: /*
002: * Copyright 1999-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.jk.core;
018:
019: import java.io.IOException;
020:
021: /**
022: *
023: * @author Henri Gomez [hgomez@apache.org]
024: * @author Dan Milstein [danmil@shore.net]
025: * @author Keith Wannamaker [Keith@Wannamaker.org]
026: * @author Kevin Seguin
027: * @author Costin Manolache
028: */
029: public class MsgContext {
030: private int type;
031: private Object notes[] = new Object[32];
032: private JkHandler next;
033: private JkChannel source;
034: private Object req;
035: private WorkerEnv wEnv;
036: private Msg msgs[] = new Msg[10];
037: private int status = 0;
038: // Control object
039: private Object control;
040:
041: // Application managed, like notes
042: private long timers[] = new long[20];
043:
044: // The context can be used by JNI components as well
045: private long jkEndpointP;
046: private long xEnvP;
047:
048: // Temp: use notes and dynamic strings
049: public static final int TIMER_RECEIVED = 0;
050: public static final int TIMER_PRE_REQUEST = 1;
051: public static final int TIMER_POST_REQUEST = 2;
052:
053: public final Object getNote(int id) {
054: return notes[id];
055: }
056:
057: public final void setNote(int id, Object o) {
058: notes[id] = o;
059: }
060:
061: /** The id of the chain */
062: public final int getType() {
063: return type;
064: }
065:
066: public final void setType(int i) {
067: type = i;
068: }
069:
070: public final void setLong(int i, long l) {
071: timers[i] = l;
072: }
073:
074: public final long getLong(int i) {
075: return timers[i];
076: }
077:
078: // Common attributes ( XXX should be notes for flexibility ? )
079:
080: public final WorkerEnv getWorkerEnv() {
081: return wEnv;
082: }
083:
084: public final void setWorkerEnv(WorkerEnv we) {
085: this .wEnv = we;
086: }
087:
088: public final JkChannel getSource() {
089: return source;
090: }
091:
092: public final void setSource(JkChannel ch) {
093: this .source = ch;
094: }
095:
096: public final int getStatus() {
097: return status;
098: }
099:
100: public final void setStatus(int s) {
101: status = s;
102: }
103:
104: public final JkHandler getNext() {
105: return next;
106: }
107:
108: public final void setNext(JkHandler ch) {
109: this .next = ch;
110: }
111:
112: /** The high level request object associated with this context
113: */
114: public final void setRequest(Object req) {
115: this .req = req;
116: }
117:
118: public final Object getRequest() {
119: return req;
120: }
121:
122: /** The context may store a number of messages ( buffers + marshalling )
123: */
124: public final Msg getMsg(int i) {
125: return msgs[i];
126: }
127:
128: public final void setMsg(int i, Msg msg) {
129: this .msgs[i] = msg;
130: }
131:
132: /** Each context contains a number of byte[] buffers used for communication.
133: * The C side will contain a char * equivalent - both buffers are long-lived
134: * and recycled.
135: *
136: * This will be called at init time. A long-lived global reference to the byte[]
137: * will be stored in the C context.
138: */
139: public byte[] getBuffer(int id) {
140: // We use a single buffer right now.
141: if (msgs[id] == null) {
142: return null;
143: }
144: return msgs[id].getBuffer();
145: }
146:
147: /** Invoke a java hook. The xEnv is the representation of the current execution
148: * environment ( the jni_env_t * )
149: */
150: public int execute() throws IOException {
151: int status = next.invoke(msgs[0], this );
152: return status;
153: }
154:
155: // -------------------- Jni support --------------------
156:
157: /** Store native execution context data when this handler is called
158: * from JNI. This will change on each call, represent temproary
159: * call data.
160: */
161: public void setJniEnv(long xEnvP) {
162: this .xEnvP = xEnvP;
163: }
164:
165: public long getJniEnv() {
166: return xEnvP;
167: }
168:
169: /** The long-lived JNI context associated with this java context.
170: * The 2 share pointers to buffers and cache data to avoid expensive
171: * jni calls.
172: */
173: public void setJniContext(long cContext) {
174: this .jkEndpointP = cContext;
175: }
176:
177: public long getJniContext() {
178: return jkEndpointP;
179: }
180:
181: public Object getControl() {
182: return control;
183: }
184:
185: public void setControl(Object control) {
186: this.control = control;
187: }
188: }
|