Search in sources :

Example 1 with GeneratedAbstractSubscribeToTopicOperationHandler

use of greengrass.GeneratedAbstractSubscribeToTopicOperationHandler in project aws-iot-device-sdk-java-v2 by aws.

the class GreengrassV2ClientTest method before.

@BeforeEach
public void before() throws IOException {
    port = randomPort();
    try (final EventLoopGroup elGroup = new EventLoopGroup(1);
        SocketOptions socketOptions = new SocketOptions()) {
        socketOptions.connectTimeoutMs = 3000;
        socketOptions.domain = SocketOptions.SocketDomain.IPv4;
        socketOptions.type = SocketOptions.SocketType.STREAM;
        GreengrassCoreIPCService service = new GreengrassCoreIPCService();
        service.setCreateLocalDeploymentHandler((c) -> new GeneratedAbstractCreateLocalDeploymentOperationHandler(c) {

            @Override
            protected void onStreamClosed() {
            }

            @Override
            public CreateLocalDeploymentResponse handleRequest(CreateLocalDeploymentRequest request) {
                return new CreateLocalDeploymentResponse().withDeploymentId("deployment");
            }

            @Override
            public void handleStreamEvent(EventStreamJsonMessage streamRequestEvent) {
            }
        });
        service.setSubscribeToTopicHandler((c) -> new GeneratedAbstractSubscribeToTopicOperationHandler(c) {

            @Override
            protected void onStreamClosed() {
                subscriptionClosed.complete(null);
            }

            @Override
            public SubscribeToTopicResponse handleRequest(SubscribeToTopicRequest request) {
                new Thread(() -> {
                    sendStreamEvent(new SubscriptionResponseMessage().withBinaryMessage(new BinaryMessage().withMessage("message".getBytes(StandardCharsets.UTF_8))));
                }).start();
                return new SubscribeToTopicResponse().withTopicName(request.getTopic());
            }

            @Override
            public void handleStreamEvent(EventStreamJsonMessage streamRequestEvent) {
            }
        });
        service.setAuthenticationHandler((headers, bytes) -> {
            authenticationRequest = new Gson().fromJson(new String(bytes), GreengrassEventStreamConnectMessage.class);
            return () -> "connected";
        });
        service.setAuthorizationHandler(authenticationData -> Authorization.ACCEPT);
        ipcServer = new RpcServer(elGroup, socketOptions, null, "127.0.0.1", port, service);
        ipcServer.runServer();
        client = GreengrassCoreIPCClientV2.builder().withPort(port).withSocketPath("127.0.0.1").withSocketDomain(SocketOptions.SocketDomain.IPv4).withAuthToken("myAuthToken").build();
    }
}
Also used : SocketOptions(software.amazon.awssdk.crt.io.SocketOptions) Gson(com.google.gson.Gson) EventStreamJsonMessage(software.amazon.awssdk.eventstreamrpc.model.EventStreamJsonMessage) BinaryMessage(software.amazon.awssdk.aws.greengrass.model.BinaryMessage) CreateLocalDeploymentRequest(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest) EventLoopGroup(software.amazon.awssdk.crt.io.EventLoopGroup) CreateLocalDeploymentResponse(software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse) SubscriptionResponseMessage(software.amazon.awssdk.aws.greengrass.model.SubscriptionResponseMessage) GeneratedAbstractCreateLocalDeploymentOperationHandler(greengrass.GeneratedAbstractCreateLocalDeploymentOperationHandler) RpcServer(software.amazon.awssdk.eventstreamrpc.RpcServer) GreengrassCoreIPCService(greengrass.GreengrassCoreIPCService) GeneratedAbstractSubscribeToTopicOperationHandler(greengrass.GeneratedAbstractSubscribeToTopicOperationHandler) SubscribeToTopicResponse(software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicResponse) GreengrassEventStreamConnectMessage(software.amazon.awssdk.eventstreamrpc.GreengrassEventStreamConnectMessage) SubscribeToTopicRequest(software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Gson (com.google.gson.Gson)1 GeneratedAbstractCreateLocalDeploymentOperationHandler (greengrass.GeneratedAbstractCreateLocalDeploymentOperationHandler)1 GeneratedAbstractSubscribeToTopicOperationHandler (greengrass.GeneratedAbstractSubscribeToTopicOperationHandler)1 GreengrassCoreIPCService (greengrass.GreengrassCoreIPCService)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 BinaryMessage (software.amazon.awssdk.aws.greengrass.model.BinaryMessage)1 CreateLocalDeploymentRequest (software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest)1 CreateLocalDeploymentResponse (software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentResponse)1 SubscribeToTopicRequest (software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicRequest)1 SubscribeToTopicResponse (software.amazon.awssdk.aws.greengrass.model.SubscribeToTopicResponse)1 SubscriptionResponseMessage (software.amazon.awssdk.aws.greengrass.model.SubscriptionResponseMessage)1 EventLoopGroup (software.amazon.awssdk.crt.io.EventLoopGroup)1 SocketOptions (software.amazon.awssdk.crt.io.SocketOptions)1 GreengrassEventStreamConnectMessage (software.amazon.awssdk.eventstreamrpc.GreengrassEventStreamConnectMessage)1 RpcServer (software.amazon.awssdk.eventstreamrpc.RpcServer)1 EventStreamJsonMessage (software.amazon.awssdk.eventstreamrpc.model.EventStreamJsonMessage)1