KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jk > core > MsgContext


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
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  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jk.core;
18
19 import java.io.IOException JavaDoc;
20
21
22 /**
23  *
24  * @author Henri Gomez [hgomez@apache.org]
25  * @author Dan Milstein [danmil@shore.net]
26  * @author Keith Wannamaker [Keith@Wannamaker.org]
27  * @author Kevin Seguin
28  * @author Costin Manolache
29  */

30 public class MsgContext {
31     private int type;
32     private Object JavaDoc notes[]=new Object JavaDoc[32];
33     private JkHandler next;
34     private JkChannel source;
35     private Object JavaDoc req;
36     private WorkerEnv wEnv;
37     private Msg msgs[]=new Msg[10];
38     private int status=0;
39     // Control object
40
private Object JavaDoc control;
41
42     // Application managed, like notes
43
private long timers[]=new long[20];
44     
45     // The context can be used by JNI components as well
46
private long jkEndpointP;
47     private long xEnvP;
48
49     // Temp: use notes and dynamic strings
50
public static final int TIMER_RECEIVED=0;
51     public static final int TIMER_PRE_REQUEST=1;
52     public static final int TIMER_POST_REQUEST=2;
53     
54     public final Object JavaDoc getNote( int id ) {
55         return notes[id];
56     }
57
58     public final void setNote( int id, Object JavaDoc o ) {
59         notes[id]=o;
60     }
61
62     /** The id of the chain */
63     public final int getType() {
64         return type;
65     }
66
67     public final void setType(int i) {
68         type=i;
69     }
70
71     public final void setLong( int i, long l) {
72         timers[i]=l;
73     }
74     
75     public final long getLong( int i) {
76         return timers[i];
77     }
78     
79     // Common attributes ( XXX should be notes for flexibility ? )
80

81     public final WorkerEnv getWorkerEnv() {
82         return wEnv;
83     }
84
85     public final void setWorkerEnv( WorkerEnv we ) {
86         this.wEnv=we;
87     }
88     
89     public final JkChannel getSource() {
90         return source;
91     }
92     
93     public final void setSource(JkChannel ch) {
94         this.source=ch;
95     }
96
97     public final int getStatus() {
98         return status;
99     }
100
101     public final void setStatus( int s ) {
102         status=s;
103     }
104     
105     public final JkHandler getNext() {
106         return next;
107     }
108     
109     public final void setNext(JkHandler ch) {
110         this.next=ch;
111     }
112
113     /** The high level request object associated with this context
114      */

115     public final void setRequest( Object JavaDoc req ) {
116         this.req=req;
117     }
118
119     public final Object JavaDoc getRequest() {
120         return req;
121     }
122
123     /** The context may store a number of messages ( buffers + marshalling )
124      */

125     public final Msg getMsg(int i) {
126         return msgs[i];
127     }
128
129     public final void setMsg(int i, Msg msg) {
130         this.msgs[i]=msg;
131     }
132     
133     /** Each context contains a number of byte[] buffers used for communication.
134      * The C side will contain a char * equivalent - both buffers are long-lived
135      * and recycled.
136      *
137      * This will be called at init time. A long-lived global reference to the byte[]
138      * will be stored in the C context.
139      */

140     public byte[] getBuffer( int id ) {
141         // We use a single buffer right now.
142
if( msgs[id]==null ) {
143             return null;
144         }
145         return msgs[id].getBuffer();
146     }
147
148     /** Invoke a java hook. The xEnv is the representation of the current execution
149      * environment ( the jni_env_t * )
150      */

151     public int execute() throws IOException JavaDoc {
152         int status=next.invoke(msgs[0], this);
153         return status;
154     }
155
156     // -------------------- Jni support --------------------
157

158     /** Store native execution context data when this handler is called
159      * from JNI. This will change on each call, represent temproary
160      * call data.
161      */

162     public void setJniEnv( long xEnvP ) {
163             this.xEnvP=xEnvP;
164     }
165
166     public long getJniEnv() {
167         return xEnvP;
168     }
169     
170     /** The long-lived JNI context associated with this java context.
171      * The 2 share pointers to buffers and cache data to avoid expensive
172      * jni calls.
173      */

174     public void setJniContext( long cContext ) {
175         this.jkEndpointP=cContext;
176     }
177
178     public long getJniContext() {
179         return jkEndpointP;
180     }
181
182     public Object JavaDoc getControl() {
183         return control;
184     }
185
186     public void setControl(Object JavaDoc control) {
187         this.control = control;
188     }
189 }
190
Popular Tags