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.Element;
07: import vicazh.hyperpool.Start;
08: import vicazh.hyperpool.stream.*;
09: import vicazh.hyperpool.stream.Selector;
10: import vicazh.hyperpool.stream.net.Stream;
11:
12: class ServersClientStream extends ClientStream {
13:
14: ServersClientStream(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: String host = url.getHost();
27: ((Element) connection.element).sendAttribute(
28: ControlListSelectorMBean.SEEK, host);
29: int index = ((ListSelectorMBean) connection.element)
30: .getIndex(host);
31: if (outputstream == null
32: || ((ServersConnection) connection).index != index) {
33: if (outputstream != null) {
34: synchronized (connection) {
35: if (((Connection) connection).getSessions().size() > 1)
36: try {
37: connection.wait();
38: } catch (InterruptedException e) {
39: }
40: }
41: connection.getServer().outputstream = null;
42: connection.setServer(new Stream(
43: (Connection) connection, session.getServer()));
44: outputstream.flush();
45: outputstream.close();
46: }
47: ((ServersConnection) connection).index = index;
48: outputstream = ((Selector) connection.element).get(
49: connection.getServer(), index);
50: ((ServersConnection) connection).priority = (Priority) ((ServersSelector) connection.element)
51: .getList().get(index);
52: }
53: super .head(method, file, version);
54: }
55:
56: public void content(int b) throws IOException {
57: try {
58: if (((ServersConnection) connection).isReverse)
59: ((Priorities) ((ListSelectorMBean) connection.element)
60: .getList())
61: .serverwrite(((ServersConnection) connection).priority);
62: else
63: ((Priorities) ((ListSelectorMBean) connection.element)
64: .getList())
65: .clientwrite(((ServersConnection) connection).priority);
66: } catch (Exception e) {
67: Start.logger.log(Level.SEVERE, e.getMessage(), e);
68: }
69: super.content(b);
70: }
71: }
|