@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.addToField1(createElement("1")); testObject.addToField1(createElement("2")); testObject.addToField1(createElement("3")); testObject.addToField1(createElement("4")); testObject.addToField1(createElement("1")); testObject.addToField1(createElement("2")); testObject.addToField1(createElement("3")); testObject.addToField1(createElement("4")); testObject.addToField1(createElement("1")); testObject.addToField1(createElement("2")); testObject.addToField1(createElement("3")); testObject.addToField1(createElement("4")); testObject.addToField1(createElement("1")); testObject.addToField1(createElement("2")); testObject.addToField1(createElement("3")); testObject.addToField1(createElement("4")); serializer = new TSerializer(new TCompactProtocol.Factory()); deserializer = new TDeserializer(new TCompactProtocol.Factory()); testData = serializer.serialize(testObject); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.addToField1(createElement("1")); testObject.addToField1(createElement("2")); testObject.addToField1(createElement("3")); testObject.addToField1(createElement("4")); testObject.addToField1(createElement("1")); testObject.addToField1(createElement("2")); testObject.addToField1(createElement("3")); testObject.addToField1(createElement("4")); testObject.addToField1(createElement("1")); testObject.addToField1(createElement("2")); testObject.addToField1(createElement("3")); testObject.addToField1(createElement("4")); testObject.addToField1(createElement("1")); testObject.addToField1(createElement("2")); testObject.addToField1(createElement("3")); testObject.addToField1(createElement("4")); byteArrayOutputStream = new ByteArrayOutputStream(); TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory(); protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream)); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { ThriftTestWriteObject testObject = new ThriftTestWriteObject(); testObject.setField1(Arrays.asList("1", "2", "3", "4", "5", "1", "2", "3", "4", "5", "1", "2", "3", "4", "5")); HashMap<String, List<String>> field2 = new HashMap<>(); field2.put("1", Arrays.asList("1", "2", "3", "4", "5")); field2.put("2", Arrays.asList("1", "2", "3", "4", "5")); field2.put("3", Arrays.asList("1", "2", "3", "4", "5")); testObject.setField2(field2); testObject.setField3("x-3"); serializer = new TSerializer(new TCompactProtocol.Factory()); deserializer = new TDeserializer(new TCompactProtocol.Factory()); testData = serializer.serialize(testObject); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.addToField1(31.415926); testObject.addToField1(61.415923); testObject.addToField1(31.415269); testObject.addToField1(53.141926); testObject.addToField1(13.145926); testObject.addToField1(43.115926); testObject.addToField1(31.419265); testObject.addToField1(23.141596); testObject.addToField1(43.161592); testObject.addToField1(0.112); byteArrayOutputStream = new ByteArrayOutputStream(); TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory(); protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream)); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.addToField1(31.415926); testObject.addToField1(61.415923); testObject.addToField1(31.415269); testObject.addToField1(53.141926); testObject.addToField1(13.145926); testObject.addToField1(43.115926); testObject.addToField1(31.419265); testObject.addToField1(23.141596); testObject.addToField1(43.161592); testObject.addToField1(0.112); serializer = new TSerializer(new TCompactProtocol.Factory()); deserializer = new TDeserializer(new TCompactProtocol.Factory()); testData = serializer.serialize(testObject); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.setField1("1"); testObject.setField2("2"); testObject.setField3("3"); testObject.setField4("4"); testObject.setField5("5"); testObject.setField6("6"); testObject.setField7("7"); testObject.setField8("8"); testObject.setField9("9"); testObject.setField10("10"); byteArrayOutputStream = new ByteArrayOutputStream(); TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory(); protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream)); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.setField1("1"); testObject.setField2("2"); testObject.setField3("3"); testObject.setField4("4"); testObject.setField5("5"); testObject.setField6("6"); testObject.setField7("7"); testObject.setField8("8"); testObject.setField9("9"); testObject.setField10("10"); serializer = new TSerializer(new TCompactProtocol.Factory()); deserializer = new TDeserializer(new TCompactProtocol.Factory()); testData = serializer.serialize(testObject); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.setField1(31.415926); testObject.setField2(61.415923); testObject.setField3(31.415269); testObject.setField4(53.141926); testObject.setField5(13.145926); testObject.setField6(43.115926); testObject.setField7(31.419265); testObject.setField8(23.141596); testObject.setField9(43.161592); testObject.setField10(0.112); byteArrayOutputStream = new ByteArrayOutputStream(); TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory(); protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream)); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.setField1(31.415926); testObject.setField2(61.415923); testObject.setField3(31.415269); testObject.setField4(53.141926); testObject.setField5(13.145926); testObject.setField6(43.115926); testObject.setField7(31.419265); testObject.setField8(23.141596); testObject.setField9(43.161592); testObject.setField10(0.112); serializer = new TSerializer(new TCompactProtocol.Factory()); deserializer = new TDeserializer(new TCompactProtocol.Factory()); testData = serializer.serialize(testObject); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.addToField1(321); testObject.addToField1(123); testObject.addToField1(132); testObject.addToField1(312); testObject.addToField1(321); testObject.addToField1(123); testObject.addToField1(132); testObject.addToField1(312); testObject.addToField1(321); testObject.addToField1(123); testObject.addToField1(132); testObject.addToField1(312); testObject.addToField1(321); testObject.addToField1(123); testObject.addToField1(132); testObject.addToField1(312); byteArrayOutputStream = new ByteArrayOutputStream(); TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory(); protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream)); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.addToField1(321); testObject.addToField1(123); testObject.addToField1(132); testObject.addToField1(312); testObject.addToField1(321); testObject.addToField1(123); testObject.addToField1(132); testObject.addToField1(312); testObject.addToField1(321); testObject.addToField1(123); testObject.addToField1(132); testObject.addToField1(312); testObject.addToField1(321); testObject.addToField1(123); testObject.addToField1(132); testObject.addToField1(312); serializer = new TSerializer(new TCompactProtocol.Factory()); deserializer = new TDeserializer(new TCompactProtocol.Factory()); testData = serializer.serialize(testObject); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.setField1(31415926); testObject.setField2(61415923); testObject.setField3(31415269); testObject.setField4(53141926); testObject.setField5(13145926); testObject.setField6(43115926); testObject.setField7(31419265); testObject.setField8(23141596); testObject.setField9(43161592); testObject.setField10(112); byteArrayOutputStream = new ByteArrayOutputStream(); TCompactProtocol.Factory protocolFactory = new TCompactProtocol.Factory(); protocol = protocolFactory.getProtocol(new TIOStreamTransport(byteArrayOutputStream)); }
@Setup(Level.Trial) public void benchSetup(BenchmarkParams params) throws TException { testObject = new ThriftTestObject(); testObject.setField1(31415926); testObject.setField2(61415923); testObject.setField3(31415269); testObject.setField4(53141926); testObject.setField5(13145926); testObject.setField6(43115926); testObject.setField7(31419265); testObject.setField8(23141596); testObject.setField9(43161592); testObject.setField10(112); serializer = new TSerializer(new TCompactProtocol.Factory()); deserializer = new TDeserializer(new TCompactProtocol.Factory()); testData = serializer.serialize(testObject); }
private void nonBlockMode() { AskerHandler handler = new AskerHandler(); Asker.Processor processor = new Asker.Processor(handler); try { TNonblockingServerTransport transport = new TNonblockingServerSocket(port); THsHaServer.Args arg = new THsHaServer.Args(transport); arg.protocolFactory(new TCompactProtocol.Factory()); // arg.transportFactory(new TFramedTransport.Factory()); // arg.processorFactory(new TProcessorFactory(processor)); arg.processor(processor); server = new THsHaServer(arg); start.countDown(); System.out.println("Starting the nonBlock server..."); server.serve(); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testBlockSync() throws TException { AskerServer server = new AskerServer(port, true); server.start(); try (TTransport transport = transport(port)) { transport.open(); TProtocol protocol = new TCompactProtocol(transport); final Asker.Client client = new Asker.Client(protocol); Helper helper = new Helper(collector); helper.checkEcho(client); helper.checkCount(client); helper.checkReverse(client); helper.checkUpperCast(client); helper.checkLowerCast(client); helper.checkRandom(client, 5 + random.nextInt(10)); } server.stop(); }
@Test public void testNonBlockSync() throws TException { AskerServer server = new AskerServer(port, false); server.start(); try (TTransport transport = new TFramedTransport(transport(port))) { transport.open(); TProtocol protocol = new TCompactProtocol(transport); final Asker.Client client = new Asker.Client(protocol); Helper helper = new Helper(collector); helper.checkEcho(client); helper.checkCount(client); helper.checkReverse(client); helper.checkUpperCast(client); helper.checkLowerCast(client); helper.checkRandom(client, 5 + random.nextInt(10)); } server.stop(); }
@Test @Ignore public void testAsync() throws TException, IOException, ExecutionException, InterruptedException { AskerServer server = new AskerServer(port, false); server.start(); try (SocketChannel socketChannel = SocketChannel.open()) { socketChannel.connect(new InetSocketAddress("localhost", port)); TNonblockingTransport transport = new TNonblockingSocket(socketChannel); final Asker.AsyncClient client = new Asker.AsyncClient( new TCompactProtocol.Factory(), new TAsyncClientManager(), transport); Helper helper = new Helper(collector); helper.checkEcho(client); helper.checkCount(client); helper.checkReverse(client); helper.checkUpperCast(client); helper.checkLowerCast(client); helper.checkRandom(client, 5 + random.nextInt(10)); } server.stop(); }
public ThriftTestingSource(String handlerName, int port, String protocol) throws Exception { TNonblockingServerTransport serverTransport = new TNonblockingServerSocket(new InetSocketAddress("0.0.0.0", port)); ThriftSourceProtocol.Iface handler = getHandler(handlerName); TProtocolFactory transportProtocolFactory = null; if (protocol != null && protocol == ThriftRpcClient.BINARY_PROTOCOL) { transportProtocolFactory = new TBinaryProtocol.Factory(); } else { transportProtocolFactory = new TCompactProtocol.Factory(); } server = new THsHaServer(new THsHaServer.Args(serverTransport).processor( new ThriftSourceProtocol.Processor(handler)).protocolFactory( transportProtocolFactory)); Executors.newSingleThreadExecutor().submit(new Runnable() { @Override public void run() { server.serve(); } }); }
private TProtocolFactory getProtocolFactory() { if (protocol.equals(BINARY_PROTOCOL)) { logger.info("Using TBinaryProtocol"); return new TBinaryProtocol.Factory(); } else { logger.info("Using TCompactProtocol"); return new TCompactProtocol.Factory(); } }
@Override protected final Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception { /* This is initialized to null because the decode function must return * null if the buffer does not contain a complete frame and cannot be * decoded. */ List<T> ms = null; ByteBuf frame = null; while (null != (frame = (ByteBuf) super.decode(ctx, buffer))) { if (ms == null) ms = new ArrayList<T>(); ByteBufInputStream is = new ByteBufInputStream(frame); TCompactProtocol thriftProtocol = new TCompactProtocol(new TIOStreamTransport(is)); T message = allocateMessage(); message.read(thriftProtocol); ms.add(message); } return ms; }
@Override protected void encode(ChannelHandlerContext ctx, T msg, ByteBuf out) throws Exception { int lengthIndex = out.writerIndex(); // length field, will be filled in later. out.writeInt(0); int startIndex = out.writerIndex(); ByteBufOutputStream os = new ByteBufOutputStream(out); TCompactProtocol thriftProtocol = new TCompactProtocol(new TIOStreamTransport(os)); msg.write(thriftProtocol); os.close(); int endIndex = out.writerIndex(); // update the length field int length = endIndex - startIndex; out.setInt(lengthIndex, length); }
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { List<SyncMessage> ms = null; ChannelBuffer frame = null; while (null != (frame = (ChannelBuffer) super.decode(ctx, channel, buffer))) { if (ms == null) ms = new ArrayList<SyncMessage>(); ChannelBufferInputStream is = new ChannelBufferInputStream(frame); TCompactProtocol thriftProtocol = new TCompactProtocol(new TIOStreamTransport(is)); SyncMessage bsm = new SyncMessage(); bsm.read(thriftProtocol); ms.add(bsm); } return ms; }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object message) throws Exception { if (message instanceof SyncMessage) { ChannelBuffer buf = new DynamicChannelBuffer(512); ChannelBufferOutputStream os = new ChannelBufferOutputStream(buf); TCompactProtocol thriftProtocol = new TCompactProtocol(new TIOStreamTransport(os)); ((SyncMessage) message).write(thriftProtocol); ChannelBuffer len = ChannelBuffers.buffer(4); len.writeInt(buf.readableBytes()); return ChannelBuffers.wrappedBuffer(len, buf); } return message; }
@Override protected Object gtsOp(Map<String, Object> params, GeoTimeSerie gts) throws WarpScriptException { GTSWrapper wrapper; if (opt) { wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, true, 1.0, true); } else { wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, true); } TSerializer serializer = new TSerializer(new TCompactProtocol.Factory()); try { byte[] bytes = serializer.serialize(wrapper); return bytes; } catch (TException te) { throw new WarpScriptException(getName() + " failed to wrap GTS."); } }
@Override protected Object gtsOp(Map<String, Object> params, GeoTimeSerie gts) throws WarpScriptException { GTSWrapper wrapper; if (opt) { wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, this.compress, 1.0, true); } else { wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, this.compress); } TSerializer serializer = new TSerializer(new TCompactProtocol.Factory()); try { byte[] bytes = serializer.serialize(wrapper); return new String(OrderPreservingBase64.encode(bytes), Charsets.US_ASCII); } catch (TException te) { throw new WarpScriptException(getName() + " failed to wrap GTS."); } }
public static String pack(GeoXPShape shape) throws WarpScriptException { long[] cells = GeoXPLib.getCells(shape); GTSEncoder encoder = new GTSEncoder(); try { for (long cell: cells) { encoder.addValue(cell, GeoTimeSerie.NO_LOCATION, GeoTimeSerie.NO_ELEVATION, true); } } catch (IOException ioe) { throw new WarpScriptException(ioe); } GTSWrapper wrapper = GTSWrapperHelper.fromGTSEncoderToGTSWrapper(encoder, true); TSerializer serializer = new TSerializer(new TCompactProtocol.Factory()); try { byte[] serialized = serializer.serialize(wrapper); return new String(OrderPreservingBase64.encode(serialized, 0, serialized.length), Charsets.US_ASCII); } catch (TException te) { throw new WarpScriptException(te); } }
void pushMetadataMessage(Metadata metadata) throws IOException { if (null == metadata) { pushMetadataMessage(null, null); return; } // // Compute class/labels Id // metadata.setClassId(GTSHelper.classId(this.classKey, metadata.getName())); metadata.setLabelsId(GTSHelper.labelsId(this.labelsKey, metadata.getLabels())); TSerializer serializer = new TSerializer(new TCompactProtocol.Factory()); try { byte[] bytes = new byte[16]; GTSHelper.fillGTSIds(bytes, 0, metadata.getClassId(), metadata.getLabelsId()); pushMetadataMessage(bytes, serializer.serialize(metadata)); } catch (TException te) { throw new IOException("Unable to push metadata."); } }
public static final String serializeLoggingEvent(KeyStore keystore, LoggingEvent event) { if (null == event) { return null; } TSerializer serializer = new TSerializer(new TCompactProtocol.Factory()); byte[] serialized = null; try { serialized = serializer.serialize(event); } catch (TException te) { return null; } if (!checkedAESKey) { checkedAESKey = true; loggingAESKey = keystore.getKey(KeyStore.AES_LOGGING); } if (null != loggingAESKey) { serialized = CryptoUtils.wrap(loggingAESKey, serialized); } return new String(OrderPreservingBase64.encode(serialized), Charsets.US_ASCII); }