List of usage examples for org.apache.thrift.transport TZlibTransport TZlibTransport
public TZlibTransport(TTransport transport)
From source file:com.facebook.buck.cli.BuildCommand.java
License:Apache License
private int executeDistributedBuild(final CommandRunnerParams params, final WeightedListeningExecutorService executorService) throws IOException, InterruptedException, ActionGraphCreationException { ProjectFilesystem filesystem = params.getCell().getFilesystem(); if (distributedBuildStateFile != null) { Path stateDumpPath = Paths.get(distributedBuildStateFile); TTransport transport;/*w w w.ja va 2s . com*/ boolean loading = Files.exists(stateDumpPath); if (loading) { transport = new TIOStreamTransport(filesystem.newFileInputStream(stateDumpPath)); } else { transport = new TIOStreamTransport(filesystem.newFileOutputStream(stateDumpPath)); } transport = new TZlibTransport(transport); TProtocol protocol = new TTupleProtocol(transport); try { DistributedBuildTypeCoercerFactory typeCoercerFactory = new DistributedBuildTypeCoercerFactory( params.getObjectMapper()); ParserTargetNodeFactory<TargetNode<?>> parserTargetNodeFactory = DefaultParserTargetNodeFactory .createForDistributedBuild(new ConstructorArgMarshaller(typeCoercerFactory), new TargetNodeFactory(typeCoercerFactory)); DistributedBuildTargetGraphCodec targetGraphCodec = new DistributedBuildTargetGraphCodec( params.getObjectMapper(), parserTargetNodeFactory, new Function<TargetNode<?>, Map<String, Object>>() { @Nullable @Override public Map<String, Object> apply(TargetNode<?> input) { try { return params.getParser().getRawTargetNode(params.getBuckEventBus(), params.getCell().getCell(input.getBuildTarget()), /* enableProfiling */ false, executorService, input); } catch (BuildFileParseException | InterruptedException e) { throw new RuntimeException(e); } } }); if (loading) { DistributedBuildState state = DistributedBuildState.load(protocol, params.getCell()); final TargetGraph targetGraph = state.createTargetGraph(targetGraphCodec); ActionGraphAndResolver actionGraphAndResolver = Preconditions .checkNotNull(params.getActionGraphCache().getActionGraph(params.getBuckEventBus(), /* checkActionGraphs */ false, targetGraph, params.getBuckConfig().getKeySeed())); BuckConfig rootCellBuckConfig = state.getRootCell().getBuckConfig(); DistributedCachingBuildEngineDelegate cachingBuildEngineDelegate = new DistributedCachingBuildEngineDelegate( new SourcePathResolver(actionGraphAndResolver.getResolver()), state); // TODO(ruibm, marcinkosiba): This is incorrect, we probably need rule-level control // over what gets built. ImmutableList<TargetNodeSpec> targetNodeSpecs = parseArgumentsAsTargetNodeSpecs( rootCellBuckConfig, getArguments()); FluentIterable<BuildTarget> targetsToBuild = FluentIterable.from(targetNodeSpecs) .transformAndConcat(new Function<TargetNodeSpec, Iterable<BuildTarget>>() { @Override public Iterable<BuildTarget> apply(TargetNodeSpec input) { return input.filter(targetGraph.getNodes()).keySet(); } }); return executeBuild(params, actionGraphAndResolver, executorService, params.getArtifactCache(), cachingBuildEngineDelegate, rootCellBuckConfig, targetsToBuild); } else { TargetGraphAndBuildTargets targetGraphAndBuildTargets = createTargetGraph(params, executorService); ActionGraphAndResolver actionGraphAndResolver = createActionGraphAndResolver(params, targetGraphAndBuildTargets); DistributedBuildCellIndexer cellIndexer = new DistributedBuildCellIndexer(params.getCell()); DistributedBuildFileHashes distributedBuildFileHashes = new DistributedBuildFileHashes( actionGraphAndResolver.getActionGraph(), new SourcePathResolver(actionGraphAndResolver.getResolver()), params.getFileHashCache(), cellIndexer, executorService, params.getBuckConfig().getKeySeed()); BuildJobState jobState = DistributedBuildState.dump(cellIndexer, distributedBuildFileHashes, targetGraphCodec, targetGraphAndBuildTargets.getTargetGraph()); jobState.write(protocol); transport.flush(); return 0; } } catch (TException e) { throw new RuntimeException(e); } finally { transport.close(); } } DistBuildConfig config = new DistBuildConfig(params.getBuckConfig()); ClientSideSlb slb = config.getFrontendConfig().createHttpClientSideSlb(params.getClock(), params.getBuckEventBus(), new CommandThreadFactory("BuildCommand.HttpLoadBalancer")); OkHttpClient client = config.createOkHttpClient(); try (HttpService httpService = new LoadBalancedService(slb, client, params.getBuckEventBus()); ThriftService<FrontendRequest, FrontendResponse> service = new ThriftOverHttpService<>( ThriftOverHttpServiceConfig.of(httpService))) { DistributedBuild build = new DistributedBuild(new DistBuildService(service, params.getBuckEventBus())); return build.executeAndPrintFailuresToEventBus(); } }
From source file:org.hawk.service.api.utils.APIUtils.java
License:Open Source License
@SuppressWarnings({ "deprecation", "restriction" })
public static <T extends TServiceClient> T connectTo(Class<T> clazz, String url, ThriftProtocol thriftProtocol,
final Credentials credentials) throws TTransportException, URISyntaxException {
try {//from ww w .j a v a 2 s .c o m
final URI parsed = new URI(url);
TTransport transport;
if (parsed.getScheme().startsWith("http")) {
final DefaultHttpClient httpClient = APIUtils.createGZipAwareHttpClient();
if (credentials != null) {
httpClient.getCredentialsProvider().setCredentials(new AuthScope(null, -1), credentials);
}
transport = new THttpClient(url, httpClient);
} else {
transport = new TZlibTransport(new TSocket(parsed.getHost(), parsed.getPort()));
transport.open();
}
Constructor<T> constructor = clazz.getDeclaredConstructor(org.apache.thrift.protocol.TProtocol.class);
return constructor.newInstance(thriftProtocol.getProtocolFactory().getProtocol(transport));
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new TTransportException(e);
}
}
From source file:org.hawk.service.servlet.Activator.java
License:Open Source License
@Override public void start(BundleContext bundleContext) throws Exception { Activator.context = bundleContext; HManager.getInstance();// w w w . j a v a 2 s. c o m String artemisHost = System.getProperty(ARTEMIS_HOST_PROPERTY); if (artemisHost == null) { artemisHost = TransportConstants.DEFAULT_HOST; } String sArtemisPort = System.getProperty(ARTEMIS_PORT_PROPERTY); int artemisPort; if (sArtemisPort == null) { artemisPort = TransportConstants.DEFAULT_PORT; } else { artemisPort = Integer.valueOf(sArtemisPort); } artemis = new Server(artemisHost, artemisPort); String sListenAll = System.getProperty(ARTEMIS_LISTENALL_PROPERTY); if (sListenAll != null) { artemis.setListenOnAllInterfaces(Boolean.valueOf(sListenAll)); } String sSSLEnabled = System.getProperty(ARTEMIS_SSL_PROPERTY); if (sSSLEnabled != null) { artemis.setSSLEnabled(Boolean.valueOf(sSSLEnabled)); } try { artemis.start(); } catch (Exception e) { throw new ServletException(e); } final String sTCPPort = System.getProperty(TCP_PORT_PROPERTY); if (sTCPPort != null) { final String sThriftProtocol = System.getProperty(TCP_TPROTOCOL_PROPERTY); final ThriftProtocol thriftProtocol = (sThriftProtocol != null) ? ThriftProtocol.valueOf(sThriftProtocol) : ThriftProtocol.TUPLE; final TServerSocket tcpServerSocket = new TServerSocket(Integer.valueOf(sTCPPort)); final HawkThriftIface hawkIface = new HawkThriftIface(ThriftProtocol.TUPLE, null, artemis); final Processor<Iface> hawkTCPProcessor = new Hawk.Processor<Hawk.Iface>(hawkIface); final Args tcpServerArgs = new TThreadPoolServer.Args(tcpServerSocket).maxWorkerThreads(10_000) .protocolFactory(new TProtocolFactory() { private static final long serialVersionUID = 1L; @Override public TProtocol getProtocol(TTransport arg0) { return thriftProtocol.getProtocolFactory().getProtocol(new TZlibTransport(arg0)); } }).processor(hawkTCPProcessor); tcpServer = new TThreadPoolServer(tcpServerArgs); new Thread(new Runnable() { @Override public void run() { final Bundle bundle = context.getBundle(); Platform.getLog(bundle).log( new Status(IStatus.INFO, bundle.getSymbolicName(), "Starting Hawk TCP server on port " + sTCPPort + " with Thrift protocol " + thriftProtocol.name())); tcpServer.serve(); } }).start(); } }