22
22
23
23
import com .devicehive .api .RequestResponseMatcher ;
24
24
import com .devicehive .model .ServerEvent ;
25
+ import com .devicehive .proxy .api .NotificationHandler ;
25
26
import com .devicehive .proxy .api .ProxyClient ;
26
27
import com .devicehive .proxy .api .ProxyMessageBuilder ;
27
28
import com .devicehive .proxy .api .payload .NotificationCreatePayload ;
28
29
import com .devicehive .proxy .api .payload .SubscribePayload ;
29
30
import com .devicehive .proxy .api .payload .TopicsPayload ;
31
+ import com .devicehive .proxy .client .WebSocketKafkaProxyClient ;
32
+ import com .devicehive .proxy .config .WebSocketKafkaProxyConfig ;
30
33
import com .devicehive .shim .api .Request ;
31
34
import com .devicehive .shim .api .RequestType ;
32
35
import com .devicehive .shim .api .Response ;
37
40
import org .slf4j .LoggerFactory ;
38
41
39
42
import java .util .Arrays ;
40
- import java .util .concurrent .CompletableFuture ;
41
- import java .util .concurrent .ExecutionException ;
42
- import java .util .concurrent .TimeUnit ;
43
- import java .util .concurrent .TimeoutException ;
43
+ import java .util .UUID ;
44
+ import java .util .concurrent .*;
44
45
import java .util .function .Consumer ;
45
46
46
47
public class FrontendProxyClient implements RpcClient {
47
48
private static final Logger logger = LoggerFactory .getLogger (FrontendProxyClient .class );
48
49
49
50
private final String requestTopic ;
50
51
private final String replyToTopic ;
51
- private final ProxyClient client ;
52
+ private final WebSocketKafkaProxyClient client ;
53
+ private final WebSocketKafkaProxyConfig proxyConfig ;
54
+ private final NotificationHandler notificationHandler ;
52
55
private final RequestResponseMatcher requestResponseMatcher ;
53
56
private final Gson gson ;
54
57
private final RingBuffer <ServerEvent > ringBuffer ;
55
58
56
- public FrontendProxyClient (String requestTopic , String replyToTopic , ProxyClient client , RequestResponseMatcher requestResponseMatcher , Gson gson , RingBuffer <ServerEvent > ringBuffer ) {
59
+ public FrontendProxyClient (String requestTopic , String replyToTopic , WebSocketKafkaProxyConfig proxyConfig , NotificationHandler notificationHandler , RequestResponseMatcher requestResponseMatcher , Gson gson , RingBuffer <ServerEvent > ringBuffer ) {
57
60
this .requestTopic = requestTopic ;
58
61
this .replyToTopic = replyToTopic ;
59
- this .client = client ;
62
+ this .proxyConfig = proxyConfig ;
63
+ this .notificationHandler = notificationHandler ;
60
64
this .requestResponseMatcher = requestResponseMatcher ;
61
65
this .gson = gson ;
62
66
this .ringBuffer = ringBuffer ;
67
+ this .client = new WebSocketKafkaProxyClient ((message , client ) -> {});
68
+ client .setWebSocketKafkaProxyConfig (proxyConfig );
63
69
}
64
70
65
71
@ Override
@@ -85,7 +91,17 @@ public void push(Request request) {
85
91
public void start () {
86
92
client .start ();
87
93
client .push (ProxyMessageBuilder .create (new TopicsPayload (Arrays .asList (requestTopic , replyToTopic )))).join ();
88
- client .push (ProxyMessageBuilder .subscribe (new SubscribePayload (replyToTopic ))).join ();
94
+
95
+ UUID uuid = UUID .randomUUID ();
96
+ Executor executionPool = Executors .newFixedThreadPool (proxyConfig .getWorkerThreads ());
97
+ for (int i = 0 ; i < proxyConfig .getWorkerThreads (); i ++) {
98
+ executionPool .execute (() -> {
99
+ WebSocketKafkaProxyClient client = new WebSocketKafkaProxyClient (notificationHandler );
100
+ client .setWebSocketKafkaProxyConfig (proxyConfig );
101
+ client .start ();
102
+ client .push (ProxyMessageBuilder .subscribe (new SubscribePayload (replyToTopic , uuid .toString ()))).join ();
103
+ });
104
+ }
89
105
90
106
pingServer ();
91
107
}
0 commit comments