|
54 | 54 | import java.util.concurrent.atomic.LongAdder;
|
55 | 55 | import java.util.function.BiConsumer;
|
56 | 56 | import java.util.function.Consumer;
|
| 57 | +import java.util.regex.Matcher; |
| 58 | +import java.util.regex.Pattern; |
57 | 59 |
|
58 | 60 | /**
|
59 | 61 | * Implementation of a InluxDB API.
|
@@ -95,6 +97,7 @@ public class InfluxDBImpl implements InfluxDB {
|
95 | 97 | private String retentionPolicy = "autogen";
|
96 | 98 | private ConsistencyLevel consistency = ConsistencyLevel.ONE;
|
97 | 99 | private final boolean messagePack;
|
| 100 | + private Boolean messagePackSupport; |
98 | 101 | private final ChunkProccesor chunkProccesor;
|
99 | 102 |
|
100 | 103 | /**
|
@@ -666,13 +669,26 @@ static class ErrorMessage {
|
666 | 669 | public String error;
|
667 | 670 | }
|
668 | 671 |
|
| 672 | + private boolean checkMessagePackSupport() { |
| 673 | + Matcher matcher = Pattern.compile("(\\d+\\.*)+").matcher(version()); |
| 674 | + if (!matcher.find()) { |
| 675 | + return false; |
| 676 | + } |
| 677 | + String s = matcher.group(); |
| 678 | + String[] versionNumbers = s.split("\\."); |
| 679 | + final int major = Integer.parseInt(versionNumbers[0]); |
| 680 | + final int minor = Integer.parseInt(versionNumbers[1]); |
| 681 | + final int fromMinor = 4; |
| 682 | + return (major >= 2) || ((major == 1) && (minor >= fromMinor)); |
| 683 | + } |
| 684 | + |
669 | 685 | private QueryResult executeQuery(final Call<QueryResult> call) {
|
670 | 686 | if (messagePack) {
|
671 |
| - String[] versionNumbers = version().split("\\."); |
672 |
| - final int major = Integer.parseInt(versionNumbers[0]); |
673 |
| - final int minor = Integer.parseInt(versionNumbers[1]); |
674 |
| - final int fromMinor = 4; |
675 |
| - if ((major < 2) && ((major != 1) || (minor < fromMinor))) { |
| 687 | + if (messagePackSupport == null) { |
| 688 | + messagePackSupport = checkMessagePackSupport(); |
| 689 | + } |
| 690 | + |
| 691 | + if (!messagePackSupport) { |
676 | 692 | throw new UnsupportedOperationException(
|
677 | 693 | "MessagePack format is only supported from InfluxDB version 1.4 and later");
|
678 | 694 | }
|
|
0 commit comments