01: package vicazh.hyperpool.stream.net.http;
02:
03: import java.io.*;
04: import java.util.logging.*;
05: import vicazh.hyperpool.Element;
06: import vicazh.hyperpool.Start;
07: import vicazh.hyperpool.stream.*;
08: import vicazh.hyperpool.stream.Selector;
09: import vicazh.hyperpool.stream.net.Stream;
10:
11: class RouterClientStream extends ClientStream {
12:
13: RouterClientStream(Session session, OutputStream outputstream) {
14: super (session, outputstream);
15: }
16:
17: public void head(String method, String file, String version)
18: throws IOException {
19: ((Element) connection.element).sendAttribute(
20: ControlListSelectorMBean.SEEK, file);
21: int index = ((ListSelectorMBean) connection.element)
22: .getIndex(file);
23: if (outputstream == null
24: || ((RouterConnection) connection).index != index) {
25: if (outputstream != null) {
26: synchronized (connection) {
27: if (((Connection) connection).getSessions().size() > 1)
28: try {
29: connection.wait();
30: } catch (InterruptedException e) {
31: }
32: }
33: connection.getServer().outputstream = null;
34: connection.setServer(new Stream(
35: (Connection) connection, session.getServer()));
36: outputstream.flush();
37: outputstream.close();
38: }
39: ((RouterConnection) connection).index = index;
40: outputstream = ((Selector) connection.element).get(
41: connection.getServer(), index);
42: ((RouterConnection) connection).priority = (Priority) ((RouterSelector) connection.element)
43: .getList().get(index);
44: }
45: super .head(method, file, version);
46: }
47:
48: public void content(int b) throws IOException {
49: try {
50: if (((RouterConnection) connection).isReverse)
51: ((Priorities) ((ListSelectorMBean) connection.element)
52: .getList())
53: .serverwrite(((RouterConnection) connection).priority);
54: else
55: ((Priorities) ((ListSelectorMBean) connection.element)
56: .getList())
57: .clientwrite(((RouterConnection) connection).priority);
58: } catch (Exception e) {
59: Start.logger.log(Level.SEVERE, e.getMessage(), e);
60: }
61: super.content(b);
62: }
63: }
|