annotate src/main/java/org/monetdb/mcl/net/HandshakeOptions.java @ 422:8368cbc670bf

Send reply size and time zone during initial handshake
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Tue, 02 Feb 2021 13:50:13 +0100 (2021-02-02)
parents
children b95d007e1dfa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
422
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
1 package org.monetdb.mcl.net;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
2
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
3 /** Keep track of MAPI handshake options.
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
4 *
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
5 * Recent server versions allow you to send configuration information during
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
6 * the authentication handshake so no additional round trips are necessary
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
7 * when that has completed.
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
8 *
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
9 * This class keeps track of the options to send, and whether they have already
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
10 * been sent.
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
11 */
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
12 public class HandshakeOptions {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
13
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
14 // public Boolean autoCommit;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
15 int replySize;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
16 // public Integer replySize;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
17 // public Integer ColumnarProtocol;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
18 int timeZone;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
19
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
20 boolean mustSendReplySize;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
21 boolean mustSendTimeZone;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
22
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
23 public int getReplySize() {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
24 return replySize;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
25 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
26
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
27 public void setReplySize(int replySize) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
28 this.replySize = replySize;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
29 this.mustSendReplySize = true;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
30 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
31
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
32 public boolean mustSendReplySize() {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
33 return mustSendReplySize;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
34 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
35
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
36 public void mustSendReplySize(boolean mustSendReplySize) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
37 this.mustSendReplySize = mustSendReplySize;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
38 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
39
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
40 public int getTimeZone() {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
41 return timeZone;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
42 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
43
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
44 public void setTimeZone(int timeZone) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
45 this.timeZone = timeZone;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
46 this.mustSendTimeZone = true;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
47 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
48
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
49 public boolean mustSendTimeZone() {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
50 return mustSendTimeZone;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
51 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
52
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
53 public void mustSendTimeZone(boolean mustSendTimeZone) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
54 this.mustSendTimeZone = mustSendTimeZone;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
55 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
56
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
57 public String formatResponse(int serverLevel) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
58 StringBuilder opts = new StringBuilder(100);
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
59 if (mustSendReplySize()) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
60 formatOption(opts, Level.ReplySize, serverLevel, replySize);
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
61 mustSendReplySize(false);
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
62 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
63 if (mustSendTimeZone()) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
64 formatOption(opts, Level.TimeZone, serverLevel, timeZone);
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
65 mustSendTimeZone(false);
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
66 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
67
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
68 return opts.toString();
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
69 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
70
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
71 private void formatOption(StringBuilder opts, Level level, int serverLevel, int value) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
72 if (!level.isSupported(serverLevel))
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
73 return;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
74 if (opts.length() > 0) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
75 opts.append(",");
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
76 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
77 opts.append(level.field);
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
78 opts.append("=");
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
79 opts.append(value);
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
80 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
81
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
82 public enum Level {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
83 ReplySize("reply_size", 2),
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
84 TimeZone("time_zone", 5);
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
85
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
86 private final int level;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
87 private final String field;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
88
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
89 Level(String field, int level) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
90 this.field = field;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
91 this.level = level;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
92 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
93
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
94 public boolean isSupported(int serverLevel) {
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
95 return this.level < serverLevel;
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
96 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
97 }
8368cbc670bf Send reply size and time zone during initial handshake
Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
parents:
diff changeset
98 }