Search in sources :

Example 1 with DistributedLogMultiStreamWriter

use of com.twitter.distributedlog.client.DistributedLogMultiStreamWriter in project distributedlog by twitter.

the class ConsoleProxyMultiWriter method main.

public static void main(String[] args) throws Exception {
    if (2 != args.length) {
        System.out.println(HELP);
        return;
    }
    String finagleNameStr = args[0];
    final String streamList = args[1];
    DistributedLogClient client = DistributedLogClientBuilder.newBuilder().clientId(ClientId$.MODULE$.apply("console-proxy-writer")).name("console-proxy-writer").thriftmux(true).finagleNameStr(finagleNameStr).build();
    String[] streamNameList = StringUtils.split(streamList, ',');
    DistributedLogMultiStreamWriter multiStreamWriter = DistributedLogMultiStreamWriter.newBuilder().streams(Lists.newArrayList(streamNameList)).bufferSize(0).client(client).flushIntervalMs(0).firstSpeculativeTimeoutMs(10000).maxSpeculativeTimeoutMs(20000).requestTimeoutMs(50000).build();
    ConsoleReader reader = new ConsoleReader();
    String line;
    while ((line = reader.readLine(PROMPT_MESSAGE)) != null) {
        multiStreamWriter.write(ByteBuffer.wrap(line.getBytes(UTF_8))).addEventListener(new FutureEventListener<DLSN>() {

            @Override
            public void onFailure(Throwable cause) {
                System.out.println("Encountered error on writing data");
                cause.printStackTrace(System.err);
                Runtime.getRuntime().exit(0);
            }

            @Override
            public void onSuccess(DLSN value) {
            // done
            }
        });
    }
    multiStreamWriter.close();
    client.close();
}
Also used : DLSN(com.twitter.distributedlog.DLSN) ConsoleReader(jline.ConsoleReader) DistributedLogMultiStreamWriter(com.twitter.distributedlog.client.DistributedLogMultiStreamWriter) DistributedLogClient(com.twitter.distributedlog.service.DistributedLogClient)

Aggregations

DLSN (com.twitter.distributedlog.DLSN)1 DistributedLogMultiStreamWriter (com.twitter.distributedlog.client.DistributedLogMultiStreamWriter)1 DistributedLogClient (com.twitter.distributedlog.service.DistributedLogClient)1 ConsoleReader (jline.ConsoleReader)1