Java Code Examples for org.apache.thrift.protocol.TCompactProtocol

The following are top voted examples for showing how to use org.apache.thrift.protocol.TCompactProtocol. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: java-benchmark   File: DeserThrift.java   View source code 7 votes vote down vote up
@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);
}
 
Example 2
Project: sw360rest   File: DemoApplication.java   View source code 7 votes vote down vote up
private void checkAndCreateAdminUser() throws TException {
    THttpClient thriftClient = new THttpClient(thriftServerUrl + "/users/thrift");
    TProtocol protocol = new TCompactProtocol(thriftClient);
    UserService.Iface userClient = new UserService.Client(protocol);

    User admin = new User("admin", "[email protected]", "SW360 Administration");
    admin.setFullname("John Doe");
    admin.setGivenname("John");
    admin.setLastname("Doe");
    admin.setUserGroup(UserGroup.ADMIN);

    try {
        userClient.getByEmail("[email protected]");
        System.out.println("sw360 admin user already exists");
    } catch (Exception e) {
        System.out.println("creating admin user  => " + userClient.addUser(admin));
    }
}
 
Example 3
Project: java-benchmark   File: SerThrift.java   View source code 6 votes vote down vote up
@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));
}
 
Example 4
Project: java-benchmark   File: DeserThrift.java   View source code 6 votes vote down vote up
@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);
}
 
Example 5
Project: java-benchmark   File: SerThrift.java   View source code 6 votes vote down vote up
@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));
}
 
Example 6
Project: java-benchmark   File: DeserThrift.java   View source code 6 votes vote down vote up
@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);
}
 
Example 7
Project: java-benchmark   File: SerThrift.java   View source code 6 votes vote down vote up
@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));
}
 
Example 8
Project: java-benchmark   File: SerThrift.java   View source code 6 votes vote down vote up
@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));
}
 
Example 9
Project: java-benchmark   File: SerThrift.java   View source code 6 votes vote down vote up
@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));
}
 
Example 10
Project: java-benchmark   File: SerThrift.java   View source code 6 votes vote down vote up
@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));
}
 
Example 11
Project: java-benchmark   File: DeserThrift.java   View source code 6 votes vote down vote up
@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);
}
 
Example 12
Project: rpc-comparison   File: AskerServer.java   View source code 6 votes vote down vote up
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();
        }
    }
 
Example 13
Project: rpc-comparison   File: FunctionTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 14
Project: rpc-comparison   File: FunctionTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 15
Project: rpc-comparison   File: FunctionTest.java   View source code 6 votes vote down vote up
@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();
}
 
Example 16
Project: flume-release-1.7.0   File: ThriftTestingSource.java   View source code 6 votes vote down vote up
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();
    }
  });
}
 
Example 17
Project: flume-release-1.7.0   File: ThriftSource.java   View source code 6 votes vote down vote up
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();
  }
}
 
Example 18
Project: fresco_floodlight   File: ThriftFrameDecoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 19
Project: fresco_floodlight   File: ThriftFrameEncoder.java   View source code 6 votes vote down vote up
@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);
}
 
Example 20
Project: iTAP-controller   File: ThriftFrameDecoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 21
Project: iTAP-controller   File: ThriftFrameEncoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 22
Project: SDN-Multicast   File: ThriftFrameDecoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 23
Project: SDN-Multicast   File: ThriftFrameEncoder.java   View source code 6 votes vote down vote up
@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);
}
 
Example 24
Project: arscheduler   File: ThriftFrameDecoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 25
Project: arscheduler   File: ThriftFrameEncoder.java   View source code 6 votes vote down vote up
@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);
}
 
Example 26
Project: QoS-floodlight   File: ThriftFrameDecoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 27
Project: QoS-floodlight   File: ThriftFrameEncoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 28
Project: floodlight1.2-delay   File: ThriftFrameDecoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 29
Project: floodlight1.2-delay   File: ThriftFrameEncoder.java   View source code 6 votes vote down vote up
@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);
}
 
Example 30
Project: floodlight-hardware   File: ThriftFrameDecoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 31
Project: floodlight-hardware   File: ThriftFrameEncoder.java   View source code 6 votes vote down vote up
@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);
}
 
Example 32
Project: warp10-platform   File: WRAPRAW.java   View source code 6 votes vote down vote up
@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.");
  }        
}
 
Example 33
Project: warp10-platform   File: WRAP.java   View source code 6 votes vote down vote up
@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.");
  }        
}
 
Example 34
Project: warp10-platform   File: GEOPACK.java   View source code 6 votes vote down vote up
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);
  }
}
 
Example 35
Project: warp10-platform   File: Ingress.java   View source code 6 votes vote down vote up
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.");
  }
}
 
Example 36
Project: warp10-platform   File: LogUtil.java   View source code 6 votes vote down vote up
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); 
}
 
Example 37
Project: ACAMPController   File: ThriftFrameDecoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 38
Project: ACAMPController   File: ThriftFrameEncoder.java   View source code 6 votes vote down vote up
@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);
}
 
Example 39
Project: fast-failover-demo   File: ThriftFrameDecoder.java   View source code 6 votes vote down vote up
@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;
}
 
Example 40
Project: fast-failover-demo   File: ThriftFrameEncoder.java   View source code 6 votes vote down vote up
@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;
}