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