1 |
|
/*
|
|
|
|
|
2 |
|
* License
d to the A
pache Soft
ware Found
ation (ASF
) under on
e or more
|
|
|
|
|
3 |
|
* contrib
utor licen
se agreeme
nts. See
the NOTICE
file dist
ributed wi
th
|
|
|
|
|
4 |
|
* this wo
rk for add
itional in
formation
regarding
copyright
ownership.
|
|
|
|
|
5 |
|
* The ASF
licenses
this file
to You und
er the Apa
che Licens
e, Version
2.0
|
|
|
|
|
6 |
|
* (the "L
icense");
you may no
t use this
file exce
pt in comp
liance wit
h
|
|
|
|
|
7 |
|
* the Lic
ense. You
may obtai
n a copy o
f the Lice
nse at
|
|
|
|
|
8 |
|
*
|
|
|
|
|
9 |
|
* ht
tp://www.a
pache.org/
licenses/L
ICENSE-2.0
|
|
|
|
|
10 |
|
*
|
|
|
|
|
11 |
|
* Unless
required b
y applicab
le law or
agreed to
in writing
, software
|
|
|
|
|
12 |
|
* distrib
uted under
the Licen
se is dist
ributed on
an "AS IS
" BASIS,
|
|
|
|
|
13 |
|
* WITHOUT
WARRANTIE
S OR CONDI
TIONS OF A
NY KIND, e
ither expr
ess or imp
lied.
|
|
|
|
|
14 |
|
* See the
License f
or the spe
cific lang
uage gover
ning permi
ssions and
|
|
|
|
|
15 |
|
* limitat
ions under
the Licen
se.
|
|
|
|
|
16 |
|
*/
|
|
|
|
|
17 |
|
|
|
|
|
|
18 |
|
|
|
|
|
|
19 |
|
package or
g.apache.c
atalina.co
met;
|
|
|
|
|
20 |
|
|
|
|
|
|
21 |
|
import jav
a.io.IOExc
eption;
|
|
|
|
|
22 |
|
|
|
|
|
|
23 |
|
import jav
ax.servlet
.ServletEx
ception;
|
|
|
|
|
24 |
|
import jav
ax.servlet
.http.Http
ServletReq
uest;
|
|
|
|
|
25 |
|
import jav
ax.servlet
.http.Http
ServletRes
ponse;
|
|
|
|
|
26 |
|
|
|
|
|
|
27 |
|
/**
|
|
|
|
|
28 |
|
* The Com
etEvent in
terface.
|
|
|
|
|
29 |
|
*
|
|
|
|
|
30 |
|
* @author
Remy Mauc
herat
|
|
|
|
|
31 |
|
*/
|
|
|
|
|
32 |
|
public int
erface Com
etEvent {
|
|
|
|
|
33 |
|
|
|
|
|
|
34 |
|
/**
|
|
|
|
|
35 |
|
* Enu
meration d
escribing
the major
events tha
t the cont
ainer can
invoke
|
|
|
|
|
36 |
|
* the
CometProc
essors eve
nt() metho
d with.<br
>
|
|
|
|
|
37 |
|
* BEG
IN - will
be called
at the beg
inning
|
|
|
|
|
38 |
|
* of
the proce
ssing of t
he connect
ion. It ca
n be used
to initial
ize any re
levant
|
|
|
|
|
39 |
|
* fi
elds using
the reque
st and res
ponse obje
cts. Betwe
en the end
of the pr
ocessing
|
|
|
|
|
40 |
|
* of
this even
t, and the
beginning
of the pr
ocessing o
f the end
or error e
vents,
|
|
|
|
|
41 |
|
* it
is possib
le to use
the respon
se object
to write d
ata on the
open conn
ection.
|
|
|
|
|
42 |
|
* No
te that th
e response
object an
d dependen
t OutputSt
ream and W
riter are
still
|
|
|
|
|
43 |
|
* no
t synchron
ized, so w
hen they a
re accesse
d by multi
ple thread
s,
|
|
|
|
|
44 |
|
* sy
nchronizat
ion is man
datory. Af
ter proces
sing the i
nitial eve
nt, the re
quest
|
|
|
|
|
45 |
|
* is
considere
d to be co
mmitted.<b
r>
|
|
|
|
|
46 |
|
* REA
D - This i
ndicates t
hat input
data is av
ailable, a
nd that on
e read can
be made
|
|
|
|
|
47 |
|
* wi
thout bloc
king. The
available
and ready
methods of
the Input
Stream or
|
|
|
|
|
48 |
|
* Re
ader may b
e used to
determine
if there i
s a risk o
f blocking
: the serv
let
|
|
|
|
|
49 |
|
* sh
ould read
while data
is report
ed availab
le. When e
ncounterin
g a read e
rror,
|
|
|
|
|
50 |
|
* th
e servlet
should rep
ort it by
propagatin
g the exce
ption prop
erly. Thro
wing
|
|
|
|
|
51 |
|
* an
exception
will caus
e the erro
r event to
be invoke
d, and the
connectio
n
|
|
|
|
|
52 |
|
* wi
ll be clos
ed.
|
|
|
|
|
53 |
|
* Al
ternately,
it is als
o possible
to catch
any except
ion, perfo
rm clean u
p
|
|
|
|
|
54 |
|
* on
any data
structure
the servle
t may be u
sing, and
using the
close meth
od
|
|
|
|
|
55 |
|
* of
the event
. It is no
t allowed
to attempt
reading d
ata from t
he request
|
|
|
|
|
56 |
|
* ob
ject outsi
de of the
execution
of this me
thod.<br>
|
|
|
|
|
57 |
|
* END
- End may
be called
to end th
e processi
ng of the
request. F
ields that
have
|
|
|
|
|
58 |
|
* be
en initial
ized in th
e begin me
thod shoul
d be reset
. After th
is event h
as
|
|
|
|
|
59 |
|
* be
en process
ed, the re
quest and
response o
bjects, as
well as a
ll their d
ependent
|
|
|
|
|
60 |
|
* ob
jects will
be recycl
ed and use
d to proce
ss other r
equests. E
nd will al
so be
|
|
|
|
|
61 |
|
* ca
lled when
data is av
ailable an
d the end
of file is
reached o
n the requ
est input
|
|
|
|
|
62 |
|
* (t
his usuall
y indicate
s the clie
nt has pip
elined a r
equest).<b
r>
|
|
|
|
|
63 |
|
* ERR
OR - Error
will be c
alled by t
he contain
er in the
case where
an IO exc
eption
|
|
|
|
|
64 |
|
* or
a similar
unrecover
able error
occurs on
the conne
ction. Fie
lds that h
ave
|
|
|
|
|
65 |
|
* be
en initial
ized in th
e begin me
thod shoul
d be reset
. After th
is event h
as
|
|
|
|
|
66 |
|
* be
en process
ed, the re
quest and
response o
bjects, as
well as a
ll their d
ependent
|
|
|
|
|
67 |
|
* ob
jects will
be recycl
ed and use
d to proce
ss other r
equests.
|
|
|
|
|
68 |
|
*/
|
|
|
|
|
69 |
|
public
enum Even
tType {BEG
IN, READ,
END, ERROR
}
|
|
|
|
|
70 |
|
|
|
|
|
|
71 |
|
|
|
|
|
|
72 |
|
/**
|
|
|
|
|
73 |
|
* Eve
nt details
.<br>
|
|
|
|
|
74 |
|
* TIM
EOUT - the
connectio
n timed ou
t (sub typ
e of ERROR
); note th
at this ER
ROR type i
s not fata
l, and
|
|
|
|
|
75 |
|
* t
he connect
ion will n
ot be clos
ed unless
the servle
t uses the
close met
hod of the
event<br>
|
|
|
|
|
76 |
|
* CLI
ENT_DISCON
NECT - the
client co
nnection w
as closed
(sub type
of ERROR)<
br>
|
|
|
|
|
77 |
|
* IOE
XCEPTION -
an IO exc
eption occ
urred, suc
h as inval
id content
, for exam
ple, an in
valid chun
k block (s
ub type of
ERROR)<br
>
|
|
|
|
|
78 |
|
* WEB
APP_RELOAD
- the web
applicatio
n is being
reloaded
(sub type
of END)<br
>
|
|
|
|
|
79 |
|
* SER
VER_SHUTDO
WN - the s
erver is s
hutting do
wn (sub ty
pe of END)
<br>
|
|
|
|
|
80 |
|
* SES
SION_END -
the servl
et ended t
he session
(sub type
of END)
|
|
|
|
|
81 |
|
*/
|
|
|
|
|
82 |
|
public
enum Even
tSubType {
TIMEOUT,
CLIENT_DIS
CONNECT, I
OEXCEPTION
, WEBAPP_R
ELOAD, SER
VER_SHUTDO
WN, SESSIO
N_END }
|
|
|
|
|
83 |
|
|
|
|
|
|
84 |
|
|
|
|
|
|
85 |
|
/**
|
|
|
|
|
86 |
|
* Ret
urns the H
ttpServlet
Request.
|
|
|
|
|
87 |
|
*
|
|
|
|
|
88 |
|
* @re
turn HttpS
ervletRequ
est
|
|
|
|
|
89 |
|
*/
|
|
|
|
|
90 |
|
public
HttpServl
etRequest
getHttpSer
vletReques
t();
|
|
|
|
|
91 |
|
|
|
|
|
|
92 |
|
/**
|
|
|
|
|
93 |
|
* Ret
urns the H
ttpServlet
Response.
|
|
|
|
|
94 |
|
*
|
|
|
|
|
95 |
|
* @re
turn HttpS
ervletResp
onse
|
|
|
|
|
96 |
|
*/
|
|
|
|
|
97 |
|
public
HttpServl
etResponse
getHttpSe
rvletRespo
nse();
|
|
|
|
|
98 |
|
|
|
|
|
|
99 |
|
/**
|
|
|
|
|
100 |
|
* Ret
urns the e
vent type.
|
|
|
|
|
101 |
|
*
|
|
|
|
|
102 |
|
* @re
turn Event
Type
|
|
|
|
|
103 |
|
*/
|
|
|
|
|
104 |
|
public
EventType
getEventT
ype();
|
|
|
|
|
105 |
|
|
|
|
|
|
106 |
|
/**
|
|
|
|
|
107 |
|
* Ret
urns the s
ub type of
this even
t.
|
|
|
|
|
108 |
|
*
|
|
|
|
|
109 |
|
* @re
turn Event
SubType
|
|
|
|
|
110 |
|
*/
|
|
|
|
|
111 |
|
public
EventSubT
ype getEve
ntSubType(
);
|
|
|
|
|
112 |
|
|
|
|
|
|
113 |
|
/**
|
|
|
|
|
114 |
|
* End
s the Come
t session.
This sign
als to the
container
that
|
|
|
|
|
115 |
|
* the
container
wants to
end the co
met sessio
n. This wi
ll send ba
ck to the
|
|
|
|
|
116 |
|
* cli
ent a noti
ce that th
e server h
as no more
data to s
end as par
t of this
|
|
|
|
|
117 |
|
* req
uest. The
servlet sh
ould perfo
rm any nee
ded cleanu
p as if it
had recei
ved
|
|
|
|
|
118 |
|
* an
END or ERR
OR event.
|
|
|
|
|
119 |
|
*
|
|
|
|
|
120 |
|
* @th
rows IOExc
eption if
an IO exce
ption occu
rs
|
|
|
|
|
121 |
|
*/
|
|
|
|
|
122 |
|
public
void clos
e() throws
IOExcepti
on;
|
|
|
|
|
123 |
|
|
|
|
|
|
124 |
|
/**
|
|
|
|
|
125 |
|
* Set
s the time
out for th
is Comet c
onnection.
Please NO
TE, that t
he impleme
ntation
|
|
|
|
|
126 |
|
* of
a per conn
ection tim
eout is OP
TIONAL and
MAY NOT b
e implemen
ted.<br>
|
|
|
|
|
127 |
|
* Thi
s method s
ets the ti
meout in m
illisecond
s of idle
time on th
e connecti
on.
|
|
|
|
|
128 |
|
* The
timeout i
s reset ev
ery time d
ata is rec
eived from
the conne
ction or d
ata is flu
shed
|
|
|
|
|
129 |
|
* usi
ng <code>r
esponse.fl
ushBuffer(
)</code>.
If a timeo
ut occurs,
the
|
|
|
|
|
130 |
|
* <co
de>error(H
ttpServlet
Request, H
ttpServlet
Response)<
/code> met
hod is inv
oked. The
|
|
|
|
|
131 |
|
* web
applicati
on SHOULD
NOT attemp
t to reuse
the reque
st and res
ponse obje
cts after
a timeout
|
|
|
|
|
132 |
|
* as
the <code>
error(Http
ServletReq
uest, Http
ServletRes
ponse)</co
de> method
indicates
.<br>
|
|
|
|
|
133 |
|
* Thi
s method s
hould not
be called
asynchrono
usly, as t
hat will h
ave no eff
ect.
|
|
|
|
|
134 |
|
*
|
|
|
|
|
135 |
|
* @pa
ram timeou
t The time
out in mil
liseconds
for this c
onnection,
must be a
positive
value, lar
ger than 0
|
|
|
|
|
136 |
|
* @th
rows IOExc
eption An
IOExceptio
n may be t
hrown to i
ndicate an
IO error,
|
|
|
|
|
137 |
|
*
or th
at the EOF
has been
reached on
the conne
ction
|
|
|
|
|
138 |
|
* @th
rows Servl
etExceptio
n An excep
tion has o
ccurred, a
s specifie
d by the r
oot
|
|
|
|
|
139 |
|
*
cause
|
|
|
|
|
140 |
|
* @th
rows Unsup
portedOper
ationExcep
tion if pe
r connecti
on timeout
is not su
pported, e
ither at a
ll or at t
his phase
|
|
|
|
|
141 |
|
*
of th
e invocati
on.
|
|
|
|
|
142 |
|
*/
|
|
|
|
|
143 |
|
public
void setT
imeout(int
timeout)
|
|
|
|
|
144 |
|
th
rows IOExc
eption, Se
rvletExcep
tion, Unsu
pportedOpe
rationExce
ption;
|
|
|
|
|
145 |
|
|
|
|
|
|
146 |
|
}
|
|
|
|
|