├── .github
├── ISSUE_TEMPLATE
│ └── bug_report.md
└── workflows
│ └── build.yml
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── codestyle
└── forbidden-apis.txt
├── conf
└── tsdb.conf
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── aliyun
│ └── hitsdb
│ └── client
│ ├── AbstractConfig.java
│ ├── BalHiTSDBClient.java
│ ├── BalTSDBClient.java
│ ├── Config.java
│ ├── HAPolicy.java
│ ├── HiTSDB.java
│ ├── HiTSDBClient.java
│ ├── HiTSDBClientFactory.java
│ ├── HiTSDBConfig.java
│ ├── IotClient.java
│ ├── IotClientFactory.java
│ ├── LindormTSDBClient.java
│ ├── LindormTSDBClientFactory.java
│ ├── TSDB.java
│ ├── TSDBClient.java
│ ├── TSDBClientFactory.java
│ ├── TSDBConfig.java
│ ├── callback
│ ├── AbstractBatchPutCallback.java
│ ├── AbstractCallback.java
│ ├── AbstractMultiFieldBatchPutCallback.java
│ ├── BatchPutCallback.java
│ ├── BatchPutDetailsCallback.java
│ ├── BatchPutIgnoreErrorsCallback.java
│ ├── BatchPutSummaryCallback.java
│ ├── Callback.java
│ ├── MultiFieldBatchPutCallback.java
│ ├── MultiFieldBatchPutDetailsCallback.java
│ ├── MultiFieldBatchPutIgnoreErrorsCallback.java
│ ├── MultiFieldBatchPutSummaryCallback.java
│ ├── QueryCallback.java
│ └── http
│ │ ├── AbstractPutHttpResponseCallback.java
│ │ ├── BaseHttpFutureCallback.java
│ │ ├── BatchPutHttpResponseCallback.java
│ │ ├── HttpResponseCallbackFactory.java
│ │ ├── MultiFieldBatchPutHttpResponseCallback.java
│ │ └── QueryHttpResponseCallback.java
│ ├── consumer
│ ├── AbstractBatchPutRunnable.java
│ ├── BatchPutRunnable.java
│ ├── BatchPutThreadFactory.java
│ ├── Consumer.java
│ ├── ConsumerFactory.java
│ ├── DefaultBatchPutConsumer.java
│ ├── MultiFieldBatchPutRunnable.java
│ └── PointsCollectionPutRunnable.java
│ ├── exception
│ ├── BufferQueueFullException.java
│ ├── NotImplementedException.java
│ └── http
│ │ ├── HttpClientConnectionRefusedException.java
│ │ ├── HttpClientException.java
│ │ ├── HttpClientInitException.java
│ │ ├── HttpClientSocketTimeoutException.java
│ │ ├── HttpServerErrorException.java
│ │ ├── HttpServerNotSupportException.java
│ │ ├── HttpServerUnauthorizedException.java
│ │ └── HttpUnknowStatusException.java
│ ├── http
│ ├── Host.java
│ ├── HttpAPI.java
│ ├── HttpAddressManager.java
│ ├── HttpClient.java
│ ├── HttpClientFactory.java
│ ├── TSDBHttpAsyncCallbackExecutor.java
│ ├── request
│ │ ├── HttpDeleteWithEntity.java
│ │ └── HttpGetWithEntity.java
│ ├── response
│ │ ├── HttpStatus.java
│ │ └── ResultResponse.java
│ └── semaphore
│ │ └── SemaphoreManager.java
│ ├── queue
│ ├── DataPointQueue.java
│ ├── DataQueue.java
│ └── DataQueueFactory.java
│ ├── util
│ ├── FileWatcher.java
│ ├── HealthManager.java
│ ├── HealthWatcher.java
│ ├── HttpUtil.java
│ ├── LinkedHashMapUtils.java
│ ├── Objects.java
│ ├── Pair.java
│ ├── PropKit.java
│ ├── WKTParser.java
│ ├── WatchManager.java
│ └── guava
│ │ ├── RateLimiter.java
│ │ └── base
│ │ ├── Preconditions.java
│ │ └── Ticker.java
│ └── value
│ ├── JSONValue.java
│ ├── Result.java
│ ├── request
│ ├── AbstractPoint.java
│ ├── ByteArrayValue.java
│ ├── ComplexValue.java
│ ├── DeleteMetaRequest.java
│ ├── DeltaOptions.java
│ ├── DumpMetaValue.java
│ ├── FieldsSerializer.java
│ ├── Filter.java
│ ├── GeoPointValue.java
│ ├── LastLimit.java
│ ├── LastPointQuery.java
│ ├── LastPointSubQuery.java
│ ├── LookupRequest.java
│ ├── LookupTagFilter.java
│ ├── MetricTimeRange.java
│ ├── MultiFieldPoint.java
│ ├── MultiFieldQuery.java
│ ├── MultiFieldSubQuery.java
│ ├── MultiFieldSubQueryDetails.java
│ ├── MultiValuedPoint.java
│ ├── MultiValuedQuery.java
│ ├── MultiValuedQueryLastRequest.java
│ ├── MultiValuedQueryMetricDetails.java
│ ├── MultiValuedSubQuery.java
│ ├── Point.java
│ ├── PointType.java
│ ├── PointsCollection.java
│ ├── Query.java
│ ├── RateOptions.java
│ ├── SQLValue.java
│ ├── SubQuery.java
│ ├── SuggestValue.java
│ ├── TTLValue.java
│ ├── TagsAddInfo.java
│ ├── TagsRemoveInfo.java
│ ├── TagsShowInfo.java
│ ├── Timeline.java
│ ├── UniqueUtil.java
│ └── ValueSerializer.java
│ ├── response
│ ├── KeyValue.java
│ ├── LastDataValue.java
│ ├── LookupDetailedResult.java
│ ├── LookupResult.java
│ ├── MultiFieldQueryLastResult.java
│ ├── MultiFieldQueryResult.java
│ ├── MultiFieldQueryValuesSerializer.java
│ ├── MultiValuedQueryLastResult.java
│ ├── MultiValuedQueryResult.java
│ ├── MultiValuedTupleComparator.java
│ ├── QueryResult.java
│ ├── QueryResultDpsSerializer.java
│ ├── SQLResult.java
│ ├── TTLResult.java
│ ├── TagResult.java
│ ├── TagsAddResult.java
│ ├── TagsShowResult.java
│ ├── UserResult.java
│ └── batch
│ │ ├── DetailsResult.java
│ │ ├── ErrorPoint.java
│ │ ├── IgnoreErrorsResult.java
│ │ ├── MultiFieldDetailsResult.java
│ │ ├── MultiFieldErrorPoint.java
│ │ ├── MultiFieldIgnoreErrorsResult.java
│ │ └── SummaryResult.java
│ └── type
│ ├── Aggregator.java
│ ├── DownsampleDataSource.java
│ ├── FilterType.java
│ ├── Granularity.java
│ ├── HttpResponseLevel.java
│ ├── QueryType.java
│ ├── Suggest.java
│ └── UserPrivilege.java
└── test
├── java
└── com
│ └── aliyun
│ └── hitsdb
│ └── client
│ ├── MultiFieldPointAsyncPutSamples.java
│ ├── MultiFieldPointAsyncPutTest.java
│ ├── TestClientHA.java
│ ├── TestClientQueryHA.java
│ ├── TestHiTSDBClientBatchPut.java
│ ├── TestHiTSDBClientBatchPutNoLogic.java
│ ├── TestHiTSDBClientBatchPutStringValue.java
│ ├── TestHiTSDBClientDeleteData.java
│ ├── TestHiTSDBClientDeleteMeta.java
│ ├── TestHiTSDBClientDumpMeta.java
│ ├── TestHiTSDBClientLast.java
│ ├── TestHiTSDBClientLastDataPointQuery.java
│ ├── TestHiTSDBClientLookup.java
│ ├── TestHiTSDBClientMultiFieldFeatures.java
│ ├── TestHiTSDBClientPutOnErrorURL.java
│ ├── TestHiTSDBClientQuery.java
│ ├── TestHiTSDBClientQueryLast.java
│ ├── TestHiTSDBClientQueryLimitAndDpValue.java
│ ├── TestHiTSDBClientQueryRate.java
│ ├── TestHiTSDBClientQueryReverse.java
│ ├── TestHiTSDBClientQueryStringValue.java
│ ├── TestHiTSDBClientSingleTimePointQuery.java
│ ├── TestHiTSDBClientSuggest.java
│ ├── TestHiTSDBClientSyncPut.java
│ ├── TestHiTSDBClientTTL.java
│ ├── TestHiTSDBClientTableOp.java
│ ├── TestHiTSDBClientVersion.java
│ ├── TestIotClient.java
│ ├── TestLastResultTimestampReverse.java
│ ├── TestLindormTSDBClient.java
│ ├── TestLindormTSDBClientFactory.java
│ ├── TestLinkedHashMapUtils.java
│ ├── TestTSDBSQL.java
│ ├── balance
│ ├── TestBalClient.java
│ ├── TestFileWatchManager.java
│ ├── TestHealthManager.java
│ └── TestPoint.java
│ ├── callback
│ ├── TestBatchPutSummaryCallback.java
│ ├── TestBatchPutSummaryCallbackWithFlush.java
│ ├── TestNoLogicCallback.java
│ └── TestPutWithTemperaryCallback.java
│ ├── compress
│ ├── TestHiTSDBClientPut.java
│ └── TestHiTSDBClientQuery.java
│ ├── configuration
│ └── TestConfiguration.java
│ ├── connection
│ ├── TestConnectionLiveTime.java
│ └── TestKeepaliveConnection.java
│ ├── error
│ └── TestHiTSDBClientBatchPutExceptionCallback.java
│ ├── example
│ ├── ExampleOfMultiField.java
│ ├── TestRead.java
│ └── TestWrite.java
│ ├── http
│ ├── TestHiTSDBRequestTime.java
│ └── TestHttpAsyncClient.java
│ ├── keepalive
│ └── TestKeepalive.java
│ ├── log
│ └── TestLog.java
│ ├── performance
│ ├── TestBlockingQueue.java
│ ├── TestFastJSON.java
│ ├── TestQueryPerformance.java
│ └── TestWritePerformance.java
│ ├── retry
│ └── TestHiTSDBClientBatchPutRetryCallback.java
│ ├── util
│ ├── DateUtils.java
│ └── UI.java
│ └── value
│ ├── FlushTest.java
│ ├── TSDBClientFactoryTest.java
│ ├── TSDBDataTypeTest.java
│ ├── TestConfig.java
│ ├── TestLastPointQuery.java
│ ├── TestMetricPoint.java
│ ├── TestMetricPointStringValue.java
│ ├── TestQuery.java
│ ├── TestTagResult.java
│ ├── request
│ ├── DeleteMetaRequestTest.java
│ ├── FilterTest.java
│ ├── LastPointQueryTest.java
│ ├── LastPointSubQueryTest.java
│ ├── MultiFieldQueryRequestTest.java
│ ├── MultiFieldSubQueryRequestTest.java
│ ├── MultiPointTest.java
│ ├── PointTest.java
│ ├── PointsCollectionTest.java
│ ├── QueryTest.java
│ ├── SubQueryTest.java
│ ├── TagsTest.java
│ └── UniqueUtilTest.java
│ └── response
│ ├── TestDetailsResult.java
│ ├── TestMultiFieldQueryResult.java
│ ├── TestPutMPutResult.java
│ ├── TestQueryResult.java
│ └── TestSummaryResult.java
└── resources
└── log4j.properties
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Version information**
11 | * SDK version
12 | The version of the aliyun-tsdb-java-sdk
13 |
14 | * TSDB engine version
15 | The version of the version of Aliyun TSDB in use
16 | which can be retrieved by the following command
17 |
18 | ````sh
19 | curl http://{TSDB host}:{TSDB port}/api/version
20 | ````
21 |
22 | **Bug description**
23 | A clear and concise description of what the bug is.
24 |
25 | **Reproduce case**
26 | Codes to reproduce the behavior:
27 |
28 | ````java
29 | ````
30 |
31 | **Expected behavior**
32 | A clear and concise description of what you expected to happen.
33 |
34 | **Exception stacktrace (Optional)**
35 | If applicable, add the error stack help describe the details.
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3 |
4 | name: Java CI with Maven
5 |
6 | on:
7 | push:
8 | branches:
9 | - master
10 | - 'release/*.*.*'
11 | pull_request:
12 | branches:
13 | - master
14 | - 'release/*.*.*'
15 |
16 | jobs:
17 | build:
18 |
19 | runs-on: ubuntu-latest
20 |
21 | steps:
22 | - uses: actions/checkout@v2
23 | - name: Set up JDK 8
24 | uses: actions/setup-java@v2
25 | with:
26 | java-version: '8'
27 | distribution: 'adopt'
28 | - name: Build with Maven
29 | run: mvn clean package -Dmaven.test.skip=true
30 | - name: Unit Test
31 | run: mvn cobertura:cobertura -Dmaven.test.skip=false -Dtest=**/value/**/**.java
32 | - name: Upload
33 | run: bash <(curl -s https://codecov.io/bash)
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | hitsdb-client.iml
2 | /.idea/
3 | /target/
4 | /.settings/
5 | /.classpath
6 | /.project
7 | .idea/
8 | .DS_Store
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | dist: trusty
3 | jdk:
4 | - oraclejdk8
5 |
6 | stages:
7 | - compile
8 | - test
9 |
10 | branches:
11 | only:
12 | - master
13 |
14 | jobs:
15 | include:
16 | - stage: compile
17 | script: mvn clean package -Dmaven.test.skip=true
18 | - stage: test
19 | script: mvn cobertura:cobertura -Dmaven.test.skip=false -Dtest=**/value/**/**.java
20 |
21 | after_success:
22 | - bash <(curl -s https://codecov.io/bash)
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Aliyun TSDB SDK for Java
3 |
4 | [](https://github.com/aliyun/aliyun-tsdb-java-sdk/actions)
5 | [](https://codecov.io/gh/aliyun/aliyun-tsdb-java-sdk)
6 | [](https://search.maven.org/search?q=g:%22com.aliyun%22%20AND%20a:%22hitsdb-client%22)
7 |
8 | The Aliyun TSDB SDK for Java enables Java developers to easily work with Aliyun TSDB, compatible OpenTSDB protocol. You can get started in minutes using ***Maven***.
9 |
10 | - [Developer Guide](https://help.aliyun.com/document_detail/61634.html)
11 | - [Issues](https://github.com/aliyun/aliyun-tsdb-java-sdk/issues)
12 | - [Release](https://github.com/aliyun/aliyun-tsdb-java-sdk/releases)
13 |
14 | ## Requirements
15 |
16 | - Java 1.6 or later
17 | - Maven
18 |
19 | ## Install
20 |
21 | The recommended way to use the Aliyun TSDB SDK for Java in your project is to consume it from Maven. Import as follows:
22 |
23 | ```
24 |
25 | com.aliyun
26 | hitsdb-client
27 | 0.3.8
28 |
29 | ```
30 |
31 | See the Setup section of [the SDK Reference](https://help.aliyun.com/document_detail/61634.html) for more information about installing the SDK through other means.
32 |
33 |
34 | ## Build
35 |
36 | Once you check out the code from GitHub, you can build it using Maven. Use the following command to build:
37 |
38 | ```
39 | mvn clean install -DskipTests
40 | ```
41 |
42 |
--------------------------------------------------------------------------------
/conf/tsdb.conf:
--------------------------------------------------------------------------------
1 |
2 | #
3 | #host = 127.0.0.1
4 | #
5 | #port = 8242
6 |
7 | #
8 | address = 127.0.0.1:8242
9 |
10 | #
11 | batchPutSize = 500
12 |
13 | #
14 | batchPutTimeLimit = 300
15 | #
16 | batchPutBufferSize = 3000
17 | #
18 | batchPutRetryCount = 1
19 | #
20 | httpConnectionPool = 64
21 | #
22 | httpConnectTimeout = 90
23 | #
24 | putRequestLimitSwitch = true
25 | #
26 | putRequestLimit = -1
27 | #
28 | batchPutConsumerThreadCount = 1
29 | #
30 | httpCompress = true
31 | #
32 | ioThreadCount = 1
33 | #
34 | backpressure = true
35 | #
36 | httpConnectionLiveTime = 0
37 | #
38 | httpKeepaliveTime = -1
39 | #
40 | maxTPS = -1
41 | #
42 | asyncPut = true
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/BalHiTSDBClient.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client;
2 |
3 | import com.aliyun.hitsdb.client.callback.AbstractBatchPutCallback;
4 | import com.aliyun.hitsdb.client.callback.QueryCallback;
5 | import com.aliyun.hitsdb.client.exception.http.HttpUnknowStatusException;
6 | import com.aliyun.hitsdb.client.http.Host;
7 | import com.aliyun.hitsdb.client.util.*;
8 | import com.aliyun.hitsdb.client.value.Result;
9 | import com.aliyun.hitsdb.client.value.request.*;
10 | import com.aliyun.hitsdb.client.value.response.*;
11 | import com.aliyun.hitsdb.client.value.type.Suggest;
12 | import org.slf4j.Logger;
13 | import org.slf4j.LoggerFactory;
14 |
15 | import java.io.File;
16 | import java.io.FileReader;
17 | import java.io.IOException;
18 | import java.util.*;
19 | import java.util.concurrent.ConcurrentHashMap;
20 | import java.util.concurrent.TimeUnit;
21 | import java.util.concurrent.atomic.AtomicBoolean;
22 |
23 |
24 | /**
25 | * @since 0.2.1
26 | * @deprecated use {@link BalTSDBClient} instead.
27 | */
28 | @Deprecated
29 | public class BalHiTSDBClient extends BalTSDBClient implements HiTSDB {
30 |
31 | public BalHiTSDBClient(File configFile) throws IOException {
32 | super(configFile);
33 | }
34 |
35 | public BalHiTSDBClient(String configFilePath) throws IOException {
36 | super(configFilePath);
37 | }
38 |
39 | public BalHiTSDBClient(File configFile, AbstractBatchPutCallback> callback) throws IOException {
40 | super(configFile, callback);
41 | }
42 |
43 | public BalHiTSDBClient(HiTSDBConfig config) {
44 | super(config);
45 | }
46 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/Config.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client;
2 |
3 | import com.aliyun.hitsdb.client.callback.AbstractBatchPutCallback;
4 | import com.aliyun.hitsdb.client.callback.AbstractMultiFieldBatchPutCallback;
5 | import com.aliyun.hitsdb.client.http.Host;
6 |
7 | import java.util.List;
8 |
9 | public interface Config {
10 | String BASICTYPE = "Basic"; // it should be "Basic" according to RFC 2617
11 | String ALITYPE = "alibaba-signature";
12 |
13 | boolean isSslEnable();
14 |
15 | String getAuthType();
16 |
17 | String getInstanceId();
18 |
19 | String getTsdbUser();
20 |
21 | String getBasicPwd();
22 |
23 | byte[] getCertContent();
24 |
25 | int getPutRequestLimit();
26 |
27 | int getBatchPutBufferSize();
28 |
29 | int getMultiFieldBatchPutBufferSize();
30 |
31 | AbstractBatchPutCallback> getBatchPutCallback();
32 |
33 | void setBatchPutCallback(AbstractBatchPutCallback callback);
34 |
35 | AbstractMultiFieldBatchPutCallback> getMultiFieldBatchPutCallback();
36 |
37 | void setMultiFieldBatchPutCallback(AbstractMultiFieldBatchPutCallback callback);
38 |
39 | boolean isAsyncPut();
40 |
41 | int getBatchPutConsumerThreadCount();
42 |
43 | int getMultiFieldBatchPutConsumerThreadCount();
44 |
45 | int getBatchPutRetryCount();
46 |
47 | int getBatchPutSize();
48 |
49 | int getBatchPutTimeLimit();
50 |
51 | String getHost();
52 |
53 | int getPort();
54 |
55 | List getAddresses();
56 |
57 | int getHttpConnectionPool();
58 |
59 | int getHttpConnectTimeout();
60 |
61 | int getHttpSocketTimeout();
62 |
63 | int getHttpConnectionRequestTimeout();
64 |
65 | int getIoThreadCount();
66 |
67 | boolean isPutRequestLimitSwitch();
68 |
69 | boolean isHttpCompress();
70 |
71 | boolean isBackpressure();
72 |
73 | int getHttpConnectionLiveTime();
74 |
75 | int getHttpKeepaliveTime();
76 |
77 | int getMaxTPS();
78 |
79 | Config copy(String host, int port);
80 |
81 | HAPolicy getHAPolicy();
82 |
83 | boolean isDeduplicationEnable();
84 |
85 | boolean isLastResultReverseEnable();
86 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/HiTSDB.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client;
2 |
3 | /**
4 | * @since 0.2.1
5 | * @deprecated use {@link TSDB} instead.
6 | */
7 | @Deprecated
8 | public interface HiTSDB extends TSDB {
9 |
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/HiTSDBClient.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client;
2 |
3 | import com.aliyun.hitsdb.client.exception.NotImplementedException;
4 | import com.aliyun.hitsdb.client.exception.http.HttpClientInitException;
5 | import com.aliyun.hitsdb.client.exception.http.HttpUnknowStatusException;
6 | import com.aliyun.hitsdb.client.value.response.SQLResult;
7 |
8 | /**
9 | * @since 0.2.1
10 | * @deprecated use {@link TSDBClient} instead.
11 | */
12 | @Deprecated
13 | public class HiTSDBClient extends TSDBClient implements HiTSDB {
14 |
15 | public HiTSDBClient(Config config) throws HttpClientInitException {
16 | super(config);
17 | }
18 |
19 | @Override
20 | public SQLResult queryBySQL(String sql) throws HttpUnknowStatusException {
21 | throw new NotImplementedException();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/HiTSDBClientFactory.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client;
2 |
3 | import com.aliyun.hitsdb.client.exception.http.HttpClientInitException;
4 |
5 | /**
6 | * @since 0.2.1
7 | * @deprecated use {@link TSDBClientFactory} instead.
8 | */
9 | @Deprecated
10 | public class HiTSDBClientFactory {
11 | public static HiTSDB connect(String host, int port) throws HttpClientInitException {
12 | HiTSDBConfig config = HiTSDBConfig.address(host, port).config();
13 | HiTSDB client = new HiTSDBClient(config);
14 | return client;
15 | }
16 |
17 | public static HiTSDB connect(HiTSDBConfig config) throws HttpClientInitException {
18 | HiTSDB client = new HiTSDBClient(config);
19 | return client;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/IotClientFactory.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client;
2 |
3 | import com.aliyun.hitsdb.client.exception.http.HttpClientInitException;
4 |
5 | /**
6 | * @author johnnyzou
7 | * @description create client for IoT(Super-tag mode) user
8 | */
9 | public class IotClientFactory {
10 | public static TSDB connect(String host, int port) throws HttpClientInitException {
11 | TSDBConfig config = TSDBConfig.address(host, port).config();
12 | TSDB client = new IotClient(config);
13 | return client;
14 | }
15 |
16 | public static TSDB connect(Config config) throws HttpClientInitException {
17 | TSDB client = new IotClient(config);
18 | return client;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/LindormTSDBClientFactory.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client;
2 |
3 | import com.aliyun.hitsdb.client.exception.http.HttpClientInitException;
4 |
5 | public class LindormTSDBClientFactory {
6 |
7 | public static LindormTSDBClient connect(String host, int port) throws HttpClientInitException {
8 | TSDBConfig config = TSDBConfig.address(host, port).config();
9 | LindormTSDBClient client = new LindormTSDBClient(config);
10 | return client;
11 | }
12 |
13 | public static LindormTSDBClient connect(Config config) throws HttpClientInitException {
14 | LindormTSDBClient client = new LindormTSDBClient(config);
15 | return client;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/TSDBClientFactory.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client;
2 |
3 | import com.aliyun.hitsdb.client.exception.http.HttpClientInitException;
4 |
5 | public class TSDBClientFactory {
6 |
7 | public static TSDB connect(String host, int port) throws HttpClientInitException {
8 | TSDBConfig config = TSDBConfig.address(host, port).config();
9 | TSDB client = new TSDBClient(config);
10 | return client;
11 | }
12 |
13 | public static TSDB connect(Config config) throws HttpClientInitException {
14 | TSDB client = new TSDBClient(config);
15 | return client;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/AbstractBatchPutCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import java.util.HashMap;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import com.aliyun.hitsdb.client.value.Result;
8 | import com.aliyun.hitsdb.client.value.request.Point;
9 |
10 | public abstract class AbstractBatchPutCallback extends AbstractCallback,R > {
11 |
12 | public static Map getPutQueryParamMap(AbstractBatchPutCallback> batchPutCallback) {
13 | Map paramsMap = new HashMap();
14 | if (batchPutCallback != null) {
15 | if (batchPutCallback instanceof BatchPutCallback) {
16 | } else if (batchPutCallback instanceof BatchPutSummaryCallback) {
17 | paramsMap.put("summary", "true");
18 | } else if (batchPutCallback instanceof BatchPutDetailsCallback) {
19 | paramsMap.put("details", "true");
20 | } else if (batchPutCallback instanceof BatchPutIgnoreErrorsCallback) {
21 | paramsMap.put("ignoreErrors", "true");
22 | }
23 | }
24 | return paramsMap;
25 | }
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/AbstractCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | public abstract class AbstractCallback implements Callback {
4 |
5 | @Override
6 | public void failed(String address, REQ request, Exception ex) {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/AbstractMultiFieldBatchPutCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import com.aliyun.hitsdb.client.value.Result;
4 | import com.aliyun.hitsdb.client.value.request.MultiFieldPoint;
5 |
6 | import java.util.HashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | public abstract class AbstractMultiFieldBatchPutCallback extends AbstractCallback,R > {
11 |
12 | public static Map getMultiFieldPutQueryParamMap(AbstractMultiFieldBatchPutCallback> multiFieldBatchPutCallback) {
13 | Map paramsMap = new HashMap();
14 | if (multiFieldBatchPutCallback != null) {
15 | if (multiFieldBatchPutCallback instanceof MultiFieldBatchPutCallback) {
16 | } else if (multiFieldBatchPutCallback instanceof MultiFieldBatchPutSummaryCallback) {
17 | paramsMap.put("summary", "true");
18 | } else if (multiFieldBatchPutCallback instanceof MultiFieldBatchPutDetailsCallback) {
19 | paramsMap.put("details", "true");
20 | } else if (multiFieldBatchPutCallback instanceof MultiFieldBatchPutIgnoreErrorsCallback) {
21 | paramsMap.put("ignoreErrors", "true");
22 | }
23 | }
24 | return paramsMap;
25 | }
26 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/BatchPutCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import java.util.List;
4 |
5 | import com.aliyun.hitsdb.client.value.Result;
6 | import com.aliyun.hitsdb.client.value.request.Point;
7 |
8 | public abstract class BatchPutCallback extends AbstractBatchPutCallback{
9 |
10 | @Override
11 | public abstract void response(String address, List points, Result result);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/BatchPutDetailsCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import java.util.List;
4 |
5 | import com.aliyun.hitsdb.client.value.request.Point;
6 | import com.aliyun.hitsdb.client.value.response.batch.DetailsResult;
7 |
8 | public abstract class BatchPutDetailsCallback extends AbstractBatchPutCallback {
9 |
10 | @Override
11 | public abstract void response(String address, List points, DetailsResult result);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/BatchPutIgnoreErrorsCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import com.aliyun.hitsdb.client.value.request.Point;
4 | import com.aliyun.hitsdb.client.value.response.batch.IgnoreErrorsResult;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Copyright @ 2020 alibaba.com
10 | * All right reserved.
11 | * Function:Batch Put IgnoreErrors Callback
12 | *
13 | * @author Benedict Jin
14 | * @since 2020/09/21
15 | */
16 | public abstract class BatchPutIgnoreErrorsCallback extends AbstractBatchPutCallback {
17 |
18 | @Override
19 | public abstract void response(String address, List points, IgnoreErrorsResult result);
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/BatchPutSummaryCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import java.util.List;
4 |
5 | import com.aliyun.hitsdb.client.value.request.Point;
6 | import com.aliyun.hitsdb.client.value.response.batch.SummaryResult;
7 |
8 | public abstract class BatchPutSummaryCallback extends AbstractBatchPutCallback {
9 |
10 | @Override
11 | public abstract void response(String address, List points, SummaryResult result);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/Callback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | public interface Callback {
4 | void response(String address, REQ input, RES output);
5 |
6 | void failed(String address, REQ input, Exception ex);
7 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/MultiFieldBatchPutCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import com.aliyun.hitsdb.client.value.Result;
4 | import com.aliyun.hitsdb.client.value.request.MultiFieldPoint;
5 |
6 | import java.util.List;
7 |
8 | public abstract class MultiFieldBatchPutCallback extends AbstractMultiFieldBatchPutCallback{
9 |
10 | @Override
11 | public abstract void response(String address, List points, Result result);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/MultiFieldBatchPutDetailsCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import com.aliyun.hitsdb.client.value.request.MultiFieldPoint;
4 | import com.aliyun.hitsdb.client.value.response.batch.MultiFieldDetailsResult;
5 |
6 | import java.util.List;
7 |
8 | public abstract class MultiFieldBatchPutDetailsCallback extends AbstractMultiFieldBatchPutCallback {
9 |
10 | @Override
11 | public abstract void response(String address, List points, MultiFieldDetailsResult result);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/MultiFieldBatchPutIgnoreErrorsCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import com.aliyun.hitsdb.client.value.request.MultiFieldPoint;
4 | import com.aliyun.hitsdb.client.value.response.batch.MultiFieldIgnoreErrorsResult;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Copyright @ 2020 alibaba.com
10 | * All right reserved.
11 | * Function:MultiField Batch Put IgnoreErrors Callback
12 | *
13 | * @author Benedict Jin
14 | * @since 2020/09/21
15 | */
16 | public abstract class MultiFieldBatchPutIgnoreErrorsCallback extends AbstractMultiFieldBatchPutCallback {
17 |
18 | @Override
19 | public abstract void response(String address, List points, MultiFieldIgnoreErrorsResult result);
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/MultiFieldBatchPutSummaryCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import com.aliyun.hitsdb.client.value.request.MultiFieldPoint;
4 | import com.aliyun.hitsdb.client.value.response.batch.SummaryResult;
5 |
6 | import java.util.List;
7 |
8 | public abstract class MultiFieldBatchPutSummaryCallback extends AbstractMultiFieldBatchPutCallback {
9 |
10 | @Override
11 | public abstract void response(String address, List points, SummaryResult result);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/QueryCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback;
2 |
3 | import java.util.List;
4 |
5 | import com.aliyun.hitsdb.client.value.request.Query;
6 | import com.aliyun.hitsdb.client.value.response.QueryResult;
7 |
8 | public abstract class QueryCallback extends AbstractCallback> {
9 |
10 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/http/BaseHttpFutureCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback.http;
2 |
3 | import java.util.concurrent.atomic.AtomicInteger;
4 |
5 | import org.apache.http.HttpResponse;
6 | import org.apache.http.concurrent.FutureCallback;
7 |
8 | public class BaseHttpFutureCallback implements FutureCallback {
9 |
10 | private final AtomicInteger unCompletedTaskNum;
11 | private final FutureCallback futureCallback;
12 |
13 | public BaseHttpFutureCallback(AtomicInteger unCompletedTaskNum, FutureCallback futureCallback) {
14 | super();
15 | this.unCompletedTaskNum = unCompletedTaskNum;
16 | this.futureCallback = futureCallback;
17 | }
18 |
19 | @Override
20 | public void completed(HttpResponse result) {
21 | futureCallback.completed(result);
22 | // 任务处理完毕,再减数
23 | unCompletedTaskNum.decrementAndGet();
24 | }
25 |
26 | @Override
27 | public void failed(Exception ex) {
28 | futureCallback.failed(ex);
29 | // 任务处理完毕,再减数
30 | unCompletedTaskNum.decrementAndGet();
31 | }
32 |
33 | @Override
34 | public void cancelled() {
35 | futureCallback.cancelled();
36 | // 任务处理完毕,再减数
37 | unCompletedTaskNum.decrementAndGet();
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/callback/http/QueryHttpResponseCallback.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.callback.http;
2 |
3 | import java.util.List;
4 |
5 | import org.apache.http.HttpResponse;
6 | import org.apache.http.concurrent.FutureCallback;
7 |
8 | import com.alibaba.fastjson.JSON;
9 | import com.aliyun.hitsdb.client.callback.QueryCallback;
10 | import com.aliyun.hitsdb.client.exception.http.HttpServerErrorException;
11 | import com.aliyun.hitsdb.client.exception.http.HttpServerNotSupportException;
12 | import com.aliyun.hitsdb.client.exception.http.HttpUnknowStatusException;
13 | import com.aliyun.hitsdb.client.http.response.HttpStatus;
14 | import com.aliyun.hitsdb.client.http.response.ResultResponse;
15 | import com.aliyun.hitsdb.client.value.request.Query;
16 | import com.aliyun.hitsdb.client.value.response.QueryResult;
17 |
18 | import static com.aliyun.hitsdb.client.TSDBClient.setTypeIfNeeded;
19 |
20 | public class QueryHttpResponseCallback implements FutureCallback {
21 |
22 | private final String address;
23 | private final Query query;
24 | private final QueryCallback callback;
25 | private final boolean compress;
26 |
27 | public QueryHttpResponseCallback(final String address, final Query query, QueryCallback callback,boolean compress) {
28 | super();
29 | this.address = address;
30 | this.query = query;
31 | this.callback = callback;
32 | this.compress = compress;
33 | }
34 |
35 | @Override
36 | public void completed(HttpResponse httpResponse) {
37 | ResultResponse resultResponse = ResultResponse.simplify(httpResponse,this.compress);
38 | HttpStatus httpStatus = resultResponse.getHttpStatus();
39 | switch (httpStatus) {
40 | case ServerSuccessNoContent:
41 | callback.response(this.address, query, null);
42 | return;
43 | case ServerSuccess:
44 | String content = resultResponse.getContent();
45 | List queryResultList = JSON.parseArray(content, QueryResult.class);
46 | setTypeIfNeeded(query, queryResultList);
47 | callback.response(this.address, query, queryResultList);
48 | return;
49 | case ServerNotSupport:
50 | callback.failed(this.address, query, new HttpServerNotSupportException(resultResponse));
51 | case ServerError:
52 | callback.failed(this.address, query, new HttpServerErrorException(resultResponse));
53 | default:
54 | callback.failed(this.address, query, new HttpUnknowStatusException(resultResponse));
55 | }
56 | }
57 |
58 | @Override
59 | public void failed(Exception ex) {
60 | callback.failed(this.address, query, ex);
61 | }
62 |
63 | @Override
64 | public void cancelled() {
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/consumer/AbstractBatchPutRunnable.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.consumer;
2 |
3 | import com.aliyun.hitsdb.client.Config;
4 | import com.aliyun.hitsdb.client.callback.http.HttpResponseCallbackFactory;
5 | import com.aliyun.hitsdb.client.http.HttpAddressManager;
6 | import com.aliyun.hitsdb.client.http.HttpClient;
7 | import com.aliyun.hitsdb.client.http.semaphore.SemaphoreManager;
8 | import com.aliyun.hitsdb.client.queue.DataQueue;
9 | import com.aliyun.hitsdb.client.util.guava.RateLimiter;
10 |
11 | import java.util.concurrent.CountDownLatch;
12 |
13 | public abstract class AbstractBatchPutRunnable {
14 | /**
15 | * 缓冲队列
16 | */
17 | protected final DataQueue dataQueue;
18 | /**
19 | * Http客户端
20 | */
21 | protected final HttpClient tsdbHttpClient;
22 | protected final HttpClient secondaryClient;
23 | /**
24 | * 消费者队列控制器。
25 | * 在优雅关闭中,若消费者队列尚未结束,则CountDownLatch用于阻塞close()方法。
26 | */
27 | protected final CountDownLatch countDownLatch;
28 | protected final Config config;
29 | protected final SemaphoreManager semaphoreManager;
30 | protected final HttpAddressManager httpAddressManager;
31 | /**
32 | * 回调包装与构造工厂
33 | */
34 | protected final HttpResponseCallbackFactory httpResponseCallbackFactory;
35 | /**
36 | * 每批次数据点个数
37 | */
38 | protected int batchSize;
39 | /**
40 | * 批次提交间隔,单位:毫秒
41 | */
42 | protected int batchPutTimeLimit;
43 | protected final RateLimiter rateLimiter;
44 |
45 | public AbstractBatchPutRunnable(DataQueue dataQueue, HttpClient httpclient, HttpClient secondaryClient, CountDownLatch countDownLatch, Config config, RateLimiter rateLimiter) {
46 | this.dataQueue = dataQueue;
47 | this.tsdbHttpClient = httpclient;
48 | this.secondaryClient = secondaryClient;
49 | this.countDownLatch = countDownLatch;
50 | this.batchSize = config.getBatchPutSize();
51 | this.batchPutTimeLimit = config.getBatchPutTimeLimit();
52 | this.config = config;
53 | this.semaphoreManager = tsdbHttpClient.getSemaphoreManager();
54 | this.httpAddressManager = tsdbHttpClient.getHttpAddressManager();
55 | this.rateLimiter = rateLimiter;
56 | this.httpResponseCallbackFactory = tsdbHttpClient.getHttpResponseCallbackFactory();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/consumer/BatchPutThreadFactory.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.consumer;
2 |
3 | import java.util.concurrent.ThreadFactory;
4 | import java.util.concurrent.atomic.AtomicInteger;
5 |
6 | class BatchPutThreadFactory implements ThreadFactory {
7 | private static final AtomicInteger poolNumber = new AtomicInteger(1);
8 | private ThreadGroup group;
9 | private String namePrefix;
10 | private AtomicInteger threadNumber;
11 |
12 | public BatchPutThreadFactory(String nameSuffix) {
13 | threadNumber = new AtomicInteger(1);
14 | SecurityManager s = System.getSecurityManager();
15 | group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
16 | namePrefix = "pool-" + poolNumber.getAndIncrement() + "-" + nameSuffix + "-";
17 | }
18 |
19 | @Override
20 | public Thread newThread(Runnable r) {
21 | Thread thread = new Thread(group, r, namePrefix + threadNumber.getAndIncrement(), 0);
22 | if (thread.isDaemon()) {
23 | // 作为守护线程存在
24 | thread.setDaemon(true);
25 | }
26 |
27 | if (thread.getPriority() != Thread.NORM_PRIORITY) {
28 | thread.setPriority(Thread.NORM_PRIORITY);
29 | }
30 |
31 | return thread;
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/consumer/Consumer.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.consumer;
2 |
3 | public interface Consumer {
4 | void start();
5 | void stop();
6 | void stop(boolean force);
7 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/consumer/ConsumerFactory.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.consumer;
2 |
3 | import com.aliyun.hitsdb.client.Config;
4 | import com.aliyun.hitsdb.client.http.HttpClient;
5 | import com.aliyun.hitsdb.client.queue.DataQueue;
6 | import com.aliyun.hitsdb.client.util.guava.RateLimiter;
7 |
8 | public class ConsumerFactory {
9 |
10 | public static Consumer createConsumer(DataQueue buffer, HttpClient httpclient, HttpClient secondaryClient, RateLimiter rateLimiter, Config config) {
11 | DefaultBatchPutConsumer consumer = new DefaultBatchPutConsumer(buffer, httpclient, secondaryClient, rateLimiter, config);
12 | return consumer;
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/BufferQueueFullException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception;
2 |
3 | public class BufferQueueFullException extends RuntimeException {
4 | private static final long serialVersionUID = -6089496689881016447L;
5 |
6 | public BufferQueueFullException(String message, Throwable cause) {
7 | super(message, cause);
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/NotImplementedException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception;
2 |
3 | public class NotImplementedException extends RuntimeException {
4 | }
5 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/http/HttpClientConnectionRefusedException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception.http;
2 |
3 | /**
4 | * @author shijiaqi
5 | */
6 | // 下一个大版本,移动到com.alibaba.hitsdb.client.exception.http.client
7 | public class HttpClientConnectionRefusedException extends HttpClientException {
8 |
9 | private static final long serialVersionUID = -4155566481009479303L;
10 |
11 | public HttpClientConnectionRefusedException(String address,Exception e) {
12 | super(e);
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/http/HttpClientException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception.http;
2 |
3 | //下一个大版本,移动到com.alibaba.hitsdb.client.exception.http.client
4 | public class HttpClientException extends RuntimeException {
5 |
6 | public HttpClientException() {
7 | }
8 |
9 | public HttpClientException(Exception e) {
10 | super(e);
11 | }
12 |
13 | public HttpClientException(String messsage) {
14 | super(messsage);
15 | }
16 |
17 | public HttpClientException(String messsage,Exception e) {
18 | super(messsage,e);
19 | }
20 |
21 | private static final long serialVersionUID = -2345036415069363458L;
22 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/http/HttpClientInitException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception.http;
2 |
3 | //下一个大版本,移动到com.alibaba.hitsdb.client.exception.http.client
4 | public class HttpClientInitException extends HttpClientException {
5 |
6 | private static final long serialVersionUID = 7092596721590181806L;
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/http/HttpClientSocketTimeoutException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception.http;
2 |
3 | public class HttpClientSocketTimeoutException extends HttpClientException {
4 | private static final long serialVersionUID = 5407907664312068303L;
5 |
6 | public HttpClientSocketTimeoutException(Exception e) {
7 | super(e);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/http/HttpServerErrorException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception.http;
2 |
3 | import com.aliyun.hitsdb.client.http.response.ResultResponse;
4 |
5 | public class HttpServerErrorException extends HttpUnknowStatusException {
6 |
7 | public HttpServerErrorException(int status, String message) {
8 | super(status, message);
9 | }
10 |
11 | public HttpServerErrorException(ResultResponse result) {
12 | super(result);
13 | }
14 |
15 | private static final long serialVersionUID = -7013317353179949073L;
16 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/http/HttpServerNotSupportException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception.http;
2 |
3 | import com.aliyun.hitsdb.client.http.response.ResultResponse;
4 |
5 | public class HttpServerNotSupportException extends HttpUnknowStatusException {
6 |
7 | public HttpServerNotSupportException(int status, String message) {
8 | super(status, message);
9 | }
10 |
11 | public HttpServerNotSupportException(ResultResponse result) {
12 | super(result);
13 | }
14 |
15 | private static final long serialVersionUID = 3183070191347274019L;
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/http/HttpServerUnauthorizedException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception.http;
2 |
3 | import com.aliyun.hitsdb.client.http.response.ResultResponse;
4 |
5 | public class HttpServerUnauthorizedException extends HttpUnknowStatusException {
6 | private static final long serialVersionUID = -8842332621020945130L;
7 |
8 | public HttpServerUnauthorizedException(int status, String message) { super(status, message); }
9 |
10 | public HttpServerUnauthorizedException(ResultResponse result) { super(result); }
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/exception/http/HttpUnknowStatusException.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.exception.http;
2 |
3 | import com.aliyun.hitsdb.client.http.response.ResultResponse;
4 |
5 | public class HttpUnknowStatusException extends RuntimeException {
6 |
7 | private static final long serialVersionUID = 3183070191347274019L;
8 |
9 | public HttpUnknowStatusException(int status, String message) {
10 | super();
11 | this.status = status;
12 | this.message = message;
13 | }
14 |
15 | public HttpUnknowStatusException(ResultResponse result) {
16 | super();
17 | this.status = result.getStatusCode();
18 | this.message = result.getContent();
19 | }
20 |
21 | private int status;
22 |
23 | private String message;
24 |
25 | public int getStatus() {
26 | return status;
27 | }
28 |
29 | public String getMessage() {
30 | return message;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/http/Host.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.http;
2 |
3 | public class Host {
4 |
5 | private String ip;
6 |
7 | private int port;
8 |
9 | public Host(String ip, int port) {
10 | this.ip = ip;
11 | this.port = port;
12 | }
13 |
14 | public Host() {
15 | }
16 |
17 | public String getIp() {
18 | return ip;
19 | }
20 |
21 | public void setIp(String ip) {
22 | this.ip = ip;
23 | }
24 |
25 | public int getPort() {
26 | return port;
27 | }
28 |
29 | public void setPort(int port) {
30 | this.port = port;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/http/HttpAPI.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.http;
2 |
3 | public interface HttpAPI {
4 | String PUT = "/api/put";
5 | String QUERY = "/api/query";
6 | String QUERY_LAST = "/api/query/last";
7 | String TTL = "/api/ttl";
8 | String DELETE_DATA = "/api/delete_data";
9 | String DELETE_META = "/api/delete_meta";
10 | String SUGGEST = "/api/suggest";
11 | String DUMP_META = "/api/dump_meta";
12 | String LOOKUP = "/api/search/lookup";
13 | String VERSION = "/api/version";
14 | String MAIN_CLUSTER_TIME = "/api/set_cluster?mainClusterTime";
15 |
16 | String UPDATE_LAST = "/api/updatelast";
17 |
18 | String TRUNCATE = "/api/truncate";
19 |
20 | String DELETE_ALL_TABLE = "/api/delete_all_table";
21 |
22 | String HEALTH = "/api/health";
23 |
24 | String VIP_HEALTH = "/api/vip_health";
25 |
26 | /**
27 | * Multi-field data model APIs
28 | */
29 | String MPUT = "/api/mput";
30 | String MQUERY = "/api/mquery";
31 | String QUERY_MLAST = "/api/query/mlast";
32 | /**
33 | * User authentication API
34 | */
35 | String USER_AUTH = "/api/users";
36 |
37 | String SQL = "/api/sqlquery";
38 |
39 | String TAGS_ADD = "/api/tags/add";
40 | String TAGS_SHOW = "/api/tags/show";
41 | String TAGS_REMOVE = "/api/tags/remove";
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/http/HttpAddressManager.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.http;
2 |
3 | import com.aliyun.hitsdb.client.Config;
4 |
5 | public class HttpAddressManager {
6 | private final String host;
7 | private final int port;
8 | private final String address;
9 |
10 | private HttpAddressManager(Config config) {
11 | host = config.getHost();
12 | port = config.getPort();
13 | address = host + ":" + port;
14 | }
15 |
16 | public static HttpAddressManager createHttpAddressManager(Config config) {
17 | return new HttpAddressManager(config);
18 | }
19 |
20 | public String getAddress() {
21 | return this.address;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/http/TSDBHttpAsyncCallbackExecutor.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.http;
2 |
3 | import java.io.IOException;
4 |
5 | import org.apache.http.Header;
6 | import org.apache.http.HttpException;
7 | import org.apache.http.HttpRequest;
8 | import org.apache.http.nio.NHttpClientConnection;
9 | import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
10 | import org.apache.http.protocol.HttpContext;
11 | import org.slf4j.Logger;
12 | import org.slf4j.LoggerFactory;
13 |
14 | public class TSDBHttpAsyncCallbackExecutor extends HttpAsyncRequestExecutor {
15 | private static final Logger LOGGER = LoggerFactory.getLogger(TSDBHttpAsyncCallbackExecutor.class);
16 | private final int liveTime;
17 |
18 | public TSDBHttpAsyncCallbackExecutor(int liveTime) {
19 | super();
20 | this.liveTime = liveTime;
21 | }
22 |
23 | @Override
24 | public void requestReady(NHttpClientConnection conn) throws IOException, HttpException {
25 | try {
26 | super.requestReady(conn);
27 | } catch (Exception ex) {
28 | LOGGER.error("", ex);
29 | }
30 |
31 | // 需要自动关闭连接
32 | if (this.liveTime > 0) {
33 | HttpRequest httpRequest = conn.getHttpRequest();
34 | if (httpRequest == null) {
35 | return;
36 | }
37 |
38 | HttpContext context = conn.getContext();
39 |
40 | long currentTimeMillis = System.currentTimeMillis();
41 | Object oldTimeMillisObj = context.getAttribute("t");
42 | if (oldTimeMillisObj == null) {
43 | context.setAttribute("t", currentTimeMillis);
44 | } else {
45 | long oldTimeMillis = (Long) oldTimeMillisObj;
46 | long dt = currentTimeMillis - oldTimeMillis;
47 | if (dt > 1000 * liveTime) { // 超时,重连
48 | tryCloseConnection(httpRequest);
49 | context.setAttribute("t", currentTimeMillis);
50 | }
51 | }
52 | }
53 | }
54 |
55 | private void tryCloseConnection(HttpRequest request) {
56 | Header[] headers = request.getHeaders("Connection");
57 | if (headers != null && headers.length > 0) {
58 | for (Header h : headers) {
59 | request.removeHeader(h);
60 | }
61 | }
62 |
63 | request.addHeader("Connection", "close");
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/http/request/HttpDeleteWithEntity.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.http.request;
2 |
3 | import java.net.URI;
4 |
5 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
6 |
7 | public class HttpDeleteWithEntity extends HttpEntityEnclosingRequestBase {
8 | public final static String METHOD_NAME = "DELETE";
9 |
10 | public HttpDeleteWithEntity() {
11 | super();
12 | }
13 |
14 | public HttpDeleteWithEntity(final URI uri) {
15 | super();
16 | setURI(uri);
17 | }
18 |
19 | public HttpDeleteWithEntity(final String uri) {
20 | super();
21 | setURI(URI.create(uri));
22 | }
23 |
24 | @Override
25 | public String getMethod() {
26 | return METHOD_NAME;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/http/request/HttpGetWithEntity.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.http.request;
2 |
3 | import java.net.URI;
4 |
5 | import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
6 |
7 | public class HttpGetWithEntity extends HttpEntityEnclosingRequestBase {
8 | public final static String METHOD_NAME = "GET";
9 |
10 | public HttpGetWithEntity() {
11 | super();
12 | }
13 |
14 | public HttpGetWithEntity(final URI uri) {
15 | super();
16 | setURI(uri);
17 | }
18 |
19 | public HttpGetWithEntity(final String uri) {
20 | super();
21 | setURI(URI.create(uri));
22 | }
23 |
24 | @Override
25 | public String getMethod() {
26 | return METHOD_NAME;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/http/response/HttpStatus.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.http.response;
2 |
3 | public enum HttpStatus {
4 | ServerSuccess,
5 | ServerSuccessNoContent,
6 | ServerNotSupport,
7 | ServerError,
8 | ServerUnauthorized,
9 | UnKnow
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/queue/DataQueue.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.queue;
2 |
3 | import com.aliyun.hitsdb.client.value.request.MultiFieldPoint;
4 | import com.aliyun.hitsdb.client.value.request.Point;
5 | import com.aliyun.hitsdb.client.value.request.PointsCollection;
6 |
7 | public interface DataQueue {
8 | void send(Point point);
9 |
10 | Point receive() throws InterruptedException;
11 |
12 | Point receive(int timeout) throws InterruptedException;
13 |
14 |
15 | void sendMultiFieldPoint(MultiFieldPoint point);
16 |
17 | MultiFieldPoint receiveMultiFieldPoint() throws InterruptedException;
18 |
19 | MultiFieldPoint receiveMultiFieldPoint(int timeout) throws InterruptedException;
20 |
21 | void sendPoints(PointsCollection points);
22 |
23 | PointsCollection receivePoints() throws InterruptedException;
24 |
25 | PointsCollection receivePoints(int timeout) throws InterruptedException;
26 |
27 | void forbiddenSend();
28 |
29 | void waitEmpty();
30 |
31 | boolean isEmpty();
32 |
33 | Point[] getPoints();
34 |
35 | MultiFieldPoint[] getMultiFieldPoints();
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/queue/DataQueueFactory.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.queue;
2 |
3 | public class DataQueueFactory {
4 |
5 | public static DataQueue createDataPointQueue(int batchPutBufferSize, int multiFieldBatchPutBufferSize, int waitTimeLimit, boolean backpressure) {
6 | return new DataPointQueue(batchPutBufferSize, multiFieldBatchPutBufferSize, waitTimeLimit, backpressure);
7 | }
8 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/util/FileWatcher.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.util;
2 |
3 | import java.io.File;
4 |
5 | public interface FileWatcher {
6 |
7 |
8 | void fileModified(File file);
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/util/HealthWatcher.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.util;
2 |
3 | public interface HealthWatcher {
4 |
5 |
6 | void health(String host, boolean health);
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/util/HttpUtil.java:
--------------------------------------------------------------------------------
1 |
2 |
3 | package com.aliyun.hitsdb.client.util;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.OutputStream;
8 | import java.net.HttpURLConnection;
9 | import java.net.URL;
10 | import java.util.Map;
11 |
12 | public class HttpUtil {
13 | /**
14 | * Send a get request
15 | * @param url
16 | * @return response
17 | * @throws IOException
18 | */
19 | static public String get(String url) throws IOException {
20 | return fetch("GET", url, null, null);
21 | }
22 |
23 | /**
24 | * Send a request
25 | * @param method HTTP method, for example "GET" or "POST"
26 | * @param url Url as string
27 | * @param body Request body as string
28 | * @param headers Optional map with headers
29 | * @return response Response as string
30 | * @throws IOException
31 | */
32 | static public String fetch(String method, String url, String body,
33 | Map headers) throws IOException {
34 | // connection
35 | URL u = new URL(url);
36 | HttpURLConnection conn = (HttpURLConnection)u.openConnection();
37 | conn.setConnectTimeout(10000);
38 | conn.setReadTimeout(10000);
39 |
40 | // method
41 | if (method != null) {
42 | conn.setRequestMethod(method);
43 | }
44 |
45 | // headers
46 | if (headers != null) {
47 | for(String key : headers.keySet()) {
48 | conn.addRequestProperty(key, headers.get(key));
49 | }
50 | }
51 |
52 | // body
53 | if (body != null) {
54 | conn.setDoOutput(true);
55 | OutputStream os = conn.getOutputStream();
56 | os.write(body.getBytes());
57 | os.flush();
58 | os.close();
59 | }
60 |
61 | // response
62 | InputStream is = conn.getInputStream();
63 | String response = streamToString(is);
64 | is.close();
65 |
66 | // handle redirects
67 | if (conn.getResponseCode() == 301) {
68 | String location = conn.getHeaderField("Location");
69 | return fetch(method, location, body, headers);
70 | }
71 |
72 | return response;
73 | }
74 |
75 | /**
76 | * Read an input stream into a string
77 | * @param in
78 | * @return
79 | * @throws IOException
80 | */
81 | static public String streamToString(InputStream in) throws IOException {
82 | StringBuffer out = new StringBuffer();
83 | byte[] b = new byte[4096];
84 | for (int n; (n = in.read(b)) != -1;) {
85 | out.append(new String(b, 0, n));
86 | }
87 | return out.toString();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/util/LinkedHashMapUtils.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.util;
2 |
3 | import java.lang.reflect.Field;
4 | import java.util.LinkedHashMap;
5 | import java.util.Map.Entry;
6 |
7 | import com.aliyun.hitsdb.client.exception.http.HttpClientException;
8 |
9 | public class LinkedHashMapUtils {
10 |
11 | private static final Field tailField;
12 | private static final Field beforeField;
13 |
14 | static {
15 | try {
16 | tailField = LinkedHashMap.class.getDeclaredField("tail");
17 | tailField.setAccessible(true);
18 | } catch (NoSuchFieldException e) {
19 | throw new LinkedHashMapException(e);
20 | } catch (SecurityException e) {
21 | throw new LinkedHashMapException(e);
22 | }
23 |
24 | try {
25 | Class> clazz = Class.forName("java.util.LinkedHashMap$Entry");
26 | beforeField = clazz.getDeclaredField("before");
27 | beforeField.setAccessible(true);
28 | } catch (ClassNotFoundException e) {
29 | throw new LinkedHashMapException(e);
30 | } catch (NoSuchFieldException e) {
31 | throw new LinkedHashMapException(e);
32 | } catch (SecurityException e) {
33 | throw new LinkedHashMapException(e);
34 | }
35 |
36 | }
37 |
38 |
39 | @SuppressWarnings("unchecked")
40 | public static Entry getTail(LinkedHashMap map) throws LinkedHashMapException {
41 | try {
42 | Entry entry = (Entry) tailField.get(map);
43 | return entry;
44 | } catch (SecurityException e) {
45 | throw new LinkedHashMapException(e);
46 | } catch (IllegalArgumentException e) {
47 | throw new LinkedHashMapException(e);
48 | } catch (IllegalAccessException e) {
49 | throw new LinkedHashMapException(e);
50 | }
51 | }
52 |
53 | @SuppressWarnings("unchecked")
54 | public static Entry getBefore(Entry entry) throws LinkedHashMapException {
55 | try {
56 | Entry beforeEntry = (Entry) beforeField.get(entry);
57 | return beforeEntry;
58 | } catch (SecurityException e) {
59 | throw new LinkedHashMapException(e);
60 | } catch (IllegalArgumentException e) {
61 | throw new LinkedHashMapException(e);
62 | } catch (IllegalAccessException e) {
63 | throw new LinkedHashMapException(e);
64 | }
65 | }
66 |
67 | }
68 |
69 | class LinkedHashMapException extends HttpClientException {
70 | private static final long serialVersionUID = 1L;
71 |
72 | LinkedHashMapException(Exception e){
73 | super(e);
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/util/Objects.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.util;
2 |
3 | public class Objects {
4 |
5 | public static T requireNonNull(T obj) {
6 | if (obj == null)
7 | throw new NullPointerException();
8 | return obj;
9 | }
10 |
11 | public static T requireNonNull(T obj, String message) {
12 | if (obj == null)
13 | throw new NullPointerException(message);
14 | return obj;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/util/Pair.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.util;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Pair implements Serializable {
6 | private static final long serialVersionUID = 2289934353998056157L;
7 |
8 | private K key;
9 |
10 | public K getKey() { return key; }
11 |
12 | private V value;
13 |
14 | public V getValue() { return value; }
15 |
16 | public Pair(K key, V value) {
17 | this.key = key;
18 | this.value = value;
19 | }
20 |
21 | @Override
22 | public String toString() {
23 | return key + "=" + value;
24 | }
25 |
26 | @Override
27 | public int hashCode() {
28 | // name's hashCode is multiplied by an arbitrary prime number (13)
29 | // in order to make sure there is a difference in the hashCode between
30 | return key.hashCode() * 13 + (value == null ? 0 : value.hashCode());
31 | }
32 |
33 | @Override
34 | public boolean equals(Object o) {
35 | if (this == o) return true;
36 | if (o instanceof Pair) {
37 | Pair pair = (Pair) o;
38 | if (key != null ? !key.equals(pair.key) : pair.key != null) return false;
39 | if (value != null ? !value.equals(pair.value) : pair.value != null) return false;
40 | return true;
41 | }
42 | return false;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/util/PropKit.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.util;
2 |
3 | import java.util.Properties;
4 |
5 | public class PropKit {
6 |
7 | private Properties properties;
8 |
9 | public PropKit(Properties properties){
10 | this.properties = properties;
11 | }
12 |
13 | public String get(String key){
14 | return properties.getProperty(key);
15 | }
16 |
17 | public boolean containsKey(String key){
18 | return properties.containsKey(key);
19 | }
20 |
21 | public Integer getInt(String key){
22 | return Integer.parseInt(properties.getProperty(key));
23 | }
24 |
25 | public Boolean getBoolean(String key){
26 | return Boolean.parseBoolean(properties.getProperty(key));
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/util/WatchManager.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.util;
2 |
3 | import java.io.File;
4 | import java.util.Map;
5 | import java.util.concurrent.*;
6 |
7 | public class WatchManager {
8 |
9 | private ConcurrentMap watchers = new ConcurrentHashMap();
10 |
11 | private ScheduledExecutorService executorService;
12 |
13 | private int intervalSeconds = 2;
14 |
15 |
16 | public WatchManager() {
17 | this.executorService = Executors.newSingleThreadScheduledExecutor();
18 | }
19 |
20 |
21 | public void start(){
22 | if(intervalSeconds > 0){
23 | this.executorService.scheduleWithFixedDelay(new WatchRunnable(),
24 | intervalSeconds,intervalSeconds,TimeUnit.SECONDS);
25 | }
26 | }
27 |
28 | public void stop() {
29 | this.executorService.shutdown();
30 | }
31 |
32 | public void setIntervalSeconds(int intervalSeconds){
33 | this.intervalSeconds = intervalSeconds;
34 | }
35 |
36 | public void watchFile(final File file,final FileWatcher watcher){
37 | final long lastModified = file.lastModified();
38 | watchers.put(file,new FileMonitor(lastModified,watcher));
39 | }
40 |
41 |
42 |
43 | private final class WatchRunnable implements Runnable {
44 |
45 | @Override
46 | public void run() {
47 | for(final Map.Entry entry : watchers.entrySet()){
48 | final File file = entry.getKey();
49 | final FileMonitor fileMonitor = entry.getValue();
50 | final long lastModified = file.lastModified();
51 | if(fileModified(fileMonitor,lastModified)){
52 | fileMonitor.lastModifiedMillis = lastModified;
53 | fileMonitor.fileWatcher.fileModified(file);
54 | }
55 | }
56 | }
57 |
58 | private boolean fileModified(final FileMonitor fileMonitor, final long lastModifiedMillis){
59 | return lastModifiedMillis != fileMonitor.lastModifiedMillis;
60 | }
61 | }
62 |
63 |
64 | private final class FileMonitor {
65 | private final FileWatcher fileWatcher;
66 | private volatile long lastModifiedMillis;
67 |
68 | public FileMonitor(final long lastModifiedMillis,final FileWatcher fileWatcher){
69 | this.fileWatcher = fileWatcher;
70 | this.lastModifiedMillis = lastModifiedMillis;
71 | }
72 |
73 | private void setLastModifiedMillis(final long lastModifiedMillis){
74 | this.lastModifiedMillis = lastModifiedMillis;
75 | }
76 |
77 | @Override
78 | public String toString() {
79 | return "FileMonitor [fileWatcher=" + fileWatcher + ", lastModifiedMillis=" + lastModifiedMillis + "]";
80 | }
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/util/guava/base/Ticker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 The Guava Authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.aliyun.hitsdb.client.util.guava.base;
17 |
18 | /**
19 | * The implementation of Ticker is derived from the Ticker class of Guava 16.0,
20 | * which is licensed under the Apache License 2.0
21 | */
22 | public abstract class Ticker {
23 | /**
24 | * Constructor for use by subclasses.
25 | */
26 | protected Ticker() {}
27 |
28 | /**
29 | * Returns the number of nanoseconds elapsed since this ticker's fixed
30 | * point of reference.
31 | */
32 | public abstract long read();
33 |
34 | /**
35 | * A ticker that reads the current time using {@link System#nanoTime}.
36 | *
37 | * @since 10.0
38 | */
39 | public static Ticker systemTicker() {
40 | return SYSTEM_TICKER;
41 | }
42 |
43 | /**
44 | * The original implementation of read() is to return Platform.systemNanoTime()
45 | * However, it is equivalent with System.nanoTime()
46 | */
47 | private static final Ticker SYSTEM_TICKER = new Ticker() {
48 | @Override
49 | public long read() {
50 | return System.nanoTime();
51 | }
52 | };
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/JSONValue.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.alibaba.fastjson.serializer.SerializerFeature;
5 |
6 | public class JSONValue {
7 |
8 | public static T parseObject(String json, Class clazz) {
9 | T object = JSON.parseObject(json, clazz);
10 | return object;
11 | }
12 |
13 | /*
14 | public static List parseList(String json, Class clazz) {
15 | List objectList = JSON.parseObject(json, new TypeReference>() {});
16 | return objectList;
17 | }
18 | */
19 |
20 | public String toJSON() {
21 | return JSON.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.SortField, SerializerFeature.SortField.MapSortField);
22 | }
23 |
24 | @Override
25 | public String toString() {
26 | return toJSON();
27 | }
28 |
29 | public void appendJSON(final StringBuilder sb) {
30 | sb.append(toJSON());
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/Result.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value;
2 |
3 | public class Result extends JSONValue {
4 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/AbstractPoint.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.alibaba.fastjson.annotation.JSONType;
4 | import com.aliyun.hitsdb.client.value.JSONValue;
5 |
6 | import java.util.Map;
7 |
8 | @JSONType(ignores = {"pointType"})
9 | public abstract class AbstractPoint extends JSONValue {
10 |
11 | protected String metric;
12 | protected Map tags;
13 | protected Long timestamp;
14 |
15 | public String getMetric() {
16 | return metric;
17 | }
18 |
19 | public Map getTags() {
20 | return tags;
21 | }
22 |
23 | public Long getTimestamp() {
24 | return timestamp;
25 | }
26 |
27 | public void setMetric(String metric) {
28 | this.metric = metric;
29 | }
30 |
31 | public void setTags(Map tags) {
32 | this.tags = tags;
33 | }
34 |
35 | public void setTimestamp(Long timestamp) {
36 | this.timestamp = timestamp;
37 | }
38 |
39 | public abstract PointType getPointType();
40 |
41 | /**
42 | * If it is true, it is a legitimate character.
43 | * @param c char
44 | * @return
45 | */
46 | public static boolean checkChar(char c) {
47 | return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') ||
48 | c == '-' || c == '_' ||
49 | c == '.' || c == ' ' || c == ',' || c == '=' || c == '/' || c == ':' ||
50 | c == '(' || c == ')' || c == '[' || c == ']' || c == '\'' || c == '/' || c == '#' ||
51 | Character.isLetter(c);
52 | }
53 |
54 |
55 | private static final long MIN_TIME = 4294968L;
56 |
57 | private static final long MAX_TIME = 9999999999999L;
58 |
59 | public static void checkTimestamp(long timestamp) {
60 | if (timestamp < MIN_TIME || timestamp > MAX_TIME) {
61 | throw new IllegalArgumentException("The timestamp must be in range [4294968,9999999999999],but is " + timestamp);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/ByteArrayValue.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 |
5 | import java.util.Base64;
6 |
7 | /**
8 | * @author cuiyuan
9 | * @date 2020/8/4 11:01 上午
10 | */
11 |
12 | public class ByteArrayValue extends ComplexValue {
13 | static public final String TypeValue = "bytes";
14 |
15 | public ByteArrayValue(final byte[] content) {
16 | super(TypeValue, Base64.getEncoder().encodeToString(content));
17 | }
18 |
19 | public byte[] decode(){
20 | return Base64.getDecoder().decode(content);
21 | }
22 |
23 | public static boolean isJsonObjectTypeMatch(JSONObject jsonObject) {
24 | return ComplexValue.isJsonObjectTypeMatch(jsonObject) && jsonObject.get(TypeKey).equals(TypeValue);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/ComplexValue.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * @author cuiyuan
9 | * @date 2020/8/10 11:53 上午
10 | */
11 |
12 | public class ComplexValue {
13 | public static final String TypeKey = "type";
14 | public static final String ContentKey = "content";
15 |
16 | String type;
17 | String content;
18 |
19 | public ComplexValue(String type, String content) {
20 | this.type = type;
21 | this.content = content;
22 | }
23 |
24 | public String getType() {
25 | return type;
26 | }
27 |
28 | public void setType(String type) {
29 | this.type = type;
30 | }
31 |
32 | public String getContent() {
33 | return content;
34 | }
35 |
36 | public void setContent(String content) {
37 | this.content = content;
38 | }
39 |
40 | public static boolean isJsonObjectTypeMatch(JSONObject jsonObject) {
41 | return jsonObject.containsKey(TypeKey) && jsonObject.containsKey(ContentKey) && jsonObject.size() == 2;
42 | }
43 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/DeleteMetaRequest.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import java.util.List;
4 | import java.util.Map;
5 |
6 | public class DeleteMetaRequest extends Timeline {
7 | public static class Builder extends Timeline.Builder {
8 | // the data is deleted at the same time by default
9 | private boolean deleteData = true;
10 | private boolean recursive;
11 |
12 | public Builder(String metric) {
13 | super(metric);
14 | this.deleteData = true; // the data is deleted at the same time by default
15 | this.recursive = true; // the timelines are deleted recursively by default
16 | }
17 |
18 | public Builder tag(String tagk, String tagv) {
19 | super.tag(tagk, tagv);
20 | return this;
21 | }
22 |
23 | public Builder tag(Map tags) {
24 | super.tag(tags);
25 | return this;
26 | }
27 |
28 | public Builder fields(List fields) {
29 | super.fields(fields);
30 | return this;
31 | }
32 |
33 | public Builder deleteData(boolean deleteData) {
34 | this.deleteData = deleteData;
35 | return this;
36 | }
37 |
38 | public Builder recursive(boolean recursive) {
39 | this.recursive = recursive;
40 | return this;
41 | }
42 |
43 | public DeleteMetaRequest build() {
44 | DeleteMetaRequest request = new DeleteMetaRequest();
45 |
46 | Timeline timeline = super.build();
47 | request.setMetric(timeline.getMetric());
48 | request.setTags(timeline.getTags());
49 | if ((timeline.getFields() != null) && (!timeline.getFields().isEmpty())) {
50 | request.setFields(timeline.getFields());
51 | }
52 | request.setDeleteData(this.deleteData);
53 | request.setRecursive(this.recursive);
54 |
55 | return request;
56 | }
57 | }
58 |
59 | private boolean deleteData;
60 | private boolean recursive;
61 |
62 | public boolean isRecursive() {
63 | return recursive;
64 | }
65 |
66 | public void setRecursive(boolean recursive) {
67 | this.recursive = recursive;
68 | }
69 |
70 | public boolean isDeleteData() {
71 | return deleteData;
72 | }
73 |
74 | public void setDeleteData(boolean deleteData) {
75 | this.deleteData = deleteData;
76 | }
77 |
78 | public DeleteMetaRequest() {
79 | super();
80 | this.deleteData = true;
81 | this.recursive = true;
82 | }
83 |
84 | public static DeleteMetaRequest.Builder metric(String metric) {
85 | return new DeleteMetaRequest.Builder(metric);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/DeltaOptions.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | /**
4 | * Created By jianhong.hjh
5 | * Date: 2019/08/30
6 | */
7 | public class DeltaOptions {
8 |
9 | private Boolean counter;
10 |
11 | private Boolean dropResets;
12 |
13 | private Long counterMax;
14 |
15 | public static class Builder {
16 |
17 | private Boolean counter;
18 |
19 | private Boolean dropResets;
20 |
21 | private Long counterMax;
22 |
23 | public Builder() {
24 |
25 | }
26 |
27 | public Builder counter(boolean counter) {
28 | this.counter = counter;
29 | return this;
30 | }
31 |
32 | public Builder dropResets(boolean dropResets) {
33 | this.dropResets = dropResets;
34 | return this;
35 | }
36 |
37 | public Builder counterMax(long counterMax) {
38 | this.counterMax = counterMax;
39 | return this;
40 | }
41 |
42 | public DeltaOptions build() {
43 | DeltaOptions rateOptions = new DeltaOptions();
44 | if (counter != null) {
45 | rateOptions.counter = counter;
46 | }
47 | if (dropResets != null) {
48 | rateOptions.dropResets = dropResets;
49 | }
50 | if (counterMax != null) {
51 | rateOptions.counterMax = counterMax;
52 | }
53 | return rateOptions;
54 | }
55 | }
56 |
57 |
58 | public static Builder newBuilder() {
59 | return new Builder();
60 | }
61 |
62 | public Boolean getCounter() {
63 | return counter;
64 | }
65 |
66 | public void setCounter(Boolean counter) {
67 | this.counter = counter;
68 | }
69 |
70 | public Boolean getDropResets() {
71 | return dropResets;
72 | }
73 |
74 | public void setDropResets(Boolean dropResets) {
75 | this.dropResets = dropResets;
76 | }
77 |
78 | public Long getCounterMax() {
79 | return counterMax;
80 | }
81 |
82 | public void setCounterMax(Long counterMax) {
83 | this.counterMax = counterMax;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/DumpMetaValue.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.aliyun.hitsdb.client.value.JSONValue;
4 |
5 | public class DumpMetaValue extends JSONValue {
6 | private String metric;
7 | private String tagkey;
8 | private String tagvalueprefix;
9 | private int max;
10 |
11 | private boolean dump_metric;
12 |
13 | public DumpMetaValue() {
14 | super();
15 | }
16 |
17 | public DumpMetaValue(String tagkey, String tagvalueprefix, int max) {
18 | super();
19 | this.tagkey = tagkey;
20 | this.tagvalueprefix = tagvalueprefix;
21 | this.max = max;
22 | this.dump_metric = false;
23 | }
24 |
25 | public DumpMetaValue(String tagkey, String tagvalueprefix, int max,boolean dumpMetric) {
26 | super();
27 | this.tagkey = tagkey;
28 | this.tagvalueprefix = tagvalueprefix;
29 | this.max = max;
30 | this.dump_metric = dumpMetric;
31 | }
32 |
33 | public DumpMetaValue(String metric,String tagkey, String tagvalueprefix, int max) {
34 | super();
35 | this.metric = metric;
36 | this.tagkey = tagkey;
37 | this.tagvalueprefix = tagvalueprefix;
38 | this.max = max;
39 | this.dump_metric = false;
40 | }
41 |
42 |
43 | public String getMetric() {
44 | return metric;
45 | }
46 |
47 | public void setMetric(String metric) {
48 | this.metric = metric;
49 | }
50 |
51 | public boolean isDump_metric() {
52 | return dump_metric;
53 | }
54 |
55 | public void setDump_metric(boolean dump_metric) {
56 | this.dump_metric = dump_metric;
57 | }
58 |
59 | public String getTagkey() {
60 | return tagkey;
61 | }
62 |
63 | public void setTagkey(String tagkey) {
64 | this.tagkey = tagkey;
65 | }
66 |
67 | public String getTagvalueprefix() {
68 | return tagvalueprefix;
69 | }
70 |
71 | public void setTagvalueprefix(String tagvalueprefix) {
72 | this.tagvalueprefix = tagvalueprefix;
73 | }
74 |
75 | public int getMax() {
76 | return max;
77 | }
78 |
79 | public void setMax(int max) {
80 | this.max = max;
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/Filter.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.aliyun.hitsdb.client.value.type.FilterType;
4 |
5 | public class Filter {
6 | private FilterType type;
7 | private String tagk;
8 | private String filter;
9 | private Boolean groupBy;
10 |
11 | public static class Builder {
12 | private FilterType type;
13 | private String tagk;
14 | private String filter;
15 | private boolean groupBy;
16 |
17 | public Builder(FilterType type, String tagk, String filter, boolean groupBy) {
18 | super();
19 | this.type = type;
20 | this.tagk = tagk;
21 | this.filter = filter;
22 | this.groupBy = groupBy;
23 | }
24 |
25 | public Builder(FilterType type, String tagk, String filter) {
26 | super();
27 | this.type = type;
28 | this.tagk = tagk;
29 | this.filter = filter;
30 | }
31 |
32 | public Filter build() {
33 | Filter f = new Filter();
34 | f.type = this.type;
35 | f.tagk = this.tagk;
36 | f.filter = this.filter;
37 | if (this.groupBy) {
38 | f.groupBy = true;
39 | }
40 |
41 | return f;
42 | }
43 |
44 | }
45 |
46 | public static Builder filter(FilterType type, String tagk, String filter) {
47 | return new Builder(type, tagk, filter);
48 | }
49 |
50 | public static Builder filter(FilterType type, String tagk, String filter, boolean groupBy) {
51 | return new Builder(type, tagk, filter, groupBy);
52 | }
53 |
54 | public static Builder filter(FilterType type, String filter) {
55 | return new Builder(type, null, filter);
56 | }
57 |
58 | public FilterType getType() {
59 | return type;
60 | }
61 |
62 | public void setType(FilterType type) {
63 | this.type = type;
64 | }
65 |
66 | public String getTagk() {
67 | return tagk;
68 | }
69 |
70 | public void setTagk(String tagk) {
71 | this.tagk = tagk;
72 | }
73 |
74 | public String getFilter() {
75 | return filter;
76 | }
77 |
78 | public void setFilter(String filter) {
79 | this.filter = filter;
80 | }
81 |
82 | public Boolean getGroupBy() {
83 | return groupBy;
84 | }
85 |
86 | public void setGroupBy(Boolean groupBy) {
87 | this.groupBy = groupBy;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/LastLimit.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | /**
4 | * @author cuiyuan
5 | * @date 2020/7/22 12:05 下午
6 | */
7 | public class LastLimit {
8 | long from;
9 | int size;
10 | boolean global;
11 |
12 | public LastLimit(long from, int size) {
13 | this(from, size, false) ;
14 | }
15 |
16 | public LastLimit(long from, int size, boolean global) {
17 | this.from = from;
18 | this.size = size;
19 | this.global = global;
20 | }
21 |
22 | public long getFrom() {
23 | return from;
24 | }
25 |
26 | public void setFrom(long from) {
27 | this.from = from;
28 | }
29 |
30 | public int getSize() {
31 | return size;
32 | }
33 |
34 | public void setSize(int size) {
35 | this.size = size;
36 | }
37 |
38 | public boolean isGlobal() {
39 | return global;
40 | }
41 |
42 | public void setGlobal(boolean global) {
43 | this.global = global;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/LookupTagFilter.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.alibaba.fastjson.serializer.SerializerFeature;
5 | import com.aliyun.hitsdb.client.value.JSONValue;
6 |
7 | public class LookupTagFilter extends JSONValue {
8 | private String key;
9 | private String value;
10 |
11 | public LookupTagFilter() {
12 | super();
13 | }
14 |
15 | public LookupTagFilter(String key, String value) {
16 | this.value = value;
17 | this.key = key;
18 | }
19 |
20 | public String getKey() {
21 | return key;
22 | }
23 |
24 | public String getValue() {
25 | return value;
26 | }
27 |
28 | public void setKey(String key) {
29 | this.key = key;
30 | }
31 |
32 | public void setValue(String value) {
33 | this.value = value;
34 | }
35 |
36 | public String toJSON() {
37 | return JSON.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect);
38 | }
39 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/MetricTimeRange.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.aliyun.hitsdb.client.value.JSONValue;
4 |
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | public class MetricTimeRange extends JSONValue {
9 | private String metric;
10 | /**
11 | * Optional tags input parameters.
12 | * added for TSDB v2.4.1 because newly added optional "tags" in api/delete_data
13 | */
14 | private Map tags;
15 | /**
16 | * Optional fields input parameters.
17 | * If provided, we only delete data that belong to provided fields.
18 | */
19 | private List fields;
20 | private long start;
21 | private long end;
22 |
23 | public MetricTimeRange() {
24 | super();
25 | }
26 |
27 | public MetricTimeRange(String metric, long start, long end) {
28 | this(metric, null, null, start, end);
29 | }
30 |
31 | public MetricTimeRange(String metric, List fields, long start, long end) {
32 | this(metric, null, fields, start, end);
33 | }
34 |
35 | public MetricTimeRange(String metric, Map tags, long start, long end) {
36 | this(metric, tags, null, start, end);
37 | }
38 |
39 | public MetricTimeRange(String metric, Map tags, List fields, long start, long end) {
40 | super();
41 | this.metric = metric;
42 | this.tags = tags;
43 | this.fields = fields;
44 | this.start = start;
45 | this.end = end;
46 | }
47 |
48 | public String getMetric() {
49 | return metric;
50 | }
51 |
52 | public void setMetric(String metric) {
53 | this.metric = metric;
54 | }
55 |
56 | public Map getTags() {
57 | return tags;
58 | }
59 |
60 | public void setTags(Map tags) {
61 | this.tags = tags;
62 | }
63 |
64 | public List getFields() {
65 | return fields;
66 | }
67 |
68 | public void setFields(List fields) {
69 | this.fields = fields;
70 | }
71 |
72 | public long getStart() {
73 | return start;
74 | }
75 |
76 | public void setStart(long start) {
77 | this.start = start;
78 | }
79 |
80 | public long getEnd() {
81 | return end;
82 | }
83 |
84 | public void setEnd(long end) {
85 | this.end = end;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/PointType.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | public enum PointType {
4 | SINGLE_VALUE,
5 | MULTI_FIELD
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/PointsCollection.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.alibaba.fastjson.annotation.JSONField;
5 | import com.alibaba.fastjson.serializer.SerializerFeature;
6 | import com.aliyun.hitsdb.client.callback.AbstractBatchPutCallback;
7 | import com.aliyun.hitsdb.client.callback.AbstractMultiFieldBatchPutCallback;
8 | import com.aliyun.hitsdb.client.util.Objects;
9 |
10 | import java.util.ArrayList;
11 | import java.util.Collection;
12 | import java.util.List;
13 |
14 | public class PointsCollection extends ArrayList {
15 | @JSONField(serialize = false)
16 | private final AbstractBatchPutCallback simplePointBatchCallbak;
17 | @JSONField(serialize = false)
18 | private final AbstractMultiFieldBatchPutCallback multiFieldBatchPutCallback;
19 |
20 | public PointsCollection(Collection points, AbstractBatchPutCallback callback) {
21 | Objects.requireNonNull(points);
22 | Objects.requireNonNull(callback);
23 |
24 | addAll(points);
25 | this.simplePointBatchCallbak = callback;
26 | this.multiFieldBatchPutCallback = null;
27 | }
28 |
29 | public PointsCollection(Collection multiFieldPoints, AbstractMultiFieldBatchPutCallback callback) {
30 | Objects.requireNonNull(multiFieldPoints);
31 | Objects.requireNonNull(callback);
32 |
33 | addAll(multiFieldPoints);
34 | this.simplePointBatchCallbak = null;
35 | this.multiFieldBatchPutCallback = callback;
36 | }
37 |
38 | public AbstractBatchPutCallback getSimplePointBatchCallbak() {
39 | return simplePointBatchCallbak;
40 | }
41 |
42 | public AbstractMultiFieldBatchPutCallback getMultiFieldBatchPutCallback() {
43 | return multiFieldBatchPutCallback;
44 | }
45 |
46 | public List asSingleFieldPoints() {
47 | List retval = new ArrayList(this.size());
48 | for (AbstractPoint p : this) {
49 | if (!(p instanceof Point)) {
50 | throw new IllegalStateException("it's not a SingleFieldPoint collection");
51 | }
52 | retval.add((Point)p);
53 | }
54 | return retval;
55 | }
56 |
57 | public List asMultiFieldPoints() {
58 | List retval = new ArrayList(this.size());
59 | for (AbstractPoint p : this) {
60 | if (!(p instanceof MultiFieldPoint)) {
61 | throw new IllegalStateException("it's not a MultiFieldPoint collection");
62 | }
63 | retval.add((MultiFieldPoint)p);
64 | }
65 | return retval;
66 | }
67 |
68 | public String toJSON() {
69 | return JSON.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.SortField, SerializerFeature.SortField.MapSortField);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/RateOptions.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | /**
4 | * Created By jianhong.hjh
5 | * Date: 2018/11/5
6 | */
7 | public class RateOptions {
8 |
9 | private Boolean counter;
10 |
11 | private Boolean dropResets;
12 |
13 | private Long counterMax;
14 |
15 | private Long resetValue;
16 |
17 | public static class Builder {
18 |
19 | private Boolean counter;
20 |
21 | private Boolean dropResets;
22 |
23 | private Long counterMax;
24 |
25 | private Long resetValue;
26 |
27 | public Builder() {
28 |
29 | }
30 |
31 | public Builder counter(boolean counter) {
32 | this.counter = counter;
33 | return this;
34 | }
35 |
36 | public Builder dropResets(boolean dropResets) {
37 | this.dropResets = dropResets;
38 | return this;
39 | }
40 |
41 | public Builder counterMax(long counterMax) {
42 | this.counterMax = counterMax;
43 | return this;
44 | }
45 |
46 | public Builder resetValue(long resetValue) {
47 | this.resetValue = resetValue;
48 | return this;
49 | }
50 |
51 | public RateOptions build() {
52 | RateOptions rateOptions = new RateOptions();
53 | if (counter != null) {
54 | rateOptions.counter = counter;
55 | }
56 | if (dropResets != null) {
57 | rateOptions.dropResets = dropResets;
58 | }
59 | if (counterMax != null) {
60 | rateOptions.counterMax = counterMax;
61 | }
62 | if (resetValue != null) {
63 | rateOptions.resetValue = resetValue;
64 | }
65 | return rateOptions;
66 | }
67 | }
68 |
69 |
70 | public static Builder newBuilder() {
71 | return new Builder();
72 | }
73 |
74 | public Boolean getCounter() {
75 | return counter;
76 | }
77 |
78 | public void setCounter(Boolean counter) {
79 | this.counter = counter;
80 | }
81 |
82 | public Boolean getDropResets() {
83 | return dropResets;
84 | }
85 |
86 | public void setDropResets(Boolean dropResets) {
87 | this.dropResets = dropResets;
88 | }
89 |
90 | public Long getCounterMax() {
91 | return counterMax;
92 | }
93 |
94 | public void setCounterMax(Long counterMax) {
95 | this.counterMax = counterMax;
96 | }
97 |
98 | public Long getResetValue() {
99 | return resetValue;
100 | }
101 |
102 | public void setResetValue(Long resetValue) {
103 | this.resetValue = resetValue;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/SQLValue.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.aliyun.hitsdb.client.value.JSONValue;
4 |
5 | public class SQLValue extends JSONValue {
6 | private String sql;
7 |
8 | public SQLValue(String sql) {
9 | this.sql = sql;
10 | }
11 |
12 | public String getSql() {
13 | return sql;
14 | }
15 |
16 | public void setSql(String sql) {
17 | this.sql = sql;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/SuggestValue.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.aliyun.hitsdb.client.value.JSONValue;
4 |
5 | public class SuggestValue extends JSONValue {
6 | private String type;
7 | /**
8 | * Optional metric input parameter.
9 | * Used for querying tagk, tagv, fields under certain metric.
10 | */
11 | private String metric;
12 | private String q;
13 | private int max;
14 |
15 | public SuggestValue() {
16 | super();
17 | }
18 |
19 | public SuggestValue(String type, String q, int max) {
20 | super();
21 | this.type = type;
22 | this.q = q;
23 | this.max = max;
24 | }
25 |
26 | public SuggestValue(String type, String metric, String q, int max) {
27 | super();
28 | this.type = type;
29 | this.metric = metric;
30 | this.q = q;
31 | this.max = max;
32 | }
33 |
34 | public String getType() {
35 | return type;
36 | }
37 |
38 | public void setType(String type) {
39 | this.type = type;
40 | }
41 |
42 | public String getMetric() {
43 | return metric;
44 | }
45 |
46 | public void setMetric(String metric) {
47 | this.metric = metric;
48 | }
49 |
50 | public String getQ() {
51 | return q;
52 | }
53 |
54 | public void setQ(String q) {
55 | this.q = q;
56 | }
57 |
58 | public int getMax() {
59 | return max;
60 | }
61 |
62 | public void setMax(int max) {
63 | this.max = max;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/TTLValue.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.aliyun.hitsdb.client.value.JSONValue;
4 |
5 | public class TTLValue extends JSONValue {
6 | private int val;
7 |
8 | public TTLValue() {
9 | super();
10 | }
11 |
12 | public TTLValue(int val) {
13 | super();
14 | this.val = val;
15 | }
16 |
17 | public int getVal() {
18 | return val;
19 | }
20 |
21 | public void setVal(int val) {
22 | this.val = val;
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/TagsAddInfo.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.aliyun.hitsdb.client.value.JSONValue;
4 |
5 | import java.util.ArrayList;
6 | import java.util.HashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 |
10 | /**
11 | * @author johnnyzou
12 | */
13 | public class TagsAddInfo extends JSONValue {
14 | private String metric;
15 | private Map tags;
16 | private List _ids;
17 |
18 | public TagsAddInfo(String metric, Map tags, List _ids) {
19 | this.metric = metric;
20 | this.tags = tags;
21 | this._ids = _ids;
22 | }
23 |
24 | public static class Builder {
25 | private String metric;
26 | private Map tags = new HashMap();
27 | private List _ids = new ArrayList();
28 |
29 | public Builder(String metric) {
30 | this.metric = metric;
31 | }
32 |
33 | public Builder tag(String tagk, String tagv) {
34 | this.tags.put(tagk, tagv);
35 | return this;
36 | }
37 |
38 | public Builder id(String id) {
39 | this._ids.add(id);
40 | return this;
41 | }
42 |
43 | public Builder ids(List ids) {
44 | this._ids.addAll(ids);
45 | return this;
46 | }
47 |
48 | public TagsAddInfo build() {
49 | if (tags.size() == 0) {
50 | throw new IllegalArgumentException("missing tags.");
51 | }
52 | if (this._ids.size() == 0) {
53 | throw new IllegalArgumentException("missing ids.");
54 | }
55 | return new TagsAddInfo(this.metric, this.tags, this._ids);
56 | }
57 | }
58 |
59 | public String getMetric() {
60 | return metric;
61 | }
62 |
63 | public Map getTags() {
64 | return tags;
65 | }
66 |
67 | public List get_ids() {
68 | return _ids;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/TagsRemoveInfo.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.aliyun.hitsdb.client.value.JSONValue;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | /**
9 | * @author johnnyzou
10 | */
11 | public class TagsRemoveInfo extends JSONValue{
12 | private String metric;
13 | private Map tags;
14 | private String _id;
15 |
16 | public TagsRemoveInfo(String metric, Map tags, String _id) {
17 | this.metric = metric;
18 | this.tags = tags;
19 | this._id = _id;
20 | }
21 |
22 | public static class Builder {
23 | private String metric;
24 | private Map tags = new HashMap();
25 | private String _id;
26 |
27 | public Builder(String metric, String _id) {
28 | this.metric = metric;
29 | this._id = _id;
30 | }
31 |
32 | public Builder tag(String tagk, String tagv) {
33 | this.tags.put(tagk, tagv);
34 | return this;
35 | }
36 |
37 | public TagsRemoveInfo build() {
38 | return new TagsRemoveInfo(this.metric, this.tags, this._id);
39 | }
40 | }
41 |
42 | public String getMetric() {
43 | return metric;
44 | }
45 |
46 | public Map getTags() {
47 | return tags;
48 | }
49 |
50 | public String get_id() {
51 | return _id;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/TagsShowInfo.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.aliyun.hitsdb.client.value.JSONValue;
4 |
5 | /**
6 | * @author johnnyzou
7 | */
8 | public class TagsShowInfo extends JSONValue {
9 | private String metric;
10 | private String _id;
11 |
12 | public TagsShowInfo(String metric, String _id) {
13 | this.metric = metric;
14 | this._id = _id;
15 | }
16 | public String getMetric() {
17 | return metric;
18 | }
19 |
20 | public String get_id() {
21 | return _id;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/Timeline.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import com.aliyun.hitsdb.client.value.JSONValue;
9 |
10 | public class Timeline extends JSONValue {
11 |
12 | public static class Builder {
13 | private String metric;
14 | private Map tags = new HashMap();
15 | /**
16 | * Optional fields input parameter.
17 | * Used for fields' timelines under specific metric.
18 | */
19 | private List fields = null;
20 |
21 | public Builder(String metric) {
22 | this.metric = metric;
23 | }
24 |
25 | public Builder tag(String tagk, String tagv) {
26 | this.tags.put(tagk, tagv);
27 | return this;
28 | }
29 |
30 | public Builder tag(Map tags) {
31 | this.tags.putAll(tags);
32 | return this;
33 | }
34 |
35 | public Builder fields(List fields) {
36 | if (fields == null || fields.isEmpty()) {
37 | return this;
38 | }
39 | this.fields = new ArrayList();
40 | this.fields.addAll(fields);
41 | return this;
42 | }
43 |
44 | public Timeline build() {
45 | Timeline timeline = new Timeline();
46 | timeline.metric = this.metric;
47 | timeline.tags = this.tags;
48 | if (this.fields != null && !this.fields.isEmpty()) {
49 | timeline.fields = fields;
50 | }
51 | return timeline;
52 | }
53 | }
54 |
55 | public static Builder metric(String metric) {
56 | return new Builder(metric);
57 | }
58 |
59 | private String metric;
60 | private Map tags;
61 | /**
62 | * Optional fields input parameter.
63 | * Used for fields' timelines under specific metric.
64 | */
65 | private List fields = null;
66 |
67 | public Timeline() {
68 | super();
69 | }
70 |
71 | public List getFields() {
72 | return fields;
73 | }
74 |
75 | public void setFields(List fields) {
76 | this.fields = fields;
77 | }
78 |
79 | public String getMetric() {
80 | return metric;
81 | }
82 |
83 | public void setMetric(String metric) {
84 | this.metric = metric;
85 | }
86 |
87 | public Map getTags() {
88 | return tags;
89 | }
90 |
91 | public void setTags(Map tags) {
92 | this.tags = tags;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/request/ValueSerializer.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.request;
2 |
3 | import com.alibaba.fastjson.JSON;
4 | import com.alibaba.fastjson.JSONObject;
5 | import com.alibaba.fastjson.parser.DefaultJSONParser;
6 | import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
7 | import com.alibaba.fastjson.serializer.JSONSerializer;
8 | import com.alibaba.fastjson.serializer.ObjectSerializer;
9 | import org.slf4j.Logger;
10 | import org.slf4j.LoggerFactory;
11 |
12 | import java.io.IOException;
13 | import java.lang.reflect.Type;
14 |
15 | /**
16 | * @author cuiyuan
17 | * @date 2020/8/4 11:30 上午
18 | */
19 | public class ValueSerializer implements ObjectSerializer, ObjectDeserializer {
20 |
21 | private static final Logger log = LoggerFactory.getLogger(ValueSerializer.class);
22 |
23 | @Override
24 | public void write(JSONSerializer jsonSerializer, Object o, Object o1, Type type, int i) throws IOException {
25 | if (o instanceof byte[]) {
26 | ByteArrayValue bv = new ByteArrayValue((byte[]) o);
27 | jsonSerializer.write(bv);
28 | return;
29 | }
30 | jsonSerializer.write(o);
31 | }
32 |
33 | @Override
34 | public Object deserialze(DefaultJSONParser parser, Type type, Object o) {
35 | Object parse = parser.parse();
36 | if (parse == null) {
37 | return null;
38 | }
39 | if (parse instanceof JSONObject) {
40 | JSONObject jsonObject = (JSONObject) parse;
41 | if (ComplexValue.isJsonObjectTypeMatch(jsonObject)) {
42 | String valueType = jsonObject.getString(ByteArrayValue.TypeKey);
43 | if (ByteArrayValue.TypeValue.equals(valueType)) {
44 | ByteArrayValue bv = JSON.parseObject(jsonObject.toJSONString(), ByteArrayValue.class);
45 | return bv.decode();
46 | } else if (GeoPointValue.TypeValue.equals(valueType)) {
47 | GeoPointValue gp = JSON.parseObject(jsonObject.toJSONString(), GeoPointValue.class);
48 | return gp;
49 | } else {
50 | log.error("Illegal value type {}", valueType);
51 | throw new IllegalArgumentException("Illegal value type " + valueType);
52 | }
53 | }
54 | }
55 | return parse;
56 | }
57 |
58 | @Override
59 | public int getFastMatchToken() {
60 | return 0;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/response/LookupDetailedResult.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.response;
2 |
3 | import java.util.LinkedHashMap;
4 | import java.util.Map;
5 |
6 | import com.alibaba.fastjson.JSON;
7 | import com.alibaba.fastjson.serializer.SerializerFeature;
8 | import com.aliyun.hitsdb.client.value.JSONValue;
9 |
10 | public class LookupDetailedResult extends JSONValue {
11 | private Map tags = new LinkedHashMap();
12 | private String metric;
13 | private String tsuid;
14 |
15 | public LookupDetailedResult() {
16 | super();
17 | }
18 |
19 | public String getTsuid() {
20 | return tsuid;
21 | }
22 |
23 | public String getMetric() {
24 | return metric;
25 | }
26 |
27 | public Map getTags() {
28 | return tags;
29 | }
30 |
31 | public void setTsuid(String tsuid) {
32 | this.tsuid = tsuid;
33 | }
34 |
35 | public void setTags(Map tags) {
36 | this.tags = tags;
37 | }
38 |
39 | public void setMetric(String metric) {
40 | this.metric = metric;
41 | }
42 |
43 | public String toJSON() {
44 | return JSON.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/response/LookupResult.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.response;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import com.alibaba.fastjson.JSON;
7 | import com.alibaba.fastjson.serializer.SerializerFeature;
8 | import com.aliyun.hitsdb.client.value.JSONValue;
9 | import com.aliyun.hitsdb.client.value.request.LookupTagFilter;
10 |
11 | public class LookupResult extends JSONValue {
12 | private String type;
13 | private String metric;
14 | private List tags = new ArrayList();
15 | private Integer limit = null;
16 | private int time;
17 | private List results = new ArrayList();
18 | private int totalResults;
19 |
20 | public LookupResult() {
21 | super();
22 | }
23 |
24 | public String getType() {
25 | return type;
26 | }
27 |
28 | public String getMetric() {
29 | return metric;
30 | }
31 |
32 | public List getTags() {
33 | return tags;
34 | }
35 |
36 | public Integer getLimit() {
37 | return limit;
38 | }
39 |
40 | public int getTime() {
41 | return time;
42 | }
43 |
44 | public List getResults() {
45 | return results;
46 | }
47 |
48 | public int getTotalResults() {
49 | return totalResults;
50 | }
51 |
52 | public void setType(String type) {
53 | this.type = type;
54 | }
55 |
56 | public void setMetric(String metric) {
57 | this.metric = metric;
58 | }
59 |
60 | public void setTags(List tags) {
61 | this.tags = tags;
62 | }
63 |
64 | public void setLimit(Integer limit) {
65 | this.limit = limit;
66 | }
67 |
68 | public void setTime(int time) {
69 | this.time = time;
70 | }
71 |
72 | public void setResults(List results) {
73 | this.results = results;
74 | }
75 |
76 | public void setTotalResults(int totalResults) {
77 | this.totalResults = totalResults;
78 | }
79 |
80 | public String toJSON() {
81 | return JSON.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/aliyun/hitsdb/client/value/response/MultiFieldQueryLastResult.java:
--------------------------------------------------------------------------------
1 | package com.aliyun.hitsdb.client.value.response;
2 |
3 | import com.alibaba.fastjson.annotation.JSONField;
4 |
5 | import java.util.ArrayList;
6 | import java.util.HashMap;
7 | import java.util.LinkedHashMap;
8 | import java.util.LinkedList;
9 | import java.util.List;
10 | import java.util.Map;
11 |
12 | public class MultiFieldQueryLastResult {
13 | private String metric;
14 | private Map tags = new HashMap();
15 | private List columns = new ArrayList();
16 | @JSONField(serializeUsing = MultiFieldQueryValuesSerializer.class, deserializeUsing = MultiFieldQueryValuesSerializer.class)
17 | private List> values = new ArrayList>();
18 |
19 | public String getMetric() {
20 | return metric;
21 | }
22 |
23 | public List getColumns() {
24 | return columns;
25 | }
26 |
27 | public List> getValues() {
28 | return values;
29 | }
30 |
31 | public void setTags(Map tags) {
32 | this.tags = tags;
33 | }
34 |
35 | public void setMetric(String metric) {
36 | this.metric = metric;
37 | }
38 |
39 | public void setColumns(List columns) {
40 | this.columns = columns;
41 | }
42 |
43 | public void setValues(List> values) {
44 | this.values = values;
45 | }
46 |
47 | public Map getTags() {
48 | return tags;
49 | }
50 |
51 | public List