package vs;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

import vs.SyslogGrpc;
import vs.SyslogOuterClass.ComplexData;
import vs.SyslogOuterClass.Message;
import vs.SyslogOuterClass.Severity;

public class SyslogClient {
    public static void main(String[] args) throws Exception {
        ManagedChannel managedChannel = ManagedChannelBuilder
                .forAddress(args[0], 9000)//
                .usePlaintext()//
                .build();
        SyslogGrpc.SyslogBlockingStub server = SyslogGrpc
                .newBlockingStub(managedChannel);

        Message m = Message //
                .newBuilder() //
                .setAppname("Test App") //
                .addData(ComplexData //
                        .newBuilder() //
                        .setKey("key 1") //
                        .setText("data 1") //
                        .build()) //
                .addData(ComplexData //
                        .newBuilder() //
                        .setKey("key 2") //
                        .setText("data 2") //
                        .build()) //
                .setPriority(Severity.Alert) //
                .build();

        if (server.checkUrgency(m).getVal()) {
            System.out.println("client received: " + server.log(m).getVal());
        }
        managedChannel.shutdown();
    }

}
