Skip to content

Commit

Permalink
replace the protocol with header protocol (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole00 authored Jan 19, 2023
1 parent 6f5e897 commit 6fbefa4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import com.facebook.thrift.TException;
import com.facebook.thrift.protocol.TCompactProtocol;
import com.facebook.thrift.protocol.THeaderProtocol;
import com.facebook.thrift.protocol.TProtocol;
import com.facebook.thrift.transport.THeaderTransport;
import com.facebook.thrift.transport.TSocket;
import com.facebook.thrift.transport.TTransport;
import com.facebook.thrift.transport.TTransportException;
Expand Down Expand Up @@ -39,8 +41,8 @@ public class SyncConnection extends Connection {

private static final Logger LOGGER = LoggerFactory.getLogger(SyncConnection.class);

protected TTransport transport = null;
protected TProtocol protocol = null;
protected THeaderTransport transport = null;
protected THeaderProtocol protocol = null;
private GraphService.Client client = null;
private int timeout = 0;
private SSLParam sslParam = null;
Expand All @@ -65,10 +67,10 @@ public void open(HostAddress address, int timeout, SSLParam sslParam)
SslUtil.getSSLSocketFactoryWithoutCA((SelfSignedSSLParam) sslParam);
}
}
this.transport = new TSocket(
this.transport = new THeaderTransport(new TSocket(
sslSocketFactory.createSocket(address.getHost(),
address.getPort()), this.timeout, this.timeout);
this.protocol = new TCompactProtocol(transport);
address.getPort()), this.timeout, this.timeout));
this.protocol = new THeaderProtocol(transport);
client = new GraphService.Client(protocol);

// check if client version matches server version
Expand All @@ -91,10 +93,10 @@ public void open(HostAddress address, int timeout)
try {
this.serverAddr = address;
this.timeout = timeout <= 0 ? Integer.MAX_VALUE : timeout;
this.transport = new TSocket(
address.getHost(), address.getPort(), this.timeout, this.timeout);
this.transport = new THeaderTransport(new TSocket(
address.getHost(), address.getPort(), this.timeout, this.timeout));
this.transport.open();
this.protocol = new TCompactProtocol(transport);
this.protocol = new THeaderProtocol(transport);
client = new GraphService.Client(protocol);

// check if client version matches server version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

package com.vesoft.nebula.client.meta;

import com.facebook.thrift.protocol.THeaderProtocol;
import com.facebook.thrift.protocol.TProtocol;
import com.facebook.thrift.transport.THeaderTransport;
import com.facebook.thrift.transport.TTransport;
import com.google.common.base.Preconditions;
import com.google.common.net.InetAddresses;
Expand All @@ -22,8 +24,8 @@ public class AbstractMetaClient implements Serializable {
protected final int executionRetry;
protected final int timeout;

protected TProtocol protocol;
protected TTransport transport;
protected THeaderProtocol protocol;
protected THeaderTransport transport;

public AbstractMetaClient(List<HostAddress> addresses, int timeout,
int connectionRetry, int executionRetry) throws UnknownHostException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import com.facebook.thrift.TException;
import com.facebook.thrift.protocol.TCompactProtocol;
import com.facebook.thrift.protocol.THeaderProtocol;
import com.facebook.thrift.transport.THeaderTransport;
import com.facebook.thrift.transport.TSocket;
import com.facebook.thrift.transport.TTransportException;
import com.google.common.base.Charsets;
Expand Down Expand Up @@ -139,17 +141,17 @@ private void getClient(String host, int port)
SslUtil.getSSLSocketFactoryWithoutCA((SelfSignedSSLParam) sslParam);
}
try {
transport = new TSocket(sslSocketFactory.createSocket(host, port), timeout,
timeout);
transport = new THeaderTransport(
new TSocket(sslSocketFactory.createSocket(host, port), timeout, timeout));
} catch (IOException e) {
throw new TTransportException(IOErrorException.E_UNKNOWN, e);
}
} else {
transport = new TSocket(host, port, timeout, timeout);
transport = new THeaderTransport(new TSocket(host, port, timeout, timeout));
transport.open();
}

protocol = new TCompactProtocol(transport);
protocol = new THeaderProtocol(transport);
client = new MetaService.Client(protocol);

// check if client version matches server version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import com.facebook.thrift.TException;
import com.facebook.thrift.protocol.TCompactProtocol;
import com.facebook.thrift.protocol.THeaderProtocol;
import com.facebook.thrift.protocol.TProtocol;
import com.facebook.thrift.transport.THeaderTransport;
import com.facebook.thrift.transport.TSocket;
import com.facebook.thrift.transport.TTransport;
import com.facebook.thrift.transport.TTransportException;
Expand All @@ -29,9 +31,9 @@
public class GraphStorageConnection implements Serializable {

private static final long serialVersionUID = -3631352515689239788L;
protected TTransport transport = null;
protected TProtocol protocol = null;

protected THeaderTransport transport = null;
protected THeaderProtocol protocol = null;
public HostAddress address;
private GraphStorageService.Client client;

Expand All @@ -52,24 +54,24 @@ protected GraphStorageConnection open(HostAddress address, int timeout, boolean
}
try {
transport =
new TSocket(
new THeaderTransport(new TSocket(
sslSocketFactory.createSocket(
InetAddress.getByName(address.getHost()).getHostAddress(),
address.getPort()),
newTimeout,
newTimeout);
newTimeout));
} catch (IOException e) {
throw new TTransportException(IOErrorException.E_UNKNOWN, e);
}
} else {
this.transport = new TSocket(
this.transport = new THeaderTransport(new TSocket(
InetAddress.getByName(address.getHost()).getHostAddress(),
address.getPort(),
newTimeout,
newTimeout);
newTimeout));
this.transport.open();
}
this.protocol = new TCompactProtocol(transport);
this.protocol = new THeaderProtocol(transport);
client = new GraphStorageService.Client(protocol);
return this;
}
Expand Down

0 comments on commit 6fbefa4

Please sign in to comment.