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

The following examples show how to use org.apache.thrift.protocol.TCompactProtocol. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: micro-integrator   Source File: Authenticator.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: dk-fitting   Source File: DKMLServer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 阻塞式、多线程处理
 *
 * @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 3
Source Project: dk-fitting   Source File: DKSearchService.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *
 * 简单的单线程模式
 *
 */
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 4
Source Project: incubator-iotdb   Source File: IoTDBConnection.java    License: Apache License 2.0 6 votes vote down vote up
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 5
Source Project: drift   Source File: TestDriftNettyMethodInvoker.java    License: Apache License 2.0 6 votes vote down vote up
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 6
Source Project: warp10-platform   Source File: TOGTS.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 7
Source Project: warp10-platform   Source File: UNWRAPENCODER.java    License: Apache License 2.0 6 votes vote down vote up
@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 8
Source Project: warp10-platform   Source File: GEOPACK.java    License: Apache License 2.0 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), StandardCharsets.US_ASCII);
  } catch (TException te) {
    throw new WarpScriptException(te);
  }
}
 
Example 9
Source Project: warp10-platform   Source File: TOMVSTRING.java    License: Apache License 2.0 6 votes vote down vote up
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 10
Source Project: warp10-platform   Source File: Ingress.java    License: Apache License 2.0 6 votes vote down vote up
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 11
Source Project: warp10-platform   Source File: LogUtil.java    License: Apache License 2.0 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), StandardCharsets.US_ASCII);
}
 
Example 12
@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 13
Source Project: armeria   Source File: ThriftProtocolFactories.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 14
Source Project: carbon-identity   Source File: Authenticator.java    License: Apache License 2.0 6 votes vote down vote up
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 15
Source Project: incubator-sentry   Source File: TestHMSPathsFullDump.java    License: Apache License 2.0 6 votes vote down vote up
@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 16
Source Project: pinpoint   Source File: TCompactProtocolByteSizeTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 17
Source Project: parquet-mr   Source File: TestThriftToParquetFileWriter.java    License: Apache License 2.0 6 votes vote down vote up
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 18
Source Project: dk-fitting   Source File: DKGraphxServer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 阻塞式、多线程处理
 *
 * @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 19
Source Project: incubator-iotdb   Source File: IoTDBConnection.java    License: Apache License 2.0 5 votes vote down vote up
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 20
Source Project: incubator-iotdb   Source File: RPCService.java    License: Apache License 2.0 5 votes vote down vote up
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 21
Source Project: drift   Source File: TestDriftNettyServerTransport.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOutOfOrderNot()
{
    TestingServerMethodInvoker methodInvoker = new TestingServerMethodInvoker();
    int invocationCount = testServerMethodInvoker(methodInvoker, true, ImmutableList.of(
            address -> testOutOfOrder(address, MESSAGES, new TTransportFactory(), new TBinaryProtocol.Factory(), methodInvoker.getFutureResults()),
            address -> testOutOfOrder(address, MESSAGES, new TTransportFactory(), new TCompactProtocol.Factory(), methodInvoker.getFutureResults()),
            address -> testOutOfOrder(address, MESSAGES, new TFramedTransport.Factory(), new TBinaryProtocol.Factory(), methodInvoker.getFutureResults()),
            address -> testOutOfOrder(address, MESSAGES, new TFramedTransport.Factory(), new TCompactProtocol.Factory(), methodInvoker.getFutureResults())));

    List<DriftLogEntry> expectedMessages = newArrayList(concat(nCopies(invocationCount, DRIFT_MESSAGES)));
    assertEquals(ImmutableList.copyOf(methodInvoker.getMessages()), expectedMessages);
}
 
Example 22
Source Project: drift   Source File: TestDriftNettyServerTransport.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOutOfOrderNotSupported()
{
    TestingServerMethodInvoker methodInvoker = new TestingServerMethodInvoker();
    int invocationCount = testServerMethodInvoker(methodInvoker, false, ImmutableList.of(
            address -> testOutOfOrderNotSupported(address, MESSAGES, new TTransportFactory(), new TBinaryProtocol.Factory(), methodInvoker.getFutureResults()),
            address -> testOutOfOrderNotSupported(address, MESSAGES, new TTransportFactory(), new TCompactProtocol.Factory(), methodInvoker.getFutureResults()),
            address -> testOutOfOrderNotSupported(address, MESSAGES, new TFramedTransport.Factory(), new TBinaryProtocol.Factory(), methodInvoker.getFutureResults()),
            address -> testOutOfOrderNotSupported(address, MESSAGES, new TFramedTransport.Factory(), new TCompactProtocol.Factory(), methodInvoker.getFutureResults())));

    List<DriftLogEntry> expectedMessages = newArrayList(concat(nCopies(invocationCount, DRIFT_MESSAGES)));
    assertEquals(ImmutableList.copyOf(methodInvoker.getMessages()), expectedMessages);
}
 
Example 23
Source Project: incubator-sentry   Source File: ThriftSerializer.java    License: Apache License 2.0 5 votes vote down vote up
@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 24
Source Project: nettythrift   Source File: ProtocolFactorySelector.java    License: Apache License 2.0 5 votes vote down vote up
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 25
Source Project: ikasoa   Source File: GeneralFactory.java    License: MIT License 5 votes vote down vote up
/**
 * 获取客户端AsyncService对象
 */
@Override
public AsyncService getAsyncService(TNonblockingTransport transport, String serviceName) throws IkasoaException {
	if (ObjectUtil.isNull(transport))
		throw new IllegalArgumentException("'transport' is null !");
	try {
		return StringUtil.isEmpty(serviceName)
				? new AsyncServiceClientImpl((TProtocolFactory) new TCompactProtocol.Factory(), transport)
				: new AsyncServiceClientImpl(new AsyncMultiplexedProtocolFactory(serviceName), transport);
	} catch (IOException e) {
		throw new IkasoaException(e);
	}
}
 
Example 26
Source Project: ikasoa   Source File: AysncServiceTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() {
	thriftServerConfiguration.setProtocolFactory(new TCompactProtocol.Factory());
	thriftServerConfiguration.setServerArgsAspect(new ServerArgsAspect() {
		@Override
		public TThreadPoolServer.Args tThreadPoolServerArgsAspect(TThreadPoolServer.Args args) {
			args.stopTimeoutVal = 1;
			return args;
		}
	});
}
 
Example 27
Source Project: ikasoa   Source File: ServerTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testAysncThriftServerImpl() {
	int serverPort = ServerUtil.getNewPort();
	ThriftServerConfiguration thriftServerConfiguration = new ThriftServerConfiguration();
	thriftServerConfiguration.setProtocolFactory(new TCompactProtocol.Factory());
	thriftServerConfiguration.setProcessorFactory(new TProcessorFactory(processor));
	thriftServerConfiguration.setServerArgsAspect(new ServerArgsAspect() {
		@Override
		public TThreadPoolServer.Args tThreadPoolServerArgsAspect(TThreadPoolServer.Args args) {
			args.stopTimeoutVal = 1;
			return args;
		}
	});
	Factory factory = new GeneralFactory(thriftServerConfiguration);
	ThriftServer thriftServer = factory.getThriftServer(serverName, serverPort, processor);
	thriftServer.run();
	waiting();
	try {
		ThriftSimpleService.AsyncClient thriftClient = new ThriftSimpleService.AsyncClient(
				new TCompactProtocol.Factory(), new TAsyncClientManager(),
				new TNonblockingSocket(TestConstants.LOCAL_HOST, serverPort));
		thriftClient.get(TestConstants.TEST_STRING, new TestCallback());
		waiting();
	} catch (Exception e) {
		fail();
	} finally {
		thriftServer.stop();
	}
}
 
Example 28
Source Project: fluo   Source File: OracleServer.java    License: Apache License 2.0 5 votes vote down vote up
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 29
Source Project: warp10-platform   Source File: QuasarTokenDecoder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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();
  }
}
 
Example 30
Source Project: LineAPI4J   Source File: LineApiImpl.java    License: MIT License 5 votes vote down vote up
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);
}