1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
package com.sun.grizzly.connectioncache.client; |
40 | |
|
41 | |
|
42 | |
import com.sun.grizzly.ConnectorHandler; |
43 | |
import com.sun.grizzly.ConnectorHandlerPool; |
44 | |
import com.sun.grizzly.ConnectorInstanceHandler; |
45 | |
import com.sun.grizzly.Controller; |
46 | |
import com.sun.grizzly.Controller.Protocol; |
47 | |
import com.sun.grizzly.DefaultConnectorHandlerPool; |
48 | |
import com.sun.grizzly.connectioncache.spi.transport.ConnectionCacheFactory; |
49 | |
import com.sun.grizzly.connectioncache.spi.transport.ConnectionFinder; |
50 | |
import com.sun.grizzly.connectioncache.spi.transport.OutboundConnectionCache; |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | 20 | public class CacheableConnectorHandlerPool implements |
59 | |
ConnectorHandlerPool<CacheableConnectorHandler> { |
60 | |
|
61 | |
private Controller controller; |
62 | |
private ConnectorHandlerPool protocolConnectorHandlerPool; |
63 | |
private ConnectorInstanceHandler<CacheableConnectorHandler> connectorInstanceHandler; |
64 | |
private OutboundConnectionCache<ConnectorHandler> outboundConnectionCache; |
65 | |
private ConnectionFinder<ConnectorHandler> connectionFinder; |
66 | |
|
67 | |
public CacheableConnectorHandlerPool(Controller controller, int highWaterMark, |
68 | |
int numberToReclaim, int maxParallel) { |
69 | 1 | this(controller, highWaterMark, numberToReclaim, maxParallel, null); |
70 | 1 | } |
71 | |
|
72 | |
public CacheableConnectorHandlerPool(Controller controller, int highWaterMark, |
73 | 1 | int numberToReclaim, int maxParallel, ConnectionFinder<ConnectorHandler> connectionFinder) { |
74 | 1 | this.controller = controller; |
75 | 1 | this.outboundConnectionCache = |
76 | |
ConnectionCacheFactory.<ConnectorHandler>makeBlockingOutboundConnectionCache( |
77 | |
"Grizzly outbound connection cache", highWaterMark, |
78 | |
numberToReclaim, maxParallel, Controller.logger()); |
79 | 1 | this.connectionFinder = connectionFinder; |
80 | 1 | protocolConnectorHandlerPool = new DefaultConnectorHandlerPool(controller); |
81 | 1 | connectorInstanceHandler = new CacheableConnectorInstanceHandler(); |
82 | 1 | } |
83 | |
|
84 | |
public CacheableConnectorHandler acquireConnectorHandler(Protocol protocol) { |
85 | 10 | CacheableConnectorHandler connectorHandler = connectorInstanceHandler.acquire(); |
86 | 10 | connectorHandler.setProtocol(protocol); |
87 | 10 | return connectorHandler; |
88 | |
} |
89 | |
|
90 | |
public void releaseConnectorHandler(CacheableConnectorHandler connectorHandler) { |
91 | 10 | connectorInstanceHandler.release(connectorHandler); |
92 | 10 | } |
93 | |
|
94 | |
OutboundConnectionCache<ConnectorHandler> getOutboundConnectionCache() { |
95 | 20 | return outboundConnectionCache; |
96 | |
} |
97 | |
|
98 | |
ConnectionFinder getConnectionFinder() { |
99 | 10 | return connectionFinder; |
100 | |
} |
101 | |
|
102 | |
Controller getController() { |
103 | 9 | return controller; |
104 | |
} |
105 | |
|
106 | |
ConnectorHandlerPool getProtocolConnectorHandlerPool() { |
107 | 1 | return protocolConnectorHandlerPool; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | 3 | private class CacheableConnectorInstanceHandler extends |
115 | |
ConnectorInstanceHandler.ConcurrentQueueConnectorInstanceHandler<CacheableConnectorHandler> { |
116 | |
|
117 | |
public CacheableConnectorHandler newInstance() { |
118 | 1 | return new CacheableConnectorHandler(CacheableConnectorHandlerPool.this); |
119 | |
} |
120 | |
} |
121 | |
} |