List of usage examples for org.apache.thrift.protocol TBinaryProtocol TBinaryProtocol
public TBinaryProtocol(TTransport trans, long stringLengthLimit, long containerLengthLimit, boolean strictRead, boolean strictWrite)
From source file:com.axmor.eclipse.typescript.core.internal.TypeScriptBridge.java
License:Open Source License
@Override public void run() { if (stopped || NOTIFY_ERROR.get()) { return;//from ww w . j a v a2s. c o m } try { this.port = getPort(); File bundleFile = FileLocator.getBundleFile(Activator.getDefault().getBundle()); String nodeJSPath = TypeScriptUtils.findNodeJS(); ProcessBuilder ps = new ProcessBuilder(nodeJSPath, new File(bundleFile, LIB_BRIDGE + "/js/new_bridge.js").getCanonicalPath(), "src=" + baseDirectory.getAbsolutePath().replace('\\', '/'), "serv=true", "port=" + port, "log=" + logLevel); ps.directory(baseDirectory.getCanonicalFile()); p = ps.start(); } catch (IOException e) { Activator.getDefault().getLog() .log(new Status(Status.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e)); if (!NOTIFY_ERROR.getAndSet(true)) { Display.getDefault().syncExec(new Runnable() { @Override public void run() { ErrorDialog.open(new Shell(), Messages.TSBridge_InitErrorTitle, Messages.TSBridge_InitErrorMessage); } }); } } if (p != null) { MessageConsole console = new MessageConsole(Messages.TSBridge_Console, null); outStream = console.newMessageStream(); errorStream = console.newMessageStream(); outStream.println("TS Bridge: port = " + port + ", directory: " + baseDirectory); transport = new TSocket("localhost", port); int errorCount = 0; TTransportException exp = null; while (!transport.isOpen() && errorCount < MAX_CONNECT_RETRY) { try { transport.open(); } catch (TTransportException e) { exp = e; try { Thread.sleep(100); } catch (InterruptedException e1) { // ignore exception } ++errorCount; } } if (!transport.isOpen() && exp != null) { Activator.getDefault().getLog() .log(new Status(Status.ERROR, Activator.PLUGIN_ID, exp.getMessage(), exp)); } TBinaryProtocol protocol = new TBinaryProtocol(transport, 10000000, 10000000, false, false); client = new TSBridgeService.Client(protocol); JSONObject versionObject = invokeBridgeMethod("getVersion", null); try { outStream.println("TypeScript Version: " + versionObject.getString("version")); } catch (JSONException e) { Activator.getDefault().getLog() .log(new Status(Status.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); } // decorate error stream errorStream.setActivateOnWrite(true); Display.getDefault().syncExec(new Runnable() { @Override public void run() { errorStream.setColor(Display.getDefault().getSystemColor(SWT.COLOR_RED)); } }); connectStreams(p.getErrorStream(), errorStream); connectStreams(p.getInputStream(), outStream); ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console }); try { p.waitFor(); } catch (InterruptedException e) { // ignore exception } } }
From source file:org.apache.sentry.api.generic.thrift.SentryGenericServiceClientDefaultImpl.java
License:Apache License
/** * Connect to the specified server configured * * @throws IOException/* ww w . j av a 2 s . c o m*/ */ @Override public void connect() throws Exception { if ((transport != null) && transport.isOpen()) { return; } // Obtain connection to Sentry server transport = transportPool.getTransport(); TMultiplexedProtocol protocol = new TMultiplexedProtocol( new TBinaryProtocol(transport.getTTransport(), maxMessageSize, maxMessageSize, true, true), SentryPolicyServiceConstants.SENTRY_GENERIC_SERVICE_NAME); client = new Client(protocol); }
From source file:org.apache.sentry.api.service.thrift.SentryPolicyServiceClientDefaultImpl.java
License:Apache License
/** * Connect to the sentry server/*from w ww.j av a2 s . co m*/ * * @throws IOException */ @Override public void connect() throws Exception { if ((transport != null) && transport.isOpen()) { return; } transport = transportPool.getTransport(); TMultiplexedProtocol protocol = new TMultiplexedProtocol( new TBinaryProtocol(transport.getTTransport(), maxMessageSize, maxMessageSize, true, true), SentryPolicyServiceConstants.SENTRY_POLICY_SERVICE_NAME); client = new Client(protocol); }