You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2019/09/04 08:01:35 UTC
[incubator-iotdb] 02/02: make session thread safe
This is an automated email from the ASF dual-hosted git repository.
qiaojialin pushed a commit to branch session_synchronized
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
commit 63c992a78d63ea84f89e95189de3806976485d19
Author: qiaojialin <64...@qq.com>
AuthorDate: Wed Sep 4 16:01:00 2019 +0800
make session thread safe
---
.../java/org/apache/iotdb/session/Session.java | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/session/src/main/java/org/apache/iotdb/session/Session.java b/session/src/main/java/org/apache/iotdb/session/Session.java
index fc3be40..4c1eb92 100644
--- a/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -32,8 +32,6 @@ import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransportException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.time.ZoneId;
@@ -44,7 +42,7 @@ public class Session {
private String username;
private String password;
private final TSProtocolVersion protocolVersion = TSProtocolVersion.IOTDB_SERVICE_PROTOCOL_V1;
- public TSIService.Iface client = null;
+ private TSIService.Iface client = null;
private TS_SessionHandle sessionHandle = null;
private TSocket transport;
private boolean isClosed = true;
@@ -65,11 +63,11 @@ public class Session {
this.password = password;
}
- public void open() throws IoTDBSessionException {
+ public synchronized void open() throws IoTDBSessionException {
open(false, 0);
}
- public void open(boolean enableRPCCompression, int connectionTimeoutInMs)
+ public synchronized void open(boolean enableRPCCompression, int connectionTimeoutInMs)
throws IoTDBSessionException {
if (!isClosed) {
return;
@@ -125,7 +123,7 @@ public class Session {
}
- public void close() throws IoTDBSessionException {
+ public synchronized void close() throws IoTDBSessionException {
if (isClosed) {
return;
}
@@ -142,7 +140,7 @@ public class Session {
}
}
- public TSExecuteBatchStatementResp insertBatch(RowBatch rowBatch) throws IoTDBSessionException {
+ public synchronized TSExecuteBatchStatementResp insertBatch(RowBatch rowBatch) throws IoTDBSessionException {
TSBatchInsertionReq request = new TSBatchInsertionReq();
request.deviceId = rowBatch.deviceId;
for (MeasurementSchema measurementSchema: rowBatch.measurements) {
@@ -160,7 +158,7 @@ public class Session {
}
}
- public TSRPCResp insert(String deviceId, long time, List<String> measurements, List<String> values)
+ public synchronized TSRPCResp insert(String deviceId, long time, List<String> measurements, List<String> values)
throws IoTDBSessionException {
TSInsertReq request = new TSInsertReq();
request.setDeviceId(deviceId);
@@ -175,7 +173,7 @@ public class Session {
}
}
- public TSRPCResp setStorageGroup(String storageGroupId) throws IoTDBSessionException {
+ public synchronized TSRPCResp setStorageGroup(String storageGroupId) throws IoTDBSessionException {
TSSetStorageGroupReq request = new TSSetStorageGroupReq();
request.setStorageGroupId(storageGroupId);
@@ -186,7 +184,7 @@ public class Session {
}
}
- public TSRPCResp createTimeseries(String path, TSDataType dataType, TSEncoding encoding, CompressionType compressor) throws IoTDBSessionException {
+ public synchronized TSRPCResp createTimeseries(String path, TSDataType dataType, TSEncoding encoding, CompressionType compressor) throws IoTDBSessionException {
TSCreateTimeseriesReq request = new TSCreateTimeseriesReq();
request.setPath(path);
request.setDataType(dataType.ordinal());
@@ -200,7 +198,7 @@ public class Session {
}
}
- public String getTimeZone() throws TException, IoTDBRPCException {
+ public synchronized String getTimeZone() throws TException, IoTDBRPCException {
if (zoneId != null) {
return zoneId.toString();
}
@@ -210,7 +208,7 @@ public class Session {
return resp.getTimeZone();
}
- public void setTimeZone(String zoneId) throws TException, IoTDBRPCException {
+ public synchronized void setTimeZone(String zoneId) throws TException, IoTDBRPCException {
TSSetTimeZoneReq req = new TSSetTimeZoneReq(zoneId);
TSRPCResp resp = client.setTimeZone(req);
RpcUtils.verifySuccess(resp.getStatus());