id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
list | docstring
stringlengths 3
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
4,200 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/buffer/NodeToPartitionMultimap.java
|
NodeToPartitionMultimap.getAbsent
|
List<PartitionInstance> getAbsent() {
List<PartitionInstance> absentPartitions = new ArrayList<>();
for (Map.Entry<Integer, List<PartitionInstance>> e : nodeIndexToHostedPartitions.entrySet()) {
if (e.getKey() < 0) {
absentPartitions.addAll(e.getValue());
}
}
return absentPartitions;
}
|
java
|
List<PartitionInstance> getAbsent() {
List<PartitionInstance> absentPartitions = new ArrayList<>();
for (Map.Entry<Integer, List<PartitionInstance>> e : nodeIndexToHostedPartitions.entrySet()) {
if (e.getKey() < 0) {
absentPartitions.addAll(e.getValue());
}
}
return absentPartitions;
}
|
[
"List",
"<",
"PartitionInstance",
">",
"getAbsent",
"(",
")",
"{",
"List",
"<",
"PartitionInstance",
">",
"absentPartitions",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"Integer",
",",
"List",
"<",
"PartitionInstance",
">",
">",
"e",
":",
"nodeIndexToHostedPartitions",
".",
"entrySet",
"(",
")",
")",
"{",
"if",
"(",
"e",
".",
"getKey",
"(",
")",
"<",
"0",
")",
"{",
"absentPartitions",
".",
"addAll",
"(",
"e",
".",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"return",
"absentPartitions",
";",
"}"
] |
Returns the partition instances whose node indexes are < 0.
|
[
"Returns",
"the",
"partition",
"instances",
"whose",
"node",
"indexes",
"are",
"<",
"0",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/buffer/NodeToPartitionMultimap.java#L68-L76
|
4,201 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/Field.java
|
Field.isMap
|
public boolean isMap() {
if (type instanceof Message) {
Message message = (Message) type;
return message.isMapEntry();
}
return false;
}
|
java
|
public boolean isMap() {
if (type instanceof Message) {
Message message = (Message) type;
return message.isMapEntry();
}
return false;
}
|
[
"public",
"boolean",
"isMap",
"(",
")",
"{",
"if",
"(",
"type",
"instanceof",
"Message",
")",
"{",
"Message",
"message",
"=",
"(",
"Message",
")",
"type",
";",
"return",
"message",
".",
"isMapEntry",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns true if this message is generated by parser as a
holder for a map entries.
|
[
"Returns",
"true",
"if",
"this",
"message",
"is",
"generated",
"by",
"parser",
"as",
"a",
"holder",
"for",
"a",
"map",
"entries",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/Field.java#L116-L122
|
4,202 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/AbstractProtoParserListener.java
|
AbstractProtoParserListener.trim
|
protected List<String> trim(List<String> comments) {
List<String> trimComments = new ArrayList<>();
int n = 0;
boolean tryRemoveWhitespace = true;
while (tryRemoveWhitespace) {
boolean allLinesAreShorter = true;
for (String comment : comments) {
if (comment.length() <= n) {
continue;
}
if (comment.charAt(n) != ' ') {
tryRemoveWhitespace = false;
}
allLinesAreShorter = false;
}
if (allLinesAreShorter) {
break;
}
if (tryRemoveWhitespace) {
n++;
}
}
for (String comment : comments) {
if (comment.length() > n) {
String substring = comment.substring(n);
trimComments.add(substring);
} else {
trimComments.add("");
}
}
return trimComments;
}
|
java
|
protected List<String> trim(List<String> comments) {
List<String> trimComments = new ArrayList<>();
int n = 0;
boolean tryRemoveWhitespace = true;
while (tryRemoveWhitespace) {
boolean allLinesAreShorter = true;
for (String comment : comments) {
if (comment.length() <= n) {
continue;
}
if (comment.charAt(n) != ' ') {
tryRemoveWhitespace = false;
}
allLinesAreShorter = false;
}
if (allLinesAreShorter) {
break;
}
if (tryRemoveWhitespace) {
n++;
}
}
for (String comment : comments) {
if (comment.length() > n) {
String substring = comment.substring(n);
trimComments.add(substring);
} else {
trimComments.add("");
}
}
return trimComments;
}
|
[
"protected",
"List",
"<",
"String",
">",
"trim",
"(",
"List",
"<",
"String",
">",
"comments",
")",
"{",
"List",
"<",
"String",
">",
"trimComments",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"int",
"n",
"=",
"0",
";",
"boolean",
"tryRemoveWhitespace",
"=",
"true",
";",
"while",
"(",
"tryRemoveWhitespace",
")",
"{",
"boolean",
"allLinesAreShorter",
"=",
"true",
";",
"for",
"(",
"String",
"comment",
":",
"comments",
")",
"{",
"if",
"(",
"comment",
".",
"length",
"(",
")",
"<=",
"n",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"comment",
".",
"charAt",
"(",
"n",
")",
"!=",
"'",
"'",
")",
"{",
"tryRemoveWhitespace",
"=",
"false",
";",
"}",
"allLinesAreShorter",
"=",
"false",
";",
"}",
"if",
"(",
"allLinesAreShorter",
")",
"{",
"break",
";",
"}",
"if",
"(",
"tryRemoveWhitespace",
")",
"{",
"n",
"++",
";",
"}",
"}",
"for",
"(",
"String",
"comment",
":",
"comments",
")",
"{",
"if",
"(",
"comment",
".",
"length",
"(",
")",
">",
"n",
")",
"{",
"String",
"substring",
"=",
"comment",
".",
"substring",
"(",
"n",
")",
";",
"trimComments",
".",
"add",
"(",
"substring",
")",
";",
"}",
"else",
"{",
"trimComments",
".",
"add",
"(",
"\"\"",
")",
";",
"}",
"}",
"return",
"trimComments",
";",
"}"
] |
Remove common leading whitespaces from all strings in the list.
Returns new list instance.
|
[
"Remove",
"common",
"leading",
"whitespaces",
"from",
"all",
"strings",
"in",
"the",
"list",
".",
"Returns",
"new",
"list",
"instance",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/AbstractProtoParserListener.java#L96-L127
|
4,203 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/TypeResolverPostProcessor.java
|
TypeResolverPostProcessor.createScopeLookupList
|
public static Deque<String> createScopeLookupList(UserTypeContainer container) {
String namespace = container.getNamespace();
Deque<String> scopeLookupList = new ArrayDeque<>();
int end = 0;
while (end >= 0) {
end = namespace.indexOf('.', end);
if (end >= 0) {
end++;
String scope = namespace.substring(0, end);
scopeLookupList.addFirst(scope);
}
}
return scopeLookupList;
}
|
java
|
public static Deque<String> createScopeLookupList(UserTypeContainer container) {
String namespace = container.getNamespace();
Deque<String> scopeLookupList = new ArrayDeque<>();
int end = 0;
while (end >= 0) {
end = namespace.indexOf('.', end);
if (end >= 0) {
end++;
String scope = namespace.substring(0, end);
scopeLookupList.addFirst(scope);
}
}
return scopeLookupList;
}
|
[
"public",
"static",
"Deque",
"<",
"String",
">",
"createScopeLookupList",
"(",
"UserTypeContainer",
"container",
")",
"{",
"String",
"namespace",
"=",
"container",
".",
"getNamespace",
"(",
")",
";",
"Deque",
"<",
"String",
">",
"scopeLookupList",
"=",
"new",
"ArrayDeque",
"<>",
"(",
")",
";",
"int",
"end",
"=",
"0",
";",
"while",
"(",
"end",
">=",
"0",
")",
"{",
"end",
"=",
"namespace",
".",
"indexOf",
"(",
"'",
"'",
",",
"end",
")",
";",
"if",
"(",
"end",
">=",
"0",
")",
"{",
"end",
"++",
";",
"String",
"scope",
"=",
"namespace",
".",
"substring",
"(",
"0",
",",
"end",
")",
";",
"scopeLookupList",
".",
"addFirst",
"(",
"scope",
")",
";",
"}",
"}",
"return",
"scopeLookupList",
";",
"}"
] |
Create a lookup list for reference resolution.
<p>Type name resolution in the protocol buffer language works like C++: first
the innermost scope is searched, then the next-innermost, and so on, with
each package considered to be "inner" to its parent package.
|
[
"Create",
"a",
"lookup",
"list",
"for",
"reference",
"resolution",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/TypeResolverPostProcessor.java#L36-L49
|
4,204 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/config/DcpControl.java
|
DcpControl.bufferAckEnabled
|
public boolean bufferAckEnabled() {
String bufSize = get(Names.CONNECTION_BUFFER_SIZE);
return bufSize != null && Integer.parseInt(bufSize) > 0;
}
|
java
|
public boolean bufferAckEnabled() {
String bufSize = get(Names.CONNECTION_BUFFER_SIZE);
return bufSize != null && Integer.parseInt(bufSize) > 0;
}
|
[
"public",
"boolean",
"bufferAckEnabled",
"(",
")",
"{",
"String",
"bufSize",
"=",
"get",
"(",
"Names",
".",
"CONNECTION_BUFFER_SIZE",
")",
";",
"return",
"bufSize",
"!=",
"null",
"&&",
"Integer",
".",
"parseInt",
"(",
"bufSize",
")",
">",
"0",
";",
"}"
] |
Shorthand getter to check if buffer acknowledgements are enabled.
|
[
"Shorthand",
"getter",
"to",
"check",
"if",
"buffer",
"acknowledgements",
"are",
"enabled",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/config/DcpControl.java#L105-L108
|
4,205 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/config/DcpControl.java
|
DcpControl.noopIntervalSeconds
|
public int noopIntervalSeconds() {
try {
return parsePositiveInteger(get(Names.SET_NOOP_INTERVAL));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Bad value for '" + Names.SET_NOOP_INTERVAL.value() + "'; " + e.getMessage());
}
}
|
java
|
public int noopIntervalSeconds() {
try {
return parsePositiveInteger(get(Names.SET_NOOP_INTERVAL));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
"Bad value for '" + Names.SET_NOOP_INTERVAL.value() + "'; " + e.getMessage());
}
}
|
[
"public",
"int",
"noopIntervalSeconds",
"(",
")",
"{",
"try",
"{",
"return",
"parsePositiveInteger",
"(",
"get",
"(",
"Names",
".",
"SET_NOOP_INTERVAL",
")",
")",
";",
"}",
"catch",
"(",
"IllegalArgumentException",
"e",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Bad value for '\"",
"+",
"Names",
".",
"SET_NOOP_INTERVAL",
".",
"value",
"(",
")",
"+",
"\"'; \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Shorthand getter for the NOOP interval.
|
[
"Shorthand",
"getter",
"for",
"the",
"NOOP",
"interval",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/config/DcpControl.java#L120-L127
|
4,206 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/config/DcpControl.java
|
DcpControl.getControls
|
public Map<String, String> getControls(Version serverVersion) {
final CompressionMode effectiveMode = compression(serverVersion);
if (compressionMode != effectiveMode) {
LOGGER.info("Couchbase Server version {} does not support {} compression mode; falling back to {}.",
serverVersion, compressionMode, effectiveMode);
} else {
LOGGER.debug("Compression mode: {}", compressionMode);
}
final Map<String, String> result = new HashMap<>(values);
result.putAll(effectiveMode.getDcpControls(serverVersion));
return result;
}
|
java
|
public Map<String, String> getControls(Version serverVersion) {
final CompressionMode effectiveMode = compression(serverVersion);
if (compressionMode != effectiveMode) {
LOGGER.info("Couchbase Server version {} does not support {} compression mode; falling back to {}.",
serverVersion, compressionMode, effectiveMode);
} else {
LOGGER.debug("Compression mode: {}", compressionMode);
}
final Map<String, String> result = new HashMap<>(values);
result.putAll(effectiveMode.getDcpControls(serverVersion));
return result;
}
|
[
"public",
"Map",
"<",
"String",
",",
"String",
">",
"getControls",
"(",
"Version",
"serverVersion",
")",
"{",
"final",
"CompressionMode",
"effectiveMode",
"=",
"compression",
"(",
"serverVersion",
")",
";",
"if",
"(",
"compressionMode",
"!=",
"effectiveMode",
")",
"{",
"LOGGER",
".",
"info",
"(",
"\"Couchbase Server version {} does not support {} compression mode; falling back to {}.\"",
",",
"serverVersion",
",",
"compressionMode",
",",
"effectiveMode",
")",
";",
"}",
"else",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Compression mode: {}\"",
",",
"compressionMode",
")",
";",
"}",
"final",
"Map",
"<",
"String",
",",
"String",
">",
"result",
"=",
"new",
"HashMap",
"<>",
"(",
"values",
")",
";",
"result",
".",
"putAll",
"(",
"effectiveMode",
".",
"getDcpControls",
"(",
"serverVersion",
")",
")",
";",
"return",
"result",
";",
"}"
] |
Returns the control settings, adjusted for the actual Couchbase Server version.
|
[
"Returns",
"the",
"control",
"settings",
"adjusted",
"for",
"the",
"actual",
"Couchbase",
"Server",
"version",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/config/DcpControl.java#L140-L153
|
4,207 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/message/ResponseStatus.java
|
ResponseStatus.valueOf
|
public static ResponseStatus valueOf(int code) {
code = code & 0xFFFF; // convert negative shorts to unsigned
if (code < 256) {
ResponseStatus status = values[code];
if (status != null) {
return status;
}
}
return new ResponseStatus(code);
}
|
java
|
public static ResponseStatus valueOf(int code) {
code = code & 0xFFFF; // convert negative shorts to unsigned
if (code < 256) {
ResponseStatus status = values[code];
if (status != null) {
return status;
}
}
return new ResponseStatus(code);
}
|
[
"public",
"static",
"ResponseStatus",
"valueOf",
"(",
"int",
"code",
")",
"{",
"code",
"=",
"code",
"&",
"0xFFFF",
";",
"// convert negative shorts to unsigned",
"if",
"(",
"code",
"<",
"256",
")",
"{",
"ResponseStatus",
"status",
"=",
"values",
"[",
"code",
"]",
";",
"if",
"(",
"status",
"!=",
"null",
")",
"{",
"return",
"status",
";",
"}",
"}",
"return",
"new",
"ResponseStatus",
"(",
"code",
")",
";",
"}"
] |
Returns the ResponseStatus with the given status code. For recognized codes, this method
is guaranteed to always return the same ResponseStatus instance, so it's safe to use == for equality checks
against the pre-defined constants.
|
[
"Returns",
"the",
"ResponseStatus",
"with",
"the",
"given",
"status",
"code",
".",
"For",
"recognized",
"codes",
"this",
"method",
"is",
"guaranteed",
"to",
"always",
"return",
"the",
"same",
"ResponseStatus",
"instance",
"so",
"it",
"s",
"safe",
"to",
"use",
"==",
"for",
"equality",
"checks",
"against",
"the",
"pre",
"-",
"defined",
"constants",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/message/ResponseStatus.java#L55-L64
|
4,208 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/AuthHandler.java
|
AuthHandler.handleAuthResponse
|
private void handleAuthResponse(final ChannelHandlerContext ctx, final ByteBuf msg) throws Exception {
if (saslClient.isComplete()) {
checkIsAuthed(ctx, MessageUtil.getResponseStatus(msg));
return;
}
ByteBuf challengeBuf = SaslAuthResponse.challenge(msg);
byte[] challenge = new byte[challengeBuf.readableBytes()];
challengeBuf.readBytes(challenge);
byte[] evaluatedBytes = saslClient.evaluateChallenge(challenge);
if (evaluatedBytes != null) {
ByteBuf content;
// This is needed against older server versions where the protocol does not
// align on cram and plain, the else block is used for all the newer cram-sha*
// mechanisms.
//
// Note that most likely this is only executed in the CRAM-MD5 case only, but
// just to play it safe keep it for both mechanisms.
if (selectedMechanism.equals("CRAM-MD5") || selectedMechanism.equals("PLAIN")) {
String[] evaluated = new String(evaluatedBytes).split(" ");
content = Unpooled.copiedBuffer(username + "\0" + evaluated[1], CharsetUtil.UTF_8);
} else {
content = Unpooled.wrappedBuffer(evaluatedBytes);
}
ByteBuf request = ctx.alloc().buffer();
SaslStepRequest.init(request);
SaslStepRequest.mechanism(selectedMechanism, request);
SaslStepRequest.challengeResponse(content, request);
ChannelFuture future = ctx.writeAndFlush(request);
future.addListener(new GenericFutureListener<Future<Void>>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
LOGGER.warn("Error during SASL Auth negotiation phase.", future);
originalPromise().setFailure(future.cause());
}
}
});
} else {
throw new AuthenticationException("SASL Challenge evaluation returned null.");
}
}
|
java
|
private void handleAuthResponse(final ChannelHandlerContext ctx, final ByteBuf msg) throws Exception {
if (saslClient.isComplete()) {
checkIsAuthed(ctx, MessageUtil.getResponseStatus(msg));
return;
}
ByteBuf challengeBuf = SaslAuthResponse.challenge(msg);
byte[] challenge = new byte[challengeBuf.readableBytes()];
challengeBuf.readBytes(challenge);
byte[] evaluatedBytes = saslClient.evaluateChallenge(challenge);
if (evaluatedBytes != null) {
ByteBuf content;
// This is needed against older server versions where the protocol does not
// align on cram and plain, the else block is used for all the newer cram-sha*
// mechanisms.
//
// Note that most likely this is only executed in the CRAM-MD5 case only, but
// just to play it safe keep it for both mechanisms.
if (selectedMechanism.equals("CRAM-MD5") || selectedMechanism.equals("PLAIN")) {
String[] evaluated = new String(evaluatedBytes).split(" ");
content = Unpooled.copiedBuffer(username + "\0" + evaluated[1], CharsetUtil.UTF_8);
} else {
content = Unpooled.wrappedBuffer(evaluatedBytes);
}
ByteBuf request = ctx.alloc().buffer();
SaslStepRequest.init(request);
SaslStepRequest.mechanism(selectedMechanism, request);
SaslStepRequest.challengeResponse(content, request);
ChannelFuture future = ctx.writeAndFlush(request);
future.addListener(new GenericFutureListener<Future<Void>>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
LOGGER.warn("Error during SASL Auth negotiation phase.", future);
originalPromise().setFailure(future.cause());
}
}
});
} else {
throw new AuthenticationException("SASL Challenge evaluation returned null.");
}
}
|
[
"private",
"void",
"handleAuthResponse",
"(",
"final",
"ChannelHandlerContext",
"ctx",
",",
"final",
"ByteBuf",
"msg",
")",
"throws",
"Exception",
"{",
"if",
"(",
"saslClient",
".",
"isComplete",
"(",
")",
")",
"{",
"checkIsAuthed",
"(",
"ctx",
",",
"MessageUtil",
".",
"getResponseStatus",
"(",
"msg",
")",
")",
";",
"return",
";",
"}",
"ByteBuf",
"challengeBuf",
"=",
"SaslAuthResponse",
".",
"challenge",
"(",
"msg",
")",
";",
"byte",
"[",
"]",
"challenge",
"=",
"new",
"byte",
"[",
"challengeBuf",
".",
"readableBytes",
"(",
")",
"]",
";",
"challengeBuf",
".",
"readBytes",
"(",
"challenge",
")",
";",
"byte",
"[",
"]",
"evaluatedBytes",
"=",
"saslClient",
".",
"evaluateChallenge",
"(",
"challenge",
")",
";",
"if",
"(",
"evaluatedBytes",
"!=",
"null",
")",
"{",
"ByteBuf",
"content",
";",
"// This is needed against older server versions where the protocol does not",
"// align on cram and plain, the else block is used for all the newer cram-sha*",
"// mechanisms.",
"//",
"// Note that most likely this is only executed in the CRAM-MD5 case only, but",
"// just to play it safe keep it for both mechanisms.",
"if",
"(",
"selectedMechanism",
".",
"equals",
"(",
"\"CRAM-MD5\"",
")",
"||",
"selectedMechanism",
".",
"equals",
"(",
"\"PLAIN\"",
")",
")",
"{",
"String",
"[",
"]",
"evaluated",
"=",
"new",
"String",
"(",
"evaluatedBytes",
")",
".",
"split",
"(",
"\" \"",
")",
";",
"content",
"=",
"Unpooled",
".",
"copiedBuffer",
"(",
"username",
"+",
"\"\\0\"",
"+",
"evaluated",
"[",
"1",
"]",
",",
"CharsetUtil",
".",
"UTF_8",
")",
";",
"}",
"else",
"{",
"content",
"=",
"Unpooled",
".",
"wrappedBuffer",
"(",
"evaluatedBytes",
")",
";",
"}",
"ByteBuf",
"request",
"=",
"ctx",
".",
"alloc",
"(",
")",
".",
"buffer",
"(",
")",
";",
"SaslStepRequest",
".",
"init",
"(",
"request",
")",
";",
"SaslStepRequest",
".",
"mechanism",
"(",
"selectedMechanism",
",",
"request",
")",
";",
"SaslStepRequest",
".",
"challengeResponse",
"(",
"content",
",",
"request",
")",
";",
"ChannelFuture",
"future",
"=",
"ctx",
".",
"writeAndFlush",
"(",
"request",
")",
";",
"future",
".",
"addListener",
"(",
"new",
"GenericFutureListener",
"<",
"Future",
"<",
"Void",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"operationComplete",
"(",
"Future",
"<",
"Void",
">",
"future",
")",
"throws",
"Exception",
"{",
"if",
"(",
"!",
"future",
".",
"isSuccess",
"(",
")",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Error during SASL Auth negotiation phase.\"",
",",
"future",
")",
";",
"originalPromise",
"(",
")",
".",
"setFailure",
"(",
"future",
".",
"cause",
"(",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"AuthenticationException",
"(",
"\"SASL Challenge evaluation returned null.\"",
")",
";",
"}",
"}"
] |
Runs the SASL challenge protocol and dispatches the next step if required.
|
[
"Runs",
"the",
"SASL",
"challenge",
"protocol",
"and",
"dispatches",
"the",
"next",
"step",
"if",
"required",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/AuthHandler.java#L123-L169
|
4,209 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/AuthHandler.java
|
AuthHandler.checkIsAuthed
|
private void checkIsAuthed(final ChannelHandlerContext ctx, final ResponseStatus status) {
if (status.isSuccess()) {
LOGGER.debug("Successfully authenticated against node {}", ctx.channel().remoteAddress());
ctx.pipeline().remove(this);
originalPromise().setSuccess();
ctx.fireChannelActive();
} else if (status == AUTH_ERROR) {
originalPromise().setFailure(new AuthenticationException("SASL Authentication Failure"));
} else {
originalPromise().setFailure(new AuthenticationException("Unhandled SASL auth status: " + status));
}
}
|
java
|
private void checkIsAuthed(final ChannelHandlerContext ctx, final ResponseStatus status) {
if (status.isSuccess()) {
LOGGER.debug("Successfully authenticated against node {}", ctx.channel().remoteAddress());
ctx.pipeline().remove(this);
originalPromise().setSuccess();
ctx.fireChannelActive();
} else if (status == AUTH_ERROR) {
originalPromise().setFailure(new AuthenticationException("SASL Authentication Failure"));
} else {
originalPromise().setFailure(new AuthenticationException("Unhandled SASL auth status: " + status));
}
}
|
[
"private",
"void",
"checkIsAuthed",
"(",
"final",
"ChannelHandlerContext",
"ctx",
",",
"final",
"ResponseStatus",
"status",
")",
"{",
"if",
"(",
"status",
".",
"isSuccess",
"(",
")",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Successfully authenticated against node {}\"",
",",
"ctx",
".",
"channel",
"(",
")",
".",
"remoteAddress",
"(",
")",
")",
";",
"ctx",
".",
"pipeline",
"(",
")",
".",
"remove",
"(",
"this",
")",
";",
"originalPromise",
"(",
")",
".",
"setSuccess",
"(",
")",
";",
"ctx",
".",
"fireChannelActive",
"(",
")",
";",
"}",
"else",
"if",
"(",
"status",
"==",
"AUTH_ERROR",
")",
"{",
"originalPromise",
"(",
")",
".",
"setFailure",
"(",
"new",
"AuthenticationException",
"(",
"\"SASL Authentication Failure\"",
")",
")",
";",
"}",
"else",
"{",
"originalPromise",
"(",
")",
".",
"setFailure",
"(",
"new",
"AuthenticationException",
"(",
"\"Unhandled SASL auth status: \"",
"+",
"status",
")",
")",
";",
"}",
"}"
] |
Check if the authentication process succeeded or failed based on the response status.
|
[
"Check",
"if",
"the",
"authentication",
"process",
"succeeded",
"or",
"failed",
"based",
"on",
"the",
"response",
"status",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/AuthHandler.java#L174-L187
|
4,210 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/AuthHandler.java
|
AuthHandler.handleListMechsResponse
|
private void handleListMechsResponse(final ChannelHandlerContext ctx, final ByteBuf msg) throws Exception {
String remote = ctx.channel().remoteAddress().toString();
String[] supportedMechanisms = SaslListMechsResponse.supportedMechs(msg);
if (supportedMechanisms.length == 0) {
throw new AuthenticationException("Received empty SASL mechanisms list from server: " + remote);
}
saslClient = Sasl.createSaslClient(supportedMechanisms, null, "couchbase", remote, null, this);
selectedMechanism = saslClient.getMechanismName();
byte[] bytePayload = saslClient.hasInitialResponse() ? saslClient.evaluateChallenge(new byte[]{}) : null;
ByteBuf payload = bytePayload != null ? ctx.alloc().buffer().writeBytes(bytePayload) : Unpooled.EMPTY_BUFFER;
ByteBuf request = ctx.alloc().buffer();
SaslAuthRequest.init(request);
SaslAuthRequest.mechanism(selectedMechanism, request);
SaslAuthRequest.challengeResponse(payload, request);
payload.release();
ChannelFuture future = ctx.writeAndFlush(request);
future.addListener(new GenericFutureListener<Future<Void>>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
LOGGER.warn("Error during SASL Auth negotiation phase.", future);
originalPromise().setFailure(future.cause());
}
}
});
}
|
java
|
private void handleListMechsResponse(final ChannelHandlerContext ctx, final ByteBuf msg) throws Exception {
String remote = ctx.channel().remoteAddress().toString();
String[] supportedMechanisms = SaslListMechsResponse.supportedMechs(msg);
if (supportedMechanisms.length == 0) {
throw new AuthenticationException("Received empty SASL mechanisms list from server: " + remote);
}
saslClient = Sasl.createSaslClient(supportedMechanisms, null, "couchbase", remote, null, this);
selectedMechanism = saslClient.getMechanismName();
byte[] bytePayload = saslClient.hasInitialResponse() ? saslClient.evaluateChallenge(new byte[]{}) : null;
ByteBuf payload = bytePayload != null ? ctx.alloc().buffer().writeBytes(bytePayload) : Unpooled.EMPTY_BUFFER;
ByteBuf request = ctx.alloc().buffer();
SaslAuthRequest.init(request);
SaslAuthRequest.mechanism(selectedMechanism, request);
SaslAuthRequest.challengeResponse(payload, request);
payload.release();
ChannelFuture future = ctx.writeAndFlush(request);
future.addListener(new GenericFutureListener<Future<Void>>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
LOGGER.warn("Error during SASL Auth negotiation phase.", future);
originalPromise().setFailure(future.cause());
}
}
});
}
|
[
"private",
"void",
"handleListMechsResponse",
"(",
"final",
"ChannelHandlerContext",
"ctx",
",",
"final",
"ByteBuf",
"msg",
")",
"throws",
"Exception",
"{",
"String",
"remote",
"=",
"ctx",
".",
"channel",
"(",
")",
".",
"remoteAddress",
"(",
")",
".",
"toString",
"(",
")",
";",
"String",
"[",
"]",
"supportedMechanisms",
"=",
"SaslListMechsResponse",
".",
"supportedMechs",
"(",
"msg",
")",
";",
"if",
"(",
"supportedMechanisms",
".",
"length",
"==",
"0",
")",
"{",
"throw",
"new",
"AuthenticationException",
"(",
"\"Received empty SASL mechanisms list from server: \"",
"+",
"remote",
")",
";",
"}",
"saslClient",
"=",
"Sasl",
".",
"createSaslClient",
"(",
"supportedMechanisms",
",",
"null",
",",
"\"couchbase\"",
",",
"remote",
",",
"null",
",",
"this",
")",
";",
"selectedMechanism",
"=",
"saslClient",
".",
"getMechanismName",
"(",
")",
";",
"byte",
"[",
"]",
"bytePayload",
"=",
"saslClient",
".",
"hasInitialResponse",
"(",
")",
"?",
"saslClient",
".",
"evaluateChallenge",
"(",
"new",
"byte",
"[",
"]",
"{",
"}",
")",
":",
"null",
";",
"ByteBuf",
"payload",
"=",
"bytePayload",
"!=",
"null",
"?",
"ctx",
".",
"alloc",
"(",
")",
".",
"buffer",
"(",
")",
".",
"writeBytes",
"(",
"bytePayload",
")",
":",
"Unpooled",
".",
"EMPTY_BUFFER",
";",
"ByteBuf",
"request",
"=",
"ctx",
".",
"alloc",
"(",
")",
".",
"buffer",
"(",
")",
";",
"SaslAuthRequest",
".",
"init",
"(",
"request",
")",
";",
"SaslAuthRequest",
".",
"mechanism",
"(",
"selectedMechanism",
",",
"request",
")",
";",
"SaslAuthRequest",
".",
"challengeResponse",
"(",
"payload",
",",
"request",
")",
";",
"payload",
".",
"release",
"(",
")",
";",
"ChannelFuture",
"future",
"=",
"ctx",
".",
"writeAndFlush",
"(",
"request",
")",
";",
"future",
".",
"addListener",
"(",
"new",
"GenericFutureListener",
"<",
"Future",
"<",
"Void",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"operationComplete",
"(",
"Future",
"<",
"Void",
">",
"future",
")",
"throws",
"Exception",
"{",
"if",
"(",
"!",
"future",
".",
"isSuccess",
"(",
")",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Error during SASL Auth negotiation phase.\"",
",",
"future",
")",
";",
"originalPromise",
"(",
")",
".",
"setFailure",
"(",
"future",
".",
"cause",
"(",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Helper method to parse the list of supported SASL mechs and dispatch the initial auth request following.
|
[
"Helper",
"method",
"to",
"parse",
"the",
"list",
"of",
"supported",
"SASL",
"mechs",
"and",
"dispatch",
"the",
"initial",
"auth",
"request",
"following",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/AuthHandler.java#L192-L221
|
4,211 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/conductor/DcpChannel.java
|
DcpChannel.getSeqnos
|
public Single<ByteBuf> getSeqnos() {
return Single.create(new Single.OnSubscribe<ByteBuf>() {
@Override
public void call(final SingleSubscriber<? super ByteBuf> subscriber) {
if (state() != LifecycleState.CONNECTED) {
subscriber.onError(new NotConnectedException());
return;
}
ByteBuf buffer = Unpooled.buffer();
DcpGetPartitionSeqnosRequest.init(buffer);
DcpGetPartitionSeqnosRequest.vbucketState(buffer, VbucketState.ACTIVE);
sendRequest(buffer).addListener(new DcpResponseListener() {
@Override
public void operationComplete(Future<DcpResponse> future) throws Exception {
if (future.isSuccess()) {
ByteBuf buf = future.getNow().buffer();
try {
subscriber.onSuccess(MessageUtil.getContent(buf).copy());
} finally {
buf.release();
}
} else {
subscriber.onError(future.cause());
}
}
});
}
});
}
|
java
|
public Single<ByteBuf> getSeqnos() {
return Single.create(new Single.OnSubscribe<ByteBuf>() {
@Override
public void call(final SingleSubscriber<? super ByteBuf> subscriber) {
if (state() != LifecycleState.CONNECTED) {
subscriber.onError(new NotConnectedException());
return;
}
ByteBuf buffer = Unpooled.buffer();
DcpGetPartitionSeqnosRequest.init(buffer);
DcpGetPartitionSeqnosRequest.vbucketState(buffer, VbucketState.ACTIVE);
sendRequest(buffer).addListener(new DcpResponseListener() {
@Override
public void operationComplete(Future<DcpResponse> future) throws Exception {
if (future.isSuccess()) {
ByteBuf buf = future.getNow().buffer();
try {
subscriber.onSuccess(MessageUtil.getContent(buf).copy());
} finally {
buf.release();
}
} else {
subscriber.onError(future.cause());
}
}
});
}
});
}
|
[
"public",
"Single",
"<",
"ByteBuf",
">",
"getSeqnos",
"(",
")",
"{",
"return",
"Single",
".",
"create",
"(",
"new",
"Single",
".",
"OnSubscribe",
"<",
"ByteBuf",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"call",
"(",
"final",
"SingleSubscriber",
"<",
"?",
"super",
"ByteBuf",
">",
"subscriber",
")",
"{",
"if",
"(",
"state",
"(",
")",
"!=",
"LifecycleState",
".",
"CONNECTED",
")",
"{",
"subscriber",
".",
"onError",
"(",
"new",
"NotConnectedException",
"(",
")",
")",
";",
"return",
";",
"}",
"ByteBuf",
"buffer",
"=",
"Unpooled",
".",
"buffer",
"(",
")",
";",
"DcpGetPartitionSeqnosRequest",
".",
"init",
"(",
"buffer",
")",
";",
"DcpGetPartitionSeqnosRequest",
".",
"vbucketState",
"(",
"buffer",
",",
"VbucketState",
".",
"ACTIVE",
")",
";",
"sendRequest",
"(",
"buffer",
")",
".",
"addListener",
"(",
"new",
"DcpResponseListener",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"operationComplete",
"(",
"Future",
"<",
"DcpResponse",
">",
"future",
")",
"throws",
"Exception",
"{",
"if",
"(",
"future",
".",
"isSuccess",
"(",
")",
")",
"{",
"ByteBuf",
"buf",
"=",
"future",
".",
"getNow",
"(",
")",
".",
"buffer",
"(",
")",
";",
"try",
"{",
"subscriber",
".",
"onSuccess",
"(",
"MessageUtil",
".",
"getContent",
"(",
"buf",
")",
".",
"copy",
"(",
")",
")",
";",
"}",
"finally",
"{",
"buf",
".",
"release",
"(",
")",
";",
"}",
"}",
"else",
"{",
"subscriber",
".",
"onError",
"(",
"future",
".",
"cause",
"(",
")",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Returns all seqnos for all vbuckets on that channel.
|
[
"Returns",
"all",
"seqnos",
"for",
"all",
"vbuckets",
"on",
"that",
"channel",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/conductor/DcpChannel.java#L448-L478
|
4,212 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/util/retry/RetryBuilder.java
|
RetryBuilder.anyOf
|
@SafeVarargs
public static RetryBuilder anyOf(Class<? extends Throwable>... types) {
RetryBuilder retryBuilder = new RetryBuilder();
retryBuilder.maxAttempts = 1;
retryBuilder.errorsStoppingRetry = Arrays.asList(types);
retryBuilder.inverse = true;
return retryBuilder;
}
|
java
|
@SafeVarargs
public static RetryBuilder anyOf(Class<? extends Throwable>... types) {
RetryBuilder retryBuilder = new RetryBuilder();
retryBuilder.maxAttempts = 1;
retryBuilder.errorsStoppingRetry = Arrays.asList(types);
retryBuilder.inverse = true;
return retryBuilder;
}
|
[
"@",
"SafeVarargs",
"public",
"static",
"RetryBuilder",
"anyOf",
"(",
"Class",
"<",
"?",
"extends",
"Throwable",
">",
"...",
"types",
")",
"{",
"RetryBuilder",
"retryBuilder",
"=",
"new",
"RetryBuilder",
"(",
")",
";",
"retryBuilder",
".",
"maxAttempts",
"=",
"1",
";",
"retryBuilder",
".",
"errorsStoppingRetry",
"=",
"Arrays",
".",
"asList",
"(",
"types",
")",
";",
"retryBuilder",
".",
"inverse",
"=",
"true",
";",
"return",
"retryBuilder",
";",
"}"
] |
Only errors that are instanceOf the specified types will trigger a retry
|
[
"Only",
"errors",
"that",
"are",
"instanceOf",
"the",
"specified",
"types",
"will",
"trigger",
"a",
"retry"
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/util/retry/RetryBuilder.java#L73-L82
|
4,213 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/util/retry/RetryBuilder.java
|
RetryBuilder.allBut
|
@SafeVarargs
public static RetryBuilder allBut(Class<? extends Throwable>... types) {
RetryBuilder retryBuilder = new RetryBuilder();
retryBuilder.maxAttempts = 1;
retryBuilder.errorsStoppingRetry = Arrays.asList(types);
retryBuilder.inverse = false;
return retryBuilder;
}
|
java
|
@SafeVarargs
public static RetryBuilder allBut(Class<? extends Throwable>... types) {
RetryBuilder retryBuilder = new RetryBuilder();
retryBuilder.maxAttempts = 1;
retryBuilder.errorsStoppingRetry = Arrays.asList(types);
retryBuilder.inverse = false;
return retryBuilder;
}
|
[
"@",
"SafeVarargs",
"public",
"static",
"RetryBuilder",
"allBut",
"(",
"Class",
"<",
"?",
"extends",
"Throwable",
">",
"...",
"types",
")",
"{",
"RetryBuilder",
"retryBuilder",
"=",
"new",
"RetryBuilder",
"(",
")",
";",
"retryBuilder",
".",
"maxAttempts",
"=",
"1",
";",
"retryBuilder",
".",
"errorsStoppingRetry",
"=",
"Arrays",
".",
"asList",
"(",
"types",
")",
";",
"retryBuilder",
".",
"inverse",
"=",
"false",
";",
"return",
"retryBuilder",
";",
"}"
] |
Only errors that are NOT instanceOf the specified types will trigger a retry
|
[
"Only",
"errors",
"that",
"are",
"NOT",
"instanceOf",
"the",
"specified",
"types",
"will",
"trigger",
"a",
"retry"
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/util/retry/RetryBuilder.java#L87-L96
|
4,214 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/util/retry/RetryBuilder.java
|
RetryBuilder.anyMatches
|
public static RetryBuilder anyMatches(Func1<Throwable, Boolean> retryErrorPredicate) {
RetryBuilder retryBuilder = new RetryBuilder();
retryBuilder.maxAttempts = 1;
retryBuilder.retryErrorPredicate = retryErrorPredicate;
return retryBuilder;
}
|
java
|
public static RetryBuilder anyMatches(Func1<Throwable, Boolean> retryErrorPredicate) {
RetryBuilder retryBuilder = new RetryBuilder();
retryBuilder.maxAttempts = 1;
retryBuilder.retryErrorPredicate = retryErrorPredicate;
return retryBuilder;
}
|
[
"public",
"static",
"RetryBuilder",
"anyMatches",
"(",
"Func1",
"<",
"Throwable",
",",
"Boolean",
">",
"retryErrorPredicate",
")",
"{",
"RetryBuilder",
"retryBuilder",
"=",
"new",
"RetryBuilder",
"(",
")",
";",
"retryBuilder",
".",
"maxAttempts",
"=",
"1",
";",
"retryBuilder",
".",
"retryErrorPredicate",
"=",
"retryErrorPredicate",
";",
"return",
"retryBuilder",
";",
"}"
] |
Any error that pass the predicate will trigger a retry
|
[
"Any",
"error",
"that",
"pass",
"the",
"predicate",
"will",
"trigger",
"a",
"retry"
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/util/retry/RetryBuilder.java#L110-L116
|
4,215 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/DynamicMessage.java
|
DynamicMessage.get
|
public Value get(String name) {
if (name.length() > 1) {
int dot;
if (name.charAt(0) == LPAREN) {
int start = name.indexOf(RPAREN);
dot = name.indexOf(DOT, start);
} else {
dot = name.indexOf(DOT);
}
if (dot > 0) {
String fieldName = name.substring(0, dot);
String rest = name.substring(dot + 1);
Key key = createKey(fieldName);
Value value = fields.get(key);
if (!value.isMessageType()) {
throw new ParserException("Invalid option name: %s", name);
}
DynamicMessage msg = value.getMessage();
return msg.get(rest);
} else {
Key key = createKey(name);
return fields.get(key);
}
} else {
Key key = Key.field(name);
return fields.get(key);
}
}
|
java
|
public Value get(String name) {
if (name.length() > 1) {
int dot;
if (name.charAt(0) == LPAREN) {
int start = name.indexOf(RPAREN);
dot = name.indexOf(DOT, start);
} else {
dot = name.indexOf(DOT);
}
if (dot > 0) {
String fieldName = name.substring(0, dot);
String rest = name.substring(dot + 1);
Key key = createKey(fieldName);
Value value = fields.get(key);
if (!value.isMessageType()) {
throw new ParserException("Invalid option name: %s", name);
}
DynamicMessage msg = value.getMessage();
return msg.get(rest);
} else {
Key key = createKey(name);
return fields.get(key);
}
} else {
Key key = Key.field(name);
return fields.get(key);
}
}
|
[
"public",
"Value",
"get",
"(",
"String",
"name",
")",
"{",
"if",
"(",
"name",
".",
"length",
"(",
")",
">",
"1",
")",
"{",
"int",
"dot",
";",
"if",
"(",
"name",
".",
"charAt",
"(",
"0",
")",
"==",
"LPAREN",
")",
"{",
"int",
"start",
"=",
"name",
".",
"indexOf",
"(",
"RPAREN",
")",
";",
"dot",
"=",
"name",
".",
"indexOf",
"(",
"DOT",
",",
"start",
")",
";",
"}",
"else",
"{",
"dot",
"=",
"name",
".",
"indexOf",
"(",
"DOT",
")",
";",
"}",
"if",
"(",
"dot",
">",
"0",
")",
"{",
"String",
"fieldName",
"=",
"name",
".",
"substring",
"(",
"0",
",",
"dot",
")",
";",
"String",
"rest",
"=",
"name",
".",
"substring",
"(",
"dot",
"+",
"1",
")",
";",
"Key",
"key",
"=",
"createKey",
"(",
"fieldName",
")",
";",
"Value",
"value",
"=",
"fields",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"!",
"value",
".",
"isMessageType",
"(",
")",
")",
"{",
"throw",
"new",
"ParserException",
"(",
"\"Invalid option name: %s\"",
",",
"name",
")",
";",
"}",
"DynamicMessage",
"msg",
"=",
"value",
".",
"getMessage",
"(",
")",
";",
"return",
"msg",
".",
"get",
"(",
"rest",
")",
";",
"}",
"else",
"{",
"Key",
"key",
"=",
"createKey",
"(",
"name",
")",
";",
"return",
"fields",
".",
"get",
"(",
"key",
")",
";",
"}",
"}",
"else",
"{",
"Key",
"key",
"=",
"Key",
".",
"field",
"(",
"name",
")",
";",
"return",
"fields",
".",
"get",
"(",
"key",
")",
";",
"}",
"}"
] |
Get option value by given option name.
|
[
"Get",
"option",
"value",
"by",
"given",
"option",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/DynamicMessage.java#L47-L74
|
4,216 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/DynamicMessage.java
|
DynamicMessage.set
|
public void set(SourceCodeLocation sourceCodeLocation, String name, Value value) {
if (name.length() > 1) {
int dot;
if (name.charAt(0) == LPAREN) {
int start = name.indexOf(RPAREN);
dot = name.indexOf(DOT, start);
} else {
dot = name.indexOf(DOT);
}
if (dot > 0) {
String fieldName = name.substring(0, dot);
String rest = name.substring(dot + 1);
Key key = createKey(fieldName);
DynamicMessage msg;
if (fields.containsKey(key)) {
msg = getChildMessage(value, key);
} else {
msg = new DynamicMessage();
fields.put(key, Value.createMessage(sourceCodeLocation, msg));
}
msg.set(sourceCodeLocation, rest, value);
} else {
Key key = createKey(name);
set(key, value);
}
} else {
Key key = Key.field(name);
set(key, value);
}
}
|
java
|
public void set(SourceCodeLocation sourceCodeLocation, String name, Value value) {
if (name.length() > 1) {
int dot;
if (name.charAt(0) == LPAREN) {
int start = name.indexOf(RPAREN);
dot = name.indexOf(DOT, start);
} else {
dot = name.indexOf(DOT);
}
if (dot > 0) {
String fieldName = name.substring(0, dot);
String rest = name.substring(dot + 1);
Key key = createKey(fieldName);
DynamicMessage msg;
if (fields.containsKey(key)) {
msg = getChildMessage(value, key);
} else {
msg = new DynamicMessage();
fields.put(key, Value.createMessage(sourceCodeLocation, msg));
}
msg.set(sourceCodeLocation, rest, value);
} else {
Key key = createKey(name);
set(key, value);
}
} else {
Key key = Key.field(name);
set(key, value);
}
}
|
[
"public",
"void",
"set",
"(",
"SourceCodeLocation",
"sourceCodeLocation",
",",
"String",
"name",
",",
"Value",
"value",
")",
"{",
"if",
"(",
"name",
".",
"length",
"(",
")",
">",
"1",
")",
"{",
"int",
"dot",
";",
"if",
"(",
"name",
".",
"charAt",
"(",
"0",
")",
"==",
"LPAREN",
")",
"{",
"int",
"start",
"=",
"name",
".",
"indexOf",
"(",
"RPAREN",
")",
";",
"dot",
"=",
"name",
".",
"indexOf",
"(",
"DOT",
",",
"start",
")",
";",
"}",
"else",
"{",
"dot",
"=",
"name",
".",
"indexOf",
"(",
"DOT",
")",
";",
"}",
"if",
"(",
"dot",
">",
"0",
")",
"{",
"String",
"fieldName",
"=",
"name",
".",
"substring",
"(",
"0",
",",
"dot",
")",
";",
"String",
"rest",
"=",
"name",
".",
"substring",
"(",
"dot",
"+",
"1",
")",
";",
"Key",
"key",
"=",
"createKey",
"(",
"fieldName",
")",
";",
"DynamicMessage",
"msg",
";",
"if",
"(",
"fields",
".",
"containsKey",
"(",
"key",
")",
")",
"{",
"msg",
"=",
"getChildMessage",
"(",
"value",
",",
"key",
")",
";",
"}",
"else",
"{",
"msg",
"=",
"new",
"DynamicMessage",
"(",
")",
";",
"fields",
".",
"put",
"(",
"key",
",",
"Value",
".",
"createMessage",
"(",
"sourceCodeLocation",
",",
"msg",
")",
")",
";",
"}",
"msg",
".",
"set",
"(",
"sourceCodeLocation",
",",
"rest",
",",
"value",
")",
";",
"}",
"else",
"{",
"Key",
"key",
"=",
"createKey",
"(",
"name",
")",
";",
"set",
"(",
"key",
",",
"value",
")",
";",
"}",
"}",
"else",
"{",
"Key",
"key",
"=",
"Key",
".",
"field",
"(",
"name",
")",
";",
"set",
"(",
"key",
",",
"value",
")",
";",
"}",
"}"
] |
Set field of an option to a given value.
|
[
"Set",
"field",
"of",
"an",
"option",
"to",
"a",
"given",
"value",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/DynamicMessage.java#L83-L112
|
4,217 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/DynamicMessage.java
|
DynamicMessage.normalizeName
|
public void normalizeName(Key key, String fullyQualifiedName) {
Value value = fields.remove(key);
if (value == null) {
throw new IllegalStateException("Could not find option for key=" + key);
}
Key newKey;
if (fullyQualifiedName.startsWith(".")) {
// TODO: we should not use format with leading dot internally
newKey = Key.extension(fullyQualifiedName.substring(1));
} else {
newKey = Key.extension(fullyQualifiedName);
}
fields.put(newKey, value);
}
|
java
|
public void normalizeName(Key key, String fullyQualifiedName) {
Value value = fields.remove(key);
if (value == null) {
throw new IllegalStateException("Could not find option for key=" + key);
}
Key newKey;
if (fullyQualifiedName.startsWith(".")) {
// TODO: we should not use format with leading dot internally
newKey = Key.extension(fullyQualifiedName.substring(1));
} else {
newKey = Key.extension(fullyQualifiedName);
}
fields.put(newKey, value);
}
|
[
"public",
"void",
"normalizeName",
"(",
"Key",
"key",
",",
"String",
"fullyQualifiedName",
")",
"{",
"Value",
"value",
"=",
"fields",
".",
"remove",
"(",
"key",
")",
";",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Could not find option for key=\"",
"+",
"key",
")",
";",
"}",
"Key",
"newKey",
";",
"if",
"(",
"fullyQualifiedName",
".",
"startsWith",
"(",
"\".\"",
")",
")",
"{",
"// TODO: we should not use format with leading dot internally",
"newKey",
"=",
"Key",
".",
"extension",
"(",
"fullyQualifiedName",
".",
"substring",
"(",
"1",
")",
")",
";",
"}",
"else",
"{",
"newKey",
"=",
"Key",
".",
"extension",
"(",
"fullyQualifiedName",
")",
";",
"}",
"fields",
".",
"put",
"(",
"newKey",
",",
"value",
")",
";",
"}"
] |
Change option name to its fully qualified name.
|
[
"Change",
"option",
"name",
"to",
"its",
"fully",
"qualified",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/DynamicMessage.java#L245-L258
|
4,218 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/DynamicMessage.java
|
DynamicMessage.toMap
|
public Map<String, Object> toMap() {
Map<String, Object> result = new HashMap<>();
for (Entry<Key, Value> keyValueEntry : fields.entrySet()) {
Key key = keyValueEntry.getKey();
Value value = keyValueEntry.getValue();
if (!key.isExtension()) {
result.put(key.getName(), transformValueToObject(value));
} else {
result.put("(" + key.getName() + ")", transformValueToObject(value));
}
}
return result;
}
|
java
|
public Map<String, Object> toMap() {
Map<String, Object> result = new HashMap<>();
for (Entry<Key, Value> keyValueEntry : fields.entrySet()) {
Key key = keyValueEntry.getKey();
Value value = keyValueEntry.getValue();
if (!key.isExtension()) {
result.put(key.getName(), transformValueToObject(value));
} else {
result.put("(" + key.getName() + ")", transformValueToObject(value));
}
}
return result;
}
|
[
"public",
"Map",
"<",
"String",
",",
"Object",
">",
"toMap",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"Object",
">",
"result",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"Entry",
"<",
"Key",
",",
"Value",
">",
"keyValueEntry",
":",
"fields",
".",
"entrySet",
"(",
")",
")",
"{",
"Key",
"key",
"=",
"keyValueEntry",
".",
"getKey",
"(",
")",
";",
"Value",
"value",
"=",
"keyValueEntry",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"!",
"key",
".",
"isExtension",
"(",
")",
")",
"{",
"result",
".",
"put",
"(",
"key",
".",
"getName",
"(",
")",
",",
"transformValueToObject",
"(",
"value",
")",
")",
";",
"}",
"else",
"{",
"result",
".",
"put",
"(",
"\"(\"",
"+",
"key",
".",
"getName",
"(",
")",
"+",
"\")\"",
",",
"transformValueToObject",
"(",
"value",
")",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Returns a map of option names as keys and option values as values..
|
[
"Returns",
"a",
"map",
"of",
"option",
"names",
"as",
"keys",
"and",
"option",
"values",
"as",
"values",
".."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/DynamicMessage.java#L263-L275
|
4,219 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/CompilerUtils.java
|
CompilerUtils.copyResource
|
public void copyResource(String name, String destinationFilename) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
String error = "Can not obtain classloader instance";
throw new IllegalStateException(error);
}
try (InputStream stream = classLoader.getResourceAsStream(name)) {
if (stream == null) {
String error = "Could not copy file, source file not found: " + name;
throw new IllegalStateException(error);
}
Path path = Paths.get(destinationFilename);
FileUtils.copyInputStreamToFile(stream, path.toFile());
} catch (IOException e) {
throw new GeneratorException("Could not copy %s", e, name);
}
}
|
java
|
public void copyResource(String name, String destinationFilename) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
String error = "Can not obtain classloader instance";
throw new IllegalStateException(error);
}
try (InputStream stream = classLoader.getResourceAsStream(name)) {
if (stream == null) {
String error = "Could not copy file, source file not found: " + name;
throw new IllegalStateException(error);
}
Path path = Paths.get(destinationFilename);
FileUtils.copyInputStreamToFile(stream, path.toFile());
} catch (IOException e) {
throw new GeneratorException("Could not copy %s", e, name);
}
}
|
[
"public",
"void",
"copyResource",
"(",
"String",
"name",
",",
"String",
"destinationFilename",
")",
"{",
"ClassLoader",
"classLoader",
"=",
"Thread",
".",
"currentThread",
"(",
")",
".",
"getContextClassLoader",
"(",
")",
";",
"if",
"(",
"classLoader",
"==",
"null",
")",
"{",
"String",
"error",
"=",
"\"Can not obtain classloader instance\"",
";",
"throw",
"new",
"IllegalStateException",
"(",
"error",
")",
";",
"}",
"try",
"(",
"InputStream",
"stream",
"=",
"classLoader",
".",
"getResourceAsStream",
"(",
"name",
")",
")",
"{",
"if",
"(",
"stream",
"==",
"null",
")",
"{",
"String",
"error",
"=",
"\"Could not copy file, source file not found: \"",
"+",
"name",
";",
"throw",
"new",
"IllegalStateException",
"(",
"error",
")",
";",
"}",
"Path",
"path",
"=",
"Paths",
".",
"get",
"(",
"destinationFilename",
")",
";",
"FileUtils",
".",
"copyInputStreamToFile",
"(",
"stream",
",",
"path",
".",
"toFile",
"(",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"GeneratorException",
"(",
"\"Could not copy %s\"",
",",
"e",
",",
"name",
")",
";",
"}",
"}"
] |
Copy a classpath resource to the given location on a filesystem.
|
[
"Copy",
"a",
"classpath",
"resource",
"to",
"the",
"given",
"location",
"on",
"a",
"filesystem",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/CompilerUtils.java#L32-L48
|
4,220 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/AbstractExtensionProvider.java
|
AbstractExtensionProvider.registerProperty
|
public final <T> void registerProperty(Class<T> object, String property, Function<T, Object> function) {
PropertyProvider extender = extenderMap.computeIfAbsent(object,
aClass -> new PropertyProviderImpl());
extender.register(property, function);
}
|
java
|
public final <T> void registerProperty(Class<T> object, String property, Function<T, Object> function) {
PropertyProvider extender = extenderMap.computeIfAbsent(object,
aClass -> new PropertyProviderImpl());
extender.register(property, function);
}
|
[
"public",
"final",
"<",
"T",
">",
"void",
"registerProperty",
"(",
"Class",
"<",
"T",
">",
"object",
",",
"String",
"property",
",",
"Function",
"<",
"T",
",",
"Object",
">",
"function",
")",
"{",
"PropertyProvider",
"extender",
"=",
"extenderMap",
".",
"computeIfAbsent",
"(",
"object",
",",
"aClass",
"->",
"new",
"PropertyProviderImpl",
"(",
")",
")",
";",
"extender",
".",
"register",
"(",
"property",
",",
"function",
")",
";",
"}"
] |
Register custom property for specified node type.
|
[
"Register",
"custom",
"property",
"for",
"specified",
"node",
"type",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/AbstractExtensionProvider.java#L28-L32
|
4,221 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getFieldType
|
public static String getFieldType(Field field) {
FieldType type = field.getType();
if (type instanceof ScalarFieldType) {
ScalarFieldType scalarFieldType = (ScalarFieldType) type;
return ScalarFieldTypeUtil.getPrimitiveType(scalarFieldType);
}
if (type instanceof UserType) {
UserType userType = (UserType) type;
return UserTypeUtil.getCanonicalName(userType);
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getFieldType(Field field) {
FieldType type = field.getType();
if (type instanceof ScalarFieldType) {
ScalarFieldType scalarFieldType = (ScalarFieldType) type;
return ScalarFieldTypeUtil.getPrimitiveType(scalarFieldType);
}
if (type instanceof UserType) {
UserType userType = (UserType) type;
return UserTypeUtil.getCanonicalName(userType);
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getFieldType",
"(",
"Field",
"field",
")",
"{",
"FieldType",
"type",
"=",
"field",
".",
"getType",
"(",
")",
";",
"if",
"(",
"type",
"instanceof",
"ScalarFieldType",
")",
"{",
"ScalarFieldType",
"scalarFieldType",
"=",
"(",
"ScalarFieldType",
")",
"type",
";",
"return",
"ScalarFieldTypeUtil",
".",
"getPrimitiveType",
"(",
"scalarFieldType",
")",
";",
"}",
"if",
"(",
"type",
"instanceof",
"UserType",
")",
"{",
"UserType",
"userType",
"=",
"(",
"UserType",
")",
"type",
";",
"return",
"UserTypeUtil",
".",
"getCanonicalName",
"(",
"userType",
")",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns a java field type for proto field.
|
[
"Returns",
"a",
"java",
"field",
"type",
"for",
"proto",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L69-L80
|
4,222 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getFieldName
|
public static String getFieldName(Field field) {
String name = field.getName();
String formattedName = Formatter.toCamelCase(name);
if (isReservedKeyword(formattedName)) {
return formattedName + '_';
}
return formattedName;
}
|
java
|
public static String getFieldName(Field field) {
String name = field.getName();
String formattedName = Formatter.toCamelCase(name);
if (isReservedKeyword(formattedName)) {
return formattedName + '_';
}
return formattedName;
}
|
[
"public",
"static",
"String",
"getFieldName",
"(",
"Field",
"field",
")",
"{",
"String",
"name",
"=",
"field",
".",
"getName",
"(",
")",
";",
"String",
"formattedName",
"=",
"Formatter",
".",
"toCamelCase",
"(",
"name",
")",
";",
"if",
"(",
"isReservedKeyword",
"(",
"formattedName",
")",
")",
"{",
"return",
"formattedName",
"+",
"'",
"'",
";",
"}",
"return",
"formattedName",
";",
"}"
] |
Returns a java field name for proto field.
|
[
"Returns",
"a",
"java",
"field",
"name",
"for",
"proto",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L85-L92
|
4,223 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getJsonFieldName
|
public static String getJsonFieldName(Field field) {
String name = field.getName();
return Formatter.toCamelCase(name);
}
|
java
|
public static String getJsonFieldName(Field field) {
String name = field.getName();
return Formatter.toCamelCase(name);
}
|
[
"public",
"static",
"String",
"getJsonFieldName",
"(",
"Field",
"field",
")",
"{",
"String",
"name",
"=",
"field",
".",
"getName",
"(",
")",
";",
"return",
"Formatter",
".",
"toCamelCase",
"(",
"name",
")",
";",
"}"
] |
Returns a json field name for proto field.
|
[
"Returns",
"a",
"json",
"field",
"name",
"for",
"proto",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L97-L100
|
4,224 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getFieldGetterName
|
public static String getFieldGetterName(Field field) {
String getterName = GETTER_PREFIX + Formatter.toPascalCase(field.getName());
if ("getClass".equals(getterName)) {
return getterName + "_";
}
return getterName;
}
|
java
|
public static String getFieldGetterName(Field field) {
String getterName = GETTER_PREFIX + Formatter.toPascalCase(field.getName());
if ("getClass".equals(getterName)) {
return getterName + "_";
}
return getterName;
}
|
[
"public",
"static",
"String",
"getFieldGetterName",
"(",
"Field",
"field",
")",
"{",
"String",
"getterName",
"=",
"GETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"\"getClass\"",
".",
"equals",
"(",
"getterName",
")",
")",
"{",
"return",
"getterName",
"+",
"\"_\"",
";",
"}",
"return",
"getterName",
";",
"}"
] |
Returns a java field getter name for proto field.
|
[
"Returns",
"a",
"java",
"field",
"getter",
"name",
"for",
"proto",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L109-L115
|
4,225 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getEnumFieldValueGetterName
|
public static String getEnumFieldValueGetterName(Field field) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE;
}
|
java
|
public static String getEnumFieldValueGetterName(Field field) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE;
}
|
[
"public",
"static",
"String",
"getEnumFieldValueGetterName",
"(",
"Field",
"field",
")",
"{",
"return",
"GETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
"+",
"VALUE",
";",
"}"
] |
Returns a java enum field value getter name for proto field.
|
[
"Returns",
"a",
"java",
"enum",
"field",
"value",
"getter",
"name",
"for",
"proto",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L134-L136
|
4,226 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getEnumFieldValueSetterName
|
public static String getEnumFieldValueSetterName(Field field) {
return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE;
}
|
java
|
public static String getEnumFieldValueSetterName(Field field) {
return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE;
}
|
[
"public",
"static",
"String",
"getEnumFieldValueSetterName",
"(",
"Field",
"field",
")",
"{",
"return",
"SETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
"+",
"VALUE",
";",
"}"
] |
Returns a java enum field value setter name for proto field.
|
[
"Returns",
"a",
"java",
"enum",
"field",
"value",
"setter",
"name",
"for",
"proto",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L141-L143
|
4,227 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getDefaultValue
|
public static String getDefaultValue(Field field) {
FieldType type = field.getType();
if (type instanceof ScalarFieldType) {
return ScalarFieldTypeUtil.getDefaultValue((ScalarFieldType) type);
}
if (type instanceof Message) {
Message m = (Message) type;
return UserTypeUtil.getCanonicalName(m) + ".getDefaultInstance()";
}
if (type instanceof Enum) {
Enum anEnum = (Enum) type;
String defaultValue;
List<EnumConstant> constants = anEnum.getConstants();
if (constants.isEmpty()) {
defaultValue = "UNRECOGNIZED";
} else {
DynamicMessage options = field.getOptions();
defaultValue = options.containsKey(DEFAULT) ? options.get(DEFAULT).getEnumName() : constants.get(0).getName();
}
return UserTypeUtil.getCanonicalName(anEnum) + "." + defaultValue;
}
throw new IllegalArgumentException(String.valueOf(type));
}
|
java
|
public static String getDefaultValue(Field field) {
FieldType type = field.getType();
if (type instanceof ScalarFieldType) {
return ScalarFieldTypeUtil.getDefaultValue((ScalarFieldType) type);
}
if (type instanceof Message) {
Message m = (Message) type;
return UserTypeUtil.getCanonicalName(m) + ".getDefaultInstance()";
}
if (type instanceof Enum) {
Enum anEnum = (Enum) type;
String defaultValue;
List<EnumConstant> constants = anEnum.getConstants();
if (constants.isEmpty()) {
defaultValue = "UNRECOGNIZED";
} else {
DynamicMessage options = field.getOptions();
defaultValue = options.containsKey(DEFAULT) ? options.get(DEFAULT).getEnumName() : constants.get(0).getName();
}
return UserTypeUtil.getCanonicalName(anEnum) + "." + defaultValue;
}
throw new IllegalArgumentException(String.valueOf(type));
}
|
[
"public",
"static",
"String",
"getDefaultValue",
"(",
"Field",
"field",
")",
"{",
"FieldType",
"type",
"=",
"field",
".",
"getType",
"(",
")",
";",
"if",
"(",
"type",
"instanceof",
"ScalarFieldType",
")",
"{",
"return",
"ScalarFieldTypeUtil",
".",
"getDefaultValue",
"(",
"(",
"ScalarFieldType",
")",
"type",
")",
";",
"}",
"if",
"(",
"type",
"instanceof",
"Message",
")",
"{",
"Message",
"m",
"=",
"(",
"Message",
")",
"type",
";",
"return",
"UserTypeUtil",
".",
"getCanonicalName",
"(",
"m",
")",
"+",
"\".getDefaultInstance()\"",
";",
"}",
"if",
"(",
"type",
"instanceof",
"Enum",
")",
"{",
"Enum",
"anEnum",
"=",
"(",
"Enum",
")",
"type",
";",
"String",
"defaultValue",
";",
"List",
"<",
"EnumConstant",
">",
"constants",
"=",
"anEnum",
".",
"getConstants",
"(",
")",
";",
"if",
"(",
"constants",
".",
"isEmpty",
"(",
")",
")",
"{",
"defaultValue",
"=",
"\"UNRECOGNIZED\"",
";",
"}",
"else",
"{",
"DynamicMessage",
"options",
"=",
"field",
".",
"getOptions",
"(",
")",
";",
"defaultValue",
"=",
"options",
".",
"containsKey",
"(",
"DEFAULT",
")",
"?",
"options",
".",
"get",
"(",
"DEFAULT",
")",
".",
"getEnumName",
"(",
")",
":",
"constants",
".",
"get",
"(",
"0",
")",
".",
"getName",
"(",
")",
";",
"}",
"return",
"UserTypeUtil",
".",
"getCanonicalName",
"(",
"anEnum",
")",
"+",
"\".\"",
"+",
"defaultValue",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"String",
".",
"valueOf",
"(",
"type",
")",
")",
";",
"}"
] |
Returns a java field default value for proto field.
|
[
"Returns",
"a",
"java",
"field",
"default",
"value",
"for",
"proto",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L176-L198
|
4,228 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.isScalarNullableType
|
public static boolean isScalarNullableType(Field field) {
FieldType type = field.getType();
return STRING.equals(type) || BYTES.equals(type) || type instanceof io.protostuff.compiler.model.Enum;
}
|
java
|
public static boolean isScalarNullableType(Field field) {
FieldType type = field.getType();
return STRING.equals(type) || BYTES.equals(type) || type instanceof io.protostuff.compiler.model.Enum;
}
|
[
"public",
"static",
"boolean",
"isScalarNullableType",
"(",
"Field",
"field",
")",
"{",
"FieldType",
"type",
"=",
"field",
".",
"getType",
"(",
")",
";",
"return",
"STRING",
".",
"equals",
"(",
"type",
")",
"||",
"BYTES",
".",
"equals",
"(",
"type",
")",
"||",
"type",
"instanceof",
"io",
".",
"protostuff",
".",
"compiler",
".",
"model",
".",
"Enum",
";",
"}"
] |
Check if field type used to store value in java is nullable type.
|
[
"Check",
"if",
"field",
"type",
"used",
"to",
"store",
"value",
"in",
"java",
"is",
"nullable",
"type",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L203-L206
|
4,229 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getRepeatedFieldType
|
public static String getRepeatedFieldType(Field field) {
FieldType type = field.getType();
if (type instanceof ScalarFieldType) {
ScalarFieldType scalarFieldType = (ScalarFieldType) type;
return LIST + "<" + ScalarFieldTypeUtil.getWrapperType(scalarFieldType) + ">";
}
if (type instanceof UserType) {
UserType userType = (UserType) type;
return LIST + "<" + UserTypeUtil.getCanonicalName(userType) + ">";
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getRepeatedFieldType(Field field) {
FieldType type = field.getType();
if (type instanceof ScalarFieldType) {
ScalarFieldType scalarFieldType = (ScalarFieldType) type;
return LIST + "<" + ScalarFieldTypeUtil.getWrapperType(scalarFieldType) + ">";
}
if (type instanceof UserType) {
UserType userType = (UserType) type;
return LIST + "<" + UserTypeUtil.getCanonicalName(userType) + ">";
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getRepeatedFieldType",
"(",
"Field",
"field",
")",
"{",
"FieldType",
"type",
"=",
"field",
".",
"getType",
"(",
")",
";",
"if",
"(",
"type",
"instanceof",
"ScalarFieldType",
")",
"{",
"ScalarFieldType",
"scalarFieldType",
"=",
"(",
"ScalarFieldType",
")",
"type",
";",
"return",
"LIST",
"+",
"\"<\"",
"+",
"ScalarFieldTypeUtil",
".",
"getWrapperType",
"(",
"scalarFieldType",
")",
"+",
"\">\"",
";",
"}",
"if",
"(",
"type",
"instanceof",
"UserType",
")",
"{",
"UserType",
"userType",
"=",
"(",
"UserType",
")",
"type",
";",
"return",
"LIST",
"+",
"\"<\"",
"+",
"UserTypeUtil",
".",
"getCanonicalName",
"(",
"userType",
")",
"+",
"\">\"",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns a java field type for proto repeated field.
|
[
"Returns",
"a",
"java",
"field",
"type",
"for",
"proto",
"repeated",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L211-L222
|
4,230 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getRepeatedFieldGetterName
|
public static String getRepeatedFieldGetterName(Field field) {
if (field.isRepeated()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + GETTER_REPEATED_SUFFIX;
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getRepeatedFieldGetterName(Field field) {
if (field.isRepeated()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + GETTER_REPEATED_SUFFIX;
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getRepeatedFieldGetterName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isRepeated",
"(",
")",
")",
"{",
"return",
"GETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
"+",
"GETTER_REPEATED_SUFFIX",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns a java field getter name for proto repeated field.
|
[
"Returns",
"a",
"java",
"field",
"getter",
"name",
"for",
"proto",
"repeated",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L259-L264
|
4,231 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.javaRepeatedEnumValueGetterByIndexName
|
public static String javaRepeatedEnumValueGetterByIndexName(Field field) {
if (field.isRepeated()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE;
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String javaRepeatedEnumValueGetterByIndexName(Field field) {
if (field.isRepeated()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE;
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"javaRepeatedEnumValueGetterByIndexName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isRepeated",
"(",
")",
")",
"{",
"return",
"GETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
"+",
"VALUE",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns a field value getter by index name for proto repeated enum field.
|
[
"Returns",
"a",
"field",
"value",
"getter",
"by",
"index",
"name",
"for",
"proto",
"repeated",
"enum",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L279-L284
|
4,232 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getRepeatedEnumConverterName
|
public static String getRepeatedEnumConverterName(Field field) {
if (field.isRepeated()) {
return "__" + Formatter.toCamelCase(field.getName()) + "Converter";
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getRepeatedEnumConverterName(Field field) {
if (field.isRepeated()) {
return "__" + Formatter.toCamelCase(field.getName()) + "Converter";
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getRepeatedEnumConverterName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isRepeated",
"(",
")",
")",
"{",
"return",
"\"__\"",
"+",
"Formatter",
".",
"toCamelCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
"+",
"\"Converter\"",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns a field converter class name for proto repeated enum field.
|
[
"Returns",
"a",
"field",
"converter",
"class",
"name",
"for",
"proto",
"repeated",
"enum",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L289-L294
|
4,233 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getRepeatedFieldSetterName
|
public static String getRepeatedFieldSetterName(Field field) {
if (field.isRepeated()) {
return SETTER_PREFIX + Formatter.toPascalCase(field.getName());
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getRepeatedFieldSetterName(Field field) {
if (field.isRepeated()) {
return SETTER_PREFIX + Formatter.toPascalCase(field.getName());
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getRepeatedFieldSetterName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isRepeated",
"(",
")",
")",
"{",
"return",
"SETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns a field setter name for proto repeated field.
|
[
"Returns",
"a",
"field",
"setter",
"name",
"for",
"proto",
"repeated",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L299-L304
|
4,234 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getRepeatedEnumValueSetterName
|
public static String getRepeatedEnumValueSetterName(Field field) {
if (field.isRepeated()) {
return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE;
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getRepeatedEnumValueSetterName(Field field) {
if (field.isRepeated()) {
return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE;
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getRepeatedEnumValueSetterName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isRepeated",
"(",
")",
")",
"{",
"return",
"SETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
"+",
"VALUE",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns a field value setter name for proto repeated enum field.
|
[
"Returns",
"a",
"field",
"value",
"setter",
"name",
"for",
"proto",
"repeated",
"enum",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L309-L314
|
4,235 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.repeatedGetCountMethodName
|
public static String repeatedGetCountMethodName(Field field) {
if (field.isRepeated()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + "Count";
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String repeatedGetCountMethodName(Field field) {
if (field.isRepeated()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + "Count";
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"repeatedGetCountMethodName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isRepeated",
"(",
")",
")",
"{",
"return",
"GETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
"+",
"\"Count\"",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns a element count getter name for proto repeated field.
|
[
"Returns",
"a",
"element",
"count",
"getter",
"name",
"for",
"proto",
"repeated",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L319-L324
|
4,236 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.toStringPart
|
public static String toStringPart(Field field) {
String getterName;
if (field.isMap()) {
getterName = getMapGetterName(field);
} else if (field.isRepeated()) {
getterName = getRepeatedFieldGetterName(field);
} else {
getterName = getFieldGetterName(field);
}
if (field.getType().isEnum() && !field.isRepeated()) {
return "\"" + getFieldName(field) + "=\" + " + getterName + "() + '(' + " + getEnumFieldValueGetterName(field) + "() + ')'";
}
return "\"" + getFieldName(field) + "=\" + " + getterName + "()";
}
|
java
|
public static String toStringPart(Field field) {
String getterName;
if (field.isMap()) {
getterName = getMapGetterName(field);
} else if (field.isRepeated()) {
getterName = getRepeatedFieldGetterName(field);
} else {
getterName = getFieldGetterName(field);
}
if (field.getType().isEnum() && !field.isRepeated()) {
return "\"" + getFieldName(field) + "=\" + " + getterName + "() + '(' + " + getEnumFieldValueGetterName(field) + "() + ')'";
}
return "\"" + getFieldName(field) + "=\" + " + getterName + "()";
}
|
[
"public",
"static",
"String",
"toStringPart",
"(",
"Field",
"field",
")",
"{",
"String",
"getterName",
";",
"if",
"(",
"field",
".",
"isMap",
"(",
")",
")",
"{",
"getterName",
"=",
"getMapGetterName",
"(",
"field",
")",
";",
"}",
"else",
"if",
"(",
"field",
".",
"isRepeated",
"(",
")",
")",
"{",
"getterName",
"=",
"getRepeatedFieldGetterName",
"(",
"field",
")",
";",
"}",
"else",
"{",
"getterName",
"=",
"getFieldGetterName",
"(",
"field",
")",
";",
"}",
"if",
"(",
"field",
".",
"getType",
"(",
")",
".",
"isEnum",
"(",
")",
"&&",
"!",
"field",
".",
"isRepeated",
"(",
")",
")",
"{",
"return",
"\"\\\"\"",
"+",
"getFieldName",
"(",
"field",
")",
"+",
"\"=\\\" + \"",
"+",
"getterName",
"+",
"\"() + '(' + \"",
"+",
"getEnumFieldValueGetterName",
"(",
"field",
")",
"+",
"\"() + ')'\"",
";",
"}",
"return",
"\"\\\"\"",
"+",
"getFieldName",
"(",
"field",
")",
"+",
"\"=\\\" + \"",
"+",
"getterName",
"+",
"\"()\"",
";",
"}"
] |
Generate part of toString method for a single field.
|
[
"Generate",
"part",
"of",
"toString",
"method",
"for",
"a",
"single",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L369-L382
|
4,237 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getMapFieldType
|
public static String getMapFieldType(Field field) {
String k = getMapFieldKeyType(field);
String v = getMapFieldValueType(field);
return "java.util.Map<" + k + ", " + v + ">";
}
|
java
|
public static String getMapFieldType(Field field) {
String k = getMapFieldKeyType(field);
String v = getMapFieldValueType(field);
return "java.util.Map<" + k + ", " + v + ">";
}
|
[
"public",
"static",
"String",
"getMapFieldType",
"(",
"Field",
"field",
")",
"{",
"String",
"k",
"=",
"getMapFieldKeyType",
"(",
"field",
")",
";",
"String",
"v",
"=",
"getMapFieldValueType",
"(",
"field",
")",
";",
"return",
"\"java.util.Map<\"",
"+",
"k",
"+",
"\", \"",
"+",
"v",
"+",
"\">\"",
";",
"}"
] |
Returns map field type name.
|
[
"Returns",
"map",
"field",
"type",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L420-L424
|
4,238 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getMapFieldKeyType
|
public static String getMapFieldKeyType(Field field) {
FieldType type = field.getType();
if (!(type instanceof Message)) {
throw new IllegalArgumentException(field.toString());
}
Message entryType = (Message) type;
ScalarFieldType keyType = (ScalarFieldType) entryType.getField(MAP_ENTRY_KEY).getType();
return ScalarFieldTypeUtil.getWrapperType(keyType);
}
|
java
|
public static String getMapFieldKeyType(Field field) {
FieldType type = field.getType();
if (!(type instanceof Message)) {
throw new IllegalArgumentException(field.toString());
}
Message entryType = (Message) type;
ScalarFieldType keyType = (ScalarFieldType) entryType.getField(MAP_ENTRY_KEY).getType();
return ScalarFieldTypeUtil.getWrapperType(keyType);
}
|
[
"public",
"static",
"String",
"getMapFieldKeyType",
"(",
"Field",
"field",
")",
"{",
"FieldType",
"type",
"=",
"field",
".",
"getType",
"(",
")",
";",
"if",
"(",
"!",
"(",
"type",
"instanceof",
"Message",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}",
"Message",
"entryType",
"=",
"(",
"Message",
")",
"type",
";",
"ScalarFieldType",
"keyType",
"=",
"(",
"ScalarFieldType",
")",
"entryType",
".",
"getField",
"(",
"MAP_ENTRY_KEY",
")",
".",
"getType",
"(",
")",
";",
"return",
"ScalarFieldTypeUtil",
".",
"getWrapperType",
"(",
"keyType",
")",
";",
"}"
] |
Returns map field key type name.
|
[
"Returns",
"map",
"field",
"key",
"type",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L429-L437
|
4,239 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getMapFieldValueType
|
public static String getMapFieldValueType(Field field) {
FieldType type = field.getType();
if (!(type instanceof Message)) {
throw new IllegalArgumentException(field.toString());
}
Message entryType = (Message) type;
Type valueType = entryType.getField(MAP_ENTRY_VALUE).getType();
String v;
if (valueType instanceof ScalarFieldType) {
ScalarFieldType scalarValueType = (ScalarFieldType) valueType;
v = ScalarFieldTypeUtil.getWrapperType(scalarValueType);
} else {
UserType userType = (UserType) valueType;
v = UserTypeUtil.getCanonicalName(userType);
}
return v;
}
|
java
|
public static String getMapFieldValueType(Field field) {
FieldType type = field.getType();
if (!(type instanceof Message)) {
throw new IllegalArgumentException(field.toString());
}
Message entryType = (Message) type;
Type valueType = entryType.getField(MAP_ENTRY_VALUE).getType();
String v;
if (valueType instanceof ScalarFieldType) {
ScalarFieldType scalarValueType = (ScalarFieldType) valueType;
v = ScalarFieldTypeUtil.getWrapperType(scalarValueType);
} else {
UserType userType = (UserType) valueType;
v = UserTypeUtil.getCanonicalName(userType);
}
return v;
}
|
[
"public",
"static",
"String",
"getMapFieldValueType",
"(",
"Field",
"field",
")",
"{",
"FieldType",
"type",
"=",
"field",
".",
"getType",
"(",
")",
";",
"if",
"(",
"!",
"(",
"type",
"instanceof",
"Message",
")",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}",
"Message",
"entryType",
"=",
"(",
"Message",
")",
"type",
";",
"Type",
"valueType",
"=",
"entryType",
".",
"getField",
"(",
"MAP_ENTRY_VALUE",
")",
".",
"getType",
"(",
")",
";",
"String",
"v",
";",
"if",
"(",
"valueType",
"instanceof",
"ScalarFieldType",
")",
"{",
"ScalarFieldType",
"scalarValueType",
"=",
"(",
"ScalarFieldType",
")",
"valueType",
";",
"v",
"=",
"ScalarFieldTypeUtil",
".",
"getWrapperType",
"(",
"scalarValueType",
")",
";",
"}",
"else",
"{",
"UserType",
"userType",
"=",
"(",
"UserType",
")",
"valueType",
";",
"v",
"=",
"UserTypeUtil",
".",
"getCanonicalName",
"(",
"userType",
")",
";",
"}",
"return",
"v",
";",
"}"
] |
Returns map field value type name.
|
[
"Returns",
"map",
"field",
"value",
"type",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L442-L458
|
4,240 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getMapGetterName
|
public static String getMapGetterName(Field field) {
if (field.isMap()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + MAP_SUFFIX;
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getMapGetterName(Field field) {
if (field.isMap()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + MAP_SUFFIX;
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getMapGetterName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isMap",
"(",
")",
")",
"{",
"return",
"GETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
"+",
"MAP_SUFFIX",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns map field getter name.
|
[
"Returns",
"map",
"field",
"getter",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L463-L468
|
4,241 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getMapSetterName
|
public static String getMapSetterName(Field field) {
if (field.isMap()) {
return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + MAP_SUFFIX;
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getMapSetterName(Field field) {
if (field.isMap()) {
return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + MAP_SUFFIX;
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getMapSetterName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isMap",
"(",
")",
")",
"{",
"return",
"SETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
"+",
"MAP_SUFFIX",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns map field setter name.
|
[
"Returns",
"map",
"field",
"setter",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L473-L478
|
4,242 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.mapGetByKeyMethodName
|
public static String mapGetByKeyMethodName(Field field) {
if (field.isMap()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName());
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String mapGetByKeyMethodName(Field field) {
if (field.isMap()) {
return GETTER_PREFIX + Formatter.toPascalCase(field.getName());
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"mapGetByKeyMethodName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isMap",
"(",
")",
")",
"{",
"return",
"GETTER_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns map field getter for particular key method name.
|
[
"Returns",
"map",
"field",
"getter",
"for",
"particular",
"key",
"method",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L483-L488
|
4,243 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getMapFieldAdderName
|
public static String getMapFieldAdderName(Field field) {
if (field.isMap()) {
return PUT_PREFIX + Formatter.toPascalCase(field.getName());
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getMapFieldAdderName(Field field) {
if (field.isMap()) {
return PUT_PREFIX + Formatter.toPascalCase(field.getName());
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getMapFieldAdderName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isMap",
"(",
")",
")",
"{",
"return",
"PUT_PREFIX",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns map field "put" method name.
|
[
"Returns",
"map",
"field",
"put",
"method",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L493-L498
|
4,244 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.getMapFieldAddAllName
|
public static String getMapFieldAddAllName(Field field) {
if (field.isMap()) {
return "putAll" + Formatter.toPascalCase(field.getName());
}
throw new IllegalArgumentException(field.toString());
}
|
java
|
public static String getMapFieldAddAllName(Field field) {
if (field.isMap()) {
return "putAll" + Formatter.toPascalCase(field.getName());
}
throw new IllegalArgumentException(field.toString());
}
|
[
"public",
"static",
"String",
"getMapFieldAddAllName",
"(",
"Field",
"field",
")",
"{",
"if",
"(",
"field",
".",
"isMap",
"(",
")",
")",
"{",
"return",
"\"putAll\"",
"+",
"Formatter",
".",
"toPascalCase",
"(",
"field",
".",
"getName",
"(",
")",
")",
";",
"}",
"throw",
"new",
"IllegalArgumentException",
"(",
"field",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Returns "putAll" method name for map field.
|
[
"Returns",
"putAll",
"method",
"name",
"for",
"map",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L503-L508
|
4,245 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.javaOneofConstantName
|
public static String javaOneofConstantName(Field field) {
String name = field.getName();
String underscored = Formatter.toUnderscoreCase(name);
return Formatter.toUpperCase(underscored);
}
|
java
|
public static String javaOneofConstantName(Field field) {
String name = field.getName();
String underscored = Formatter.toUnderscoreCase(name);
return Formatter.toUpperCase(underscored);
}
|
[
"public",
"static",
"String",
"javaOneofConstantName",
"(",
"Field",
"field",
")",
"{",
"String",
"name",
"=",
"field",
".",
"getName",
"(",
")",
";",
"String",
"underscored",
"=",
"Formatter",
".",
"toUnderscoreCase",
"(",
"name",
")",
";",
"return",
"Formatter",
".",
"toUpperCase",
"(",
"underscored",
")",
";",
"}"
] |
Returns an one-of enum constant name for oneof field.
|
[
"Returns",
"an",
"one",
"-",
"of",
"enum",
"constant",
"name",
"for",
"oneof",
"field",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L513-L517
|
4,246 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java
|
MessageFieldUtil.isNumericType
|
public static boolean isNumericType(Field field) {
FieldType type = field.getType();
boolean scalar = type instanceof ScalarFieldType;
return scalar && !(BOOL.equals(type) || STRING.equals(type) || BYTES.equals(type));
}
|
java
|
public static boolean isNumericType(Field field) {
FieldType type = field.getType();
boolean scalar = type instanceof ScalarFieldType;
return scalar && !(BOOL.equals(type) || STRING.equals(type) || BYTES.equals(type));
}
|
[
"public",
"static",
"boolean",
"isNumericType",
"(",
"Field",
"field",
")",
"{",
"FieldType",
"type",
"=",
"field",
".",
"getType",
"(",
")",
";",
"boolean",
"scalar",
"=",
"type",
"instanceof",
"ScalarFieldType",
";",
"return",
"scalar",
"&&",
"!",
"(",
"BOOL",
".",
"equals",
"(",
"type",
")",
"||",
"STRING",
".",
"equals",
"(",
"type",
")",
"||",
"BYTES",
".",
"equals",
"(",
"type",
")",
")",
";",
"}"
] |
Check if field type is numeric.
|
[
"Check",
"if",
"field",
"type",
"is",
"numeric",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageFieldUtil.java#L522-L526
|
4,247 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/Client.java
|
Client.getSeqnos
|
private Observable<PartitionAndSeqno> getSeqnos() {
return conductor.getSeqnos().flatMap(new Func1<ByteBuf, Observable<PartitionAndSeqno>>() {
@Override
public Observable<PartitionAndSeqno> call(ByteBuf buf) {
int numPairs = buf.readableBytes() / 10; // 2 byte short + 8 byte long
List<PartitionAndSeqno> pairs = new ArrayList<>(numPairs);
for (int i = 0; i < numPairs; i++) {
pairs.add(new PartitionAndSeqno(buf.getShort(10 * i), buf.getLong(10 * i + 2)));
}
buf.release();
return Observable.from(pairs);
}
});
}
|
java
|
private Observable<PartitionAndSeqno> getSeqnos() {
return conductor.getSeqnos().flatMap(new Func1<ByteBuf, Observable<PartitionAndSeqno>>() {
@Override
public Observable<PartitionAndSeqno> call(ByteBuf buf) {
int numPairs = buf.readableBytes() / 10; // 2 byte short + 8 byte long
List<PartitionAndSeqno> pairs = new ArrayList<>(numPairs);
for (int i = 0; i < numPairs; i++) {
pairs.add(new PartitionAndSeqno(buf.getShort(10 * i), buf.getLong(10 * i + 2)));
}
buf.release();
return Observable.from(pairs);
}
});
}
|
[
"private",
"Observable",
"<",
"PartitionAndSeqno",
">",
"getSeqnos",
"(",
")",
"{",
"return",
"conductor",
".",
"getSeqnos",
"(",
")",
".",
"flatMap",
"(",
"new",
"Func1",
"<",
"ByteBuf",
",",
"Observable",
"<",
"PartitionAndSeqno",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Observable",
"<",
"PartitionAndSeqno",
">",
"call",
"(",
"ByteBuf",
"buf",
")",
"{",
"int",
"numPairs",
"=",
"buf",
".",
"readableBytes",
"(",
")",
"/",
"10",
";",
"// 2 byte short + 8 byte long",
"List",
"<",
"PartitionAndSeqno",
">",
"pairs",
"=",
"new",
"ArrayList",
"<>",
"(",
"numPairs",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numPairs",
";",
"i",
"++",
")",
"{",
"pairs",
".",
"add",
"(",
"new",
"PartitionAndSeqno",
"(",
"buf",
".",
"getShort",
"(",
"10",
"*",
"i",
")",
",",
"buf",
".",
"getLong",
"(",
"10",
"*",
"i",
"+",
"2",
")",
")",
")",
";",
"}",
"buf",
".",
"release",
"(",
")",
";",
"return",
"Observable",
".",
"from",
"(",
"pairs",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Get the current sequence numbers from all partitions.
@return an {@link Observable} of partition and sequence number.
|
[
"Get",
"the",
"current",
"sequence",
"numbers",
"from",
"all",
"partitions",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/Client.java#L173-L186
|
4,248 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/Client.java
|
Client.handleFailoverLogResponse
|
private void handleFailoverLogResponse(final ByteBuf event) {
short partition = DcpFailoverLogResponse.vbucket(event);
PartitionState ps = sessionState().get(partition);
ps.setFailoverLog(DcpFailoverLogResponse.entries(event));
sessionState().set(partition, ps);
}
|
java
|
private void handleFailoverLogResponse(final ByteBuf event) {
short partition = DcpFailoverLogResponse.vbucket(event);
PartitionState ps = sessionState().get(partition);
ps.setFailoverLog(DcpFailoverLogResponse.entries(event));
sessionState().set(partition, ps);
}
|
[
"private",
"void",
"handleFailoverLogResponse",
"(",
"final",
"ByteBuf",
"event",
")",
"{",
"short",
"partition",
"=",
"DcpFailoverLogResponse",
".",
"vbucket",
"(",
"event",
")",
";",
"PartitionState",
"ps",
"=",
"sessionState",
"(",
")",
".",
"get",
"(",
"partition",
")",
";",
"ps",
".",
"setFailoverLog",
"(",
"DcpFailoverLogResponse",
".",
"entries",
"(",
"event",
")",
")",
";",
"sessionState",
"(",
")",
".",
"set",
"(",
"partition",
",",
"ps",
")",
";",
"}"
] |
Helper method to handle a failover log response.
@param event the buffer representing the {@link DcpFailoverLogResponse}.
|
[
"Helper",
"method",
"to",
"handle",
"a",
"failover",
"log",
"response",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/Client.java#L264-L269
|
4,249 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/Client.java
|
Client.selectInitializedPartitions
|
private List<Short> selectInitializedPartitions(int clusterPartitions, List<Short> partitions) {
List<Short> initializedPartitions = new ArrayList<>();
SessionState state = sessionState();
for (short partition : partitions) {
PartitionState ps = state.get(partition);
if (ps != null) {
if (MathUtils.lessThanUnsigned(ps.getStartSeqno(), ps.getEndSeqno())) {
initializedPartitions.add(partition);
} else {
LOGGER.debug("Skipping partition {}, because startSeqno({}) >= endSeqno({})",
partition, ps.getStartSeqno(), ps.getEndSeqno());
}
} else {
LOGGER.debug("Skipping partition {}, because its state is null", partition);
}
}
if (initializedPartitions.size() > clusterPartitions) {
throw new IllegalStateException("Session State has " + initializedPartitions
+ " partitions while the cluster has " + clusterPartitions + "!");
}
return initializedPartitions;
}
|
java
|
private List<Short> selectInitializedPartitions(int clusterPartitions, List<Short> partitions) {
List<Short> initializedPartitions = new ArrayList<>();
SessionState state = sessionState();
for (short partition : partitions) {
PartitionState ps = state.get(partition);
if (ps != null) {
if (MathUtils.lessThanUnsigned(ps.getStartSeqno(), ps.getEndSeqno())) {
initializedPartitions.add(partition);
} else {
LOGGER.debug("Skipping partition {}, because startSeqno({}) >= endSeqno({})",
partition, ps.getStartSeqno(), ps.getEndSeqno());
}
} else {
LOGGER.debug("Skipping partition {}, because its state is null", partition);
}
}
if (initializedPartitions.size() > clusterPartitions) {
throw new IllegalStateException("Session State has " + initializedPartitions
+ " partitions while the cluster has " + clusterPartitions + "!");
}
return initializedPartitions;
}
|
[
"private",
"List",
"<",
"Short",
">",
"selectInitializedPartitions",
"(",
"int",
"clusterPartitions",
",",
"List",
"<",
"Short",
">",
"partitions",
")",
"{",
"List",
"<",
"Short",
">",
"initializedPartitions",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"SessionState",
"state",
"=",
"sessionState",
"(",
")",
";",
"for",
"(",
"short",
"partition",
":",
"partitions",
")",
"{",
"PartitionState",
"ps",
"=",
"state",
".",
"get",
"(",
"partition",
")",
";",
"if",
"(",
"ps",
"!=",
"null",
")",
"{",
"if",
"(",
"MathUtils",
".",
"lessThanUnsigned",
"(",
"ps",
".",
"getStartSeqno",
"(",
")",
",",
"ps",
".",
"getEndSeqno",
"(",
")",
")",
")",
"{",
"initializedPartitions",
".",
"add",
"(",
"partition",
")",
";",
"}",
"else",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Skipping partition {}, because startSeqno({}) >= endSeqno({})\"",
",",
"partition",
",",
"ps",
".",
"getStartSeqno",
"(",
")",
",",
"ps",
".",
"getEndSeqno",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Skipping partition {}, because its state is null\"",
",",
"partition",
")",
";",
"}",
"}",
"if",
"(",
"initializedPartitions",
".",
"size",
"(",
")",
">",
"clusterPartitions",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Session State has \"",
"+",
"initializedPartitions",
"+",
"\" partitions while the cluster has \"",
"+",
"clusterPartitions",
"+",
"\"!\"",
")",
";",
"}",
"return",
"initializedPartitions",
";",
"}"
] |
Helper method to check on stream start that some kind of state is initialized to avoid a common error
of starting without initializing.
|
[
"Helper",
"method",
"to",
"check",
"on",
"stream",
"start",
"that",
"some",
"kind",
"of",
"state",
"is",
"initialized",
"to",
"avoid",
"a",
"common",
"error",
"of",
"starting",
"without",
"initializing",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/Client.java#L413-L436
|
4,250 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/Client.java
|
Client.partitionsForVbids
|
private static List<Short> partitionsForVbids(int numPartitions, Short... vbids) {
if (vbids.length > 0) {
Arrays.sort(vbids);
return Arrays.asList(vbids);
}
List<Short> partitions = new ArrayList<>(vbids.length);
for (short i = 0; i < numPartitions; i++) {
partitions.add(i);
}
return partitions;
}
|
java
|
private static List<Short> partitionsForVbids(int numPartitions, Short... vbids) {
if (vbids.length > 0) {
Arrays.sort(vbids);
return Arrays.asList(vbids);
}
List<Short> partitions = new ArrayList<>(vbids.length);
for (short i = 0; i < numPartitions; i++) {
partitions.add(i);
}
return partitions;
}
|
[
"private",
"static",
"List",
"<",
"Short",
">",
"partitionsForVbids",
"(",
"int",
"numPartitions",
",",
"Short",
"...",
"vbids",
")",
"{",
"if",
"(",
"vbids",
".",
"length",
">",
"0",
")",
"{",
"Arrays",
".",
"sort",
"(",
"vbids",
")",
";",
"return",
"Arrays",
".",
"asList",
"(",
"vbids",
")",
";",
"}",
"List",
"<",
"Short",
">",
"partitions",
"=",
"new",
"ArrayList",
"<>",
"(",
"vbids",
".",
"length",
")",
";",
"for",
"(",
"short",
"i",
"=",
"0",
";",
"i",
"<",
"numPartitions",
";",
"i",
"++",
")",
"{",
"partitions",
".",
"add",
"(",
"i",
")",
";",
"}",
"return",
"partitions",
";",
"}"
] |
Helper method to turn the array of vbids into a list.
@param numPartitions the number of partitions on the cluster as a fallback.
@param vbids the potentially empty array of selected vbids.
@return a sorted list of partitions to use.
|
[
"Helper",
"method",
"to",
"turn",
"the",
"array",
"of",
"vbids",
"into",
"a",
"list",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/Client.java#L472-L483
|
4,251 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/Client.java
|
Client.initFromBeginningToInfinity
|
private Completable initFromBeginningToInfinity() {
return Completable.create(new Completable.OnSubscribe() {
@Override
public void call(CompletableSubscriber subscriber) {
LOGGER.info("Initializing state from beginning to no end.");
try {
sessionState().setToBeginningWithNoEnd(numPartitions());
subscriber.onCompleted();
} catch (Exception ex) {
LOGGER.warn("Failed to initialize state from beginning to no end.", ex);
subscriber.onError(ex);
}
}
});
}
|
java
|
private Completable initFromBeginningToInfinity() {
return Completable.create(new Completable.OnSubscribe() {
@Override
public void call(CompletableSubscriber subscriber) {
LOGGER.info("Initializing state from beginning to no end.");
try {
sessionState().setToBeginningWithNoEnd(numPartitions());
subscriber.onCompleted();
} catch (Exception ex) {
LOGGER.warn("Failed to initialize state from beginning to no end.", ex);
subscriber.onError(ex);
}
}
});
}
|
[
"private",
"Completable",
"initFromBeginningToInfinity",
"(",
")",
"{",
"return",
"Completable",
".",
"create",
"(",
"new",
"Completable",
".",
"OnSubscribe",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"call",
"(",
"CompletableSubscriber",
"subscriber",
")",
"{",
"LOGGER",
".",
"info",
"(",
"\"Initializing state from beginning to no end.\"",
")",
";",
"try",
"{",
"sessionState",
"(",
")",
".",
"setToBeginningWithNoEnd",
"(",
"numPartitions",
"(",
")",
")",
";",
"subscriber",
".",
"onCompleted",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Failed to initialize state from beginning to no end.\"",
",",
"ex",
")",
";",
"subscriber",
".",
"onError",
"(",
"ex",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Initializes the session state from beginning to no end.
|
[
"Initializes",
"the",
"session",
"state",
"from",
"beginning",
"to",
"no",
"end",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/Client.java#L649-L664
|
4,252 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/Client.java
|
Client.initFromNowToInfinity
|
private Completable initFromNowToInfinity() {
return initWithCallback(new Action1<PartitionAndSeqno>() {
@Override
public void call(PartitionAndSeqno partitionAndSeqno) {
short partition = partitionAndSeqno.partition();
long seqno = partitionAndSeqno.seqno();
PartitionState partitionState = sessionState().get(partition);
partitionState.setStartSeqno(seqno);
partitionState.setSnapshotStartSeqno(seqno);
partitionState.setSnapshotEndSeqno(seqno);
sessionState().set(partition, partitionState);
}
});
}
|
java
|
private Completable initFromNowToInfinity() {
return initWithCallback(new Action1<PartitionAndSeqno>() {
@Override
public void call(PartitionAndSeqno partitionAndSeqno) {
short partition = partitionAndSeqno.partition();
long seqno = partitionAndSeqno.seqno();
PartitionState partitionState = sessionState().get(partition);
partitionState.setStartSeqno(seqno);
partitionState.setSnapshotStartSeqno(seqno);
partitionState.setSnapshotEndSeqno(seqno);
sessionState().set(partition, partitionState);
}
});
}
|
[
"private",
"Completable",
"initFromNowToInfinity",
"(",
")",
"{",
"return",
"initWithCallback",
"(",
"new",
"Action1",
"<",
"PartitionAndSeqno",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"call",
"(",
"PartitionAndSeqno",
"partitionAndSeqno",
")",
"{",
"short",
"partition",
"=",
"partitionAndSeqno",
".",
"partition",
"(",
")",
";",
"long",
"seqno",
"=",
"partitionAndSeqno",
".",
"seqno",
"(",
")",
";",
"PartitionState",
"partitionState",
"=",
"sessionState",
"(",
")",
".",
"get",
"(",
"partition",
")",
";",
"partitionState",
".",
"setStartSeqno",
"(",
"seqno",
")",
";",
"partitionState",
".",
"setSnapshotStartSeqno",
"(",
"seqno",
")",
";",
"partitionState",
".",
"setSnapshotEndSeqno",
"(",
"seqno",
")",
";",
"sessionState",
"(",
")",
".",
"set",
"(",
"partition",
",",
"partitionState",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Initializes the session state from now to no end.
|
[
"Initializes",
"the",
"session",
"state",
"from",
"now",
"to",
"no",
"end",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/Client.java#L669-L682
|
4,253 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/Client.java
|
Client.initFromBeginningToNow
|
private Completable initFromBeginningToNow() {
return initWithCallback(new Action1<PartitionAndSeqno>() {
@Override
public void call(PartitionAndSeqno partitionAndSeqno) {
short partition = partitionAndSeqno.partition();
long seqno = partitionAndSeqno.seqno();
PartitionState partitionState = sessionState().get(partition);
partitionState.setEndSeqno(seqno);
sessionState().set(partition, partitionState);
}
});
}
|
java
|
private Completable initFromBeginningToNow() {
return initWithCallback(new Action1<PartitionAndSeqno>() {
@Override
public void call(PartitionAndSeqno partitionAndSeqno) {
short partition = partitionAndSeqno.partition();
long seqno = partitionAndSeqno.seqno();
PartitionState partitionState = sessionState().get(partition);
partitionState.setEndSeqno(seqno);
sessionState().set(partition, partitionState);
}
});
}
|
[
"private",
"Completable",
"initFromBeginningToNow",
"(",
")",
"{",
"return",
"initWithCallback",
"(",
"new",
"Action1",
"<",
"PartitionAndSeqno",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"call",
"(",
"PartitionAndSeqno",
"partitionAndSeqno",
")",
"{",
"short",
"partition",
"=",
"partitionAndSeqno",
".",
"partition",
"(",
")",
";",
"long",
"seqno",
"=",
"partitionAndSeqno",
".",
"seqno",
"(",
")",
";",
"PartitionState",
"partitionState",
"=",
"sessionState",
"(",
")",
".",
"get",
"(",
"partition",
")",
";",
"partitionState",
".",
"setEndSeqno",
"(",
"seqno",
")",
";",
"sessionState",
"(",
")",
".",
"set",
"(",
"partition",
",",
"partitionState",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Initializes the session state from beginning to now.
|
[
"Initializes",
"the",
"session",
"state",
"from",
"beginning",
"to",
"now",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/Client.java#L687-L698
|
4,254 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/ClasspathFileReader.java
|
ClasspathFileReader.readResource
|
public static InputStream readResource(String name) {
String classpath = System.getProperty("java.class.path");
LOGGER.trace("Reading {} from classpath={}", name, classpath);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
throw new IllegalStateException("Can not obtain classloader instance from current thread");
}
return classLoader.getResourceAsStream(name);
}
|
java
|
public static InputStream readResource(String name) {
String classpath = System.getProperty("java.class.path");
LOGGER.trace("Reading {} from classpath={}", name, classpath);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
throw new IllegalStateException("Can not obtain classloader instance from current thread");
}
return classLoader.getResourceAsStream(name);
}
|
[
"public",
"static",
"InputStream",
"readResource",
"(",
"String",
"name",
")",
"{",
"String",
"classpath",
"=",
"System",
".",
"getProperty",
"(",
"\"java.class.path\"",
")",
";",
"LOGGER",
".",
"trace",
"(",
"\"Reading {} from classpath={}\"",
",",
"name",
",",
"classpath",
")",
";",
"ClassLoader",
"classLoader",
"=",
"Thread",
".",
"currentThread",
"(",
")",
".",
"getContextClassLoader",
"(",
")",
";",
"if",
"(",
"classLoader",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Can not obtain classloader instance from current thread\"",
")",
";",
"}",
"return",
"classLoader",
".",
"getResourceAsStream",
"(",
"name",
")",
";",
"}"
] |
Load resource from classpath.
|
[
"Load",
"resource",
"from",
"classpath",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/ClasspathFileReader.java#L22-L30
|
4,255 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/DefaultConnectionNameGenerator.java
|
DefaultConnectionNameGenerator.forProduct
|
public static DefaultConnectionNameGenerator forProduct(String productName, String productVersion, String... comments) {
return new DefaultConnectionNameGenerator(
new UserAgentBuilder().append(productName, productVersion, comments));
}
|
java
|
public static DefaultConnectionNameGenerator forProduct(String productName, String productVersion, String... comments) {
return new DefaultConnectionNameGenerator(
new UserAgentBuilder().append(productName, productVersion, comments));
}
|
[
"public",
"static",
"DefaultConnectionNameGenerator",
"forProduct",
"(",
"String",
"productName",
",",
"String",
"productVersion",
",",
"String",
"...",
"comments",
")",
"{",
"return",
"new",
"DefaultConnectionNameGenerator",
"(",
"new",
"UserAgentBuilder",
"(",
")",
".",
"append",
"(",
"productName",
",",
"productVersion",
",",
"comments",
")",
")",
";",
"}"
] |
Returns a new connection name generator that includes the given product information in the User Agent string.
@param productName Product name to include in the User Agent string.
@param productVersion Optional product version to include in the User Agent string. May be null.
@param comments Optional comments to include in the User Agent string.
|
[
"Returns",
"a",
"new",
"connection",
"name",
"generator",
"that",
"includes",
"the",
"given",
"product",
"information",
"in",
"the",
"User",
"Agent",
"string",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/DefaultConnectionNameGenerator.java#L55-L58
|
4,256 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/buffer/PersistedSeqnos.java
|
PersistedSeqnos.update
|
public synchronized long update(final PartitionInstance partitionInstance, final long vbuuid, final long seqno) {
return update(partitionInstance.partition(), partitionInstance.slot(), vbuuid, seqno);
}
|
java
|
public synchronized long update(final PartitionInstance partitionInstance, final long vbuuid, final long seqno) {
return update(partitionInstance.partition(), partitionInstance.slot(), vbuuid, seqno);
}
|
[
"public",
"synchronized",
"long",
"update",
"(",
"final",
"PartitionInstance",
"partitionInstance",
",",
"final",
"long",
"vbuuid",
",",
"final",
"long",
"seqno",
")",
"{",
"return",
"update",
"(",
"partitionInstance",
".",
"partition",
"(",
")",
",",
"partitionInstance",
".",
"slot",
"(",
")",
",",
"vbuuid",
",",
"seqno",
")",
";",
"}"
] |
Updates the dataset with information about the given partition instance
|
[
"Updates",
"the",
"dataset",
"with",
"information",
"about",
"the",
"given",
"partition",
"instance"
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/buffer/PersistedSeqnos.java#L135-L137
|
4,257 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/CompositeParseTreeListener.java
|
CompositeParseTreeListener.create
|
@SafeVarargs
public static <T extends ParseTreeListener> T create(Class<T> type, T... delegates) {
ImmutableList<T> listeners = ImmutableList.copyOf(delegates);
return Reflection.newProxy(type, new AbstractInvocationHandler() {
@Override
@ParametersAreNonnullByDefault
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
for (T listener : listeners) {
method.invoke(listener, args);
}
return null;
}
@Override
public String toString() {
return MoreObjects.toStringHelper("CompositeParseTreeListener")
.add("listeners", listeners)
.toString();
}
});
}
|
java
|
@SafeVarargs
public static <T extends ParseTreeListener> T create(Class<T> type, T... delegates) {
ImmutableList<T> listeners = ImmutableList.copyOf(delegates);
return Reflection.newProxy(type, new AbstractInvocationHandler() {
@Override
@ParametersAreNonnullByDefault
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
for (T listener : listeners) {
method.invoke(listener, args);
}
return null;
}
@Override
public String toString() {
return MoreObjects.toStringHelper("CompositeParseTreeListener")
.add("listeners", listeners)
.toString();
}
});
}
|
[
"@",
"SafeVarargs",
"public",
"static",
"<",
"T",
"extends",
"ParseTreeListener",
">",
"T",
"create",
"(",
"Class",
"<",
"T",
">",
"type",
",",
"T",
"...",
"delegates",
")",
"{",
"ImmutableList",
"<",
"T",
">",
"listeners",
"=",
"ImmutableList",
".",
"copyOf",
"(",
"delegates",
")",
";",
"return",
"Reflection",
".",
"newProxy",
"(",
"type",
",",
"new",
"AbstractInvocationHandler",
"(",
")",
"{",
"@",
"Override",
"@",
"ParametersAreNonnullByDefault",
"protected",
"Object",
"handleInvocation",
"(",
"Object",
"proxy",
",",
"Method",
"method",
",",
"Object",
"[",
"]",
"args",
")",
"throws",
"Throwable",
"{",
"for",
"(",
"T",
"listener",
":",
"listeners",
")",
"{",
"method",
".",
"invoke",
"(",
"listener",
",",
"args",
")",
";",
"}",
"return",
"null",
";",
"}",
"@",
"Override",
"public",
"String",
"toString",
"(",
")",
"{",
"return",
"MoreObjects",
".",
"toStringHelper",
"(",
"\"CompositeParseTreeListener\"",
")",
".",
"add",
"(",
"\"listeners\"",
",",
"listeners",
")",
".",
"toString",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Create new composite listener for a collection of delegates.
|
[
"Create",
"new",
"composite",
"listener",
"for",
"a",
"collection",
"of",
"delegates",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/CompositeParseTreeListener.java#L27-L49
|
4,258 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/ProtoUtil.java
|
ProtoUtil.getPackage
|
public static String getPackage(Proto proto) {
DynamicMessage.Value javaPackage = proto.getOptions().get(OPTION_JAVA_PACKAGE);
if (javaPackage != null) {
return javaPackage.getString();
}
return proto.getPackage().getValue();
}
|
java
|
public static String getPackage(Proto proto) {
DynamicMessage.Value javaPackage = proto.getOptions().get(OPTION_JAVA_PACKAGE);
if (javaPackage != null) {
return javaPackage.getString();
}
return proto.getPackage().getValue();
}
|
[
"public",
"static",
"String",
"getPackage",
"(",
"Proto",
"proto",
")",
"{",
"DynamicMessage",
".",
"Value",
"javaPackage",
"=",
"proto",
".",
"getOptions",
"(",
")",
".",
"get",
"(",
"OPTION_JAVA_PACKAGE",
")",
";",
"if",
"(",
"javaPackage",
"!=",
"null",
")",
"{",
"return",
"javaPackage",
".",
"getString",
"(",
")",
";",
"}",
"return",
"proto",
".",
"getPackage",
"(",
")",
".",
"getValue",
"(",
")",
";",
"}"
] |
Returns java package name.
|
[
"Returns",
"java",
"package",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/ProtoUtil.java#L22-L28
|
4,259 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/ProtoUtil.java
|
ProtoUtil.getPackagePath
|
public static String getPackagePath(Proto proto) {
String javaPackage = getPackage(proto);
return javaPackage.replace('.', '/');
}
|
java
|
public static String getPackagePath(Proto proto) {
String javaPackage = getPackage(proto);
return javaPackage.replace('.', '/');
}
|
[
"public",
"static",
"String",
"getPackagePath",
"(",
"Proto",
"proto",
")",
"{",
"String",
"javaPackage",
"=",
"getPackage",
"(",
"proto",
")",
";",
"return",
"javaPackage",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
";",
"}"
] |
Returns a relative path where java class should be placed,
computed from java package.
|
[
"Returns",
"a",
"relative",
"path",
"where",
"java",
"class",
"should",
"be",
"placed",
"computed",
"from",
"java",
"package",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/ProtoUtil.java#L34-L37
|
4,260 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/EnumUtil.java
|
EnumUtil.getName
|
public static String getName(EnumConstant constant) {
String name = constant.getName();
String underscored = Formatter.toUnderscoreCase(name);
return Formatter.toUpperCase(underscored);
}
|
java
|
public static String getName(EnumConstant constant) {
String name = constant.getName();
String underscored = Formatter.toUnderscoreCase(name);
return Formatter.toUpperCase(underscored);
}
|
[
"public",
"static",
"String",
"getName",
"(",
"EnumConstant",
"constant",
")",
"{",
"String",
"name",
"=",
"constant",
".",
"getName",
"(",
")",
";",
"String",
"underscored",
"=",
"Formatter",
".",
"toUnderscoreCase",
"(",
"name",
")",
";",
"return",
"Formatter",
".",
"toUpperCase",
"(",
"underscored",
")",
";",
"}"
] |
Returns constant name for java enum.
|
[
"Returns",
"constant",
"name",
"for",
"java",
"enum",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/EnumUtil.java#L20-L24
|
4,261 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/UsageIndex.java
|
UsageIndex.build
|
public static UsageIndex build(Collection<Proto> protos) {
UsageIndex usageIndex = new UsageIndex();
for (Proto proto : protos) {
ProtoWalker.newInstance(proto.getContext())
.onMessage(message -> {
for (Field field : message.getFields()) {
usageIndex.register(field.getType(), message);
}
})
.onService(service -> {
for (ServiceMethod serviceMethod : service.getMethods()) {
usageIndex.register(serviceMethod.getArgType(), service);
usageIndex.register(serviceMethod.getReturnType(), service);
}
})
.walk();
}
return usageIndex;
}
|
java
|
public static UsageIndex build(Collection<Proto> protos) {
UsageIndex usageIndex = new UsageIndex();
for (Proto proto : protos) {
ProtoWalker.newInstance(proto.getContext())
.onMessage(message -> {
for (Field field : message.getFields()) {
usageIndex.register(field.getType(), message);
}
})
.onService(service -> {
for (ServiceMethod serviceMethod : service.getMethods()) {
usageIndex.register(serviceMethod.getArgType(), service);
usageIndex.register(serviceMethod.getReturnType(), service);
}
})
.walk();
}
return usageIndex;
}
|
[
"public",
"static",
"UsageIndex",
"build",
"(",
"Collection",
"<",
"Proto",
">",
"protos",
")",
"{",
"UsageIndex",
"usageIndex",
"=",
"new",
"UsageIndex",
"(",
")",
";",
"for",
"(",
"Proto",
"proto",
":",
"protos",
")",
"{",
"ProtoWalker",
".",
"newInstance",
"(",
"proto",
".",
"getContext",
"(",
")",
")",
".",
"onMessage",
"(",
"message",
"->",
"{",
"for",
"(",
"Field",
"field",
":",
"message",
".",
"getFields",
"(",
")",
")",
"{",
"usageIndex",
".",
"register",
"(",
"field",
".",
"getType",
"(",
")",
",",
"message",
")",
";",
"}",
"}",
")",
".",
"onService",
"(",
"service",
"->",
"{",
"for",
"(",
"ServiceMethod",
"serviceMethod",
":",
"service",
".",
"getMethods",
"(",
")",
")",
"{",
"usageIndex",
".",
"register",
"(",
"serviceMethod",
".",
"getArgType",
"(",
")",
",",
"service",
")",
";",
"usageIndex",
".",
"register",
"(",
"serviceMethod",
".",
"getReturnType",
"(",
")",
",",
"service",
")",
";",
"}",
"}",
")",
".",
"walk",
"(",
")",
";",
"}",
"return",
"usageIndex",
";",
"}"
] |
Build usage index for given collection of proto files.
|
[
"Build",
"usage",
"index",
"for",
"given",
"collection",
"of",
"proto",
"files",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/UsageIndex.java#L20-L38
|
4,262 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/conductor/Conductor.java
|
Conductor.disconnected
|
public boolean disconnected() {
if (!configProvider.isState(LifecycleState.DISCONNECTED)) {
return false;
}
for (DcpChannel channel : channels) {
if (!channel.isState(LifecycleState.DISCONNECTED)) {
return false;
}
}
return true;
}
|
java
|
public boolean disconnected() {
if (!configProvider.isState(LifecycleState.DISCONNECTED)) {
return false;
}
for (DcpChannel channel : channels) {
if (!channel.isState(LifecycleState.DISCONNECTED)) {
return false;
}
}
return true;
}
|
[
"public",
"boolean",
"disconnected",
"(",
")",
"{",
"if",
"(",
"!",
"configProvider",
".",
"isState",
"(",
"LifecycleState",
".",
"DISCONNECTED",
")",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"DcpChannel",
"channel",
":",
"channels",
")",
"{",
"if",
"(",
"!",
"channel",
".",
"isState",
"(",
"LifecycleState",
".",
"DISCONNECTED",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Returns true if all channels and the config provider are in a disconnected state.
|
[
"Returns",
"true",
"if",
"all",
"channels",
"and",
"the",
"config",
"provider",
"are",
"in",
"a",
"disconnected",
"state",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/conductor/Conductor.java#L102-L114
|
4,263 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoContext.java
|
ProtoContext.peek
|
@SuppressWarnings("unchecked")
public <T> T peek(Class<T> declarationClass) {
Object declaration = declarationStack.peek();
if (declaration == null) {
throw new IllegalStateException("Declaration stack is empty");
}
if (declarationClass.isAssignableFrom(declaration.getClass())) {
return (T) declaration;
}
return fail(declaration, declarationClass);
}
|
java
|
@SuppressWarnings("unchecked")
public <T> T peek(Class<T> declarationClass) {
Object declaration = declarationStack.peek();
if (declaration == null) {
throw new IllegalStateException("Declaration stack is empty");
}
if (declarationClass.isAssignableFrom(declaration.getClass())) {
return (T) declaration;
}
return fail(declaration, declarationClass);
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"<",
"T",
">",
"T",
"peek",
"(",
"Class",
"<",
"T",
">",
"declarationClass",
")",
"{",
"Object",
"declaration",
"=",
"declarationStack",
".",
"peek",
"(",
")",
";",
"if",
"(",
"declaration",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Declaration stack is empty\"",
")",
";",
"}",
"if",
"(",
"declarationClass",
".",
"isAssignableFrom",
"(",
"declaration",
".",
"getClass",
"(",
")",
")",
")",
"{",
"return",
"(",
"T",
")",
"declaration",
";",
"}",
"return",
"fail",
"(",
"declaration",
",",
"declarationClass",
")",
";",
"}"
] |
Peek an element from a declaration stack.
Used by parse listeners.
|
[
"Peek",
"an",
"element",
"from",
"a",
"declaration",
"stack",
".",
"Used",
"by",
"parse",
"listeners",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoContext.java#L59-L69
|
4,264 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoContext.java
|
ProtoContext.pop
|
@SuppressWarnings("unchecked")
public <T> T pop(Class<T> declarationClass) {
Object declaration = declarationStack.pop();
if (declarationClass.isAssignableFrom(declaration.getClass())) {
return (T) declaration;
}
return fail(declaration, declarationClass);
}
|
java
|
@SuppressWarnings("unchecked")
public <T> T pop(Class<T> declarationClass) {
Object declaration = declarationStack.pop();
if (declarationClass.isAssignableFrom(declaration.getClass())) {
return (T) declaration;
}
return fail(declaration, declarationClass);
}
|
[
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"<",
"T",
">",
"T",
"pop",
"(",
"Class",
"<",
"T",
">",
"declarationClass",
")",
"{",
"Object",
"declaration",
"=",
"declarationStack",
".",
"pop",
"(",
")",
";",
"if",
"(",
"declarationClass",
".",
"isAssignableFrom",
"(",
"declaration",
".",
"getClass",
"(",
")",
")",
")",
"{",
"return",
"(",
"T",
")",
"declaration",
";",
"}",
"return",
"fail",
"(",
"declaration",
",",
"declarationClass",
")",
";",
"}"
] |
Pop an element from from a declaration stack.
Used by parse listeners.
|
[
"Pop",
"an",
"element",
"from",
"from",
"a",
"declaration",
"stack",
".",
"Used",
"by",
"parse",
"listeners",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoContext.java#L83-L90
|
4,265 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoContext.java
|
ProtoContext.register
|
public <T extends Type & Element> void register(String fullyQualifiedName, T type) {
if (resolve(fullyQualifiedName) != null) {
throw new ParserException(type, "Cannot register duplicate type: %s", fullyQualifiedName);
}
symbolTable.put(fullyQualifiedName, type);
}
|
java
|
public <T extends Type & Element> void register(String fullyQualifiedName, T type) {
if (resolve(fullyQualifiedName) != null) {
throw new ParserException(type, "Cannot register duplicate type: %s", fullyQualifiedName);
}
symbolTable.put(fullyQualifiedName, type);
}
|
[
"public",
"<",
"T",
"extends",
"Type",
"&",
"Element",
">",
"void",
"register",
"(",
"String",
"fullyQualifiedName",
",",
"T",
"type",
")",
"{",
"if",
"(",
"resolve",
"(",
"fullyQualifiedName",
")",
"!=",
"null",
")",
"{",
"throw",
"new",
"ParserException",
"(",
"type",
",",
"\"Cannot register duplicate type: %s\"",
",",
"fullyQualifiedName",
")",
";",
"}",
"symbolTable",
".",
"put",
"(",
"fullyQualifiedName",
",",
"type",
")",
";",
"}"
] |
Register user type in symbol table. Full name should start with ".".
|
[
"Register",
"user",
"type",
"in",
"symbol",
"table",
".",
"Full",
"name",
"should",
"start",
"with",
".",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoContext.java#L95-L100
|
4,266 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoContext.java
|
ProtoContext.resolve
|
public <T extends Type> T resolve(String typeName, Class<T> clazz) {
Type instance = resolve(typeName);
if (instance == null) {
return null;
}
if (clazz.isAssignableFrom(instance.getClass())) {
return clazz.cast(instance);
} else {
throw new ParserException("Type error: %s of type %s can not be cast to %s",
typeName, instance.getClass(), clazz);
}
}
|
java
|
public <T extends Type> T resolve(String typeName, Class<T> clazz) {
Type instance = resolve(typeName);
if (instance == null) {
return null;
}
if (clazz.isAssignableFrom(instance.getClass())) {
return clazz.cast(instance);
} else {
throw new ParserException("Type error: %s of type %s can not be cast to %s",
typeName, instance.getClass(), clazz);
}
}
|
[
"public",
"<",
"T",
"extends",
"Type",
">",
"T",
"resolve",
"(",
"String",
"typeName",
",",
"Class",
"<",
"T",
">",
"clazz",
")",
"{",
"Type",
"instance",
"=",
"resolve",
"(",
"typeName",
")",
";",
"if",
"(",
"instance",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"clazz",
".",
"isAssignableFrom",
"(",
"instance",
".",
"getClass",
"(",
")",
")",
")",
"{",
"return",
"clazz",
".",
"cast",
"(",
"instance",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ParserException",
"(",
"\"Type error: %s of type %s can not be cast to %s\"",
",",
"typeName",
",",
"instance",
".",
"getClass",
"(",
")",
",",
"clazz",
")",
";",
"}",
"}"
] |
Resolve a type declaration by it's name using this proto context.
|
[
"Resolve",
"a",
"type",
"declaration",
"by",
"it",
"s",
"name",
"using",
"this",
"proto",
"context",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoContext.java#L116-L127
|
4,267 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/ConfigHandler.java
|
ConfigHandler.channelRead0
|
@Override
protected void channelRead0(final ChannelHandlerContext ctx, final HttpObject msg) throws Exception {
if (msg instanceof HttpContent) {
HttpContent content = (HttpContent) msg;
decodeChunk((InetSocketAddress) ctx.channel().remoteAddress(), content.content());
}
}
|
java
|
@Override
protected void channelRead0(final ChannelHandlerContext ctx, final HttpObject msg) throws Exception {
if (msg instanceof HttpContent) {
HttpContent content = (HttpContent) msg;
decodeChunk((InetSocketAddress) ctx.channel().remoteAddress(), content.content());
}
}
|
[
"@",
"Override",
"protected",
"void",
"channelRead0",
"(",
"final",
"ChannelHandlerContext",
"ctx",
",",
"final",
"HttpObject",
"msg",
")",
"throws",
"Exception",
"{",
"if",
"(",
"msg",
"instanceof",
"HttpContent",
")",
"{",
"HttpContent",
"content",
"=",
"(",
"HttpContent",
")",
"msg",
";",
"decodeChunk",
"(",
"(",
"InetSocketAddress",
")",
"ctx",
".",
"channel",
"(",
")",
".",
"remoteAddress",
"(",
")",
",",
"content",
".",
"content",
"(",
")",
")",
";",
"}",
"}"
] |
If we get a new content chunk, send it towards decoding.
|
[
"If",
"we",
"get",
"a",
"new",
"content",
"chunk",
"send",
"it",
"towards",
"decoding",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/ConfigHandler.java#L83-L89
|
4,268 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/ConfigHandler.java
|
ConfigHandler.decodeChunk
|
private void decodeChunk(InetSocketAddress address, final ByteBuf chunk) {
responseContent.writeBytes(chunk);
String currentChunk = responseContent.toString(CharsetUtil.UTF_8);
int separatorIndex = currentChunk.indexOf("\n\n\n\n");
if (separatorIndex > 0) {
String rawConfig = currentChunk
.substring(0, separatorIndex)
.trim()
.replace("$HOST", address.getAddress().getHostAddress());
NetworkAddress origin = NetworkAddress.create(address.getAddress().getHostAddress());
CouchbaseBucketConfig config = (CouchbaseBucketConfig) BucketConfigParser.parse(rawConfig, environment, origin);
synchronized (currentBucketConfigRev) {
if (config.rev() > currentBucketConfigRev.get()) {
LOGGER.trace("Publishing bucket config: {}", RedactableArgument.system(rawConfig));
currentBucketConfigRev.set(config.rev());
configStream.onNext(config);
} else {
LOGGER.trace("Ignoring config, since rev has not changed.");
}
}
responseContent.clear();
responseContent.writeBytes(currentChunk.substring(separatorIndex + 4).getBytes(CharsetUtil.UTF_8));
}
}
|
java
|
private void decodeChunk(InetSocketAddress address, final ByteBuf chunk) {
responseContent.writeBytes(chunk);
String currentChunk = responseContent.toString(CharsetUtil.UTF_8);
int separatorIndex = currentChunk.indexOf("\n\n\n\n");
if (separatorIndex > 0) {
String rawConfig = currentChunk
.substring(0, separatorIndex)
.trim()
.replace("$HOST", address.getAddress().getHostAddress());
NetworkAddress origin = NetworkAddress.create(address.getAddress().getHostAddress());
CouchbaseBucketConfig config = (CouchbaseBucketConfig) BucketConfigParser.parse(rawConfig, environment, origin);
synchronized (currentBucketConfigRev) {
if (config.rev() > currentBucketConfigRev.get()) {
LOGGER.trace("Publishing bucket config: {}", RedactableArgument.system(rawConfig));
currentBucketConfigRev.set(config.rev());
configStream.onNext(config);
} else {
LOGGER.trace("Ignoring config, since rev has not changed.");
}
}
responseContent.clear();
responseContent.writeBytes(currentChunk.substring(separatorIndex + 4).getBytes(CharsetUtil.UTF_8));
}
}
|
[
"private",
"void",
"decodeChunk",
"(",
"InetSocketAddress",
"address",
",",
"final",
"ByteBuf",
"chunk",
")",
"{",
"responseContent",
".",
"writeBytes",
"(",
"chunk",
")",
";",
"String",
"currentChunk",
"=",
"responseContent",
".",
"toString",
"(",
"CharsetUtil",
".",
"UTF_8",
")",
";",
"int",
"separatorIndex",
"=",
"currentChunk",
".",
"indexOf",
"(",
"\"\\n\\n\\n\\n\"",
")",
";",
"if",
"(",
"separatorIndex",
">",
"0",
")",
"{",
"String",
"rawConfig",
"=",
"currentChunk",
".",
"substring",
"(",
"0",
",",
"separatorIndex",
")",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"\"$HOST\"",
",",
"address",
".",
"getAddress",
"(",
")",
".",
"getHostAddress",
"(",
")",
")",
";",
"NetworkAddress",
"origin",
"=",
"NetworkAddress",
".",
"create",
"(",
"address",
".",
"getAddress",
"(",
")",
".",
"getHostAddress",
"(",
")",
")",
";",
"CouchbaseBucketConfig",
"config",
"=",
"(",
"CouchbaseBucketConfig",
")",
"BucketConfigParser",
".",
"parse",
"(",
"rawConfig",
",",
"environment",
",",
"origin",
")",
";",
"synchronized",
"(",
"currentBucketConfigRev",
")",
"{",
"if",
"(",
"config",
".",
"rev",
"(",
")",
">",
"currentBucketConfigRev",
".",
"get",
"(",
")",
")",
"{",
"LOGGER",
".",
"trace",
"(",
"\"Publishing bucket config: {}\"",
",",
"RedactableArgument",
".",
"system",
"(",
"rawConfig",
")",
")",
";",
"currentBucketConfigRev",
".",
"set",
"(",
"config",
".",
"rev",
"(",
")",
")",
";",
"configStream",
".",
"onNext",
"(",
"config",
")",
";",
"}",
"else",
"{",
"LOGGER",
".",
"trace",
"(",
"\"Ignoring config, since rev has not changed.\"",
")",
";",
"}",
"}",
"responseContent",
".",
"clear",
"(",
")",
";",
"responseContent",
".",
"writeBytes",
"(",
"currentChunk",
".",
"substring",
"(",
"separatorIndex",
"+",
"4",
")",
".",
"getBytes",
"(",
"CharsetUtil",
".",
"UTF_8",
")",
")",
";",
"}",
"}"
] |
Helper method to decode and analyze the chunk.
@param chunk the chunk to analyze.
|
[
"Helper",
"method",
"to",
"decode",
"and",
"analyze",
"the",
"chunk",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/ConfigHandler.java#L96-L122
|
4,269 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/ConfigHandler.java
|
ConfigHandler.handlerRemoved
|
@Override
public void handlerRemoved(final ChannelHandlerContext ctx) throws Exception {
if (responseContent != null && responseContent.refCnt() > 0) {
responseContent.release();
responseContent = null;
}
}
|
java
|
@Override
public void handlerRemoved(final ChannelHandlerContext ctx) throws Exception {
if (responseContent != null && responseContent.refCnt() > 0) {
responseContent.release();
responseContent = null;
}
}
|
[
"@",
"Override",
"public",
"void",
"handlerRemoved",
"(",
"final",
"ChannelHandlerContext",
"ctx",
")",
"throws",
"Exception",
"{",
"if",
"(",
"responseContent",
"!=",
"null",
"&&",
"responseContent",
".",
"refCnt",
"(",
")",
">",
"0",
")",
"{",
"responseContent",
".",
"release",
"(",
")",
";",
"responseContent",
"=",
"null",
";",
"}",
"}"
] |
Once the handler is removed, make sure the response content is released and freed.
|
[
"Once",
"the",
"handler",
"is",
"removed",
"make",
"sure",
"the",
"response",
"content",
"is",
"released",
"and",
"freed",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/ConfigHandler.java#L135-L141
|
4,270 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/UserTypeUtil.java
|
UserTypeUtil.getClassName
|
public static String getClassName(UserType userType) {
String name = userType.getName();
return Formatter.toPascalCase(name);
}
|
java
|
public static String getClassName(UserType userType) {
String name = userType.getName();
return Formatter.toPascalCase(name);
}
|
[
"public",
"static",
"String",
"getClassName",
"(",
"UserType",
"userType",
")",
"{",
"String",
"name",
"=",
"userType",
".",
"getName",
"(",
")",
";",
"return",
"Formatter",
".",
"toPascalCase",
"(",
"name",
")",
";",
"}"
] |
Returns a java class name for a user type.
|
[
"Returns",
"a",
"java",
"class",
"name",
"for",
"a",
"user",
"type",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/UserTypeUtil.java#L22-L25
|
4,271 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/UserTypeUtil.java
|
UserTypeUtil.getCanonicalName
|
public static String getCanonicalName(UserType userType) {
String name = getClassName(userType);
String canonicalName;
if (userType.isNested()) {
Message parent = (Message) userType.getParent();
canonicalName = getCanonicalName(parent) + '.' + name;
} else {
Proto proto = userType.getProto();
String pkg = ProtoUtil.getPackage(proto);
if (pkg.isEmpty()) {
canonicalName = name;
} else {
canonicalName = pkg + '.' + name;
}
}
return canonicalName;
}
|
java
|
public static String getCanonicalName(UserType userType) {
String name = getClassName(userType);
String canonicalName;
if (userType.isNested()) {
Message parent = (Message) userType.getParent();
canonicalName = getCanonicalName(parent) + '.' + name;
} else {
Proto proto = userType.getProto();
String pkg = ProtoUtil.getPackage(proto);
if (pkg.isEmpty()) {
canonicalName = name;
} else {
canonicalName = pkg + '.' + name;
}
}
return canonicalName;
}
|
[
"public",
"static",
"String",
"getCanonicalName",
"(",
"UserType",
"userType",
")",
"{",
"String",
"name",
"=",
"getClassName",
"(",
"userType",
")",
";",
"String",
"canonicalName",
";",
"if",
"(",
"userType",
".",
"isNested",
"(",
")",
")",
"{",
"Message",
"parent",
"=",
"(",
"Message",
")",
"userType",
".",
"getParent",
"(",
")",
";",
"canonicalName",
"=",
"getCanonicalName",
"(",
"parent",
")",
"+",
"'",
"'",
"+",
"name",
";",
"}",
"else",
"{",
"Proto",
"proto",
"=",
"userType",
".",
"getProto",
"(",
")",
";",
"String",
"pkg",
"=",
"ProtoUtil",
".",
"getPackage",
"(",
"proto",
")",
";",
"if",
"(",
"pkg",
".",
"isEmpty",
"(",
")",
")",
"{",
"canonicalName",
"=",
"name",
";",
"}",
"else",
"{",
"canonicalName",
"=",
"pkg",
"+",
"'",
"'",
"+",
"name",
";",
"}",
"}",
"return",
"canonicalName",
";",
"}"
] |
Returns java canonical class name for a user type.
|
[
"Returns",
"java",
"canonical",
"class",
"name",
"for",
"a",
"user",
"type",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/UserTypeUtil.java#L30-L46
|
4,272 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/DcpConnectHandler.java
|
DcpConnectHandler.getServerVersion
|
public static Version getServerVersion(Channel channel) {
Version version = channel.attr(SERVER_VERSION).get();
if (version == null) {
throw new IllegalStateException("Server version attribute not yet set by "
+ DcpConnectHandler.class.getSimpleName());
}
return version;
}
|
java
|
public static Version getServerVersion(Channel channel) {
Version version = channel.attr(SERVER_VERSION).get();
if (version == null) {
throw new IllegalStateException("Server version attribute not yet set by "
+ DcpConnectHandler.class.getSimpleName());
}
return version;
}
|
[
"public",
"static",
"Version",
"getServerVersion",
"(",
"Channel",
"channel",
")",
"{",
"Version",
"version",
"=",
"channel",
".",
"attr",
"(",
"SERVER_VERSION",
")",
".",
"get",
"(",
")",
";",
"if",
"(",
"version",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"Server version attribute not yet set by \"",
"+",
"DcpConnectHandler",
".",
"class",
".",
"getSimpleName",
"(",
")",
")",
";",
"}",
"return",
"version",
";",
"}"
] |
Returns the Couchbase Server version associated with the given channel.
@throws IllegalStateException if {@link DcpConnectHandler} has not yet issued
a Version request and processed the result.
|
[
"Returns",
"the",
"Couchbase",
"Server",
"version",
"associated",
"with",
"the",
"given",
"channel",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/DcpConnectHandler.java#L98-L105
|
4,273 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/DcpConnectHandler.java
|
DcpConnectHandler.channelActive
|
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
ByteBuf request = ctx.alloc().buffer();
VersionRequest.init(request);
ctx.writeAndFlush(request);
}
|
java
|
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
ByteBuf request = ctx.alloc().buffer();
VersionRequest.init(request);
ctx.writeAndFlush(request);
}
|
[
"@",
"Override",
"public",
"void",
"channelActive",
"(",
"final",
"ChannelHandlerContext",
"ctx",
")",
"throws",
"Exception",
"{",
"ByteBuf",
"request",
"=",
"ctx",
".",
"alloc",
"(",
")",
".",
"buffer",
"(",
")",
";",
"VersionRequest",
".",
"init",
"(",
"request",
")",
";",
"ctx",
".",
"writeAndFlush",
"(",
"request",
")",
";",
"}"
] |
Once the channel becomes active, sends the initial open connection request.
|
[
"Once",
"the",
"channel",
"becomes",
"active",
"sends",
"the",
"initial",
"open",
"connection",
"request",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/DcpConnectHandler.java#L121-L126
|
4,274 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/Message.java
|
Message.getOneof
|
public Oneof getOneof(String name) {
for (Oneof oneof : getOneofs()) {
if (name.equals(oneof.getName())) {
return oneof;
}
}
return null;
}
|
java
|
public Oneof getOneof(String name) {
for (Oneof oneof : getOneofs()) {
if (name.equals(oneof.getName())) {
return oneof;
}
}
return null;
}
|
[
"public",
"Oneof",
"getOneof",
"(",
"String",
"name",
")",
"{",
"for",
"(",
"Oneof",
"oneof",
":",
"getOneofs",
"(",
")",
")",
"{",
"if",
"(",
"name",
".",
"equals",
"(",
"oneof",
".",
"getName",
"(",
")",
")",
")",
"{",
"return",
"oneof",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Get oneof node by it's name.
|
[
"Get",
"oneof",
"node",
"by",
"it",
"s",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/Message.java#L89-L96
|
4,275 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/DcpControlHandler.java
|
DcpControlHandler.negotiate
|
private void negotiate(final ChannelHandlerContext ctx) {
if (controlSettings.hasNext()) {
Map.Entry<String, String> setting = controlSettings.next();
LOGGER.debug("Negotiating DCP Control {}: {}", setting.getKey(), setting.getValue());
ByteBuf request = ctx.alloc().buffer();
DcpControlRequest.init(request);
DcpControlRequest.key(setting.getKey(), request);
DcpControlRequest.value(Unpooled.copiedBuffer(setting.getValue(), CharsetUtil.UTF_8), request);
ctx.writeAndFlush(request);
} else {
originalPromise().setSuccess();
ctx.pipeline().remove(this);
ctx.fireChannelActive();
LOGGER.debug("Negotiated all DCP Control settings against Node {}", ctx.channel().remoteAddress());
}
}
|
java
|
private void negotiate(final ChannelHandlerContext ctx) {
if (controlSettings.hasNext()) {
Map.Entry<String, String> setting = controlSettings.next();
LOGGER.debug("Negotiating DCP Control {}: {}", setting.getKey(), setting.getValue());
ByteBuf request = ctx.alloc().buffer();
DcpControlRequest.init(request);
DcpControlRequest.key(setting.getKey(), request);
DcpControlRequest.value(Unpooled.copiedBuffer(setting.getValue(), CharsetUtil.UTF_8), request);
ctx.writeAndFlush(request);
} else {
originalPromise().setSuccess();
ctx.pipeline().remove(this);
ctx.fireChannelActive();
LOGGER.debug("Negotiated all DCP Control settings against Node {}", ctx.channel().remoteAddress());
}
}
|
[
"private",
"void",
"negotiate",
"(",
"final",
"ChannelHandlerContext",
"ctx",
")",
"{",
"if",
"(",
"controlSettings",
".",
"hasNext",
"(",
")",
")",
"{",
"Map",
".",
"Entry",
"<",
"String",
",",
"String",
">",
"setting",
"=",
"controlSettings",
".",
"next",
"(",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Negotiating DCP Control {}: {}\"",
",",
"setting",
".",
"getKey",
"(",
")",
",",
"setting",
".",
"getValue",
"(",
")",
")",
";",
"ByteBuf",
"request",
"=",
"ctx",
".",
"alloc",
"(",
")",
".",
"buffer",
"(",
")",
";",
"DcpControlRequest",
".",
"init",
"(",
"request",
")",
";",
"DcpControlRequest",
".",
"key",
"(",
"setting",
".",
"getKey",
"(",
")",
",",
"request",
")",
";",
"DcpControlRequest",
".",
"value",
"(",
"Unpooled",
".",
"copiedBuffer",
"(",
"setting",
".",
"getValue",
"(",
")",
",",
"CharsetUtil",
".",
"UTF_8",
")",
",",
"request",
")",
";",
"ctx",
".",
"writeAndFlush",
"(",
"request",
")",
";",
"}",
"else",
"{",
"originalPromise",
"(",
")",
".",
"setSuccess",
"(",
")",
";",
"ctx",
".",
"pipeline",
"(",
")",
".",
"remove",
"(",
"this",
")",
";",
"ctx",
".",
"fireChannelActive",
"(",
")",
";",
"LOGGER",
".",
"debug",
"(",
"\"Negotiated all DCP Control settings against Node {}\"",
",",
"ctx",
".",
"channel",
"(",
")",
".",
"remoteAddress",
"(",
")",
")",
";",
"}",
"}"
] |
Helper method to walk the iterator and create a new request that defines which control param
should be negotiated right now.
|
[
"Helper",
"method",
"to",
"walk",
"the",
"iterator",
"and",
"create",
"a",
"new",
"request",
"that",
"defines",
"which",
"control",
"param",
"should",
"be",
"negotiated",
"right",
"now",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/DcpControlHandler.java#L71-L88
|
4,276 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/DcpControlHandler.java
|
DcpControlHandler.channelActive
|
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
controlSettings = dcpControl.getControls(getServerVersion(ctx.channel())).entrySet().iterator();
negotiate(ctx);
}
|
java
|
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
controlSettings = dcpControl.getControls(getServerVersion(ctx.channel())).entrySet().iterator();
negotiate(ctx);
}
|
[
"@",
"Override",
"public",
"void",
"channelActive",
"(",
"final",
"ChannelHandlerContext",
"ctx",
")",
"throws",
"Exception",
"{",
"controlSettings",
"=",
"dcpControl",
".",
"getControls",
"(",
"getServerVersion",
"(",
"ctx",
".",
"channel",
"(",
")",
")",
")",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"negotiate",
"(",
"ctx",
")",
";",
"}"
] |
Once the channel becomes active, start negotiating the dcp control params.
|
[
"Once",
"the",
"channel",
"becomes",
"active",
"start",
"negotiating",
"the",
"dcp",
"control",
"params",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/DcpControlHandler.java#L93-L97
|
4,277 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/state/SessionState.java
|
SessionState.setFromJson
|
public void setFromJson(final byte[] persisted) {
try {
SessionState decoded = JACKSON.readValue(persisted, SessionState.class);
decoded.foreachPartition(new Action1<PartitionState>() {
int i = 0;
@Override
public void call(PartitionState dps) {
partitionStates.set(i++, dps);
}
});
} catch (Exception ex) {
throw new RuntimeException("Could not decode SessionState from JSON.", ex);
}
}
|
java
|
public void setFromJson(final byte[] persisted) {
try {
SessionState decoded = JACKSON.readValue(persisted, SessionState.class);
decoded.foreachPartition(new Action1<PartitionState>() {
int i = 0;
@Override
public void call(PartitionState dps) {
partitionStates.set(i++, dps);
}
});
} catch (Exception ex) {
throw new RuntimeException("Could not decode SessionState from JSON.", ex);
}
}
|
[
"public",
"void",
"setFromJson",
"(",
"final",
"byte",
"[",
"]",
"persisted",
")",
"{",
"try",
"{",
"SessionState",
"decoded",
"=",
"JACKSON",
".",
"readValue",
"(",
"persisted",
",",
"SessionState",
".",
"class",
")",
";",
"decoded",
".",
"foreachPartition",
"(",
"new",
"Action1",
"<",
"PartitionState",
">",
"(",
")",
"{",
"int",
"i",
"=",
"0",
";",
"@",
"Override",
"public",
"void",
"call",
"(",
"PartitionState",
"dps",
")",
"{",
"partitionStates",
".",
"set",
"(",
"i",
"++",
",",
"dps",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not decode SessionState from JSON.\"",
",",
"ex",
")",
";",
"}",
"}"
] |
Recovers the session state from persisted JSON.
@param persisted the persisted JSON format.
|
[
"Recovers",
"the",
"session",
"state",
"from",
"persisted",
"JSON",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/state/SessionState.java#L103-L117
|
4,278 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/state/SessionState.java
|
SessionState.isAtEnd
|
public boolean isAtEnd() {
final AtomicBoolean atEnd = new AtomicBoolean(true);
foreachPartition(ps -> {
if (!ps.isAtEnd()) {
atEnd.set(false);
}
});
return atEnd.get();
}
|
java
|
public boolean isAtEnd() {
final AtomicBoolean atEnd = new AtomicBoolean(true);
foreachPartition(ps -> {
if (!ps.isAtEnd()) {
atEnd.set(false);
}
});
return atEnd.get();
}
|
[
"public",
"boolean",
"isAtEnd",
"(",
")",
"{",
"final",
"AtomicBoolean",
"atEnd",
"=",
"new",
"AtomicBoolean",
"(",
"true",
")",
";",
"foreachPartition",
"(",
"ps",
"->",
"{",
"if",
"(",
"!",
"ps",
".",
"isAtEnd",
"(",
")",
")",
"{",
"atEnd",
".",
"set",
"(",
"false",
")",
";",
"}",
"}",
")",
";",
"return",
"atEnd",
".",
"get",
"(",
")",
";",
"}"
] |
Check if the current sequence numbers for all partitions are >= the ones set as end.
@return true if all are at the end, false otherwise.
|
[
"Check",
"if",
"the",
"current",
"sequence",
"numbers",
"for",
"all",
"partitions",
"are",
">",
"=",
"the",
"ones",
"set",
"as",
"end",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/state/SessionState.java#L146-L154
|
4,279 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/state/SessionState.java
|
SessionState.foreachPartition
|
public void foreachPartition(final Action1<PartitionState> action) {
int len = partitionStates.length();
for (int i = 0; i < len; i++) {
PartitionState ps = partitionStates.get(i);
if (ps == null) {
continue;
}
action.call(ps);
}
}
|
java
|
public void foreachPartition(final Action1<PartitionState> action) {
int len = partitionStates.length();
for (int i = 0; i < len; i++) {
PartitionState ps = partitionStates.get(i);
if (ps == null) {
continue;
}
action.call(ps);
}
}
|
[
"public",
"void",
"foreachPartition",
"(",
"final",
"Action1",
"<",
"PartitionState",
">",
"action",
")",
"{",
"int",
"len",
"=",
"partitionStates",
".",
"length",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"PartitionState",
"ps",
"=",
"partitionStates",
".",
"get",
"(",
"i",
")",
";",
"if",
"(",
"ps",
"==",
"null",
")",
"{",
"continue",
";",
"}",
"action",
".",
"call",
"(",
"ps",
")",
";",
"}",
"}"
] |
Provides an iterator over all partitions, calling the callback for each one.
@param action the action to be called with the state for every partition.
|
[
"Provides",
"an",
"iterator",
"over",
"all",
"partitions",
"calling",
"the",
"callback",
"for",
"each",
"one",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/state/SessionState.java#L189-L198
|
4,280 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/Util.java
|
Util.removeFirstAndLastChar
|
public static String removeFirstAndLastChar(String text) {
Preconditions.checkNotNull(text, "text can not be null");
int n = text.length();
return text.substring(1, n - 1);
}
|
java
|
public static String removeFirstAndLastChar(String text) {
Preconditions.checkNotNull(text, "text can not be null");
int n = text.length();
return text.substring(1, n - 1);
}
|
[
"public",
"static",
"String",
"removeFirstAndLastChar",
"(",
"String",
"text",
")",
"{",
"Preconditions",
".",
"checkNotNull",
"(",
"text",
",",
"\"text can not be null\"",
")",
";",
"int",
"n",
"=",
"text",
".",
"length",
"(",
")",
";",
"return",
"text",
".",
"substring",
"(",
"1",
",",
"n",
"-",
"1",
")",
";",
"}"
] |
Remove first and last character from given string and return result.
@param text given string
@return substring of given string - without first and last characters
|
[
"Remove",
"first",
"and",
"last",
"character",
"from",
"given",
"string",
"and",
"return",
"result",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/Util.java#L30-L34
|
4,281 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/Enum.java
|
Enum.getConstantNames
|
public Set<String> getConstantNames() {
return constants.stream()
.map(EnumConstant::getName)
.collect(Collectors.toSet());
}
|
java
|
public Set<String> getConstantNames() {
return constants.stream()
.map(EnumConstant::getName)
.collect(Collectors.toSet());
}
|
[
"public",
"Set",
"<",
"String",
">",
"getConstantNames",
"(",
")",
"{",
"return",
"constants",
".",
"stream",
"(",
")",
".",
"map",
"(",
"EnumConstant",
"::",
"getName",
")",
".",
"collect",
"(",
"Collectors",
".",
"toSet",
"(",
")",
")",
";",
"}"
] |
Returns a list of all enum constant names.
|
[
"Returns",
"a",
"list",
"of",
"all",
"enum",
"constant",
"names",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/Enum.java#L38-L42
|
4,282 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/Enum.java
|
Enum.getConstant
|
public EnumConstant getConstant(String name) {
for (EnumConstant enumConstant : getConstants()) {
if (enumConstant.getName().equals(name)) {
return enumConstant;
}
}
return null;
}
|
java
|
public EnumConstant getConstant(String name) {
for (EnumConstant enumConstant : getConstants()) {
if (enumConstant.getName().equals(name)) {
return enumConstant;
}
}
return null;
}
|
[
"public",
"EnumConstant",
"getConstant",
"(",
"String",
"name",
")",
"{",
"for",
"(",
"EnumConstant",
"enumConstant",
":",
"getConstants",
"(",
")",
")",
"{",
"if",
"(",
"enumConstant",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"name",
")",
")",
"{",
"return",
"enumConstant",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Get enum constant by it's name.
|
[
"Get",
"enum",
"constant",
"by",
"it",
"s",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/Enum.java#L47-L54
|
4,283 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/buffer/StreamEventBuffer.java
|
StreamEventBuffer.clear
|
public void clear(final short vbucket) {
final Queue<BufferedEvent> queue = partitionQueues.get(vbucket);
synchronized (queue) {
LOGGER.debug("Clearing stream event buffer for partition {}", vbucket);
for (BufferedEvent bufferedEvent : queue) {
bufferedEvent.discard();
}
queue.clear();
}
}
|
java
|
public void clear(final short vbucket) {
final Queue<BufferedEvent> queue = partitionQueues.get(vbucket);
synchronized (queue) {
LOGGER.debug("Clearing stream event buffer for partition {}", vbucket);
for (BufferedEvent bufferedEvent : queue) {
bufferedEvent.discard();
}
queue.clear();
}
}
|
[
"public",
"void",
"clear",
"(",
"final",
"short",
"vbucket",
")",
"{",
"final",
"Queue",
"<",
"BufferedEvent",
">",
"queue",
"=",
"partitionQueues",
".",
"get",
"(",
"vbucket",
")",
";",
"synchronized",
"(",
"queue",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Clearing stream event buffer for partition {}\"",
",",
"vbucket",
")",
";",
"for",
"(",
"BufferedEvent",
"bufferedEvent",
":",
"queue",
")",
"{",
"bufferedEvent",
".",
"discard",
"(",
")",
";",
"}",
"queue",
".",
"clear",
"(",
")",
";",
"}",
"}"
] |
Discard all buffered events in the given vbucket.
|
[
"Discard",
"all",
"buffered",
"events",
"in",
"the",
"given",
"vbucket",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/buffer/StreamEventBuffer.java#L175-L184
|
4,284 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/buffer/StreamEventBuffer.java
|
StreamEventBuffer.rollback
|
private void rollback(final short vbucket, final long toSeqno) {
final Queue<BufferedEvent> queue = partitionQueues.get(vbucket);
synchronized (queue) {
for (Iterator<BufferedEvent> i = queue.iterator(); i.hasNext(); ) {
final BufferedEvent event = i.next();
final boolean eventSeqnoIsGreaterThanRollbackSeqno = Long.compareUnsigned(event.seqno, toSeqno) > 0;
if (eventSeqnoIsGreaterThanRollbackSeqno) {
LOGGER.trace("Dropping event with seqno {} from stream buffer for partition {}", event.seqno, vbucket);
event.discard();
i.remove();
}
}
}
}
|
java
|
private void rollback(final short vbucket, final long toSeqno) {
final Queue<BufferedEvent> queue = partitionQueues.get(vbucket);
synchronized (queue) {
for (Iterator<BufferedEvent> i = queue.iterator(); i.hasNext(); ) {
final BufferedEvent event = i.next();
final boolean eventSeqnoIsGreaterThanRollbackSeqno = Long.compareUnsigned(event.seqno, toSeqno) > 0;
if (eventSeqnoIsGreaterThanRollbackSeqno) {
LOGGER.trace("Dropping event with seqno {} from stream buffer for partition {}", event.seqno, vbucket);
event.discard();
i.remove();
}
}
}
}
|
[
"private",
"void",
"rollback",
"(",
"final",
"short",
"vbucket",
",",
"final",
"long",
"toSeqno",
")",
"{",
"final",
"Queue",
"<",
"BufferedEvent",
">",
"queue",
"=",
"partitionQueues",
".",
"get",
"(",
"vbucket",
")",
";",
"synchronized",
"(",
"queue",
")",
"{",
"for",
"(",
"Iterator",
"<",
"BufferedEvent",
">",
"i",
"=",
"queue",
".",
"iterator",
"(",
")",
";",
"i",
".",
"hasNext",
"(",
")",
";",
")",
"{",
"final",
"BufferedEvent",
"event",
"=",
"i",
".",
"next",
"(",
")",
";",
"final",
"boolean",
"eventSeqnoIsGreaterThanRollbackSeqno",
"=",
"Long",
".",
"compareUnsigned",
"(",
"event",
".",
"seqno",
",",
"toSeqno",
")",
">",
"0",
";",
"if",
"(",
"eventSeqnoIsGreaterThanRollbackSeqno",
")",
"{",
"LOGGER",
".",
"trace",
"(",
"\"Dropping event with seqno {} from stream buffer for partition {}\"",
",",
"event",
".",
"seqno",
",",
"vbucket",
")",
";",
"event",
".",
"discard",
"(",
")",
";",
"i",
".",
"remove",
"(",
")",
";",
"}",
"}",
"}",
"}"
] |
Discard any buffered events in the given vBucket with sequence numbers
higher than the given sequence number.
|
[
"Discard",
"any",
"buffered",
"events",
"in",
"the",
"given",
"vBucket",
"with",
"sequence",
"numbers",
"higher",
"than",
"the",
"given",
"sequence",
"number",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/buffer/StreamEventBuffer.java#L190-L204
|
4,285 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/buffer/StreamEventBuffer.java
|
StreamEventBuffer.onSeqnoPersisted
|
void onSeqnoPersisted(final short vbucket, final long seqno) {
final Queue<BufferedEvent> queue = partitionQueues.get(vbucket);
synchronized (queue) {
// while the head of the queue has a seqno <= the given seqno
while (!queue.isEmpty() && Long.compareUnsigned(queue.peek().seqno, seqno) < 1) {
final BufferedEvent event = queue.poll();
try {
switch (event.type) {
case DATA: // mutation, deletion, expiration
dataEventHandler.onEvent(event.flowController, event.event);
break;
case CONTROL: // snapshot
controlEventHandler.onEvent(event.flowController, event.event);
break;
case STREAM_END_OK:
eventBus.publish(new StreamEndEvent(vbucket, StreamEndReason.OK));
break;
default:
throw new RuntimeException("Unexpected event type: " + event.type);
}
} catch (Throwable t) {
LOGGER.error("Event handler threw exception", t);
}
}
}
}
|
java
|
void onSeqnoPersisted(final short vbucket, final long seqno) {
final Queue<BufferedEvent> queue = partitionQueues.get(vbucket);
synchronized (queue) {
// while the head of the queue has a seqno <= the given seqno
while (!queue.isEmpty() && Long.compareUnsigned(queue.peek().seqno, seqno) < 1) {
final BufferedEvent event = queue.poll();
try {
switch (event.type) {
case DATA: // mutation, deletion, expiration
dataEventHandler.onEvent(event.flowController, event.event);
break;
case CONTROL: // snapshot
controlEventHandler.onEvent(event.flowController, event.event);
break;
case STREAM_END_OK:
eventBus.publish(new StreamEndEvent(vbucket, StreamEndReason.OK));
break;
default:
throw new RuntimeException("Unexpected event type: " + event.type);
}
} catch (Throwable t) {
LOGGER.error("Event handler threw exception", t);
}
}
}
}
|
[
"void",
"onSeqnoPersisted",
"(",
"final",
"short",
"vbucket",
",",
"final",
"long",
"seqno",
")",
"{",
"final",
"Queue",
"<",
"BufferedEvent",
">",
"queue",
"=",
"partitionQueues",
".",
"get",
"(",
"vbucket",
")",
";",
"synchronized",
"(",
"queue",
")",
"{",
"// while the head of the queue has a seqno <= the given seqno",
"while",
"(",
"!",
"queue",
".",
"isEmpty",
"(",
")",
"&&",
"Long",
".",
"compareUnsigned",
"(",
"queue",
".",
"peek",
"(",
")",
".",
"seqno",
",",
"seqno",
")",
"<",
"1",
")",
"{",
"final",
"BufferedEvent",
"event",
"=",
"queue",
".",
"poll",
"(",
")",
";",
"try",
"{",
"switch",
"(",
"event",
".",
"type",
")",
"{",
"case",
"DATA",
":",
"// mutation, deletion, expiration",
"dataEventHandler",
".",
"onEvent",
"(",
"event",
".",
"flowController",
",",
"event",
".",
"event",
")",
";",
"break",
";",
"case",
"CONTROL",
":",
"// snapshot",
"controlEventHandler",
".",
"onEvent",
"(",
"event",
".",
"flowController",
",",
"event",
".",
"event",
")",
";",
"break",
";",
"case",
"STREAM_END_OK",
":",
"eventBus",
".",
"publish",
"(",
"new",
"StreamEndEvent",
"(",
"vbucket",
",",
"StreamEndReason",
".",
"OK",
")",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"RuntimeException",
"(",
"\"Unexpected event type: \"",
"+",
"event",
".",
"type",
")",
";",
"}",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"LOGGER",
".",
"error",
"(",
"\"Event handler threw exception\"",
",",
"t",
")",
";",
"}",
"}",
"}",
"}"
] |
Send to the wrapped handler all events with sequence numbers <= the given sequence number.
|
[
"Send",
"to",
"the",
"wrapped",
"handler",
"all",
"events",
"with",
"sequence",
"numbers",
"<",
"=",
"the",
"given",
"sequence",
"number",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/buffer/StreamEventBuffer.java#L216-L247
|
4,286 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/ServiceUtil.java
|
ServiceUtil.getMethodName
|
public static String getMethodName(ServiceMethod serviceMethod) {
String name = serviceMethod.getName();
String formattedName = Formatter.toCamelCase(name);
if (isReservedKeyword(formattedName)) {
return formattedName + '_';
}
return formattedName;
}
|
java
|
public static String getMethodName(ServiceMethod serviceMethod) {
String name = serviceMethod.getName();
String formattedName = Formatter.toCamelCase(name);
if (isReservedKeyword(formattedName)) {
return formattedName + '_';
}
return formattedName;
}
|
[
"public",
"static",
"String",
"getMethodName",
"(",
"ServiceMethod",
"serviceMethod",
")",
"{",
"String",
"name",
"=",
"serviceMethod",
".",
"getName",
"(",
")",
";",
"String",
"formattedName",
"=",
"Formatter",
".",
"toCamelCase",
"(",
"name",
")",
";",
"if",
"(",
"isReservedKeyword",
"(",
"formattedName",
")",
")",
"{",
"return",
"formattedName",
"+",
"'",
"'",
";",
"}",
"return",
"formattedName",
";",
"}"
] |
Returns java method name for corresponding rpc method.
|
[
"Returns",
"java",
"method",
"name",
"for",
"corresponding",
"rpc",
"method",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/ServiceUtil.java#L26-L33
|
4,287 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageUtil.java
|
MessageUtil.bitFieldNames
|
public static List<String> bitFieldNames(Message message) {
int fieldCount = message.getFieldCount();
if (fieldCount == 0) {
return Collections.emptyList();
}
List<String> result = new ArrayList<>();
int n = (fieldCount - 1) / 32 + 1;
for (int i = 0; i < n; i++) {
result.add("__bitField" + i);
}
return result;
}
|
java
|
public static List<String> bitFieldNames(Message message) {
int fieldCount = message.getFieldCount();
if (fieldCount == 0) {
return Collections.emptyList();
}
List<String> result = new ArrayList<>();
int n = (fieldCount - 1) / 32 + 1;
for (int i = 0; i < n; i++) {
result.add("__bitField" + i);
}
return result;
}
|
[
"public",
"static",
"List",
"<",
"String",
">",
"bitFieldNames",
"(",
"Message",
"message",
")",
"{",
"int",
"fieldCount",
"=",
"message",
".",
"getFieldCount",
"(",
")",
";",
"if",
"(",
"fieldCount",
"==",
"0",
")",
"{",
"return",
"Collections",
".",
"emptyList",
"(",
")",
";",
"}",
"List",
"<",
"String",
">",
"result",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"int",
"n",
"=",
"(",
"fieldCount",
"-",
"1",
")",
"/",
"32",
"+",
"1",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"result",
".",
"add",
"(",
"\"__bitField\"",
"+",
"i",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
Returns a list of bit fields used for field presence checks.
|
[
"Returns",
"a",
"list",
"of",
"bit",
"fields",
"used",
"for",
"field",
"presence",
"checks",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageUtil.java#L28-L39
|
4,288 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/java/MessageUtil.java
|
MessageUtil.getOneofNotSetConstantName
|
public static String getOneofNotSetConstantName(Oneof oneof) {
String name = oneof.getName();
String underscored = Formatter.toUnderscoreCase(name);
return Formatter.toUpperCase(underscored) + "_NOT_SET";
}
|
java
|
public static String getOneofNotSetConstantName(Oneof oneof) {
String name = oneof.getName();
String underscored = Formatter.toUnderscoreCase(name);
return Formatter.toUpperCase(underscored) + "_NOT_SET";
}
|
[
"public",
"static",
"String",
"getOneofNotSetConstantName",
"(",
"Oneof",
"oneof",
")",
"{",
"String",
"name",
"=",
"oneof",
".",
"getName",
"(",
")",
";",
"String",
"underscored",
"=",
"Formatter",
".",
"toUnderscoreCase",
"(",
"name",
")",
";",
"return",
"Formatter",
".",
"toUpperCase",
"(",
"underscored",
")",
"+",
"\"_NOT_SET\"",
";",
"}"
] |
Returns a "not set" name for one-of enum constant.
|
[
"Returns",
"a",
"not",
"set",
"name",
"for",
"one",
"-",
"of",
"enum",
"constant",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/java/MessageUtil.java#L49-L53
|
4,289 |
protostuff/protostuff-compiler
|
protostuff-generator/src/main/java/io/protostuff/generator/ProtostuffCompiler.java
|
ProtostuffCompiler.compile
|
public void compile(ModuleConfiguration configuration) {
LOGGER.debug("Compiling module {}", configuration);
FileReaderFactory fileReaderFactory = injector.getInstance(FileReaderFactory.class);
Importer importer = injector.getInstance(Importer.class);
CompilerRegistry registry = injector.getInstance(CompilerRegistry.class);
ProtoCompiler compiler = registry.findCompiler(configuration.getGenerator());
if (compiler == null) {
throw new GeneratorException("Unknown template: %s | %s", configuration.getGenerator(), registry.availableCompilers());
}
FileReader fileReader = fileReaderFactory.create(configuration.getIncludePaths());
Map<String, Proto> importedFiles = new HashMap<>();
for (String path : configuration.getProtoFiles()) {
LOGGER.info("Parse {}", path);
ProtoContext context = importer.importFile(fileReader, path);
Proto proto = context.getProto();
importedFiles.put(path, proto);
}
ImmutableModule.Builder builder = ImmutableModule.builder();
builder.name(configuration.getName());
builder.output(configuration.getOutput());
builder.options(configuration.getOptions());
for (Proto proto : importedFiles.values()) {
builder.addProtos(proto);
}
UsageIndex index = UsageIndex.build(importedFiles.values());
builder.usageIndex(index);
ImmutableModule module = builder.build();
for (Proto proto : importedFiles.values()) {
proto.setModule(module);
}
compiler.compile(module);
}
|
java
|
public void compile(ModuleConfiguration configuration) {
LOGGER.debug("Compiling module {}", configuration);
FileReaderFactory fileReaderFactory = injector.getInstance(FileReaderFactory.class);
Importer importer = injector.getInstance(Importer.class);
CompilerRegistry registry = injector.getInstance(CompilerRegistry.class);
ProtoCompiler compiler = registry.findCompiler(configuration.getGenerator());
if (compiler == null) {
throw new GeneratorException("Unknown template: %s | %s", configuration.getGenerator(), registry.availableCompilers());
}
FileReader fileReader = fileReaderFactory.create(configuration.getIncludePaths());
Map<String, Proto> importedFiles = new HashMap<>();
for (String path : configuration.getProtoFiles()) {
LOGGER.info("Parse {}", path);
ProtoContext context = importer.importFile(fileReader, path);
Proto proto = context.getProto();
importedFiles.put(path, proto);
}
ImmutableModule.Builder builder = ImmutableModule.builder();
builder.name(configuration.getName());
builder.output(configuration.getOutput());
builder.options(configuration.getOptions());
for (Proto proto : importedFiles.values()) {
builder.addProtos(proto);
}
UsageIndex index = UsageIndex.build(importedFiles.values());
builder.usageIndex(index);
ImmutableModule module = builder.build();
for (Proto proto : importedFiles.values()) {
proto.setModule(module);
}
compiler.compile(module);
}
|
[
"public",
"void",
"compile",
"(",
"ModuleConfiguration",
"configuration",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Compiling module {}\"",
",",
"configuration",
")",
";",
"FileReaderFactory",
"fileReaderFactory",
"=",
"injector",
".",
"getInstance",
"(",
"FileReaderFactory",
".",
"class",
")",
";",
"Importer",
"importer",
"=",
"injector",
".",
"getInstance",
"(",
"Importer",
".",
"class",
")",
";",
"CompilerRegistry",
"registry",
"=",
"injector",
".",
"getInstance",
"(",
"CompilerRegistry",
".",
"class",
")",
";",
"ProtoCompiler",
"compiler",
"=",
"registry",
".",
"findCompiler",
"(",
"configuration",
".",
"getGenerator",
"(",
")",
")",
";",
"if",
"(",
"compiler",
"==",
"null",
")",
"{",
"throw",
"new",
"GeneratorException",
"(",
"\"Unknown template: %s | %s\"",
",",
"configuration",
".",
"getGenerator",
"(",
")",
",",
"registry",
".",
"availableCompilers",
"(",
")",
")",
";",
"}",
"FileReader",
"fileReader",
"=",
"fileReaderFactory",
".",
"create",
"(",
"configuration",
".",
"getIncludePaths",
"(",
")",
")",
";",
"Map",
"<",
"String",
",",
"Proto",
">",
"importedFiles",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"String",
"path",
":",
"configuration",
".",
"getProtoFiles",
"(",
")",
")",
"{",
"LOGGER",
".",
"info",
"(",
"\"Parse {}\"",
",",
"path",
")",
";",
"ProtoContext",
"context",
"=",
"importer",
".",
"importFile",
"(",
"fileReader",
",",
"path",
")",
";",
"Proto",
"proto",
"=",
"context",
".",
"getProto",
"(",
")",
";",
"importedFiles",
".",
"put",
"(",
"path",
",",
"proto",
")",
";",
"}",
"ImmutableModule",
".",
"Builder",
"builder",
"=",
"ImmutableModule",
".",
"builder",
"(",
")",
";",
"builder",
".",
"name",
"(",
"configuration",
".",
"getName",
"(",
")",
")",
";",
"builder",
".",
"output",
"(",
"configuration",
".",
"getOutput",
"(",
")",
")",
";",
"builder",
".",
"options",
"(",
"configuration",
".",
"getOptions",
"(",
")",
")",
";",
"for",
"(",
"Proto",
"proto",
":",
"importedFiles",
".",
"values",
"(",
")",
")",
"{",
"builder",
".",
"addProtos",
"(",
"proto",
")",
";",
"}",
"UsageIndex",
"index",
"=",
"UsageIndex",
".",
"build",
"(",
"importedFiles",
".",
"values",
"(",
")",
")",
";",
"builder",
".",
"usageIndex",
"(",
"index",
")",
";",
"ImmutableModule",
"module",
"=",
"builder",
".",
"build",
"(",
")",
";",
"for",
"(",
"Proto",
"proto",
":",
"importedFiles",
".",
"values",
"(",
")",
")",
"{",
"proto",
".",
"setModule",
"(",
"module",
")",
";",
"}",
"compiler",
".",
"compile",
"(",
"module",
")",
";",
"}"
] |
Compile module - parse source files and generate code using specified outputs.
|
[
"Compile",
"module",
"-",
"parse",
"source",
"files",
"and",
"generate",
"code",
"using",
"specified",
"outputs",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-generator/src/main/java/io/protostuff/generator/ProtostuffCompiler.java#L42-L73
|
4,290 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/model/Service.java
|
Service.getMethod
|
public ServiceMethod getMethod(String name) {
for (ServiceMethod serviceMethod : getMethods()) {
if (serviceMethod.getName().equals(name)) {
return serviceMethod;
}
}
return null;
}
|
java
|
public ServiceMethod getMethod(String name) {
for (ServiceMethod serviceMethod : getMethods()) {
if (serviceMethod.getName().equals(name)) {
return serviceMethod;
}
}
return null;
}
|
[
"public",
"ServiceMethod",
"getMethod",
"(",
"String",
"name",
")",
"{",
"for",
"(",
"ServiceMethod",
"serviceMethod",
":",
"getMethods",
"(",
")",
")",
"{",
"if",
"(",
"serviceMethod",
".",
"getName",
"(",
")",
".",
"equals",
"(",
"name",
")",
")",
"{",
"return",
"serviceMethod",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Get a service method by it's name.
|
[
"Get",
"a",
"service",
"method",
"by",
"it",
"s",
"name",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/model/Service.java#L62-L69
|
4,291 |
protostuff/protostuff-compiler
|
protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoWalker.java
|
ProtoWalker.walk
|
public void walk() {
for (Processor<Proto> protoProcessor : protoProcessors) {
protoProcessor.run(context, proto);
}
walk(proto);
}
|
java
|
public void walk() {
for (Processor<Proto> protoProcessor : protoProcessors) {
protoProcessor.run(context, proto);
}
walk(proto);
}
|
[
"public",
"void",
"walk",
"(",
")",
"{",
"for",
"(",
"Processor",
"<",
"Proto",
">",
"protoProcessor",
":",
"protoProcessors",
")",
"{",
"protoProcessor",
".",
"run",
"(",
"context",
",",
"proto",
")",
";",
"}",
"walk",
"(",
"proto",
")",
";",
"}"
] |
Start walking.
|
[
"Start",
"walking",
"."
] |
665256c42cb41da849e8321ffcab088350ace171
|
https://github.com/protostuff/protostuff-compiler/blob/665256c42cb41da849e8321ffcab088350ace171/protostuff-parser/src/main/java/io/protostuff/compiler/parser/ProtoWalker.java#L134-L139
|
4,292 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/StartStreamHandler.java
|
StartStreamHandler.channelActive
|
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
String terseUri = "/pools/default/bs/" + bucket;
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, terseUri);
request.headers().add(HttpHeaders.Names.ACCEPT, "application/json");
addHttpBasicAuth(ctx, request);
ctx.writeAndFlush(request);
}
|
java
|
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
String terseUri = "/pools/default/bs/" + bucket;
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, terseUri);
request.headers().add(HttpHeaders.Names.ACCEPT, "application/json");
addHttpBasicAuth(ctx, request);
ctx.writeAndFlush(request);
}
|
[
"@",
"Override",
"public",
"void",
"channelActive",
"(",
"final",
"ChannelHandlerContext",
"ctx",
")",
"throws",
"Exception",
"{",
"String",
"terseUri",
"=",
"\"/pools/default/bs/\"",
"+",
"bucket",
";",
"FullHttpRequest",
"request",
"=",
"new",
"DefaultFullHttpRequest",
"(",
"HttpVersion",
".",
"HTTP_1_1",
",",
"HttpMethod",
".",
"GET",
",",
"terseUri",
")",
";",
"request",
".",
"headers",
"(",
")",
".",
"add",
"(",
"HttpHeaders",
".",
"Names",
".",
"ACCEPT",
",",
"\"application/json\"",
")",
";",
"addHttpBasicAuth",
"(",
"ctx",
",",
"request",
")",
";",
"ctx",
".",
"writeAndFlush",
"(",
"request",
")",
";",
"}"
] |
Once the channel is active, start to send the HTTP request to begin chunking.
|
[
"Once",
"the",
"channel",
"is",
"active",
"start",
"to",
"send",
"the",
"HTTP",
"request",
"to",
"begin",
"chunking",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/StartStreamHandler.java#L54-L61
|
4,293 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/StartStreamHandler.java
|
StartStreamHandler.addHttpBasicAuth
|
private void addHttpBasicAuth(final ChannelHandlerContext ctx, final HttpRequest request) {
ByteBuf raw = ctx.alloc().buffer(username.length() + password.length() + 1);
raw.writeBytes((username + ":" + password).getBytes(CharsetUtil.UTF_8));
ByteBuf encoded = Base64.encode(raw, false);
request.headers().add(HttpHeaders.Names.AUTHORIZATION, "Basic " + encoded.toString(CharsetUtil.UTF_8));
encoded.release();
raw.release();
}
|
java
|
private void addHttpBasicAuth(final ChannelHandlerContext ctx, final HttpRequest request) {
ByteBuf raw = ctx.alloc().buffer(username.length() + password.length() + 1);
raw.writeBytes((username + ":" + password).getBytes(CharsetUtil.UTF_8));
ByteBuf encoded = Base64.encode(raw, false);
request.headers().add(HttpHeaders.Names.AUTHORIZATION, "Basic " + encoded.toString(CharsetUtil.UTF_8));
encoded.release();
raw.release();
}
|
[
"private",
"void",
"addHttpBasicAuth",
"(",
"final",
"ChannelHandlerContext",
"ctx",
",",
"final",
"HttpRequest",
"request",
")",
"{",
"ByteBuf",
"raw",
"=",
"ctx",
".",
"alloc",
"(",
")",
".",
"buffer",
"(",
"username",
".",
"length",
"(",
")",
"+",
"password",
".",
"length",
"(",
")",
"+",
"1",
")",
";",
"raw",
".",
"writeBytes",
"(",
"(",
"username",
"+",
"\":\"",
"+",
"password",
")",
".",
"getBytes",
"(",
"CharsetUtil",
".",
"UTF_8",
")",
")",
";",
"ByteBuf",
"encoded",
"=",
"Base64",
".",
"encode",
"(",
"raw",
",",
"false",
")",
";",
"request",
".",
"headers",
"(",
")",
".",
"add",
"(",
"HttpHeaders",
".",
"Names",
".",
"AUTHORIZATION",
",",
"\"Basic \"",
"+",
"encoded",
".",
"toString",
"(",
"CharsetUtil",
".",
"UTF_8",
")",
")",
";",
"encoded",
".",
"release",
"(",
")",
";",
"raw",
".",
"release",
"(",
")",
";",
"}"
] |
Helper method to add authentication credentials to the config stream request.
|
[
"Helper",
"method",
"to",
"add",
"authentication",
"credentials",
"to",
"the",
"config",
"stream",
"request",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/StartStreamHandler.java#L91-L98
|
4,294 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/DcpMessageHandler.java
|
DcpMessageHandler.userEventTriggered
|
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
if (e.state() == IdleState.READER_IDLE) {
LOGGER.warn("Closing dead connection.");
ctx.close();
return;
}
}
super.userEventTriggered(ctx, evt);
}
|
java
|
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
if (e.state() == IdleState.READER_IDLE) {
LOGGER.warn("Closing dead connection.");
ctx.close();
return;
}
}
super.userEventTriggered(ctx, evt);
}
|
[
"@",
"Override",
"public",
"void",
"userEventTriggered",
"(",
"ChannelHandlerContext",
"ctx",
",",
"Object",
"evt",
")",
"throws",
"Exception",
"{",
"if",
"(",
"evt",
"instanceof",
"IdleStateEvent",
")",
"{",
"IdleStateEvent",
"e",
"=",
"(",
"IdleStateEvent",
")",
"evt",
";",
"if",
"(",
"e",
".",
"state",
"(",
")",
"==",
"IdleState",
".",
"READER_IDLE",
")",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Closing dead connection.\"",
")",
";",
"ctx",
".",
"close",
"(",
")",
";",
"return",
";",
"}",
"}",
"super",
".",
"userEventTriggered",
"(",
"ctx",
",",
"evt",
")",
";",
"}"
] |
Close dead connection in response to idle event from IdleStateHandler.
|
[
"Close",
"dead",
"connection",
"in",
"response",
"to",
"idle",
"event",
"from",
"IdleStateHandler",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/DcpMessageHandler.java#L323-L335
|
4,295 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/DcpMessageHandler.java
|
DcpMessageHandler.handleRequest
|
private void handleRequest(final ChannelHandlerContext ctx, final ByteBuf message) {
if (isDataMessage(message)) {
dataEventHandler.onEvent(flowController, message);
} else if (isControlMessage(message)) {
controlHandler.onEvent(flowController, message);
} else if (DcpNoopRequest.is(message)) {
try {
ByteBuf buffer = ctx.alloc().buffer();
DcpNoopResponse.init(buffer);
MessageUtil.setOpaque(MessageUtil.getOpaque(message), buffer);
ctx.writeAndFlush(buffer);
} finally {
message.release();
}
} else {
try {
LOGGER.warn("Unknown DCP Message, ignoring. \n{}", MessageUtil.humanize(message));
} finally {
message.release();
}
}
}
|
java
|
private void handleRequest(final ChannelHandlerContext ctx, final ByteBuf message) {
if (isDataMessage(message)) {
dataEventHandler.onEvent(flowController, message);
} else if (isControlMessage(message)) {
controlHandler.onEvent(flowController, message);
} else if (DcpNoopRequest.is(message)) {
try {
ByteBuf buffer = ctx.alloc().buffer();
DcpNoopResponse.init(buffer);
MessageUtil.setOpaque(MessageUtil.getOpaque(message), buffer);
ctx.writeAndFlush(buffer);
} finally {
message.release();
}
} else {
try {
LOGGER.warn("Unknown DCP Message, ignoring. \n{}", MessageUtil.humanize(message));
} finally {
message.release();
}
}
}
|
[
"private",
"void",
"handleRequest",
"(",
"final",
"ChannelHandlerContext",
"ctx",
",",
"final",
"ByteBuf",
"message",
")",
"{",
"if",
"(",
"isDataMessage",
"(",
"message",
")",
")",
"{",
"dataEventHandler",
".",
"onEvent",
"(",
"flowController",
",",
"message",
")",
";",
"}",
"else",
"if",
"(",
"isControlMessage",
"(",
"message",
")",
")",
"{",
"controlHandler",
".",
"onEvent",
"(",
"flowController",
",",
"message",
")",
";",
"}",
"else",
"if",
"(",
"DcpNoopRequest",
".",
"is",
"(",
"message",
")",
")",
"{",
"try",
"{",
"ByteBuf",
"buffer",
"=",
"ctx",
".",
"alloc",
"(",
")",
".",
"buffer",
"(",
")",
";",
"DcpNoopResponse",
".",
"init",
"(",
"buffer",
")",
";",
"MessageUtil",
".",
"setOpaque",
"(",
"MessageUtil",
".",
"getOpaque",
"(",
"message",
")",
",",
"buffer",
")",
";",
"ctx",
".",
"writeAndFlush",
"(",
"buffer",
")",
";",
"}",
"finally",
"{",
"message",
".",
"release",
"(",
")",
";",
"}",
"}",
"else",
"{",
"try",
"{",
"LOGGER",
".",
"warn",
"(",
"\"Unknown DCP Message, ignoring. \\n{}\"",
",",
"MessageUtil",
".",
"humanize",
"(",
"message",
")",
")",
";",
"}",
"finally",
"{",
"message",
".",
"release",
"(",
")",
";",
"}",
"}",
"}"
] |
Dispatch incoming message to either the data or the control feeds.
|
[
"Dispatch",
"incoming",
"message",
"to",
"either",
"the",
"data",
"or",
"the",
"control",
"feeds",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/DcpMessageHandler.java#L340-L361
|
4,296 |
couchbase/java-dcp-client
|
src/main/java/com/couchbase/client/dcp/transport/netty/DcpMessageHandler.java
|
DcpMessageHandler.isDataMessage
|
private static boolean isDataMessage(final ByteBuf msg) {
return DcpMutationMessage.is(msg) || DcpDeletionMessage.is(msg) || DcpExpirationMessage.is(msg);
}
|
java
|
private static boolean isDataMessage(final ByteBuf msg) {
return DcpMutationMessage.is(msg) || DcpDeletionMessage.is(msg) || DcpExpirationMessage.is(msg);
}
|
[
"private",
"static",
"boolean",
"isDataMessage",
"(",
"final",
"ByteBuf",
"msg",
")",
"{",
"return",
"DcpMutationMessage",
".",
"is",
"(",
"msg",
")",
"||",
"DcpDeletionMessage",
".",
"is",
"(",
"msg",
")",
"||",
"DcpExpirationMessage",
".",
"is",
"(",
"msg",
")",
";",
"}"
] |
Helper method to check if the given byte buffer is a data message.
@param msg the message to check.
@return true if it is, false otherwise.
|
[
"Helper",
"method",
"to",
"check",
"if",
"the",
"given",
"byte",
"buffer",
"is",
"a",
"data",
"message",
"."
] |
75359d8c081d6c575f8087cf7c28d24ab24c6421
|
https://github.com/couchbase/java-dcp-client/blob/75359d8c081d6c575f8087cf7c28d24ab24c6421/src/main/java/com/couchbase/client/dcp/transport/netty/DcpMessageHandler.java#L379-L381
|
4,297 |
stormpath/stormpath-shiro
|
core/src/main/java/com/stormpath/shiro/realm/ApplicationRealm.java
|
ApplicationRealm.ensureApplicationReference
|
protected final Application ensureApplicationReference() {
if (this.application == null) {
assertState();
Application tmpApp = applicationResolver.getApplication(client, applicationRestUrl);
if (tmpApp == null) {
throw new IllegalStateException("ApplicationResolver returned 'null' Application, this is likely a configuration error.");
}
this.application = tmpApp;
}
return this.application;
}
|
java
|
protected final Application ensureApplicationReference() {
if (this.application == null) {
assertState();
Application tmpApp = applicationResolver.getApplication(client, applicationRestUrl);
if (tmpApp == null) {
throw new IllegalStateException("ApplicationResolver returned 'null' Application, this is likely a configuration error.");
}
this.application = tmpApp;
}
return this.application;
}
|
[
"protected",
"final",
"Application",
"ensureApplicationReference",
"(",
")",
"{",
"if",
"(",
"this",
".",
"application",
"==",
"null",
")",
"{",
"assertState",
"(",
")",
";",
"Application",
"tmpApp",
"=",
"applicationResolver",
".",
"getApplication",
"(",
"client",
",",
"applicationRestUrl",
")",
";",
"if",
"(",
"tmpApp",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalStateException",
"(",
"\"ApplicationResolver returned 'null' Application, this is likely a configuration error.\"",
")",
";",
"}",
"this",
".",
"application",
"=",
"tmpApp",
";",
"}",
"return",
"this",
".",
"application",
";",
"}"
] |
acquisition, so it is negligible if this executes a few times instead of just once.
|
[
"acquisition",
"so",
"it",
"is",
"negligible",
"if",
"this",
"executes",
"a",
"few",
"times",
"instead",
"of",
"just",
"once",
"."
] |
7a3c4fd3bd0ed9bb4546932495c79e6ad6fa1a92
|
https://github.com/stormpath/stormpath-shiro/blob/7a3c4fd3bd0ed9bb4546932495c79e6ad6fa1a92/core/src/main/java/com/stormpath/shiro/realm/ApplicationRealm.java#L337-L347
|
4,298 |
uPortal-Project/uportal-home
|
web/src/main/java/edu/wisc/my/home/api/RestProxyApplicationConfiguration.java
|
RestProxyApplicationConfiguration.restTemplate
|
@Bean
public RestTemplate restTemplate(){
RestTemplate restTemplate=new RestTemplate();
List<HttpMessageConverter<?>> mc=restTemplate.getMessageConverters();
MappingJackson2HttpMessageConverter json=new MappingJackson2HttpMessageConverter();
List<MediaType> supportedMediaTypes=new ArrayList<MediaType>();
supportedMediaTypes.add(new MediaType("text","javascript",Charset.forName("utf-8")));
supportedMediaTypes.add(new MediaType("application", "javascript", Charset.forName("UTF-8")));
json.setSupportedMediaTypes(supportedMediaTypes);
mc.add(json);
restTemplate.setMessageConverters(mc);
return restTemplate;
}
|
java
|
@Bean
public RestTemplate restTemplate(){
RestTemplate restTemplate=new RestTemplate();
List<HttpMessageConverter<?>> mc=restTemplate.getMessageConverters();
MappingJackson2HttpMessageConverter json=new MappingJackson2HttpMessageConverter();
List<MediaType> supportedMediaTypes=new ArrayList<MediaType>();
supportedMediaTypes.add(new MediaType("text","javascript",Charset.forName("utf-8")));
supportedMediaTypes.add(new MediaType("application", "javascript", Charset.forName("UTF-8")));
json.setSupportedMediaTypes(supportedMediaTypes);
mc.add(json);
restTemplate.setMessageConverters(mc);
return restTemplate;
}
|
[
"@",
"Bean",
"public",
"RestTemplate",
"restTemplate",
"(",
")",
"{",
"RestTemplate",
"restTemplate",
"=",
"new",
"RestTemplate",
"(",
")",
";",
"List",
"<",
"HttpMessageConverter",
"<",
"?",
">",
">",
"mc",
"=",
"restTemplate",
".",
"getMessageConverters",
"(",
")",
";",
"MappingJackson2HttpMessageConverter",
"json",
"=",
"new",
"MappingJackson2HttpMessageConverter",
"(",
")",
";",
"List",
"<",
"MediaType",
">",
"supportedMediaTypes",
"=",
"new",
"ArrayList",
"<",
"MediaType",
">",
"(",
")",
";",
"supportedMediaTypes",
".",
"add",
"(",
"new",
"MediaType",
"(",
"\"text\"",
",",
"\"javascript\"",
",",
"Charset",
".",
"forName",
"(",
"\"utf-8\"",
")",
")",
")",
";",
"supportedMediaTypes",
".",
"add",
"(",
"new",
"MediaType",
"(",
"\"application\"",
",",
"\"javascript\"",
",",
"Charset",
".",
"forName",
"(",
"\"UTF-8\"",
")",
")",
")",
";",
"json",
".",
"setSupportedMediaTypes",
"(",
"supportedMediaTypes",
")",
";",
"mc",
".",
"add",
"(",
"json",
")",
";",
"restTemplate",
".",
"setMessageConverters",
"(",
"mc",
")",
";",
"return",
"restTemplate",
";",
"}"
] |
This bean adds in unsupported return types. Necessary because even though
rest proxy accepts all types, there are still a few that are unsupported
@return a {@link RestTemplate}
|
[
"This",
"bean",
"adds",
"in",
"unsupported",
"return",
"types",
".",
"Necessary",
"because",
"even",
"though",
"rest",
"proxy",
"accepts",
"all",
"types",
"there",
"are",
"still",
"a",
"few",
"that",
"are",
"unsupported"
] |
beefe0e95920cb9e6e78f1005ea1e8e3064c0f69
|
https://github.com/uPortal-Project/uportal-home/blob/beefe0e95920cb9e6e78f1005ea1e8e3064c0f69/web/src/main/java/edu/wisc/my/home/api/RestProxyApplicationConfiguration.java#L61-L73
|
4,299 |
seedstack/seed
|
security/specs/src/main/java/org/seedstack/seed/security/principals/Principals.java
|
Principals.getSimplePrincipals
|
public static Collection<SimplePrincipalProvider> getSimplePrincipals(
Collection<PrincipalProvider<?>> principalProviders) {
Collection<SimplePrincipalProvider> principals = new ArrayList<>();
for (PrincipalProvider<?> principal : principalProviders) {
if (principal instanceof SimplePrincipalProvider) {
principals.add((SimplePrincipalProvider) principal);
}
}
return principals;
}
|
java
|
public static Collection<SimplePrincipalProvider> getSimplePrincipals(
Collection<PrincipalProvider<?>> principalProviders) {
Collection<SimplePrincipalProvider> principals = new ArrayList<>();
for (PrincipalProvider<?> principal : principalProviders) {
if (principal instanceof SimplePrincipalProvider) {
principals.add((SimplePrincipalProvider) principal);
}
}
return principals;
}
|
[
"public",
"static",
"Collection",
"<",
"SimplePrincipalProvider",
">",
"getSimplePrincipals",
"(",
"Collection",
"<",
"PrincipalProvider",
"<",
"?",
">",
">",
"principalProviders",
")",
"{",
"Collection",
"<",
"SimplePrincipalProvider",
">",
"principals",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"PrincipalProvider",
"<",
"?",
">",
"principal",
":",
"principalProviders",
")",
"{",
"if",
"(",
"principal",
"instanceof",
"SimplePrincipalProvider",
")",
"{",
"principals",
".",
"add",
"(",
"(",
"SimplePrincipalProvider",
")",
"principal",
")",
";",
"}",
"}",
"return",
"principals",
";",
"}"
] |
Extracts the simple principals of the collection of principals
@param principalProviders the principals to extract from
@return the simple principals
|
[
"Extracts",
"the",
"simple",
"principals",
"of",
"the",
"collection",
"of",
"principals"
] |
d9cf33bfb2fffcdbb0976f4726e943acda90e828
|
https://github.com/seedstack/seed/blob/d9cf33bfb2fffcdbb0976f4726e943acda90e828/security/specs/src/main/java/org/seedstack/seed/security/principals/Principals.java#L153-L162
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.