Java Code Examples for org.apache.thrift.TException#printStackTrace()

The following examples show how to use org.apache.thrift.TException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AgentInfoSenderTest.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(RequestPacket requestPacket, PinpointSocket pinpointSocket) {
    logger.debug("handleRequest packet:{}, remote:{}", requestPacket, pinpointSocket.getRemoteAddress());

    int requestCount = this.requestCount.incrementAndGet();
    if (requestCount < successCondition) {
        return;
    }

    try {
        HeaderTBaseSerializer serializer = HeaderTBaseSerializerFactory.DEFAULT_FACTORY.createSerializer();

        TResult result = new TResult(true);
        byte[] resultBytes = serializer.serialize(result);

        this.successCount.incrementAndGet();

        pinpointSocket.response(requestPacket.getRequestId(), resultBytes);
    } catch (TException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
 
Example 2
Source File: SimpleCarreraConsumerExample.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TTransportException, InterruptedException {

        CarreraConfig config =
                new CarreraConfig("cg_test", "127.0.0.1:9713");
        config.setRetryInterval(1000);
        final SimpleCarreraConsumer consumer = new SimpleCarreraConsumer(config);

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    LOGGER.info("stopping...");
                    consumer.stop();
                } finally {
                    LogManager.shutdown(); //shutdown log4j2.
                }
            }
        }));

        consumer.startConsume(new MessageProcessor() {
            @Override
            public Result process(Message message, Context context) {
                LOGGER.info("process key:{}, value.length:{}, offset:{}, context:{}", message.getKey(),
                        message.getValue().length, message.getOffset(), context);
                return Result.SUCCESS;
            }
        });

        try {
            List<ConsumeStats> consumeStatses = consumer.getConsumeStats("test_group_name");
            System.out.println(consumeStatses);

            consumeStatses = consumer.getConsumeStats("test_topic_name");
            System.out.println(consumeStatses);
        } catch (TException e) {
            e.printStackTrace();
        }
    }
 
Example 3
Source File: DataCleanKerberosImpl.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        String hostIp = "192.168.1.166";
        String hostName = "root";
        String hostPassword = "123456";
        int fdSum = 8;
        //数据分隔符
        String spStr = ",";
        String srcDirName = "/test/in/";
        String dstDirName = "/test/out/";
        String hostPort = "10000";

        String user = "hive/[email protected]";
        String keytabPath = "/root/hive.keytab";
        String krb5Path = "/etc/krb5.conf";
        String principalPath = "principal=hive/[email protected]";

        String fdNum = "8";
        String regExStr = "2";
        System.out.print("---------------------");
        //对不符合规则的数据进行清洗,得到符合字段数目的数据
        DataCleanKerberosImpl dataCleanKerberos = new DataCleanKerberosImpl();
        try {
            dataCleanKerberos.formatFieldKerberos(spStr,fdSum,fdNum,regExStr, srcDirName,dstDirName, hostIp, hostPort, hostName, hostPassword ,user,krb5Path,keytabPath,principalPath);
        } catch (TException e) {
            e.printStackTrace();
        }
        System.out.print("结束");


    }
 
Example 4
Source File: SimpleCarreraConsumerExample.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TTransportException, InterruptedException {

        CarreraConfig config =
                new CarreraConfig("cg_test", "127.0.0.1:9713");
        config.setRetryInterval(1000);
        final SimpleCarreraConsumer consumer = new SimpleCarreraConsumer(config);

        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    LOGGER.info("stopping...");
                    consumer.stop();
                } finally {
                    LogManager.shutdown(); //shutdown log4j2.
                }
            }
        }));

        consumer.startConsume(new MessageProcessor() {
            @Override
            public Result process(Message message, Context context) {
                LOGGER.info("process key:{}, value.length:{}, offset:{}, context:{}", message.getKey(),
                        message.getValue().length, message.getOffset(), context);
                return Result.SUCCESS;
            }
        });

        try {
            List<ConsumeStats> consumeStatses = consumer.getConsumeStats("test_group_name");
            System.out.println(consumeStatses);

            consumeStatses = consumer.getConsumeStats("test_topic_name");
            System.out.println(consumeStatses);
        } catch (TException e) {
            e.printStackTrace();
        }
    }
 
Example 5
Source File: ThriftExample.java    From pragmatic-java-engineer with GNU General Public License v3.0 5 votes vote down vote up
public static void testRpcClient() {
    TTransport transport = new TSocket("localhost", 8088, 3000);

    TestService.Client testService =
            new TestService.Client(new TBinaryProtocol(transport));
    try {
        transport.open();
        int result = testService.add(1, 2);
        System.out.println(result);
    } catch (TException e) {
        e.printStackTrace();
    } finally {
        transport.close();
    }
}
 
Example 6
Source File: ThriftQueueClientDemo.java    From bigqueue with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args){
	ThriftQueueClientDemo clientDemo = new ThriftQueueClientDemo();
	try {
		clientDemo.run();
	} catch (TException e) {
		e.printStackTrace();
	}
}
 
Example 7
Source File: StreamTransformer.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (3 != args.length) {
        System.out.println(HELP);
        return;
    }

    String dlUriStr = args[0];
    final String srcStreamName = args[1];
    final String targetStreamName = args[2];

    URI uri = URI.create(dlUriStr);
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    conf.setOutputBufferSize(16*1024); // 16KB
    conf.setPeriodicFlushFrequencyMilliSeconds(5); // 5ms
    Namespace namespace = NamespaceBuilder.newBuilder()
            .conf(conf)
            .uri(uri)
            .build();

    // open the dlm
    System.out.println("Opening log stream " + srcStreamName);
    DistributedLogManager srcDlm = namespace.openLog(srcStreamName);
    System.out.println("Opening log stream " + targetStreamName);
    DistributedLogManager targetDlm = namespace.openLog(targetStreamName);

    Transformer<byte[], byte[]> replicationTransformer =
            new IdenticalTransformer<byte[]>();

    LogRecordWithDLSN lastTargetRecord;
    DLSN srcDlsn;
    try {
        lastTargetRecord = targetDlm.getLastLogRecord();
        TransformedRecord lastTransformedRecord = new TransformedRecord();
        try {
            lastTransformedRecord.read(protocolFactory.getProtocol(
                    new TIOStreamTransport(new ByteArrayInputStream(lastTargetRecord.getPayload()))));
            srcDlsn = DLSN.deserializeBytes(lastTransformedRecord.getSrcDlsn());
            System.out.println("Last transformed record is " + srcDlsn);
        } catch (TException e) {
            System.err.println("Error on reading last transformed record");
            e.printStackTrace(System.err);
            srcDlsn = DLSN.InitialDLSN;
        }
    } catch (LogNotFoundException lnfe) {
        srcDlsn = DLSN.InitialDLSN;
    } catch (LogEmptyException lee) {
        srcDlsn = DLSN.InitialDLSN;
    }

    AsyncLogWriter targetWriter = FutureUtils.result(targetDlm.openAsyncLogWriter());
    try {
        readLoop(srcDlm, srcDlsn, targetWriter, replicationTransformer);
    } finally {
        FutureUtils.result(targetWriter.asyncClose(), 5, TimeUnit.SECONDS);
        targetDlm.close();
        srcDlm.close();
        namespace.close();
    }

}
 
Example 8
Source File: StreamTransformer.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (3 != args.length) {
        System.out.println(HELP);
        return;
    }

    String dlUriStr = args[0];
    final String srcStreamName = args[1];
    final String targetStreamName = args[2];

    URI uri = URI.create(dlUriStr);
    DistributedLogConfiguration conf = new DistributedLogConfiguration();
    conf.setOutputBufferSize(16*1024); // 16KB
    conf.setPeriodicFlushFrequencyMilliSeconds(5); // 5ms
    DistributedLogNamespace namespace = DistributedLogNamespaceBuilder.newBuilder()
            .conf(conf)
            .uri(uri)
            .build();

    // open the dlm
    System.out.println("Opening log stream " + srcStreamName);
    DistributedLogManager srcDlm = namespace.openLog(srcStreamName);
    System.out.println("Opening log stream " + targetStreamName);
    DistributedLogManager targetDlm = namespace.openLog(targetStreamName);

    Transformer<byte[], byte[]> replicationTransformer =
            new IdenticalTransformer<byte[]>();

    LogRecordWithDLSN lastTargetRecord;
    DLSN srcDlsn;
    try {
        lastTargetRecord = targetDlm.getLastLogRecord();
        TransformedRecord lastTransformedRecord = new TransformedRecord();
        try {
            lastTransformedRecord.read(protocolFactory.getProtocol(
                    new TIOStreamTransport(new ByteArrayInputStream(lastTargetRecord.getPayload()))));
            srcDlsn = DLSN.deserializeBytes(lastTransformedRecord.getSrcDlsn());
            System.out.println("Last transformed record is " + srcDlsn);
        } catch (TException e) {
            System.err.println("Error on reading last transformed record");
            e.printStackTrace(System.err);
            srcDlsn = DLSN.InitialDLSN;
        }
    } catch (LogNotFoundException lnfe) {
        srcDlsn = DLSN.InitialDLSN;
    } catch (LogEmptyException lee) {
        srcDlsn = DLSN.InitialDLSN;
    }

    AsyncLogWriter targetWriter = FutureUtils.result(targetDlm.openAsyncLogWriter());
    try {
        readLoop(srcDlm, srcDlsn, targetWriter, replicationTransformer);
    } finally {
        FutureUtils.result(targetWriter.asyncClose(), Duration.apply(5, TimeUnit.SECONDS));
        targetDlm.close();
        srcDlm.close();
        namespace.close();
    }

}
 
Example 9
Source File: RemoteInterpreterServerTest.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Test
public void testInterpreter() throws IOException, TException, InterruptedException {
  final RemoteInterpreterServer server = new RemoteInterpreterServer("localhost",
      RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(), ":", "groupId", true);
  server.intpEventClient = mock(RemoteInterpreterEventClient.class);

  Map<String, String> intpProperties = new HashMap<>();
  intpProperties.put("property_1", "value_1");
  intpProperties.put("zeppelin.interpreter.localRepo", "/tmp");

  // create Test1Interpreter in session_1
  server.createInterpreter("group_1", "session_1", Test1Interpreter.class.getName(),
      intpProperties, "user_1");
  Test1Interpreter interpreter1 = (Test1Interpreter)
      ((LazyOpenInterpreter) server.getInterpreterGroup().get("session_1").get(0))
          .getInnerInterpreter();
  assertEquals(1, server.getInterpreterGroup().getSessionNum());
  assertEquals(1, server.getInterpreterGroup().get("session_1").size());
  assertEquals(2, interpreter1.getProperties().size());
  assertEquals("value_1", interpreter1.getProperty("property_1"));

  // create Test2Interpreter in session_1
  server.createInterpreter("group_1", "session_1", Test1Interpreter.class.getName(),
      intpProperties, "user_1");
  assertEquals(2, server.getInterpreterGroup().get("session_1").size());

  // create Test1Interpreter in session_2
  server.createInterpreter("group_1", "session_2", Test1Interpreter.class.getName(),
      intpProperties, "user_1");
  assertEquals(2, server.getInterpreterGroup().getSessionNum());
  assertEquals(2, server.getInterpreterGroup().get("session_1").size());
  assertEquals(1, server.getInterpreterGroup().get("session_2").size());

  final RemoteInterpreterContext intpContext = new RemoteInterpreterContext();
  intpContext.setNoteId("note_1");
  intpContext.setParagraphId("paragraph_1");
  intpContext.setGui("{}");
  intpContext.setNoteGui("{}");
  intpContext.setLocalProperties(new HashMap<>());

  // single output of SUCCESS
  RemoteInterpreterResult result = server.interpret("session_1", Test1Interpreter.class.getName(),
      "SINGLE_OUTPUT_SUCCESS", intpContext);
  assertEquals("SUCCESS", result.code);
  assertEquals(1, result.getMsg().size());
  assertEquals("SINGLE_OUTPUT_SUCCESS", result.getMsg().get(0).getData());

  // combo output of SUCCESS
  result = server.interpret("session_1", Test1Interpreter.class.getName(), "COMBO_OUTPUT_SUCCESS",
      intpContext);
  assertEquals("SUCCESS", result.code);
  assertEquals(2, result.getMsg().size());
  assertEquals("INTERPRETER_OUT", result.getMsg().get(0).getData());
  assertEquals("SINGLE_OUTPUT_SUCCESS", result.getMsg().get(1).getData());

  // single output of ERROR
  result = server.interpret("session_1", Test1Interpreter.class.getName(), "SINGLE_OUTPUT_ERROR",
      intpContext);
  assertEquals("ERROR", result.code);
  assertEquals(1, result.getMsg().size());
  assertEquals("SINGLE_OUTPUT_ERROR", result.getMsg().get(0).getData());

  // getFormType
  String formType = server.getFormType("session_1", Test1Interpreter.class.getName());
  assertEquals("NATIVE", formType);

  // cancel
  Thread sleepThread = new Thread() {
    @Override
    public void run() {
      try {
        server.interpret("session_1", Test1Interpreter.class.getName(), "SLEEP", intpContext);
      } catch (TException e) {
        e.printStackTrace();
      }
    }
  };
  sleepThread.start();

  Thread.sleep(1000);
  assertFalse(interpreter1.cancelled.get());
  server.cancel("session_1", Test1Interpreter.class.getName(), intpContext);
  // Sleep 1 second, because cancel is async.
  Thread.sleep(1000);
  assertTrue(interpreter1.cancelled.get());

  // getProgress
  assertEquals(10, server.getProgress("session_1", Test1Interpreter.class.getName(),
      intpContext));

  // close
  server.close("session_1", Test1Interpreter.class.getName());
  assertTrue(interpreter1.closed.get());
}