-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
AgentServerTestMain.java
91 lines (78 loc) · 3.26 KB
/
AgentServerTestMain.java
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright 2019 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.collector.receiver.grpc;
import com.navercorp.pinpoint.collector.receiver.DispatchHandler;
import com.navercorp.pinpoint.collector.receiver.grpc.service.AgentService;
import com.navercorp.pinpoint.common.server.util.AddressFilter;
import com.navercorp.pinpoint.grpc.server.ServerOption;
import com.navercorp.pinpoint.grpc.trace.PResult;
import com.navercorp.pinpoint.io.request.ServerRequest;
import com.navercorp.pinpoint.io.request.ServerResponse;
import io.grpc.BindableService;
import io.grpc.Status;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author jaehong.kim
*/
public class AgentServerTestMain {
public static final String IP = "0.0.0.0";
public static final int PORT = 9997;
public void run() throws Exception {
GrpcReceiver grpcReceiver = new GrpcReceiver();
grpcReceiver.setEnable(true);
grpcReceiver.setBeanName("AgentServer");
grpcReceiver.setBindIp(IP);
grpcReceiver.setBindPort(PORT);
BindableService agentService = new AgentService(new MockDispatchHandler());
grpcReceiver.setBindableServiceList(Arrays.asList(agentService));
grpcReceiver.setAddressFilter(new MockAddressFilter());
grpcReceiver.setExecutor(Executors.newFixedThreadPool(8));
grpcReceiver.setServerOption(new ServerOption.Builder().build());
grpcReceiver.afterPropertiesSet();
grpcReceiver.blockUntilShutdown();
grpcReceiver.destroy();
}
public static void main(String[] args) throws Exception {
AgentServerTestMain main = new AgentServerTestMain();
try {
main.run();
} catch (Exception e) {
System.out.println("Failed to run");
e.printStackTrace();
}
}
private static class MockDispatchHandler implements DispatchHandler {
private static AtomicInteger counter = new AtomicInteger(0);
@Override
public void dispatchSendMessage(ServerRequest serverRequest) {
System.out.println("Dispatch send message " + serverRequest);
}
@Override
public void dispatchRequestMessage(ServerRequest serverRequest, ServerResponse serverResponse) {
System.out.println("Dispatch request message " + serverRequest + ", " + serverResponse);
serverResponse.write(PResult.newBuilder().setMessage("Success" + counter.getAndIncrement()).build());
}
}
private static class MockAddressFilter implements AddressFilter {
@Override
public boolean accept(InetAddress address) {
return true;
}
}
}