01: package vicazh.hyperpool.stream.net.http;
02:
03: import java.io.*;
04: import java.util.*;
05: import vicazh.hyperpool.stream.Connection;
06:
07: /**
08: * The reconnect service
09: *
10: * @author Victor Zhigunov
11: * @version 0.4.0
12: */
13: public class ReconnectService extends Service implements
14: ReconnectServiceMBean, Serializable {
15: private int retry;
16:
17: public void setRetry(int retry) {
18: this .retry = retry;
19: }
20:
21: public int getRetry() {
22: return retry;
23: }
24:
25: private int timeout;
26:
27: public void setTimeout(int timeout) {
28: this .timeout = timeout;
29: }
30:
31: public int getTimeout() {
32: return timeout;
33: }
34:
35: public Connection getConnection() {
36: return new ReconnectConnection(this );
37: }
38:
39: public void setAttribute(String name, Object value)
40: throws Exception {
41: if (name.equals(ReconnectServiceMBean.OPTIONS)) {
42: setRetry(((ReconnectService) value).getRetry());
43: setTimeout(((ReconnectService) value).getTimeout());
44: super .setAttribute(name, value);
45: } else if (name.equals(ReconnectServiceMBean.RECONNECT))
46: for (Connection c : getConnections())
47: if (c.hashCode() == (Integer) value) {
48: try {
49: ((ReconnectConnection) c).clientout.close();
50: } catch (IOException e) {
51: }
52: break;
53: }
54: }
55:
56: public List<ReconnectItem> getItems() {
57: List<ReconnectItem> list = new ArrayList<ReconnectItem>();
58: for (Connection c : getConnections())
59: list.add(new ReconnectItem((ReconnectConnection) c));
60: return list;
61: }
62: }
|