org.apache.thrift.protocol.TCompactProtocol Java Examples
The following examples show how to use
org.apache.thrift.protocol.TCompactProtocol.
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: Authenticator.java From micro-integrator with Apache License 2.0 | 6 votes |
private boolean authenticate() throws EntitlementProxyException { boolean isAuthenticated; try { THttpClient client = new THttpClient(serverUrl); TProtocol protocol = new TCompactProtocol(client); AuthenticatorService.Client authClient = new AuthenticatorService.Client(protocol); client.open(); sessionId = authClient.authenticate(userName, password); client.close(); isAuthenticated = true; } catch (Exception e) { throw new EntitlementProxyException("Error while authenticating with ThriftAuthenticator", e); } return isAuthenticated; }
Example #2
Source File: TCompactProtocolByteSizeTest.java From pinpoint with Apache License 2.0 | 6 votes |
@Test public void test() throws TException { TCompactProtocol.Factory factory = new TCompactProtocol.Factory(); ByteArrayOutputStream baos = new ByteArrayOutputStream(16); TIOStreamTransport transport = new TIOStreamTransport(baos); TProtocol protocol = factory.getProtocol(transport); long l = TimeUnit.DAYS.toMillis(1); logger.debug("day:{}", l); long currentTime = System.currentTimeMillis(); logger.debug("currentTime:{}" + currentTime); protocol.writeI64(l); byte[] buffer = baos.toByteArray(); logger.debug("{}", buffer.length); }
Example #3
Source File: TOGTS.java From warp10-platform with Apache License 2.0 | 6 votes |
/** * try to decode an encoder from its opb64 string representation or its byte array representation. * * @param o string, encoder, or byte array * @return a GTSDecoder object * @throws WarpScriptException */ private GTSDecoder getDecoderFromObject(Object o) throws WarpScriptException { GTSDecoder decoder; if (o instanceof GTSEncoder) { decoder = ((GTSEncoder) o).getUnsafeDecoder(false); } else { try { byte[] bytes = o instanceof String ? OrderPreservingBase64.decode(o.toString().getBytes(StandardCharsets.US_ASCII)) : (byte[]) o; TDeserializer deser = new TDeserializer(new TCompactProtocol.Factory()); GTSWrapper wrapper = new GTSWrapper(); deser.deserialize(wrapper, bytes); decoder = GTSWrapperHelper.fromGTSWrapperToGTSDecoder(wrapper); } catch (TException te) { throw new WarpScriptException(getName() + " failed to unwrap encoder.", te); } } return decoder; }
Example #4
Source File: TestHMSPathsFullDump.java From incubator-sentry with Apache License 2.0 | 6 votes |
@Test public void testThrftSerialization() throws TException { HMSPathsDumper serDe = genHMSPathsDumper(); long t1 = System.currentTimeMillis(); TPathsDump pathsDump = serDe.createPathsDump(); TProtocolFactory protoFactory = useCompact ? new TCompactProtocol.Factory( ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT, ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT) : new TBinaryProtocol.Factory(true, true, ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT, ServiceConstants.ClientConfig.SENTRY_HDFS_THRIFT_MAX_MESSAGE_SIZE_DEFAULT); byte[] ser = new TSerializer(protoFactory).serialize(pathsDump); long serTime = System.currentTimeMillis() - t1; System.out.println("Serialization Time: " + serTime + ", " + ser.length); t1 = System.currentTimeMillis(); TPathsDump tPathsDump = new TPathsDump(); new TDeserializer(protoFactory).deserialize(tPathsDump, ser); HMSPaths fromDump = serDe.initializeFromDump(tPathsDump); System.out.println("Deserialization Time: " + (System.currentTimeMillis() - t1)); Assert.assertEquals(new HashSet<String>(Arrays.asList("db9.tbl999")), fromDump.findAuthzObject(new String[]{"user", "hive", "warehouse", "db9", "tbl999"}, false)); Assert.assertEquals(new HashSet<String>(Arrays.asList("db9.tbl999")), fromDump.findAuthzObject(new String[]{"user", "hive", "warehouse", "db9", "tbl999", "part99"}, false)); }
Example #5
Source File: TestThriftToParquetFileWriter.java From parquet-mr with Apache License 2.0 | 6 votes |
private <T extends TBase<?,?>> Path createFile(T... tObjs) throws IOException, InterruptedException, TException { final Path fileToCreate = new Path("target/test/TestThriftToParquetFileWriter/"+tObjs[0].getClass()+".parquet"); LOG.info("File created: {}", fileToCreate.toString()); Configuration conf = new Configuration(); final FileSystem fs = fileToCreate.getFileSystem(conf); if (fs.exists(fileToCreate)) { fs.delete(fileToCreate, true); } TProtocolFactory protocolFactory = new TCompactProtocol.Factory(); TaskAttemptID taskId = new TaskAttemptID("local", 0, true, 0, 0); ThriftToParquetFileWriter w = new ThriftToParquetFileWriter(fileToCreate, ContextUtil.newTaskAttemptContext(conf, taskId), protocolFactory, (Class<? extends TBase<?, ?>>) tObjs[0].getClass()); for(T tObj:tObjs) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final TProtocol protocol = protocolFactory.getProtocol(new TIOStreamTransport(baos)); tObj.write(protocol); w.write(new BytesWritable(baos.toByteArray())); } w.close(); return fileToCreate; }
Example #6
Source File: UNWRAPENCODER.java From warp10-platform with Apache License 2.0 | 6 votes |
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object top = stack.pop(); if (!(top instanceof String) && !(top instanceof byte[])) { throw new WarpScriptException(getName() + " operates on a string or byte array."); } byte[] bytes = top instanceof String ? OrderPreservingBase64.decode(top.toString().getBytes(StandardCharsets.US_ASCII)) : (byte[]) top; TDeserializer deser = new TDeserializer(new TCompactProtocol.Factory()); try { GTSWrapper wrapper = new GTSWrapper(); deser.deserialize(wrapper, bytes); stack.push(GTSWrapperHelper.fromGTSWrapperToGTSEncoder(wrapper)); } catch (TException te) { throw new WarpScriptException(getName() + " failed to unwrap encoder.", te); } catch (IOException ioe) { throw new WarpScriptException(getName() + " failed to unwrap encoder.", ioe); } return stack; }
Example #7
Source File: GEOPACK.java From warp10-platform with Apache License 2.0 | 6 votes |
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), StandardCharsets.US_ASCII); } catch (TException te) { throw new WarpScriptException(te); } }
Example #8
Source File: TOMVSTRING.java From warp10-platform with Apache License 2.0 | 6 votes |
private static StringBuilder bytesToString(StringBuilder sb, byte[] bytes) { TDeserializer deser = new TDeserializer(new TCompactProtocol.Factory()); GTSWrapper wrapper = new GTSWrapper(); try { deser.deserialize(wrapper, bytes); return wrapperToString(sb, wrapper); } catch (TException te) { if (null == sb) { sb = new StringBuilder(); } sb.append("b64:"); sb.append(Base64.encodeBase64URLSafeString(bytes)); return sb; } }
Example #9
Source File: Ingress.java From warp10-platform with Apache License 2.0 | 6 votes |
void pushMetadataMessage(Metadata metadata) throws IOException { if (null == metadata) { pushMetadataMessage(null, null); return; } // // Compute class/labels Id // // 128bits 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 #10
Source File: TestDriftNettyMethodInvoker.java From drift with Apache License 2.0 | 6 votes |
private static List<DriftLogEntry> testMethodInvoker(ServerMethodInvoker methodInvoker) { int invocationCount = testMethodInvoker(methodInvoker, ImmutableList.of( address -> logThrift(address, MESSAGES, new TTransportFactory(), new TBinaryProtocol.Factory()), address -> logThrift(address, MESSAGES, new TTransportFactory(), new TCompactProtocol.Factory()), address -> logThrift(address, MESSAGES, new TFramedTransport.Factory(), new TBinaryProtocol.Factory()), address -> logThrift(address, MESSAGES, new TFramedTransport.Factory(), new TCompactProtocol.Factory()), address -> logThriftAsync(address, MESSAGES), address -> logNiftyInvocationHandler(address, DRIFT_MESSAGES, Transport.UNFRAMED, BINARY), address -> logNiftyInvocationHandler(address, DRIFT_MESSAGES, Transport.UNFRAMED, Protocol.COMPACT), address -> logNiftyInvocationHandler(address, DRIFT_MESSAGES, Transport.UNFRAMED, Protocol.FB_COMPACT), address -> logNiftyInvocationHandler(address, DRIFT_MESSAGES, FRAMED, BINARY), address -> logNiftyInvocationHandler(address, DRIFT_MESSAGES, FRAMED, Protocol.COMPACT), address -> logNiftyInvocationHandler(address, DRIFT_MESSAGES, FRAMED, Protocol.FB_COMPACT), address -> logNiftyInvocationHandler(address, DRIFT_MESSAGES, Transport.HEADER, BINARY), address -> logNiftyInvocationHandler(address, DRIFT_MESSAGES, Transport.HEADER, Protocol.FB_COMPACT))); return newArrayList(concat(nCopies(invocationCount, DRIFT_MESSAGES))); }
Example #11
Source File: Authenticator.java From carbon-identity with Apache License 2.0 | 6 votes |
private boolean authenticate() throws EntitlementProxyException { boolean isAuthenticated; try { THttpClient client = new THttpClient(serverUrl); TProtocol protocol = new TCompactProtocol(client); AuthenticatorService.Client authClient = new AuthenticatorService.Client(protocol); client.open(); sessionId = authClient.authenticate(userName, password); client.close(); isAuthenticated = true; } catch (Exception e) { throw new EntitlementProxyException("Error while authenticating with ThriftAuthenticator", e); } return isAuthenticated; }
Example #12
Source File: ThriftProtocolFactories.java From armeria with Apache License 2.0 | 6 votes |
/** * Returns the {@link SerializationFormat} for the specified {@link TProtocolFactory}. * * @throws IllegalArgumentException if the specified {@link TProtocolFactory} is not known by this class */ public static SerializationFormat toSerializationFormat(TProtocolFactory protoFactory) { requireNonNull(protoFactory, "protoFactory"); if (protoFactory instanceof TBinaryProtocol.Factory) { return ThriftSerializationFormats.BINARY; } else if (protoFactory instanceof TCompactProtocol.Factory) { return ThriftSerializationFormats.COMPACT; } else if (protoFactory instanceof TJSONProtocol.Factory) { return ThriftSerializationFormats.JSON; } else if (protoFactory instanceof TTextProtocolFactory) { final TTextProtocolFactory factory = (TTextProtocolFactory) protoFactory; return factory.usesNamedEnums() ? ThriftSerializationFormats.TEXT_NAMED_ENUM : ThriftSerializationFormats.TEXT; } else { throw new IllegalArgumentException( "unsupported TProtocolFactory: " + protoFactory.getClass().getName()); } }
Example #13
Source File: IoTDBConnection.java From incubator-iotdb with Apache License 2.0 | 6 votes |
public IoTDBConnection(String url, Properties info) throws SQLException, TTransportException { if (url == null) { throw new IoTDBURLException("Input url cannot be null"); } params = Utils.parseUrl(url, info); openTransport(); if(Config.rpcThriftCompressionEnable) { setClient(new TSIService.Client(new TCompactProtocol(transport))); } else { setClient(new TSIService.Client(new TBinaryProtocol(transport))); } // open client session openSession(); // Wrap the client with a thread-safe proxy to serialize the RPC calls setClient(RpcUtils.newSynchronizedClient(getClient())); autoCommit = false; }
Example #14
Source File: DKSearchService.java From dk-fitting with Apache License 2.0 | 6 votes |
/** * * 简单的单线程模式 * */ public void startService(){ System.out.println( " start ...." ); //单接口声明 //TProcessor tProcessor=new DKSearchOutput.Processor<DKSearchOutput.Iface>( new DKSearchOutputImpl() ); //多接口声明 TMultiplexedProcessor processor = new TMultiplexedProcessor(); processor.registerProcessor( "DKSearchOutput",new DKSearchOutput.Processor<DKSearchOutput.Iface>( new DKSearchOutputImpl() ) ); processor.registerProcessor( "DKSearchInput",new DKSearchInput.Processor<DKSearchInput.Iface>(new DKSearchInputImpl() ) ); processor.registerProcessor( "DKSearchService",new SearchService.Processor<SearchService.Iface>(new SearchServiceImpl() ) ); try { TServerSocket serverSocket=new TServerSocket( Integer.valueOf(prop.get("dkSearch.port")) ); TServer.Args targs=new TServer.Args( serverSocket ); targs.processor( processor ); //二进制TBinaryProtocol //二进制高密度TCompactProtocol targs.protocolFactory( new TCompactProtocol.Factory( ) ); TServer tServer=new TSimpleServer( targs ); tServer.serve(); } catch (TTransportException e) { System.err.println("Service Start error"); e.printStackTrace(); } }
Example #15
Source File: LogUtil.java From warp10-platform with Apache License 2.0 | 6 votes |
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), StandardCharsets.US_ASCII); }
Example #16
Source File: DKMLServer.java From dk-fitting with Apache License 2.0 | 6 votes |
/** * 阻塞式、多线程处理 * * @param args */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static void main(String[] args) { try { int port = Integer.valueOf(prop.get("dkml.port")); //设置传输通道,普通通道 TServerTransport serverTransport = new TServerSocket(port); //使用高密度二进制协议 TProtocolFactory proFactory = new TCompactProtocol.Factory(); //设置处理器 TProcessor processor = new DKML.Processor(new DKMLImpl()); //创建服务器 TServer server = new TThreadPoolServer( new TThreadPoolServer.Args(serverTransport) .protocolFactory(proFactory) .processor(processor) ); System.out.println("Start server on port "+ port +"..."); server.serve(); } catch (Exception e) { e.printStackTrace(); } }
Example #17
Source File: ThriftFrameDecoder.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@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 #18
Source File: RPCService.java From incubator-iotdb with Apache License 2.0 | 5 votes |
public RPCServiceThread(CountDownLatch threadStopLatch) throws ClassNotFoundException, IllegalAccessException, InstantiationException { if(IoTDBDescriptor.getInstance().getConfig().isRpcThriftCompressionEnable()) { protocolFactory = new TCompactProtocol.Factory(); } else { protocolFactory = new TBinaryProtocol.Factory(); } IoTDBConfig config = IoTDBDescriptor.getInstance().getConfig(); impl = (TSServiceImpl) Class.forName(config.getRpcImplClassName()).newInstance(); processor = new TSIService.Processor<>(impl); this.threadStopLatch = threadStopLatch; }
Example #19
Source File: ProtocolFactorySelector.java From nettythrift with Apache License 2.0 | 5 votes |
public ProtocolFactorySelector(@SuppressWarnings("rawtypes") Class interfaceClass) { protocolFactoryMap.put((short) -32767, new TBinaryProtocol.Factory()); protocolFactoryMap.put((short) -32223, new TCompactProtocol.Factory()); protocolFactoryMap.put((short) 23345, new TJSONProtocol.Factory()); if (interfaceClass != null) { protocolFactoryMap.put((short) 23330, new TSimpleJSONProtocol.Factory(interfaceClass)); } }
Example #20
Source File: TestParquetTupleScheme.java From parquet-mr with Apache License 2.0 | 5 votes |
private void createFileForRead() throws Exception { final Path fileToCreate = new Path(parquetInputPath + "/names.parquet"); final Configuration conf = new Configuration(); final FileSystem fs = fileToCreate.getFileSystem(conf); if (fs.exists(fileToCreate)) fs.delete(fileToCreate, true); TProtocolFactory protocolFactory = new TCompactProtocol.Factory(); TaskAttemptID taskId = new TaskAttemptID("local", 0, true, 0, 0); ThriftToParquetFileWriter w = new ThriftToParquetFileWriter(fileToCreate, ContextUtil.newTaskAttemptContext(conf, taskId), protocolFactory, Name.class); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final TProtocol protocol = protocolFactory.getProtocol(new TIOStreamTransport(baos)); Name n1 = new Name(); n1.setFirst_name("Alice"); n1.setLast_name("Practice"); Name n2 = new Name(); n2.setFirst_name("Bob"); n2.setLast_name("Hope"); Name n3 = new Name(); n3.setFirst_name("Charlie"); n3.setLast_name("Horse"); n1.write(protocol); w.write(new BytesWritable(baos.toByteArray())); baos.reset(); n2.write(protocol); w.write(new BytesWritable(baos.toByteArray())); baos.reset(); n3.write(protocol); w.write(new BytesWritable(baos.toByteArray())); w.close(); }
Example #21
Source File: DKGraphxServer.java From dk-fitting with Apache License 2.0 | 5 votes |
/** * 阻塞式、多线程处理 * * @param args */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static void main(String[] args) { try { int port = Integer.valueOf(prop.get("dkgraphx.port")); //设置传输通道,普通通道 TServerTransport serverTransport = new TServerSocket(port); //使用高密度二进制协议 TProtocolFactory proFactory = new TCompactProtocol.Factory(); //设置处理器 TProcessor processor = new DKGraphx.Processor(new DKGraphxImpl()); //创建服务器 TServer server = new TThreadPoolServer( new TThreadPoolServer.Args(serverTransport) .protocolFactory(proFactory) .processor(processor) ); System.out.println("Start server on port "+ port +"..."); server.serve(); } catch (Exception e) { e.printStackTrace(); } }
Example #22
Source File: ThriftSerializer.java From incubator-sentry with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") public static TBase deserialize(TBase baseObject, byte[] serialized) throws IOException { TDeserializer deserializer = new TDeserializer(new TCompactProtocol.Factory(maxMessageSize, maxMessageSize)); try { deserializer.deserialize(baseObject, serialized); } catch (TException e) { throw new IOException("Error deserializing thrift object " + baseObject, e); } return baseObject; }
Example #23
Source File: IoTDBConnection.java From incubator-iotdb with Apache License 2.0 | 5 votes |
boolean reconnect() { boolean flag = false; for (int i = 1; i <= Config.RETRY_NUM; i++) { try { if (transport != null) { transport.close(); openTransport(); if(Config.rpcThriftCompressionEnable) { setClient(new TSIService.Client(new TCompactProtocol(transport))); } else { setClient(new TSIService.Client(new TBinaryProtocol(transport))); } openSession(); setClient(RpcUtils.newSynchronizedClient(getClient())); flag = true; break; } } catch (Exception e) { try { Thread.sleep(Config.RETRY_INTERVAL); } catch (InterruptedException e1) { logger.error("reconnect is interrupted.", e1); } } } return flag; }
Example #24
Source File: CommandHeaderTBaseDeserializerFactory.java From pinpoint with Apache License 2.0 | 5 votes |
public CommandHeaderTBaseDeserializerFactory() { TypeLocator<TBase<?, ?>> commandTbaseLocator = TCommandRegistry.build(Arrays.asList(TCommandType.values())); TProtocolFactory protocolFactory = new TCompactProtocol.Factory(); HeaderTBaseDeserializerFactory deserializerFactory = new HeaderTBaseDeserializerFactory(protocolFactory, commandTbaseLocator); this.factory = new ThreadLocalHeaderTBaseDeserializerFactory<HeaderTBaseDeserializer>(deserializerFactory); }
Example #25
Source File: TradeReader.java From ThriftBook with Apache License 2.0 | 5 votes |
public static void main(String[] argv) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.TimeoutException, TException, TTransportException { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("localhost"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.queueDeclare(QUEUE_NAME, false, false, false, null); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(QUEUE_NAME, true, consumer); System.out.println("Waiting for trade reports..."); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); byte[] data = delivery.getBody(); TMemoryBuffer trans = new TMemoryBuffer(data.length); trans.write(data, 0, data.length); TCompactProtocol proto = new TCompactProtocol(trans); TradeReport tr = new TradeReport(); tr.read(proto); System.out.println("[" + tr.seq_num + "] " + tr.symbol + " @ " + tr.price + " x " + tr.size); } }
Example #26
Source File: CompFileWrite.java From ThriftBook with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws TException { TTransport trans = new TSimpleFileTransport("data.comp", false, true); TProtocol proto = new TCompactProtocol(trans); Trade trade = new Trade(); trade.symbol = "F"; trade.price = 13.10; trade.size = 2500; proto.writeStructBegin(new TStruct()); proto.writeFieldBegin(new TField("symbol", TType.STRING, (short) 1)); proto.writeString(trade.symbol); proto.writeFieldEnd(); proto.writeFieldBegin(new TField("price", TType.DOUBLE, (short) 2)); proto.writeDouble(trade.price); proto.writeFieldEnd(); proto.writeFieldBegin(new TField("size", TType.I32, (short) 3)); proto.writeI32(trade.size); proto.writeFieldEnd(); proto.writeFieldStop(); proto.writeStructEnd(); System.out.println("Wrote trade to file"); }
Example #27
Source File: ThriftServer.java From hbase with Apache License 2.0 | 5 votes |
protected TProtocolFactory getProtocolFactory() { TProtocolFactory protocolFactory; if (conf.getBoolean(COMPACT_CONF_KEY, COMPACT_CONF_DEFAULT)) { LOG.debug("Using compact protocol"); protocolFactory = new TCompactProtocol.Factory(); } else { LOG.debug("Using binary protocol"); protocolFactory = new TBinaryProtocol.Factory(); } return protocolFactory; }
Example #28
Source File: LineApiImpl.java From LineAPI4J with MIT License | 5 votes |
public void loginWithAuthToken(String authToken) throws Exception { THttpClient transport = new THttpClient(LINE_HTTP_IN_URL, httpClient); transport.setCustomHeader(X_LINE_ACCESS, authToken); transport.open(); TProtocol protocol = new TCompactProtocol(transport); setClient(new TalkService.Client(protocol)); setAuthToken(authToken); }
Example #29
Source File: OracleServer.java From fluo with Apache License 2.0 | 5 votes |
private InetSocketAddress startServer() throws TTransportException { Preconditions.checkState( curatorFramework != null && curatorFramework.getState() == CuratorFrameworkState.STARTED); if (env.getConfiguration().containsKey(FluoConfigurationImpl.ORACLE_PORT_PROP)) { port = env.getConfiguration().getInt(FluoConfigurationImpl.ORACLE_PORT_PROP); Preconditions.checkArgument(port >= 1 && port <= 65535, FluoConfigurationImpl.ORACLE_PORT_PROP + " must be valid port (1-65535)"); } else { port = PortUtils.getRandomFreePort(); } InetSocketAddress addr = new InetSocketAddress(port); TNonblockingServerSocket socket = new TNonblockingServerSocket(addr); THsHaServer.Args serverArgs = new THsHaServer.Args(socket); TProcessor processor = new OracleService.Processor<OracleService.Iface>(this); serverArgs.processor(processor); serverArgs.maxReadBufferBytes = ORACLE_MAX_READ_BUFFER_BYTES; serverArgs.inputProtocolFactory(new TCompactProtocol.Factory()); serverArgs.outputProtocolFactory(new TCompactProtocol.Factory()); server = new THsHaServer(serverArgs); serverThread = new Thread(server::serve); serverThread.setDaemon(true); serverThread.start(); return addr; }
Example #30
Source File: QuasarTokenDecoder.java From warp10-platform with Apache License 2.0 | 5 votes |
/** * Deserialize the given byte array into any type of Thrift tokens * This method avoid an explicit cast on the deserialized token * @param base The Thrift instance * @param bytes the serialized thrift token */ private void deserializeThriftToken(TBase<?, ?> base, byte[] bytes) throws TException { // Thrift deserialization TMemoryInputTransport trans_ = new TMemoryInputTransport(); TProtocol protocol_ = new TCompactProtocol.Factory().getProtocol(trans_); try { trans_.reset(bytes); // TRASH THE 8 fist bytes (SIP HASH) trans_.consumeBuffer(8); base.read(protocol_); } finally { trans_.clear(); protocol_.reset(); } }