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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
asterisk-java/asterisk-java | src/main/java/org/asteriskjava/manager/action/UpdateConfigAction.java | UpdateConfigAction.setAttributes | public void setAttributes(Map<String, String> actions)
{
this.actions = actions;
this.actionCounter = actions.keySet().size();
} | java | public void setAttributes(Map<String, String> actions)
{
this.actions = actions;
this.actionCounter = actions.keySet().size();
} | [
"public",
"void",
"setAttributes",
"(",
"Map",
"<",
"String",
",",
"String",
">",
"actions",
")",
"{",
"this",
".",
"actions",
"=",
"actions",
";",
"this",
".",
"actionCounter",
"=",
"actions",
".",
"keySet",
"(",
")",
".",
"size",
"(",
")",
";",
"}"... | You may use this field to directly, programmatically add your own Map of
key,value pairs that you would like to send for this command. Setting
your own map will reset the command index to the number of keys in the
Map
@see org.asteriskjava.manager.action.UpdateConfigAction#addCommand
@param actions the actions to set | [
"You",
"may",
"use",
"this",
"field",
"to",
"directly",
"programmatically",
"add",
"your",
"own",
"Map",
"of",
"key",
"value",
"pairs",
"that",
"you",
"would",
"like",
"to",
"send",
"for",
"this",
"command",
".",
"Setting",
"your",
"own",
"map",
"will",
... | cdc9849270d97ef75afa447a02c5194ed29121eb | https://github.com/asterisk-java/asterisk-java/blob/cdc9849270d97ef75afa447a02c5194ed29121eb/src/main/java/org/asteriskjava/manager/action/UpdateConfigAction.java#L238-L242 | train |
Netflix/netflix-commons | netflix-statistics/src/main/java/com/netflix/stats/distribution/DataAccumulator.java | DataAccumulator.publish | public void publish() {
/*
* Some care is required here to correctly swap the DataBuffers,
* but not hold the synchronization object while compiling stats
* (a potentially long computation). This ensures that continued
* data collection (calls to noteValue()) will not be blocked for any
* significant period.
*/
DataBuffer tmp = null;
Lock l = null;
synchronized (swapLock) {
// Swap buffers
tmp = current;
current = previous;
previous = tmp;
// Start collection in the new "current" buffer
l = current.getLock();
l.lock();
try {
current.startCollection();
} finally {
l.unlock();
}
// Grab lock on new "previous" buffer
l = tmp.getLock();
l.lock();
}
// Release synchronizaton *before* publishing data
try {
tmp.endCollection();
publish(tmp);
} finally {
l.unlock();
}
} | java | public void publish() {
/*
* Some care is required here to correctly swap the DataBuffers,
* but not hold the synchronization object while compiling stats
* (a potentially long computation). This ensures that continued
* data collection (calls to noteValue()) will not be blocked for any
* significant period.
*/
DataBuffer tmp = null;
Lock l = null;
synchronized (swapLock) {
// Swap buffers
tmp = current;
current = previous;
previous = tmp;
// Start collection in the new "current" buffer
l = current.getLock();
l.lock();
try {
current.startCollection();
} finally {
l.unlock();
}
// Grab lock on new "previous" buffer
l = tmp.getLock();
l.lock();
}
// Release synchronizaton *before* publishing data
try {
tmp.endCollection();
publish(tmp);
} finally {
l.unlock();
}
} | [
"public",
"void",
"publish",
"(",
")",
"{",
"/*\n * Some care is required here to correctly swap the DataBuffers,\n * but not hold the synchronization object while compiling stats\n * (a potentially long computation). This ensures that continued\n * data collection (call... | Swaps the data collection buffers, and computes statistics
about the data collected up til now. | [
"Swaps",
"the",
"data",
"collection",
"buffers",
"and",
"computes",
"statistics",
"about",
"the",
"data",
"collected",
"up",
"til",
"now",
"."
] | 7a158af76906d4a9b753e9344ce3e7abeb91dc01 | https://github.com/Netflix/netflix-commons/blob/7a158af76906d4a9b753e9344ce3e7abeb91dc01/netflix-statistics/src/main/java/com/netflix/stats/distribution/DataAccumulator.java#L74-L108 | train |
Netflix/netflix-commons | netflix-statistics/src/main/java/com/netflix/stats/distribution/DataBuffer.java | DataBuffer.getPercentiles | public double[] getPercentiles(double[] percents, double[] percentiles) {
for (int i = 0; i < percents.length; i++) {
percentiles[i] = computePercentile(percents[i]);
}
return percentiles;
} | java | public double[] getPercentiles(double[] percents, double[] percentiles) {
for (int i = 0; i < percents.length; i++) {
percentiles[i] = computePercentile(percents[i]);
}
return percentiles;
} | [
"public",
"double",
"[",
"]",
"getPercentiles",
"(",
"double",
"[",
"]",
"percents",
",",
"double",
"[",
"]",
"percentiles",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"percents",
".",
"length",
";",
"i",
"++",
")",
"{",
"percentile... | Gets the requested percentile statistics.
@param percents array of percentile values to compute,
which must be in the range {@code [0 .. 100]}
@param percentiles array to fill in with the percentile values;
must be the same length as {@code percents}
@return the {@code percentiles} array
@see <a href="http://en.wikipedia.org/wiki/Percentile">Percentile (Wikipedia)</a>
@see <a href="http://cnx.org/content/m10805/latest/">Percentile</a> | [
"Gets",
"the",
"requested",
"percentile",
"statistics",
"."
] | 7a158af76906d4a9b753e9344ce3e7abeb91dc01 | https://github.com/Netflix/netflix-commons/blob/7a158af76906d4a9b753e9344ce3e7abeb91dc01/netflix-statistics/src/main/java/com/netflix/stats/distribution/DataBuffer.java#L164-L169 | train |
Netflix/netflix-commons | netflix-eventbus/src/main/java/com/netflix/eventbus/utils/EventBusUtils.java | EventBusUtils.applyFilters | public static boolean applyFilters(Object event, Set<EventFilter> filters, StatsTimer filterStats,
String invokerDesc, Logger logger) {
if (filters.isEmpty()) {
return true;
}
Stopwatch filterStart = filterStats.start();
try {
for (EventFilter filter : filters) {
if (!filter.apply(event)) {
logger.debug(
"Event: " + event + " filtered out for : " + invokerDesc + " due to the filter: " + filter);
return false;
}
}
return true;
} finally {
filterStart.stop();
}
} | java | public static boolean applyFilters(Object event, Set<EventFilter> filters, StatsTimer filterStats,
String invokerDesc, Logger logger) {
if (filters.isEmpty()) {
return true;
}
Stopwatch filterStart = filterStats.start();
try {
for (EventFilter filter : filters) {
if (!filter.apply(event)) {
logger.debug(
"Event: " + event + " filtered out for : " + invokerDesc + " due to the filter: " + filter);
return false;
}
}
return true;
} finally {
filterStart.stop();
}
} | [
"public",
"static",
"boolean",
"applyFilters",
"(",
"Object",
"event",
",",
"Set",
"<",
"EventFilter",
">",
"filters",
",",
"StatsTimer",
"filterStats",
",",
"String",
"invokerDesc",
",",
"Logger",
"logger",
")",
"{",
"if",
"(",
"filters",
".",
"isEmpty",
"(... | Utility method to apply filters for an event, this can be used both by publisher & subscriber code.
@param event The event to apply filter on.
@param filters Filters to apply.
@param filterStats Stats timer for applying the filter.
@param invokerDesc A string description for the invoker, this is required just for logging.
@param logger Logger instance to use for logging.
@return <code>true</code> if the event should be processed, <code>false</code> if the event should not be
processed any further i.e. it is filtered out. This will log a debug message when the event is filtered. | [
"Utility",
"method",
"to",
"apply",
"filters",
"for",
"an",
"event",
"this",
"can",
"be",
"used",
"both",
"by",
"publisher",
"&",
"subscriber",
"code",
"."
] | 7a158af76906d4a9b753e9344ce3e7abeb91dc01 | https://github.com/Netflix/netflix-commons/blob/7a158af76906d4a9b753e9344ce3e7abeb91dc01/netflix-eventbus/src/main/java/com/netflix/eventbus/utils/EventBusUtils.java#L156-L174 | train |
Netflix/netflix-commons | netflix-infix/src/main/java/com/netflix/infix/lang/infix/antlr/EqualityComparisonBaseTreeNode.java | EqualityComparisonBaseTreeNode.getEqualFilter | protected Predicate<Object> getEqualFilter() {
String xpath = getXPath(getChild(0));
Tree valueNode = getChild(1);
switch(valueNode.getType()){
case NUMBER:
Number value = (Number)((ValueTreeNode)valueNode).getValue();
return new PathValueEventFilter(xpath, new NumericValuePredicate(value, "="));
case STRING:
String sValue = (String)((ValueTreeNode)valueNode).getValue();
return new PathValueEventFilter(xpath, new StringValuePredicate(sValue));
case TRUE:
return new PathValueEventFilter(xpath, BooleanValuePredicate.TRUE);
case FALSE:
return new PathValueEventFilter(xpath, BooleanValuePredicate.FALSE);
case NULL:
return new PathValueEventFilter(xpath, NullValuePredicate.INSTANCE);
case XPATH_FUN_NAME:
String aPath = (String)((ValueTreeNode)valueNode).getValue();
return new PathValueEventFilter(xpath, new XPathValuePredicate(aPath, xpath));
case TIME_MILLIS_FUN_NAME:
TimeMillisValueTreeNode timeNode = (TimeMillisValueTreeNode)valueNode;
return new PathValueEventFilter(xpath,
new TimeMillisValuePredicate(
timeNode.getValueFormat(),
timeNode.getValue(),
"="));
case TIME_STRING_FUN_NAME:
TimeStringValueTreeNode timeStringNode = (TimeStringValueTreeNode)valueNode;
return new PathValueEventFilter(xpath,
new TimeStringValuePredicate(
timeStringNode.getValueTimeFormat(),
timeStringNode.getInputTimeFormat(),
timeStringNode.getValue(),
"="));
default:
throw new UnexpectedTokenException(valueNode, "Number", "String", "TRUE", "FALSE");
}
} | java | protected Predicate<Object> getEqualFilter() {
String xpath = getXPath(getChild(0));
Tree valueNode = getChild(1);
switch(valueNode.getType()){
case NUMBER:
Number value = (Number)((ValueTreeNode)valueNode).getValue();
return new PathValueEventFilter(xpath, new NumericValuePredicate(value, "="));
case STRING:
String sValue = (String)((ValueTreeNode)valueNode).getValue();
return new PathValueEventFilter(xpath, new StringValuePredicate(sValue));
case TRUE:
return new PathValueEventFilter(xpath, BooleanValuePredicate.TRUE);
case FALSE:
return new PathValueEventFilter(xpath, BooleanValuePredicate.FALSE);
case NULL:
return new PathValueEventFilter(xpath, NullValuePredicate.INSTANCE);
case XPATH_FUN_NAME:
String aPath = (String)((ValueTreeNode)valueNode).getValue();
return new PathValueEventFilter(xpath, new XPathValuePredicate(aPath, xpath));
case TIME_MILLIS_FUN_NAME:
TimeMillisValueTreeNode timeNode = (TimeMillisValueTreeNode)valueNode;
return new PathValueEventFilter(xpath,
new TimeMillisValuePredicate(
timeNode.getValueFormat(),
timeNode.getValue(),
"="));
case TIME_STRING_FUN_NAME:
TimeStringValueTreeNode timeStringNode = (TimeStringValueTreeNode)valueNode;
return new PathValueEventFilter(xpath,
new TimeStringValuePredicate(
timeStringNode.getValueTimeFormat(),
timeStringNode.getInputTimeFormat(),
timeStringNode.getValue(),
"="));
default:
throw new UnexpectedTokenException(valueNode, "Number", "String", "TRUE", "FALSE");
}
} | [
"protected",
"Predicate",
"<",
"Object",
">",
"getEqualFilter",
"(",
")",
"{",
"String",
"xpath",
"=",
"getXPath",
"(",
"getChild",
"(",
"0",
")",
")",
";",
"Tree",
"valueNode",
"=",
"getChild",
"(",
"1",
")",
";",
"switch",
"(",
"valueNode",
".",
"get... | but I can't get ANTLR to generated nested tree with added node. | [
"but",
"I",
"can",
"t",
"get",
"ANTLR",
"to",
"generated",
"nested",
"tree",
"with",
"added",
"node",
"."
] | 7a158af76906d4a9b753e9344ce3e7abeb91dc01 | https://github.com/Netflix/netflix-commons/blob/7a158af76906d4a9b753e9344ce3e7abeb91dc01/netflix-infix/src/main/java/com/netflix/infix/lang/infix/antlr/EqualityComparisonBaseTreeNode.java#L24-L63 | train |
Netflix/netflix-commons | netflix-commons-util/src/main/java/com/netflix/util/HashCode.java | HashCode.equalObjects | public static boolean equalObjects(Object o1, Object o2) {
if (o1 == null) {
return (o2 == null);
} else if (o2 == null) {
return false;
} else {
return o1.equals(o2);
}
} | java | public static boolean equalObjects(Object o1, Object o2) {
if (o1 == null) {
return (o2 == null);
} else if (o2 == null) {
return false;
} else {
return o1.equals(o2);
}
} | [
"public",
"static",
"boolean",
"equalObjects",
"(",
"Object",
"o1",
",",
"Object",
"o2",
")",
"{",
"if",
"(",
"o1",
"==",
"null",
")",
"{",
"return",
"(",
"o2",
"==",
"null",
")",
";",
"}",
"else",
"if",
"(",
"o2",
"==",
"null",
")",
"{",
"return... | Utility function to make it easy to compare two, possibly null, objects.
@param o1 first object
@param o2 second object
@return true iff either both objects are null, or
neither are null and they are equal. | [
"Utility",
"function",
"to",
"make",
"it",
"easy",
"to",
"compare",
"two",
"possibly",
"null",
"objects",
"."
] | 7a158af76906d4a9b753e9344ce3e7abeb91dc01 | https://github.com/Netflix/netflix-commons/blob/7a158af76906d4a9b753e9344ce3e7abeb91dc01/netflix-commons-util/src/main/java/com/netflix/util/HashCode.java#L318-L326 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.save | @SuppressWarnings("deprecation")
@Override
public <S extends T> S save(final S entity) {
if (arangoOperations.getVersion().getVersion().compareTo("3.4.0") < 0) {
arangoOperations.upsert(entity, UpsertStrategy.REPLACE);
} else {
arangoOperations.repsert(entity);
}
return entity;
} | java | @SuppressWarnings("deprecation")
@Override
public <S extends T> S save(final S entity) {
if (arangoOperations.getVersion().getVersion().compareTo("3.4.0") < 0) {
arangoOperations.upsert(entity, UpsertStrategy.REPLACE);
} else {
arangoOperations.repsert(entity);
}
return entity;
} | [
"@",
"SuppressWarnings",
"(",
"\"deprecation\"",
")",
"@",
"Override",
"public",
"<",
"S",
"extends",
"T",
">",
"S",
"save",
"(",
"final",
"S",
"entity",
")",
"{",
"if",
"(",
"arangoOperations",
".",
"getVersion",
"(",
")",
".",
"getVersion",
"(",
")",
... | Saves the passed entity to the database using upsert from the template
@param entity
the entity to be saved to the database
@return the updated entity with any id/key/rev saved | [
"Saves",
"the",
"passed",
"entity",
"to",
"the",
"database",
"using",
"upsert",
"from",
"the",
"template"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L83-L92 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.saveAll | @SuppressWarnings("deprecation")
@Override
public <S extends T> Iterable<S> saveAll(final Iterable<S> entities) {
if (arangoOperations.getVersion().getVersion().compareTo("3.4.0") < 0) {
arangoOperations.upsert(entities, UpsertStrategy.UPDATE);
} else {
final S first = StreamSupport.stream(entities.spliterator(), false).findFirst().get();
arangoOperations.repsert(entities, (Class<S>) first.getClass());
}
return entities;
} | java | @SuppressWarnings("deprecation")
@Override
public <S extends T> Iterable<S> saveAll(final Iterable<S> entities) {
if (arangoOperations.getVersion().getVersion().compareTo("3.4.0") < 0) {
arangoOperations.upsert(entities, UpsertStrategy.UPDATE);
} else {
final S first = StreamSupport.stream(entities.spliterator(), false).findFirst().get();
arangoOperations.repsert(entities, (Class<S>) first.getClass());
}
return entities;
} | [
"@",
"SuppressWarnings",
"(",
"\"deprecation\"",
")",
"@",
"Override",
"public",
"<",
"S",
"extends",
"T",
">",
"Iterable",
"<",
"S",
">",
"saveAll",
"(",
"final",
"Iterable",
"<",
"S",
">",
"entities",
")",
"{",
"if",
"(",
"arangoOperations",
".",
"getV... | Saves the given iterable of entities to the database
@param entities
the iterable of entities to be saved to the database
@return the iterable of updated entities with any id/key/rev saved in each entity | [
"Saves",
"the",
"given",
"iterable",
"of",
"entities",
"to",
"the",
"database"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L101-L111 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.findById | @Override
public Optional<T> findById(final ID id) {
return arangoOperations.find(id, domainClass);
} | java | @Override
public Optional<T> findById(final ID id) {
return arangoOperations.find(id, domainClass);
} | [
"@",
"Override",
"public",
"Optional",
"<",
"T",
">",
"findById",
"(",
"final",
"ID",
"id",
")",
"{",
"return",
"arangoOperations",
".",
"find",
"(",
"id",
",",
"domainClass",
")",
";",
"}"
] | Finds if a document with the given id exists in the database
@param id
the id of the document to search for
@return the object representing the document if found | [
"Finds",
"if",
"a",
"document",
"with",
"the",
"given",
"id",
"exists",
"in",
"the",
"database"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L120-L123 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.findAllById | @Override
public Iterable<T> findAllById(final Iterable<ID> ids) {
return arangoOperations.find(ids, domainClass);
} | java | @Override
public Iterable<T> findAllById(final Iterable<ID> ids) {
return arangoOperations.find(ids, domainClass);
} | [
"@",
"Override",
"public",
"Iterable",
"<",
"T",
">",
"findAllById",
"(",
"final",
"Iterable",
"<",
"ID",
">",
"ids",
")",
"{",
"return",
"arangoOperations",
".",
"find",
"(",
"ids",
",",
"domainClass",
")",
";",
"}"
] | Finds all documents with the an id or key in the argument
@param ids
an iterable with ids/keys of documents to get
@return an iterable with documents in the collection which have a id/key in the argument | [
"Finds",
"all",
"documents",
"with",
"the",
"an",
"id",
"or",
"key",
"in",
"the",
"argument"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L154-L157 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.delete | @Override
public void delete(final T entity) {
String id = null;
try {
id = (String) arangoOperations.getConverter().getMappingContext().getPersistentEntity(domainClass)
.getIdProperty().getField().get(entity);
} catch (final IllegalAccessException e) {
e.printStackTrace();
}
arangoOperations.delete(id, domainClass);
} | java | @Override
public void delete(final T entity) {
String id = null;
try {
id = (String) arangoOperations.getConverter().getMappingContext().getPersistentEntity(domainClass)
.getIdProperty().getField().get(entity);
} catch (final IllegalAccessException e) {
e.printStackTrace();
}
arangoOperations.delete(id, domainClass);
} | [
"@",
"Override",
"public",
"void",
"delete",
"(",
"final",
"T",
"entity",
")",
"{",
"String",
"id",
"=",
"null",
";",
"try",
"{",
"id",
"=",
"(",
"String",
")",
"arangoOperations",
".",
"getConverter",
"(",
")",
".",
"getMappingContext",
"(",
")",
".",... | Deletes document in the database representing the given object, by getting it's id
@param entity
the entity to be deleted from the database | [
"Deletes",
"document",
"in",
"the",
"database",
"representing",
"the",
"given",
"object",
"by",
"getting",
"it",
"s",
"id"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L186-L196 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.findAll | @Override
public Iterable<T> findAll(final Sort sort) {
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return findAllInternal(sort, null, new HashMap<>());
}
};
} | java | @Override
public Iterable<T> findAll(final Sort sort) {
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return findAllInternal(sort, null, new HashMap<>());
}
};
} | [
"@",
"Override",
"public",
"Iterable",
"<",
"T",
">",
"findAll",
"(",
"final",
"Sort",
"sort",
")",
"{",
"return",
"new",
"Iterable",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Iterator",
"<",
"T",
">",
"iterator",
"(",
")",
"{",
"re... | Gets all documents in the collection for the class type of this repository, with the given sort applied
@param sort
the sort object to use for sorting
@return an iterable with all the documents in the collection | [
"Gets",
"all",
"documents",
"in",
"the",
"collection",
"for",
"the",
"class",
"type",
"of",
"this",
"repository",
"with",
"the",
"given",
"sort",
"applied"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L224-L232 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.findAll | @Override
public Page<T> findAll(final Pageable pageable) {
if (pageable == null) {
LOGGER.debug("Pageable in findAll(Pageable) is null");
}
final ArangoCursor<T> result = findAllInternal(pageable, null, new HashMap<>());
final List<T> content = result.asListRemaining();
return new PageImpl<>(content, pageable, result.getStats().getFullCount());
} | java | @Override
public Page<T> findAll(final Pageable pageable) {
if (pageable == null) {
LOGGER.debug("Pageable in findAll(Pageable) is null");
}
final ArangoCursor<T> result = findAllInternal(pageable, null, new HashMap<>());
final List<T> content = result.asListRemaining();
return new PageImpl<>(content, pageable, result.getStats().getFullCount());
} | [
"@",
"Override",
"public",
"Page",
"<",
"T",
">",
"findAll",
"(",
"final",
"Pageable",
"pageable",
")",
"{",
"if",
"(",
"pageable",
"==",
"null",
")",
"{",
"LOGGER",
".",
"debug",
"(",
"\"Pageable in findAll(Pageable) is null\"",
")",
";",
"}",
"final",
"A... | Gets all documents in the collection for the class type of this repository, with pagination
@param pageable
the pageable object to use for pagination of the results
@return an iterable with all the documents in the collection | [
"Gets",
"all",
"documents",
"in",
"the",
"collection",
"for",
"the",
"class",
"type",
"of",
"this",
"repository",
"with",
"pagination"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L241-L250 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.findOne | @Override
public <S extends T> Optional<S> findOne(final Example<S> example) {
final ArangoCursor cursor = findAllInternal((Pageable) null, example, new HashMap());
return cursor.hasNext() ? Optional.ofNullable((S) cursor.next()) : Optional.empty();
} | java | @Override
public <S extends T> Optional<S> findOne(final Example<S> example) {
final ArangoCursor cursor = findAllInternal((Pageable) null, example, new HashMap());
return cursor.hasNext() ? Optional.ofNullable((S) cursor.next()) : Optional.empty();
} | [
"@",
"Override",
"public",
"<",
"S",
"extends",
"T",
">",
"Optional",
"<",
"S",
">",
"findOne",
"(",
"final",
"Example",
"<",
"S",
">",
"example",
")",
"{",
"final",
"ArangoCursor",
"cursor",
"=",
"findAllInternal",
"(",
"(",
"Pageable",
")",
"null",
"... | Finds one document which matches the given example object
@param example
example object to construct query with
@param <S>
@return An object representing the example if it exists, else null | [
"Finds",
"one",
"document",
"which",
"matches",
"the",
"given",
"example",
"object"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L269-L273 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.findAll | @Override
public <S extends T> Iterable<S> findAll(final Example<S> example) {
final ArangoCursor cursor = findAllInternal((Pageable) null, example, new HashMap<>());
return cursor;
} | java | @Override
public <S extends T> Iterable<S> findAll(final Example<S> example) {
final ArangoCursor cursor = findAllInternal((Pageable) null, example, new HashMap<>());
return cursor;
} | [
"@",
"Override",
"public",
"<",
"S",
"extends",
"T",
">",
"Iterable",
"<",
"S",
">",
"findAll",
"(",
"final",
"Example",
"<",
"S",
">",
"example",
")",
"{",
"final",
"ArangoCursor",
"cursor",
"=",
"findAllInternal",
"(",
"(",
"Pageable",
")",
"null",
"... | Finds all documents which match with the given example
@param example
example object to construct query with
@param <S>
@return iterable of all matching documents | [
"Finds",
"all",
"documents",
"which",
"match",
"with",
"the",
"given",
"example"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L283-L287 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.findAll | @Override
public <S extends T> Iterable<S> findAll(final Example<S> example, final Sort sort) {
final ArangoCursor cursor = findAllInternal(sort, example, new HashMap());
return cursor;
} | java | @Override
public <S extends T> Iterable<S> findAll(final Example<S> example, final Sort sort) {
final ArangoCursor cursor = findAllInternal(sort, example, new HashMap());
return cursor;
} | [
"@",
"Override",
"public",
"<",
"S",
"extends",
"T",
">",
"Iterable",
"<",
"S",
">",
"findAll",
"(",
"final",
"Example",
"<",
"S",
">",
"example",
",",
"final",
"Sort",
"sort",
")",
"{",
"final",
"ArangoCursor",
"cursor",
"=",
"findAllInternal",
"(",
"... | Finds all documents which match with the given example, then apply the given sort to results
@param example
example object to construct query with
@param sort
sort object to sort results
@param <S>
@return sorted iterable of all matching documents | [
"Finds",
"all",
"documents",
"which",
"match",
"with",
"the",
"given",
"example",
"then",
"apply",
"the",
"given",
"sort",
"to",
"results"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L299-L303 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.findAll | @Override
public <S extends T> Page<S> findAll(final Example<S> example, final Pageable pageable) {
final ArangoCursor cursor = findAllInternal(pageable, example, new HashMap());
final List<T> content = cursor.asListRemaining();
return new PageImpl<>((List<S>) content, pageable, cursor.getStats().getFullCount());
} | java | @Override
public <S extends T> Page<S> findAll(final Example<S> example, final Pageable pageable) {
final ArangoCursor cursor = findAllInternal(pageable, example, new HashMap());
final List<T> content = cursor.asListRemaining();
return new PageImpl<>((List<S>) content, pageable, cursor.getStats().getFullCount());
} | [
"@",
"Override",
"public",
"<",
"S",
"extends",
"T",
">",
"Page",
"<",
"S",
">",
"findAll",
"(",
"final",
"Example",
"<",
"S",
">",
"example",
",",
"final",
"Pageable",
"pageable",
")",
"{",
"final",
"ArangoCursor",
"cursor",
"=",
"findAllInternal",
"(",... | Finds all documents which match with the given example, with pagination
@param example
example object to construct query with
@param pageable
pageable object to apply pagination with
@param <S>
@return iterable of all matching documents, with pagination | [
"Finds",
"all",
"documents",
"which",
"match",
"with",
"the",
"given",
"example",
"with",
"pagination"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L315-L320 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java | SimpleArangoRepository.count | @Override
public <S extends T> long count(final Example<S> example) {
final Map<String, Object> bindVars = new HashMap<>();
final String predicate = exampleConverter.convertExampleToPredicate(example, bindVars);
final String filter = predicate.length() == 0 ? "" : " FILTER " + predicate;
final String query = String.format("FOR e IN %s%s COLLECT WITH COUNT INTO length RETURN length",
getCollectionName(), filter);
final ArangoCursor<Long> cursor = arangoOperations.query(query, bindVars, null, Long.class);
return cursor.next();
} | java | @Override
public <S extends T> long count(final Example<S> example) {
final Map<String, Object> bindVars = new HashMap<>();
final String predicate = exampleConverter.convertExampleToPredicate(example, bindVars);
final String filter = predicate.length() == 0 ? "" : " FILTER " + predicate;
final String query = String.format("FOR e IN %s%s COLLECT WITH COUNT INTO length RETURN length",
getCollectionName(), filter);
final ArangoCursor<Long> cursor = arangoOperations.query(query, bindVars, null, Long.class);
return cursor.next();
} | [
"@",
"Override",
"public",
"<",
"S",
"extends",
"T",
">",
"long",
"count",
"(",
"final",
"Example",
"<",
"S",
">",
"example",
")",
"{",
"final",
"Map",
"<",
"String",
",",
"Object",
">",
"bindVars",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"fina... | Counts the number of documents in the collection which match with the given example
@param example
example object to construct query with
@param <S>
@return number of matching documents found | [
"Counts",
"the",
"number",
"of",
"documents",
"in",
"the",
"collection",
"which",
"match",
"with",
"the",
"given",
"example"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/SimpleArangoRepository.java#L330-L339 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/query/derived/BindParameterBinding.java | BindParameterBinding.escapeSpecialCharacters | private String escapeSpecialCharacters(final String string) {
final StringBuilder escaped = new StringBuilder();
for (final char character : string.toCharArray()) {
if (character == '%' || character == '_' || character == '\\') {
escaped.append('\\');
}
escaped.append(character);
}
return escaped.toString();
} | java | private String escapeSpecialCharacters(final String string) {
final StringBuilder escaped = new StringBuilder();
for (final char character : string.toCharArray()) {
if (character == '%' || character == '_' || character == '\\') {
escaped.append('\\');
}
escaped.append(character);
}
return escaped.toString();
} | [
"private",
"String",
"escapeSpecialCharacters",
"(",
"final",
"String",
"string",
")",
"{",
"final",
"StringBuilder",
"escaped",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"final",
"char",
"character",
":",
"string",
".",
"toCharArray",
"(",
")",
... | Escapes special characters which could be used in an operand of LIKE operator
@param string
@return | [
"Escapes",
"special",
"characters",
"which",
"could",
"be",
"used",
"in",
"an",
"operand",
"of",
"LIKE",
"operator"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/query/derived/BindParameterBinding.java#L166-L175 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/core/util/MetadataUtils.java | MetadataUtils.determineDocumentKeyFromId | public static String determineDocumentKeyFromId(final String id) {
final int lastSlash = id.lastIndexOf(KEY_DELIMITER);
return id.substring(lastSlash + 1);
} | java | public static String determineDocumentKeyFromId(final String id) {
final int lastSlash = id.lastIndexOf(KEY_DELIMITER);
return id.substring(lastSlash + 1);
} | [
"public",
"static",
"String",
"determineDocumentKeyFromId",
"(",
"final",
"String",
"id",
")",
"{",
"final",
"int",
"lastSlash",
"=",
"id",
".",
"lastIndexOf",
"(",
"KEY_DELIMITER",
")",
";",
"return",
"id",
".",
"substring",
"(",
"lastSlash",
"+",
"1",
")",... | Provides a substring with _key.
@param id
string consisting of concatenation of collection name, /, & _key.
@return _key | [
"Provides",
"a",
"substring",
"with",
"_key",
"."
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/core/util/MetadataUtils.java#L26-L29 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/core/util/MetadataUtils.java | MetadataUtils.determineCollectionFromId | public static String determineCollectionFromId(final String id) {
final int delimiter = id.indexOf(KEY_DELIMITER);
return delimiter == -1 ? null : id.substring(0, delimiter);
} | java | public static String determineCollectionFromId(final String id) {
final int delimiter = id.indexOf(KEY_DELIMITER);
return delimiter == -1 ? null : id.substring(0, delimiter);
} | [
"public",
"static",
"String",
"determineCollectionFromId",
"(",
"final",
"String",
"id",
")",
"{",
"final",
"int",
"delimiter",
"=",
"id",
".",
"indexOf",
"(",
"KEY_DELIMITER",
")",
";",
"return",
"delimiter",
"==",
"-",
"1",
"?",
"null",
":",
"id",
".",
... | Provides a substring with collection name.
@param id
string consisting of concatenation of collection name, /, & _key.
@return collection name (or null if no key delimiter is present) | [
"Provides",
"a",
"substring",
"with",
"collection",
"name",
"."
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/core/util/MetadataUtils.java#L38-L41 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java | DerivedQueryCreator.shouldIgnoreCase | private boolean shouldIgnoreCase(final Part part) {
final Class<?> propertyClass = part.getProperty().getLeafProperty().getType();
final boolean isLowerable = String.class.isAssignableFrom(propertyClass);
final boolean shouldIgnoreCase = part.shouldIgnoreCase() != Part.IgnoreCaseType.NEVER && isLowerable
&& !UNSUPPORTED_IGNORE_CASE.contains(part.getType());
if (part.shouldIgnoreCase() == Part.IgnoreCaseType.ALWAYS
&& (!isLowerable || UNSUPPORTED_IGNORE_CASE.contains(part.getType()))) {
LOGGER.debug("Ignoring case for \"{}\" type is meaningless", propertyClass);
}
return shouldIgnoreCase;
} | java | private boolean shouldIgnoreCase(final Part part) {
final Class<?> propertyClass = part.getProperty().getLeafProperty().getType();
final boolean isLowerable = String.class.isAssignableFrom(propertyClass);
final boolean shouldIgnoreCase = part.shouldIgnoreCase() != Part.IgnoreCaseType.NEVER && isLowerable
&& !UNSUPPORTED_IGNORE_CASE.contains(part.getType());
if (part.shouldIgnoreCase() == Part.IgnoreCaseType.ALWAYS
&& (!isLowerable || UNSUPPORTED_IGNORE_CASE.contains(part.getType()))) {
LOGGER.debug("Ignoring case for \"{}\" type is meaningless", propertyClass);
}
return shouldIgnoreCase;
} | [
"private",
"boolean",
"shouldIgnoreCase",
"(",
"final",
"Part",
"part",
")",
"{",
"final",
"Class",
"<",
"?",
">",
"propertyClass",
"=",
"part",
".",
"getProperty",
"(",
")",
".",
"getLeafProperty",
"(",
")",
".",
"getType",
"(",
")",
";",
"final",
"bool... | Determines whether the case for a Part should be ignored based on property type and IgnoreCase keywords in the
method name
@param part
@return | [
"Determines",
"whether",
"the",
"case",
"for",
"a",
"Part",
"should",
"be",
"ignored",
"based",
"on",
"property",
"type",
"and",
"IgnoreCase",
"keywords",
"in",
"the",
"method",
"name"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java#L332-L342 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java | DerivedQueryCreator.checkUniquePoint | private void checkUniquePoint(final Point point) {
final boolean isStillUnique = (uniquePoint == null || uniquePoint.equals(point));
if (!isStillUnique) {
isUnique = false;
}
if (!geoFields.isEmpty()) {
Assert.isTrue(uniquePoint == null || uniquePoint.equals(point),
"Different Points are used - Distance is ambiguous");
uniquePoint = point;
}
} | java | private void checkUniquePoint(final Point point) {
final boolean isStillUnique = (uniquePoint == null || uniquePoint.equals(point));
if (!isStillUnique) {
isUnique = false;
}
if (!geoFields.isEmpty()) {
Assert.isTrue(uniquePoint == null || uniquePoint.equals(point),
"Different Points are used - Distance is ambiguous");
uniquePoint = point;
}
} | [
"private",
"void",
"checkUniquePoint",
"(",
"final",
"Point",
"point",
")",
"{",
"final",
"boolean",
"isStillUnique",
"=",
"(",
"uniquePoint",
"==",
"null",
"||",
"uniquePoint",
".",
"equals",
"(",
"point",
")",
")",
";",
"if",
"(",
"!",
"isStillUnique",
"... | Ensures that Points used in geospatial parts of non-nested properties are the same in case geospatial return type
is expected
@param point | [
"Ensures",
"that",
"Points",
"used",
"in",
"geospatial",
"parts",
"of",
"non",
"-",
"nested",
"properties",
"are",
"the",
"same",
"in",
"case",
"geospatial",
"return",
"type",
"is",
"expected"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java#L350-L360 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java | DerivedQueryCreator.checkUniqueLocation | private void checkUniqueLocation(final Part part) {
isUnique = isUnique == null ? true : isUnique;
isUnique = (uniqueLocation == null || uniqueLocation.equals(ignorePropertyCase(part))) ? isUnique : false;
if (!geoFields.isEmpty()) {
Assert.isTrue(isUnique, "Different location fields are used - Distance is ambiguous");
}
uniqueLocation = ignorePropertyCase(part);
} | java | private void checkUniqueLocation(final Part part) {
isUnique = isUnique == null ? true : isUnique;
isUnique = (uniqueLocation == null || uniqueLocation.equals(ignorePropertyCase(part))) ? isUnique : false;
if (!geoFields.isEmpty()) {
Assert.isTrue(isUnique, "Different location fields are used - Distance is ambiguous");
}
uniqueLocation = ignorePropertyCase(part);
} | [
"private",
"void",
"checkUniqueLocation",
"(",
"final",
"Part",
"part",
")",
"{",
"isUnique",
"=",
"isUnique",
"==",
"null",
"?",
"true",
":",
"isUnique",
";",
"isUnique",
"=",
"(",
"uniqueLocation",
"==",
"null",
"||",
"uniqueLocation",
".",
"equals",
"(",
... | Ensures that the same geo fields are used in geospatial parts of non-nested properties are the same in case
geospatial return type is expected
@param part | [
"Ensures",
"that",
"the",
"same",
"geo",
"fields",
"are",
"used",
"in",
"geospatial",
"parts",
"of",
"non",
"-",
"nested",
"properties",
"are",
"the",
"same",
"in",
"case",
"geospatial",
"return",
"type",
"is",
"expected"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/query/derived/DerivedQueryCreator.java#L368-L375 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java | ArangoResultConverter.convertResult | public Object convertResult(final Class<?> type) {
try {
if (type.isArray()) {
return TYPE_MAP.get("array").invoke(this);
}
if (!TYPE_MAP.containsKey(type)) {
return getNext(result);
}
return TYPE_MAP.get(type).invoke(this);
} catch (final Exception e) {
e.printStackTrace();
return null;
}
} | java | public Object convertResult(final Class<?> type) {
try {
if (type.isArray()) {
return TYPE_MAP.get("array").invoke(this);
}
if (!TYPE_MAP.containsKey(type)) {
return getNext(result);
}
return TYPE_MAP.get(type).invoke(this);
} catch (final Exception e) {
e.printStackTrace();
return null;
}
} | [
"public",
"Object",
"convertResult",
"(",
"final",
"Class",
"<",
"?",
">",
"type",
")",
"{",
"try",
"{",
"if",
"(",
"type",
".",
"isArray",
"(",
")",
")",
"{",
"return",
"TYPE_MAP",
".",
"get",
"(",
"\"array\"",
")",
".",
"invoke",
"(",
"this",
")"... | Called to convert result from ArangoCursor to given type, by invoking the appropriate converter method
@param type
@return result in desired type | [
"Called",
"to",
"convert",
"result",
"from",
"ArangoCursor",
"to",
"given",
"type",
"by",
"invoking",
"the",
"appropriate",
"converter",
"method"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java#L114-L127 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java | ArangoResultConverter.buildSet | private Set<?> buildSet(final ArangoCursor<?> cursor) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(cursor, 0), false).collect(Collectors.toSet());
} | java | private Set<?> buildSet(final ArangoCursor<?> cursor) {
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(cursor, 0), false).collect(Collectors.toSet());
} | [
"private",
"Set",
"<",
"?",
">",
"buildSet",
"(",
"final",
"ArangoCursor",
"<",
"?",
">",
"cursor",
")",
"{",
"return",
"StreamSupport",
".",
"stream",
"(",
"Spliterators",
".",
"spliteratorUnknownSize",
"(",
"cursor",
",",
"0",
")",
",",
"false",
")",
"... | Creates a Set return type from the given cursor
@param cursor
query result from driver
@return Set containing the results | [
"Creates",
"a",
"Set",
"return",
"type",
"from",
"the",
"given",
"cursor"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java#L136-L138 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java | ArangoResultConverter.buildGeoResult | private GeoResult<?> buildGeoResult(final ArangoCursor<?> cursor) {
GeoResult<?> geoResult = null;
while (cursor.hasNext() && geoResult == null) {
final Object object = cursor.next();
if (!(object instanceof VPackSlice)) {
continue;
}
final VPackSlice slice = (VPackSlice) object;
final VPackSlice distSlice = slice.get("_distance");
final Double distanceInMeters = distSlice.isDouble() ? distSlice.getAsDouble() : null;
if (distanceInMeters == null) {
continue;
}
final Object entity = operations.getConverter().read(domainClass, slice);
final Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS);
geoResult = new GeoResult<>(entity, distance);
}
return geoResult;
} | java | private GeoResult<?> buildGeoResult(final ArangoCursor<?> cursor) {
GeoResult<?> geoResult = null;
while (cursor.hasNext() && geoResult == null) {
final Object object = cursor.next();
if (!(object instanceof VPackSlice)) {
continue;
}
final VPackSlice slice = (VPackSlice) object;
final VPackSlice distSlice = slice.get("_distance");
final Double distanceInMeters = distSlice.isDouble() ? distSlice.getAsDouble() : null;
if (distanceInMeters == null) {
continue;
}
final Object entity = operations.getConverter().read(domainClass, slice);
final Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS);
geoResult = new GeoResult<>(entity, distance);
}
return geoResult;
} | [
"private",
"GeoResult",
"<",
"?",
">",
"buildGeoResult",
"(",
"final",
"ArangoCursor",
"<",
"?",
">",
"cursor",
")",
"{",
"GeoResult",
"<",
"?",
">",
"geoResult",
"=",
"null",
";",
"while",
"(",
"cursor",
".",
"hasNext",
"(",
")",
"&&",
"geoResult",
"=... | Build a GeoResult from the given ArangoCursor
@param cursor
query result from driver
@return GeoResult object | [
"Build",
"a",
"GeoResult",
"from",
"the",
"given",
"ArangoCursor"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java#L147-L167 | train |
arangodb/spring-data | src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java | ArangoResultConverter.buildGeoResults | @SuppressWarnings({ "rawtypes", "unchecked" })
private GeoResults<?> buildGeoResults(final ArangoCursor<?> cursor) {
final List<GeoResult<?>> list = new LinkedList<>();
cursor.forEachRemaining(o -> {
final GeoResult<?> geoResult = buildGeoResult(o);
if (geoResult != null) {
list.add(geoResult);
}
});
return new GeoResults(list);
} | java | @SuppressWarnings({ "rawtypes", "unchecked" })
private GeoResults<?> buildGeoResults(final ArangoCursor<?> cursor) {
final List<GeoResult<?>> list = new LinkedList<>();
cursor.forEachRemaining(o -> {
final GeoResult<?> geoResult = buildGeoResult(o);
if (geoResult != null) {
list.add(geoResult);
}
});
return new GeoResults(list);
} | [
"@",
"SuppressWarnings",
"(",
"{",
"\"rawtypes\"",
",",
"\"unchecked\"",
"}",
")",
"private",
"GeoResults",
"<",
"?",
">",
"buildGeoResults",
"(",
"final",
"ArangoCursor",
"<",
"?",
">",
"cursor",
")",
"{",
"final",
"List",
"<",
"GeoResult",
"<",
"?",
">",... | Build a GeoResults object with the ArangoCursor returned by query execution
@param cursor
ArangoCursor containing query results
@return GeoResults object with all results | [
"Build",
"a",
"GeoResults",
"object",
"with",
"the",
"ArangoCursor",
"returned",
"by",
"query",
"execution"
] | ff8ae53986b353964b9b90bd8199996d5aabf0c1 | https://github.com/arangodb/spring-data/blob/ff8ae53986b353964b9b90bd8199996d5aabf0c1/src/main/java/com/arangodb/springframework/repository/query/ArangoResultConverter.java#L200-L210 | train |
Netflix/denominator | model/src/main/java/denominator/model/Zone.java | Zone.create | @Deprecated
public static Zone create(String name, String id) {
return new Zone(id, name, 86400, "nil@" + name);
} | java | @Deprecated
public static Zone create(String name, String id) {
return new Zone(id, name, 86400, "nil@" + name);
} | [
"@",
"Deprecated",
"public",
"static",
"Zone",
"create",
"(",
"String",
"name",
",",
"String",
"id",
")",
"{",
"return",
"new",
"Zone",
"(",
"id",
",",
"name",
",",
"86400",
",",
"\"nil@\"",
"+",
"name",
")",
";",
"}"
] | Represent a zone with a fake email and a TTL of 86400.
@param name corresponds to {@link #name()}
@param id nullable, corresponds to {@link #id()}
@deprecated Use {@link #create(String, String, int, String)}. This will be removed in version
5. | [
"Represent",
"a",
"zone",
"with",
"a",
"fake",
"email",
"and",
"a",
"TTL",
"of",
"86400",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/model/src/main/java/denominator/model/Zone.java#L136-L139 | train |
Netflix/denominator | model/src/main/java/denominator/model/StringRecordBuilder.java | StringRecordBuilder.addAll | public StringRecordBuilder<D> addAll(String... records) {
return addAll(Arrays.asList(checkNotNull(records, "records")));
} | java | public StringRecordBuilder<D> addAll(String... records) {
return addAll(Arrays.asList(checkNotNull(records, "records")));
} | [
"public",
"StringRecordBuilder",
"<",
"D",
">",
"addAll",
"(",
"String",
"...",
"records",
")",
"{",
"return",
"addAll",
"(",
"Arrays",
".",
"asList",
"(",
"checkNotNull",
"(",
"records",
",",
"\"records\"",
")",
")",
")",
";",
"}"
] | adds values to the builder
ex.
<pre>
builder.addAll("192.0.2.1", "192.0.2.2");
</pre> | [
"adds",
"values",
"to",
"the",
"builder"
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/model/src/main/java/denominator/model/StringRecordBuilder.java#L47-L49 | train |
Netflix/denominator | clouddns/src/main/java/denominator/clouddns/CloudDNSZoneApi.java | CloudDNSZoneApi.zipWithSOA | private Zone zipWithSOA(Zone next) {
Record soa = api.recordsByNameAndType(Integer.parseInt(next.id()), next.name(), "SOA").get(0);
return Zone.create(next.id(), next.name(), soa.ttl, next.email());
} | java | private Zone zipWithSOA(Zone next) {
Record soa = api.recordsByNameAndType(Integer.parseInt(next.id()), next.name(), "SOA").get(0);
return Zone.create(next.id(), next.name(), soa.ttl, next.email());
} | [
"private",
"Zone",
"zipWithSOA",
"(",
"Zone",
"next",
")",
"{",
"Record",
"soa",
"=",
"api",
".",
"recordsByNameAndType",
"(",
"Integer",
".",
"parseInt",
"(",
"next",
".",
"id",
"(",
")",
")",
",",
"next",
".",
"name",
"(",
")",
",",
"\"SOA\"",
")",... | CloudDNS doesn't expose the domain's ttl in the list api. | [
"CloudDNS",
"doesn",
"t",
"expose",
"the",
"domain",
"s",
"ttl",
"in",
"the",
"list",
"api",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/clouddns/src/main/java/denominator/clouddns/CloudDNSZoneApi.java#L41-L44 | train |
Netflix/denominator | clouddns/src/main/java/denominator/clouddns/CloudDNSResourceRecordSetApi.java | CloudDNSResourceRecordSetApi.getPriority | private Integer getPriority(Map<String, Object> mutableRData) {
Integer priority = null;
if (mutableRData.containsKey("priority")) { // SRVData
priority = Integer.class.cast(mutableRData.remove("priority"));
} else if (mutableRData.containsKey("preference")) { // MXData
priority = Integer.class.cast(mutableRData.remove("preference"));
}
return priority;
} | java | private Integer getPriority(Map<String, Object> mutableRData) {
Integer priority = null;
if (mutableRData.containsKey("priority")) { // SRVData
priority = Integer.class.cast(mutableRData.remove("priority"));
} else if (mutableRData.containsKey("preference")) { // MXData
priority = Integer.class.cast(mutableRData.remove("preference"));
}
return priority;
} | [
"private",
"Integer",
"getPriority",
"(",
"Map",
"<",
"String",
",",
"Object",
">",
"mutableRData",
")",
"{",
"Integer",
"priority",
"=",
"null",
";",
"if",
"(",
"mutableRData",
".",
"containsKey",
"(",
"\"priority\"",
")",
")",
"{",
"// SRVData",
"priority"... | Has the side effect of removing the priority from the mutableRData.
@return null or the priority, if it exists for a MX or SRV record | [
"Has",
"the",
"side",
"effect",
"of",
"removing",
"the",
"priority",
"from",
"the",
"mutableRData",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/clouddns/src/main/java/denominator/clouddns/CloudDNSResourceRecordSetApi.java#L119-L129 | train |
Netflix/denominator | model/src/main/java/denominator/model/ResourceRecordSets.java | ResourceRecordSets.alwaysVisible | public static Filter<ResourceRecordSet<?>> alwaysVisible() {
return new Filter<ResourceRecordSet<?>>() {
@Override
public boolean apply(ResourceRecordSet<?> in) {
return in != null && in.qualifier() == null;
}
@Override
public String toString() {
return "alwaysVisible()";
}
};
} | java | public static Filter<ResourceRecordSet<?>> alwaysVisible() {
return new Filter<ResourceRecordSet<?>>() {
@Override
public boolean apply(ResourceRecordSet<?> in) {
return in != null && in.qualifier() == null;
}
@Override
public String toString() {
return "alwaysVisible()";
}
};
} | [
"public",
"static",
"Filter",
"<",
"ResourceRecordSet",
"<",
"?",
">",
">",
"alwaysVisible",
"(",
")",
"{",
"return",
"new",
"Filter",
"<",
"ResourceRecordSet",
"<",
"?",
">",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"boolean",
"apply",
"(",
"Resou... | Returns true if the input has no visibility qualifier. Typically indicates a basic record set. | [
"Returns",
"true",
"if",
"the",
"input",
"has",
"no",
"visibility",
"qualifier",
".",
"Typically",
"indicates",
"a",
"basic",
"record",
"set",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/model/src/main/java/denominator/model/ResourceRecordSets.java#L133-L146 | train |
Netflix/denominator | model/src/main/java/denominator/model/ResourceRecordSets.java | ResourceRecordSets.soa | public static ResourceRecordSet<SOAData> soa(ResourceRecordSet<?> soa, String email, int ttl) {
SOAData soaData = (SOAData) soa.records().get(0);
soaData = soaData.toBuilder().serial(soaData.serial() + 1).rname(email).build();
return ResourceRecordSet.<SOAData>builder()
.name(soa.name())
.type("SOA")
.ttl(ttl)
.add(soaData)
.build();
} | java | public static ResourceRecordSet<SOAData> soa(ResourceRecordSet<?> soa, String email, int ttl) {
SOAData soaData = (SOAData) soa.records().get(0);
soaData = soaData.toBuilder().serial(soaData.serial() + 1).rname(email).build();
return ResourceRecordSet.<SOAData>builder()
.name(soa.name())
.type("SOA")
.ttl(ttl)
.add(soaData)
.build();
} | [
"public",
"static",
"ResourceRecordSet",
"<",
"SOAData",
">",
"soa",
"(",
"ResourceRecordSet",
"<",
"?",
">",
"soa",
",",
"String",
"email",
",",
"int",
"ttl",
")",
"{",
"SOAData",
"soaData",
"=",
"(",
"SOAData",
")",
"soa",
".",
"records",
"(",
")",
"... | Returns an updated SOA rrset, with an incremented serial number and the specified parameters. | [
"Returns",
"an",
"updated",
"SOA",
"rrset",
"with",
"an",
"incremented",
"serial",
"number",
"and",
"the",
"specified",
"parameters",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/model/src/main/java/denominator/model/ResourceRecordSets.java#L151-L160 | train |
Netflix/denominator | model/src/main/java/denominator/common/Util.java | Util.split | public static List<String> split(char delim, String toSplit) {
checkNotNull(toSplit, "toSplit");
if (toSplit.indexOf(delim) == -1) {
return Arrays.asList(toSplit); // sortable in JRE 7 and 8
}
List<String> out = new LinkedList<String>();
StringBuilder currentString = new StringBuilder();
for (char c : toSplit.toCharArray()) {
if (c == delim) {
out.add(emptyToNull(currentString.toString()));
currentString.setLength(0);
} else {
currentString.append(c);
}
}
out.add(emptyToNull(currentString.toString()));
return out;
} | java | public static List<String> split(char delim, String toSplit) {
checkNotNull(toSplit, "toSplit");
if (toSplit.indexOf(delim) == -1) {
return Arrays.asList(toSplit); // sortable in JRE 7 and 8
}
List<String> out = new LinkedList<String>();
StringBuilder currentString = new StringBuilder();
for (char c : toSplit.toCharArray()) {
if (c == delim) {
out.add(emptyToNull(currentString.toString()));
currentString.setLength(0);
} else {
currentString.append(c);
}
}
out.add(emptyToNull(currentString.toString()));
return out;
} | [
"public",
"static",
"List",
"<",
"String",
">",
"split",
"(",
"char",
"delim",
",",
"String",
"toSplit",
")",
"{",
"checkNotNull",
"(",
"toSplit",
",",
"\"toSplit\"",
")",
";",
"if",
"(",
"toSplit",
".",
"indexOf",
"(",
"delim",
")",
"==",
"-",
"1",
... | empty fields will result in null elements in the result. | [
"empty",
"fields",
"will",
"result",
"in",
"null",
"elements",
"in",
"the",
"result",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/model/src/main/java/denominator/common/Util.java#L77-L94 | train |
Netflix/denominator | ultradns/src/main/java/denominator/ultradns/UltraDNSZoneApi.java | UltraDNSZoneApi.iterator | @Override
public Iterator<Zone> iterator() {
final Iterator<String> delegate = api.getZonesOfAccount(account.get()).iterator();
return new Iterator<Zone>() {
@Override
public boolean hasNext() {
return delegate.hasNext();
}
@Override
public Zone next() {
return fromSOA(delegate.next());
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
} | java | @Override
public Iterator<Zone> iterator() {
final Iterator<String> delegate = api.getZonesOfAccount(account.get()).iterator();
return new Iterator<Zone>() {
@Override
public boolean hasNext() {
return delegate.hasNext();
}
@Override
public Zone next() {
return fromSOA(delegate.next());
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
} | [
"@",
"Override",
"public",
"Iterator",
"<",
"Zone",
">",
"iterator",
"(",
")",
"{",
"final",
"Iterator",
"<",
"String",
">",
"delegate",
"=",
"api",
".",
"getZonesOfAccount",
"(",
"account",
".",
"get",
"(",
")",
")",
".",
"iterator",
"(",
")",
";",
... | in UltraDNS, zones are scoped to an account. | [
"in",
"UltraDNS",
"zones",
"are",
"scoped",
"to",
"an",
"account",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/ultradns/src/main/java/denominator/ultradns/UltraDNSZoneApi.java#L30-L49 | train |
Netflix/denominator | model/src/main/java/denominator/model/NumbersAreUnsignedIntsLinkedHashMap.java | NumbersAreUnsignedIntsLinkedHashMap.put | @Override
public Object put(String key, Object val) {
val = val != null && val instanceof Number ? Number.class.cast(val).intValue() : val;
return super.put(key, val);
} | java | @Override
public Object put(String key, Object val) {
val = val != null && val instanceof Number ? Number.class.cast(val).intValue() : val;
return super.put(key, val);
} | [
"@",
"Override",
"public",
"Object",
"put",
"(",
"String",
"key",
",",
"Object",
"val",
")",
"{",
"val",
"=",
"val",
"!=",
"null",
"&&",
"val",
"instanceof",
"Number",
"?",
"Number",
".",
"class",
".",
"cast",
"(",
"val",
")",
".",
"intValue",
"(",
... | a ctor that allows passing a map. | [
"a",
"ctor",
"that",
"allows",
"passing",
"a",
"map",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/model/src/main/java/denominator/model/NumbersAreUnsignedIntsLinkedHashMap.java#L17-L21 | train |
Netflix/denominator | route53/src/main/java/denominator/route53/InstanceProfileCredentialsProvider.java | InstanceProfileCredentialsProvider.parseJson | static Map<String, String> parseJson(String in) {
if (in == null) {
return Collections.emptyMap();
}
String noBraces = in.replace('{', ' ').replace('}', ' ').trim();
Map<String, String> builder = new LinkedHashMap<String, String>();
Matcher matcher = JSON_FIELDS.matcher(noBraces);
while (matcher.find()) {
String key = keyMap.get(matcher.group(1));
if (key != null) {
builder.put(key, matcher.group(2));
}
}
return builder;
} | java | static Map<String, String> parseJson(String in) {
if (in == null) {
return Collections.emptyMap();
}
String noBraces = in.replace('{', ' ').replace('}', ' ').trim();
Map<String, String> builder = new LinkedHashMap<String, String>();
Matcher matcher = JSON_FIELDS.matcher(noBraces);
while (matcher.find()) {
String key = keyMap.get(matcher.group(1));
if (key != null) {
builder.put(key, matcher.group(2));
}
}
return builder;
} | [
"static",
"Map",
"<",
"String",
",",
"String",
">",
"parseJson",
"(",
"String",
"in",
")",
"{",
"if",
"(",
"in",
"==",
"null",
")",
"{",
"return",
"Collections",
".",
"emptyMap",
"(",
")",
";",
"}",
"String",
"noBraces",
"=",
"in",
".",
"replace",
... | IAM Instance Profile format is simple, non-nested json.
ex.
<pre>
{
"Code" : "Success",
"LastUpdated" : "2013-02-26T02:03:57Z",
"Type" : "AWS-HMAC",
"AccessKeyId" : "AAAAA",
"SecretAccessKey" : "SSSSSSS",
"Token" : "TTTTTTT",
"Expiration" : "2013-02-26T08:12:23Z"
}
</pre>
This impl avoids choosing a json library by parsing the simple structure above directly. | [
"IAM",
"Instance",
"Profile",
"format",
"is",
"simple",
"non",
"-",
"nested",
"json",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/route53/src/main/java/denominator/route53/InstanceProfileCredentialsProvider.java#L73-L87 | train |
Netflix/denominator | core/src/main/java/denominator/hook/InstanceMetadataHook.java | InstanceMetadataHook.list | public static List<String> list(URI metadataService, String path) {
checkArgument(checkNotNull(path, "path").endsWith("/"), "path must end with '/'; %s provided",
path);
String content = get(metadataService, path);
if (content != null) {
return split('\n', content);
}
return Collections.<String>emptyList();
} | java | public static List<String> list(URI metadataService, String path) {
checkArgument(checkNotNull(path, "path").endsWith("/"), "path must end with '/'; %s provided",
path);
String content = get(metadataService, path);
if (content != null) {
return split('\n', content);
}
return Collections.<String>emptyList();
} | [
"public",
"static",
"List",
"<",
"String",
">",
"list",
"(",
"URI",
"metadataService",
",",
"String",
"path",
")",
"{",
"checkArgument",
"(",
"checkNotNull",
"(",
"path",
",",
"\"path\"",
")",
".",
"endsWith",
"(",
"\"/\"",
")",
",",
"\"path must end with '/... | Retrieves a list of resources at a path, if present.
@param metadataService endpoint with trailing slash. ex. {@code http://169.254.169.254/latest/meta-data/}
@param path path of a listable resource, such as {@code iam/security-credentials/};
must end in slash
@return empty if {@code metadataService} service cannot be contacted or no data at path. | [
"Retrieves",
"a",
"list",
"of",
"resources",
"at",
"a",
"path",
"if",
"present",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/core/src/main/java/denominator/hook/InstanceMetadataHook.java#L50-L58 | train |
Netflix/denominator | core/src/main/java/denominator/hook/InstanceMetadataHook.java | InstanceMetadataHook.get | public static String get(URI metadataService, String path) {
checkNotNull(metadataService, "metadataService");
checkArgument(metadataService.getPath().endsWith("/"),
"metadataService must end with '/'; %s provided",
metadataService);
checkNotNull(path, "path");
InputStream stream = null;
try {
stream = openStream(metadataService + path);
String content = slurp(new InputStreamReader(stream));
if (content.isEmpty()) {
return null;
}
return content;
} catch (IOException e) {
return null;
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException e) {
}
}
} | java | public static String get(URI metadataService, String path) {
checkNotNull(metadataService, "metadataService");
checkArgument(metadataService.getPath().endsWith("/"),
"metadataService must end with '/'; %s provided",
metadataService);
checkNotNull(path, "path");
InputStream stream = null;
try {
stream = openStream(metadataService + path);
String content = slurp(new InputStreamReader(stream));
if (content.isEmpty()) {
return null;
}
return content;
} catch (IOException e) {
return null;
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException e) {
}
}
} | [
"public",
"static",
"String",
"get",
"(",
"URI",
"metadataService",
",",
"String",
"path",
")",
"{",
"checkNotNull",
"(",
"metadataService",
",",
"\"metadataService\"",
")",
";",
"checkArgument",
"(",
"metadataService",
".",
"getPath",
"(",
")",
".",
"endsWith",... | Retrieves content at a path, if present.
@param metadataService endpoint with trailing slash. ex. {@code http://169.254.169.254/latest/meta-data/}
@param path path to the metadata desired. ex. {@code public-ipv4} or {@code
iam/security-credentials/role-name}
@return null if {@code metadataService} service cannot be contacted or no data at path. | [
"Retrieves",
"content",
"at",
"a",
"path",
"if",
"present",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/core/src/main/java/denominator/hook/InstanceMetadataHook.java#L79-L103 | train |
Netflix/denominator | route53/src/main/java/denominator/route53/Route53AllProfileResourceRecordSetApi.java | Route53AllProfileResourceRecordSetApi.iterateByName | @Override
public Iterator<ResourceRecordSet<?>> iterateByName(String name) {
Filter<ResourceRecordSet<?>> filter = andNotAlias(nameEqualTo(name));
return lazyIterateRRSets(api.listResourceRecordSets(zoneId, name), filter);
} | java | @Override
public Iterator<ResourceRecordSet<?>> iterateByName(String name) {
Filter<ResourceRecordSet<?>> filter = andNotAlias(nameEqualTo(name));
return lazyIterateRRSets(api.listResourceRecordSets(zoneId, name), filter);
} | [
"@",
"Override",
"public",
"Iterator",
"<",
"ResourceRecordSet",
"<",
"?",
">",
">",
"iterateByName",
"(",
"String",
"name",
")",
"{",
"Filter",
"<",
"ResourceRecordSet",
"<",
"?",
">",
">",
"filter",
"=",
"andNotAlias",
"(",
"nameEqualTo",
"(",
"name",
")... | lists and lazily transforms all record sets for a name which are not aliases into denominator
format. | [
"lists",
"and",
"lazily",
"transforms",
"all",
"record",
"sets",
"for",
"a",
"name",
"which",
"are",
"not",
"aliases",
"into",
"denominator",
"format",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/route53/src/main/java/denominator/route53/Route53AllProfileResourceRecordSetApi.java#L58-L62 | train |
Netflix/denominator | example-android/src/main/java/denominator/example/android/ui/HomeActivity.java | HomeActivity.onKeyDown | @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
startActivity(new Intent(this, PreferencesActivity.class));
return true;
}
return super.onKeyDown(keyCode, event);
} | java | @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
startActivity(new Intent(this, PreferencesActivity.class));
return true;
}
return super.onKeyDown(keyCode, event);
} | [
"@",
"Override",
"public",
"boolean",
"onKeyDown",
"(",
"int",
"keyCode",
",",
"KeyEvent",
"event",
")",
"{",
"if",
"(",
"keyCode",
"==",
"KeyEvent",
".",
"KEYCODE_MENU",
")",
"{",
"startActivity",
"(",
"new",
"Intent",
"(",
"this",
",",
"PreferencesActivity... | wire up preferences screen when menu button is pressed. | [
"wire",
"up",
"preferences",
"screen",
"when",
"menu",
"button",
"is",
"pressed",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/example-android/src/main/java/denominator/example/android/ui/HomeActivity.java#L71-L78 | train |
Netflix/denominator | example-android/src/main/java/denominator/example/android/ui/HomeActivity.java | HomeActivity.onZones | @Subscribe
public void onZones(ZoneList.SuccessEvent event) {
String durationEvent = getString(R.string.list_duration, event.duration);
Toast.makeText(this, durationEvent, LENGTH_SHORT).show();
} | java | @Subscribe
public void onZones(ZoneList.SuccessEvent event) {
String durationEvent = getString(R.string.list_duration, event.duration);
Toast.makeText(this, durationEvent, LENGTH_SHORT).show();
} | [
"@",
"Subscribe",
"public",
"void",
"onZones",
"(",
"ZoneList",
".",
"SuccessEvent",
"event",
")",
"{",
"String",
"durationEvent",
"=",
"getString",
"(",
"R",
".",
"string",
".",
"list_duration",
",",
"event",
".",
"duration",
")",
";",
"Toast",
".",
"make... | flash the response time of doing the list. | [
"flash",
"the",
"response",
"time",
"of",
"doing",
"the",
"list",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/example-android/src/main/java/denominator/example/android/ui/HomeActivity.java#L83-L87 | train |
Netflix/denominator | example-android/src/main/java/denominator/example/android/ui/HomeActivity.java | HomeActivity.onFailure | @Subscribe
public void onFailure(Throwable t) {
Toast.makeText(this, t.getMessage(), LENGTH_LONG).show();
} | java | @Subscribe
public void onFailure(Throwable t) {
Toast.makeText(this, t.getMessage(), LENGTH_LONG).show();
} | [
"@",
"Subscribe",
"public",
"void",
"onFailure",
"(",
"Throwable",
"t",
")",
"{",
"Toast",
".",
"makeText",
"(",
"this",
",",
"t",
".",
"getMessage",
"(",
")",
",",
"LENGTH_LONG",
")",
".",
"show",
"(",
")",
";",
"}"
] | show any error messages posted to the bus. | [
"show",
"any",
"error",
"messages",
"posted",
"to",
"the",
"bus",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/example-android/src/main/java/denominator/example/android/ui/HomeActivity.java#L92-L95 | train |
Netflix/denominator | route53/src/main/java/denominator/route53/Route53ZoneApi.java | Route53ZoneApi.iterateByName | @Override
public Iterator<Zone> iterateByName(final String name) {
final Iterator<HostedZone> delegate = api.listHostedZonesByName(name).iterator();
return new PeekingIterator<Zone>() {
@Override
protected Zone computeNext() {
if (delegate.hasNext()) {
HostedZone next = delegate.next();
if (next.name.equals(name)) {
return zipWithSOA(next);
}
}
return endOfData();
}
};
} | java | @Override
public Iterator<Zone> iterateByName(final String name) {
final Iterator<HostedZone> delegate = api.listHostedZonesByName(name).iterator();
return new PeekingIterator<Zone>() {
@Override
protected Zone computeNext() {
if (delegate.hasNext()) {
HostedZone next = delegate.next();
if (next.name.equals(name)) {
return zipWithSOA(next);
}
}
return endOfData();
}
};
} | [
"@",
"Override",
"public",
"Iterator",
"<",
"Zone",
">",
"iterateByName",
"(",
"final",
"String",
"name",
")",
"{",
"final",
"Iterator",
"<",
"HostedZone",
">",
"delegate",
"=",
"api",
".",
"listHostedZonesByName",
"(",
"name",
")",
".",
"iterator",
"(",
"... | This implementation assumes that there isn't more than one page of zones with the same name. | [
"This",
"implementation",
"assumes",
"that",
"there",
"isn",
"t",
"more",
"than",
"one",
"page",
"of",
"zones",
"with",
"the",
"same",
"name",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/route53/src/main/java/denominator/route53/Route53ZoneApi.java#L39-L54 | train |
Netflix/denominator | route53/src/main/java/denominator/route53/Route53ZoneApi.java | Route53ZoneApi.deleteEverythingExceptNSAndSOA | private void deleteEverythingExceptNSAndSOA(String id, String name) {
List<ActionOnResourceRecordSet> deletes = new ArrayList<ActionOnResourceRecordSet>();
ResourceRecordSetList page = api.listResourceRecordSets(id);
while (!page.isEmpty()) {
for (ResourceRecordSet<?> rrset : page) {
if (rrset.type().equals("SOA") || rrset.type().equals("NS") && rrset.name().equals(name)) {
continue;
}
deletes.add(ActionOnResourceRecordSet.delete(rrset));
}
if (!deletes.isEmpty()) {
api.changeResourceRecordSets(id, deletes);
}
if (page.next == null) {
page.clear();
} else {
deletes.clear();
page = api.listResourceRecordSets(id, page.next.name, page.next.type, page.next.identifier);
}
}
} | java | private void deleteEverythingExceptNSAndSOA(String id, String name) {
List<ActionOnResourceRecordSet> deletes = new ArrayList<ActionOnResourceRecordSet>();
ResourceRecordSetList page = api.listResourceRecordSets(id);
while (!page.isEmpty()) {
for (ResourceRecordSet<?> rrset : page) {
if (rrset.type().equals("SOA") || rrset.type().equals("NS") && rrset.name().equals(name)) {
continue;
}
deletes.add(ActionOnResourceRecordSet.delete(rrset));
}
if (!deletes.isEmpty()) {
api.changeResourceRecordSets(id, deletes);
}
if (page.next == null) {
page.clear();
} else {
deletes.clear();
page = api.listResourceRecordSets(id, page.next.name, page.next.type, page.next.identifier);
}
}
} | [
"private",
"void",
"deleteEverythingExceptNSAndSOA",
"(",
"String",
"id",
",",
"String",
"name",
")",
"{",
"List",
"<",
"ActionOnResourceRecordSet",
">",
"deletes",
"=",
"new",
"ArrayList",
"<",
"ActionOnResourceRecordSet",
">",
"(",
")",
";",
"ResourceRecordSetList... | Works through the zone, deleting each page of rrsets, except the zone's SOA and the NS rrsets.
Once the zone is cleared, it can be deleted.
<p/>Users can modify the zone's SOA and NS rrsets, but they cannot be deleted except via
deleting the zone. | [
"Works",
"through",
"the",
"zone",
"deleting",
"each",
"page",
"of",
"rrsets",
"except",
"the",
"zone",
"s",
"SOA",
"and",
"the",
"NS",
"rrsets",
".",
"Once",
"the",
"zone",
"is",
"cleared",
"it",
"can",
"be",
"deleted",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/route53/src/main/java/denominator/route53/Route53ZoneApi.java#L101-L121 | train |
Netflix/denominator | cli/src/main/java/denominator/cli/Denominator.java | Denominator.logModule | static Object logModule(boolean quiet, boolean verbose) {
checkArgument(!(quiet && verbose), "quiet and verbose flags cannot be used at the same time!");
Logger.Level logLevel;
if (quiet) {
return null;
} else if (verbose) {
logLevel = Logger.Level.FULL;
} else {
logLevel = Logger.Level.BASIC;
}
return new LogModule(logLevel);
} | java | static Object logModule(boolean quiet, boolean verbose) {
checkArgument(!(quiet && verbose), "quiet and verbose flags cannot be used at the same time!");
Logger.Level logLevel;
if (quiet) {
return null;
} else if (verbose) {
logLevel = Logger.Level.FULL;
} else {
logLevel = Logger.Level.BASIC;
}
return new LogModule(logLevel);
} | [
"static",
"Object",
"logModule",
"(",
"boolean",
"quiet",
",",
"boolean",
"verbose",
")",
"{",
"checkArgument",
"(",
"!",
"(",
"quiet",
"&&",
"verbose",
")",
",",
"\"quiet and verbose flags cannot be used at the same time!\"",
")",
";",
"Logger",
".",
"Level",
"lo... | Returns a log configuration module or null if none is needed. | [
"Returns",
"a",
"log",
"configuration",
"module",
"or",
"null",
"if",
"none",
"is",
"needed",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/cli/src/main/java/denominator/cli/Denominator.java#L179-L190 | train |
Netflix/denominator | ultradns/src/main/java/denominator/ultradns/GroupGeoRecordByNameTypeIterator.java | GroupGeoRecordByNameTypeIterator.hasNext | @Override
public boolean hasNext() {
if (!peekingIterator.hasNext()) {
return false;
}
DirectionalRecord record = peekingIterator.peek();
if (record.noResponseRecord) {
// TODO: log as this is unsupported
peekingIterator.next();
}
return true;
} | java | @Override
public boolean hasNext() {
if (!peekingIterator.hasNext()) {
return false;
}
DirectionalRecord record = peekingIterator.peek();
if (record.noResponseRecord) {
// TODO: log as this is unsupported
peekingIterator.next();
}
return true;
} | [
"@",
"Override",
"public",
"boolean",
"hasNext",
"(",
")",
"{",
"if",
"(",
"!",
"peekingIterator",
".",
"hasNext",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"DirectionalRecord",
"record",
"=",
"peekingIterator",
".",
"peek",
"(",
")",
";",
"if",
... | skips no response records as they aren't portable | [
"skips",
"no",
"response",
"records",
"as",
"they",
"aren",
"t",
"portable"
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/ultradns/src/main/java/denominator/ultradns/GroupGeoRecordByNameTypeIterator.java#L44-L55 | train |
Netflix/denominator | clouddns/src/main/java/denominator/clouddns/CloudDNSFunctions.java | CloudDNSFunctions.awaitComplete | static String awaitComplete(CloudDNS api, Job job) {
RetryableException retryableException = new RetryableException(
format("Job %s did not complete. Check your logs.", job.id), null);
Retryer retryer = new Retryer.Default(500, 1000, 30);
while (true) {
job = api.getStatus(job.id);
if ("COMPLETED".equals(job.status)) {
return job.resultId;
} else if ("ERROR".equals(job.status)) {
throw new IllegalStateException(
format("Job %s failed with error: %s", job.id, job.errorDetails));
}
retryer.continueOrPropagate(retryableException);
}
} | java | static String awaitComplete(CloudDNS api, Job job) {
RetryableException retryableException = new RetryableException(
format("Job %s did not complete. Check your logs.", job.id), null);
Retryer retryer = new Retryer.Default(500, 1000, 30);
while (true) {
job = api.getStatus(job.id);
if ("COMPLETED".equals(job.status)) {
return job.resultId;
} else if ("ERROR".equals(job.status)) {
throw new IllegalStateException(
format("Job %s failed with error: %s", job.id, job.errorDetails));
}
retryer.continueOrPropagate(retryableException);
}
} | [
"static",
"String",
"awaitComplete",
"(",
"CloudDNS",
"api",
",",
"Job",
"job",
")",
"{",
"RetryableException",
"retryableException",
"=",
"new",
"RetryableException",
"(",
"format",
"(",
"\"Job %s did not complete. Check your logs.\"",
",",
"job",
".",
"id",
")",
"... | Returns the ID of the object created or null. | [
"Returns",
"the",
"ID",
"of",
"the",
"object",
"created",
"or",
"null",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/clouddns/src/main/java/denominator/clouddns/CloudDNSFunctions.java#L25-L42 | train |
Netflix/denominator | clouddns/src/main/java/denominator/clouddns/CloudDNSFunctions.java | CloudDNSFunctions.toRDataMap | static Map<String, Object> toRDataMap(Record record) {
if ("MX".equals(record.type)) {
return MXData.create(record.priority, record.data());
} else if ("TXT".equals(record.type)) {
return TXTData.create(record.data());
} else if ("SRV".equals(record.type)) {
List<String> rdata = split(' ', record.data());
return SRVData.builder()
.priority(record.priority)
.weight(Integer.valueOf(rdata.get(0)))
.port(Integer.valueOf(rdata.get(1)))
.target(rdata.get(2)).build();
} else if ("SOA".equals(record.type)) {
List<String> threeParts = split(' ', record.data());
return SOAData.builder()
.mname(threeParts.get(0))
.rname(threeParts.get(1))
.serial(Integer.valueOf(threeParts.get(2)))
.refresh(record.ttl)
.retry(record.ttl)
.expire(record.ttl).minimum(record.ttl).build();
} else {
return Util.toMap(record.type, record.data());
}
} | java | static Map<String, Object> toRDataMap(Record record) {
if ("MX".equals(record.type)) {
return MXData.create(record.priority, record.data());
} else if ("TXT".equals(record.type)) {
return TXTData.create(record.data());
} else if ("SRV".equals(record.type)) {
List<String> rdata = split(' ', record.data());
return SRVData.builder()
.priority(record.priority)
.weight(Integer.valueOf(rdata.get(0)))
.port(Integer.valueOf(rdata.get(1)))
.target(rdata.get(2)).build();
} else if ("SOA".equals(record.type)) {
List<String> threeParts = split(' ', record.data());
return SOAData.builder()
.mname(threeParts.get(0))
.rname(threeParts.get(1))
.serial(Integer.valueOf(threeParts.get(2)))
.refresh(record.ttl)
.retry(record.ttl)
.expire(record.ttl).minimum(record.ttl).build();
} else {
return Util.toMap(record.type, record.data());
}
} | [
"static",
"Map",
"<",
"String",
",",
"Object",
">",
"toRDataMap",
"(",
"Record",
"record",
")",
"{",
"if",
"(",
"\"MX\"",
".",
"equals",
"(",
"record",
".",
"type",
")",
")",
"{",
"return",
"MXData",
".",
"create",
"(",
"record",
".",
"priority",
","... | Special-cases priority field and the strange and incomplete SOA record. | [
"Special",
"-",
"cases",
"priority",
"field",
"and",
"the",
"strange",
"and",
"incomplete",
"SOA",
"record",
"."
] | c565e3b8c6043051252e0947029511f9ac5d306f | https://github.com/Netflix/denominator/blob/c565e3b8c6043051252e0947029511f9ac5d306f/clouddns/src/main/java/denominator/clouddns/CloudDNSFunctions.java#L47-L71 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggingConfiguration.java | LoggingConfiguration.stop | public void stop() {
MessageBatcher batcher = null;
for (String originalAppenderName : originalAsyncAppenderNameMap.keySet()) {
String batcherName = AsyncAppender.class.getName() + "." + originalAppenderName;
batcher = BatcherFactory.getBatcher(batcherName);
if (batcher == null) {
continue;
}
batcher.stop();
}
for (String originalAppenderName : originalAsyncAppenderNameMap.keySet()) {
String batcherName = AsyncAppender.class.getName() + "." + originalAppenderName;
batcher = BatcherFactory.getBatcher(batcherName);
if (batcher == null) {
continue;
}
BatcherFactory.removeBatcher(batcherName);
}
} | java | public void stop() {
MessageBatcher batcher = null;
for (String originalAppenderName : originalAsyncAppenderNameMap.keySet()) {
String batcherName = AsyncAppender.class.getName() + "." + originalAppenderName;
batcher = BatcherFactory.getBatcher(batcherName);
if (batcher == null) {
continue;
}
batcher.stop();
}
for (String originalAppenderName : originalAsyncAppenderNameMap.keySet()) {
String batcherName = AsyncAppender.class.getName() + "." + originalAppenderName;
batcher = BatcherFactory.getBatcher(batcherName);
if (batcher == null) {
continue;
}
BatcherFactory.removeBatcher(batcherName);
}
} | [
"public",
"void",
"stop",
"(",
")",
"{",
"MessageBatcher",
"batcher",
"=",
"null",
";",
"for",
"(",
"String",
"originalAppenderName",
":",
"originalAsyncAppenderNameMap",
".",
"keySet",
"(",
")",
")",
"{",
"String",
"batcherName",
"=",
"AsyncAppender",
".",
"c... | Shuts down blitz4j cleanly by flushing out all the async related
messages. | [
"Shuts",
"down",
"blitz4j",
"cleanly",
"by",
"flushing",
"out",
"all",
"the",
"async",
"related",
"messages",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java#L259-L278 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggingConfiguration.java | LoggingConfiguration.reconfigure | public synchronized void reconfigure(Properties props) {
// First isolate any property that is different from the immutable
// set of original initialization properties
Properties newOverrideProps = new Properties();
for (Entry<Object, Object> prop : props.entrySet()) {
if (isLog4JProperty(prop.getKey().toString())) {
Object initialValue = initialProps.get(prop.getKey());
if (initialValue == null || !initialValue.equals(prop.getValue())) {
newOverrideProps.put(prop.getKey(), prop.getValue());
}
}
}
// Compare against our cached set of override
if (!overrideProps.equals(newOverrideProps)) {
this.overrideProps.clear();
this.overrideProps.putAll(newOverrideProps);
reConfigureAsynchronously();
}
} | java | public synchronized void reconfigure(Properties props) {
// First isolate any property that is different from the immutable
// set of original initialization properties
Properties newOverrideProps = new Properties();
for (Entry<Object, Object> prop : props.entrySet()) {
if (isLog4JProperty(prop.getKey().toString())) {
Object initialValue = initialProps.get(prop.getKey());
if (initialValue == null || !initialValue.equals(prop.getValue())) {
newOverrideProps.put(prop.getKey(), prop.getValue());
}
}
}
// Compare against our cached set of override
if (!overrideProps.equals(newOverrideProps)) {
this.overrideProps.clear();
this.overrideProps.putAll(newOverrideProps);
reConfigureAsynchronously();
}
} | [
"public",
"synchronized",
"void",
"reconfigure",
"(",
"Properties",
"props",
")",
"{",
"// First isolate any property that is different from the immutable",
"// set of original initialization properties",
"Properties",
"newOverrideProps",
"=",
"new",
"Properties",
"(",
")",
";",
... | Set a snapshot of all LOG4J properties and reconfigure if properties have been
changed.
@param props Complete set of ALL log4j configuration properties including all
appenders and log level overrides | [
"Set",
"a",
"snapshot",
"of",
"all",
"LOG4J",
"properties",
"and",
"reconfigure",
"if",
"properties",
"have",
"been",
"changed",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java#L345-L364 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggingConfiguration.java | LoggingConfiguration.reConfigureAsynchronously | private void reConfigureAsynchronously() {
refreshCount.incrementAndGet();
if (pendingRefreshes.incrementAndGet() == 1) {
executorPool.submit(new Runnable() {
@Override
public void run() {
do {
try {
Thread.sleep(MIN_DELAY_BETWEEN_REFRESHES);
logger.info("Configuring log4j dynamically");
reconfigure();
}
catch (Exception th) {
logger.error("Cannot dynamically configure log4j :", th);
}
} while (0 != pendingRefreshes.getAndSet(0));
}
});
}
} | java | private void reConfigureAsynchronously() {
refreshCount.incrementAndGet();
if (pendingRefreshes.incrementAndGet() == 1) {
executorPool.submit(new Runnable() {
@Override
public void run() {
do {
try {
Thread.sleep(MIN_DELAY_BETWEEN_REFRESHES);
logger.info("Configuring log4j dynamically");
reconfigure();
}
catch (Exception th) {
logger.error("Cannot dynamically configure log4j :", th);
}
} while (0 != pendingRefreshes.getAndSet(0));
}
});
}
} | [
"private",
"void",
"reConfigureAsynchronously",
"(",
")",
"{",
"refreshCount",
".",
"incrementAndGet",
"(",
")",
";",
"if",
"(",
"pendingRefreshes",
".",
"incrementAndGet",
"(",
")",
"==",
"1",
")",
"{",
"executorPool",
".",
"submit",
"(",
"new",
"Runnable",
... | Refresh the configuration asynchronously | [
"Refresh",
"the",
"configuration",
"asynchronously"
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java#L369-L388 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggingConfiguration.java | LoggingConfiguration.reconfigure | private void reconfigure() throws ConfigurationException, FileNotFoundException {
Properties consolidatedProps = getConsolidatedProperties();
logger.info("The root category for log4j.rootCategory now is {}", consolidatedProps.getProperty(LOG4J_ROOT_CATEGORY));
logger.info("The root category for log4j.rootLogger now is {}", consolidatedProps.getProperty(LOG4J_ROOT_LOGGER));
// Pause the async appenders so that the appenders are not accessed
for (String originalAppenderName : originalAsyncAppenderNameMap.keySet()) {
MessageBatcher asyncBatcher = BatcherFactory.getBatcher(AsyncAppender.class.getName() + "." + originalAppenderName);
if (asyncBatcher == null) {
continue;
}
asyncBatcher.pause();
}
// Configure log4j using the new set of properties
configureLog4j(consolidatedProps);
// Resume all the batchers to continue logging
for (String originalAppenderName : originalAsyncAppenderNameMap.keySet()) {
MessageBatcher asyncBatcher = BatcherFactory.getBatcher(AsyncAppender.class.getName() + "." + originalAppenderName);
if (asyncBatcher == null) {
continue;
}
asyncBatcher.resume();
}
} | java | private void reconfigure() throws ConfigurationException, FileNotFoundException {
Properties consolidatedProps = getConsolidatedProperties();
logger.info("The root category for log4j.rootCategory now is {}", consolidatedProps.getProperty(LOG4J_ROOT_CATEGORY));
logger.info("The root category for log4j.rootLogger now is {}", consolidatedProps.getProperty(LOG4J_ROOT_LOGGER));
// Pause the async appenders so that the appenders are not accessed
for (String originalAppenderName : originalAsyncAppenderNameMap.keySet()) {
MessageBatcher asyncBatcher = BatcherFactory.getBatcher(AsyncAppender.class.getName() + "." + originalAppenderName);
if (asyncBatcher == null) {
continue;
}
asyncBatcher.pause();
}
// Configure log4j using the new set of properties
configureLog4j(consolidatedProps);
// Resume all the batchers to continue logging
for (String originalAppenderName : originalAsyncAppenderNameMap.keySet()) {
MessageBatcher asyncBatcher = BatcherFactory.getBatcher(AsyncAppender.class.getName() + "." + originalAppenderName);
if (asyncBatcher == null) {
continue;
}
asyncBatcher.resume();
}
} | [
"private",
"void",
"reconfigure",
"(",
")",
"throws",
"ConfigurationException",
",",
"FileNotFoundException",
"{",
"Properties",
"consolidatedProps",
"=",
"getConsolidatedProperties",
"(",
")",
";",
"logger",
".",
"info",
"(",
"\"The root category for log4j.rootCategory now... | Reconfigure log4j at run-time.
@param name
- The name of the property that changed
@param value
- The new value of the property
@throws FileNotFoundException
@throws ConfigurationException | [
"Reconfigure",
"log4j",
"at",
"run",
"-",
"time",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java#L408-L434 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggingConfiguration.java | LoggingConfiguration.configureLog4j | private void configureLog4j(Properties props) throws ConfigurationException, FileNotFoundException {
if (blitz4jConfig.shouldUseLockFree() && (props.getProperty(LOG4J_LOGGER_FACTORY) == null)) {
props.setProperty(LOG4J_LOGGER_FACTORY, LOG4J_FACTORY_IMPL);
}
convertConfiguredAppendersToAsync(props);
clearAsyncAppenderList();
logger.info("Configuring log4j with properties :" + props);
PropertyConfigurator.configure(props);
} | java | private void configureLog4j(Properties props) throws ConfigurationException, FileNotFoundException {
if (blitz4jConfig.shouldUseLockFree() && (props.getProperty(LOG4J_LOGGER_FACTORY) == null)) {
props.setProperty(LOG4J_LOGGER_FACTORY, LOG4J_FACTORY_IMPL);
}
convertConfiguredAppendersToAsync(props);
clearAsyncAppenderList();
logger.info("Configuring log4j with properties :" + props);
PropertyConfigurator.configure(props);
} | [
"private",
"void",
"configureLog4j",
"(",
"Properties",
"props",
")",
"throws",
"ConfigurationException",
",",
"FileNotFoundException",
"{",
"if",
"(",
"blitz4jConfig",
".",
"shouldUseLockFree",
"(",
")",
"&&",
"(",
"props",
".",
"getProperty",
"(",
"LOG4J_LOGGER_FA... | Configure log4j with the given properties.
@param props
The properties that needs to be configured for log4j
@throws ConfigurationException
@throws FileNotFoundException | [
"Configure",
"log4j",
"with",
"the",
"given",
"properties",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java#L444-L452 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggingConfiguration.java | LoggingConfiguration.closeNonexistingAsyncAppenders | private void closeNonexistingAsyncAppenders() {
org.apache.log4j.Logger rootLogger = LogManager.getRootLogger();
if (NFLockFreeLogger.class.isInstance(rootLogger)) {
((NFLockFreeLogger)rootLogger).reconcileAppenders();
}
Enumeration enums = LogManager.getCurrentLoggers();
while (enums.hasMoreElements()) {
Object myLogger = enums.nextElement();
if (NFLockFreeLogger.class.isInstance(myLogger)) {
((NFLockFreeLogger)myLogger).reconcileAppenders();
}
}
} | java | private void closeNonexistingAsyncAppenders() {
org.apache.log4j.Logger rootLogger = LogManager.getRootLogger();
if (NFLockFreeLogger.class.isInstance(rootLogger)) {
((NFLockFreeLogger)rootLogger).reconcileAppenders();
}
Enumeration enums = LogManager.getCurrentLoggers();
while (enums.hasMoreElements()) {
Object myLogger = enums.nextElement();
if (NFLockFreeLogger.class.isInstance(myLogger)) {
((NFLockFreeLogger)myLogger).reconcileAppenders();
}
}
} | [
"private",
"void",
"closeNonexistingAsyncAppenders",
"(",
")",
"{",
"org",
".",
"apache",
".",
"log4j",
".",
"Logger",
"rootLogger",
"=",
"LogManager",
".",
"getRootLogger",
"(",
")",
";",
"if",
"(",
"NFLockFreeLogger",
".",
"class",
".",
"isInstance",
"(",
... | Closes any asynchronous appenders that were not removed during configuration. | [
"Closes",
"any",
"asynchronous",
"appenders",
"that",
"were",
"not",
"removed",
"during",
"configuration",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggingConfiguration.java#L541-L553 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggerCache.java | LoggerCache.getOrCreateLogger | public Logger getOrCreateLogger(String clazz) {
Logger logger = appenderLoggerMap.get(clazz);
if (logger == null) {
// If multiple threads do the puts, that is fine as it is a one time thing
logger = Logger.getLogger(clazz);
appenderLoggerMap.put(clazz, logger);
}
return logger;
} | java | public Logger getOrCreateLogger(String clazz) {
Logger logger = appenderLoggerMap.get(clazz);
if (logger == null) {
// If multiple threads do the puts, that is fine as it is a one time thing
logger = Logger.getLogger(clazz);
appenderLoggerMap.put(clazz, logger);
}
return logger;
} | [
"public",
"Logger",
"getOrCreateLogger",
"(",
"String",
"clazz",
")",
"{",
"Logger",
"logger",
"=",
"appenderLoggerMap",
".",
"get",
"(",
"clazz",
")",
";",
"if",
"(",
"logger",
"==",
"null",
")",
"{",
"// If multiple threads do the puts, that is fine as it is a one... | Get the logger to be used for the given class.
@param clazz - The class for which the logger needs to be returned
@return- The log4j logger object | [
"Get",
"the",
"logger",
"to",
"be",
"used",
"for",
"the",
"given",
"class",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggerCache.java#L53-L61 | train |
Netflix/blitz4j | src/main/java/com/netflix/logging/messaging/MessageBatcher.java | MessageBatcher.setProcessorMaxThreads | public void setProcessorMaxThreads(int maxThreads) {
if (processor.getCorePoolSize() > maxThreads) {
processor.setCorePoolSize(maxThreads);
}
processor.setMaximumPoolSize(maxThreads);
} | java | public void setProcessorMaxThreads(int maxThreads) {
if (processor.getCorePoolSize() > maxThreads) {
processor.setCorePoolSize(maxThreads);
}
processor.setMaximumPoolSize(maxThreads);
} | [
"public",
"void",
"setProcessorMaxThreads",
"(",
"int",
"maxThreads",
")",
"{",
"if",
"(",
"processor",
".",
"getCorePoolSize",
"(",
")",
">",
"maxThreads",
")",
"{",
"processor",
".",
"setCorePoolSize",
"(",
"maxThreads",
")",
";",
"}",
"processor",
".",
"s... | Set the max threads for the processors
@param maxThreads - max threads that can be launched for processing | [
"Set",
"the",
"max",
"threads",
"for",
"the",
"processors"
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/logging/messaging/MessageBatcher.java#L192-L197 | train |
Netflix/blitz4j | src/main/java/com/netflix/logging/messaging/MessageBatcher.java | MessageBatcher.process | public boolean process(T message) {
// If this batcher has been shutdown, do not accept any more messages
if (isShutDown) {
return false;
}
try {
queueSizeTracer.record(queue.size());
} catch (Throwable ignored) {
}
if (!queue.offer(message)) {
numberDropped.incrementAndGet();
queueOverflowCounter.increment();
return false;
}
numberAdded.incrementAndGet();
return true;
} | java | public boolean process(T message) {
// If this batcher has been shutdown, do not accept any more messages
if (isShutDown) {
return false;
}
try {
queueSizeTracer.record(queue.size());
} catch (Throwable ignored) {
}
if (!queue.offer(message)) {
numberDropped.incrementAndGet();
queueOverflowCounter.increment();
return false;
}
numberAdded.incrementAndGet();
return true;
} | [
"public",
"boolean",
"process",
"(",
"T",
"message",
")",
"{",
"// If this batcher has been shutdown, do not accept any more messages",
"if",
"(",
"isShutDown",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"queueSizeTracer",
".",
"record",
"(",
"queue",
".",
... | Processes the message sent to the batcher. This method just writes the
message to the queue and returns immediately. If the queue is full, the
messages are dropped immediately and corresponding counter is
incremented.
@param message
- The message to be processed
@return boolean - true if the message is queued for processing,false(this
could happen if the queue is full) otherwise | [
"Processes",
"the",
"message",
"sent",
"to",
"the",
"batcher",
".",
"This",
"method",
"just",
"writes",
"the",
"message",
"to",
"the",
"queue",
"and",
"returns",
"immediately",
".",
"If",
"the",
"queue",
"is",
"full",
"the",
"messages",
"are",
"dropped",
"... | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/logging/messaging/MessageBatcher.java#L219-L236 | train |
Netflix/blitz4j | src/main/java/com/netflix/logging/messaging/MessageBatcher.java | MessageBatcher.processSync | public void processSync(T message) {
// If this batcher has been shutdown, do not accept any more messages
if (isShutDown) {
return;
}
try {
queueSizeTracer.record(queue.size());
} catch (Throwable ignored) {
}
try {
Stopwatch s = batchSyncPutTracer.start();
queue.put(message);
s.stop();
} catch (InterruptedException e) {
return;
}
numberAdded.incrementAndGet();
} | java | public void processSync(T message) {
// If this batcher has been shutdown, do not accept any more messages
if (isShutDown) {
return;
}
try {
queueSizeTracer.record(queue.size());
} catch (Throwable ignored) {
}
try {
Stopwatch s = batchSyncPutTracer.start();
queue.put(message);
s.stop();
} catch (InterruptedException e) {
return;
}
numberAdded.incrementAndGet();
} | [
"public",
"void",
"processSync",
"(",
"T",
"message",
")",
"{",
"// If this batcher has been shutdown, do not accept any more messages",
"if",
"(",
"isShutDown",
")",
"{",
"return",
";",
"}",
"try",
"{",
"queueSizeTracer",
".",
"record",
"(",
"queue",
".",
"size",
... | Processes the message sent to the batcher. This method tries to write to
the queue. If the queue is full, the send blocks and waits for the
available space.
@param message
- The message to be processed | [
"Processes",
"the",
"message",
"sent",
"to",
"the",
"batcher",
".",
"This",
"method",
"tries",
"to",
"write",
"to",
"the",
"queue",
".",
"If",
"the",
"queue",
"is",
"full",
"the",
"send",
"blocks",
"and",
"waits",
"for",
"the",
"available",
"space",
"."
... | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/logging/messaging/MessageBatcher.java#L246-L265 | train |
Netflix/blitz4j | src/main/java/com/netflix/logging/messaging/MessageBatcher.java | MessageBatcher.process | public void process(List<T> objects) {
for (T message : objects) {
// If this batcher has been shutdown, do not accept any more
// messages
if (isShutDown) {
return;
}
process(message);
}
} | java | public void process(List<T> objects) {
for (T message : objects) {
// If this batcher has been shutdown, do not accept any more
// messages
if (isShutDown) {
return;
}
process(message);
}
} | [
"public",
"void",
"process",
"(",
"List",
"<",
"T",
">",
"objects",
")",
"{",
"for",
"(",
"T",
"message",
":",
"objects",
")",
"{",
"// If this batcher has been shutdown, do not accept any more",
"// messages",
"if",
"(",
"isShutDown",
")",
"{",
"return",
";",
... | Processes the messages sent to the batcher. This method just writes the
message to the queue and returns immediately. If the queue is full, the
messages are dropped immediately and corresponding counter is
incremented.
@param message
- The messages to be processed | [
"Processes",
"the",
"messages",
"sent",
"to",
"the",
"batcher",
".",
"This",
"method",
"just",
"writes",
"the",
"message",
"to",
"the",
"queue",
"and",
"returns",
"immediately",
".",
"If",
"the",
"queue",
"is",
"full",
"the",
"messages",
"are",
"dropped",
... | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/logging/messaging/MessageBatcher.java#L276-L285 | train |
Netflix/blitz4j | src/main/java/com/netflix/logging/messaging/MessageBatcher.java | MessageBatcher.getSize | @Monitor(name = "batcherQueueSize", type = DataSourceType.GAUGE)
public int getSize() {
if (queue != null) {
return queue.size();
} else {
return 0;
}
} | java | @Monitor(name = "batcherQueueSize", type = DataSourceType.GAUGE)
public int getSize() {
if (queue != null) {
return queue.size();
} else {
return 0;
}
} | [
"@",
"Monitor",
"(",
"name",
"=",
"\"batcherQueueSize\"",
",",
"type",
"=",
"DataSourceType",
".",
"GAUGE",
")",
"public",
"int",
"getSize",
"(",
")",
"{",
"if",
"(",
"queue",
"!=",
"null",
")",
"{",
"return",
"queue",
".",
"size",
"(",
")",
";",
"}"... | The size of the the queue in which the messages are batches
@return- size of the queue | [
"The",
"size",
"of",
"the",
"the",
"queue",
"in",
"which",
"the",
"messages",
"are",
"batches"
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/logging/messaging/MessageBatcher.java#L518-L525 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/NFAppenderAttachableImpl.java | NFAppenderAttachableImpl.reconcileAppenders | public void reconcileAppenders() {
for (Appender appender : appenderList) {
if (!configuredAppenderList.contains(appender.getName())) {
appender.close();
appenderList.remove(appender);
}
}
} | java | public void reconcileAppenders() {
for (Appender appender : appenderList) {
if (!configuredAppenderList.contains(appender.getName())) {
appender.close();
appenderList.remove(appender);
}
}
} | [
"public",
"void",
"reconcileAppenders",
"(",
")",
"{",
"for",
"(",
"Appender",
"appender",
":",
"appenderList",
")",
"{",
"if",
"(",
"!",
"configuredAppenderList",
".",
"contains",
"(",
"appender",
".",
"getName",
"(",
")",
")",
")",
"{",
"appender",
".",
... | Reconciles the appender list after configuration to ensure that the asynchrnous
appenders are not left over after the configuration. This is needed because the
appenders are not cleaned out completely during configuration for it to retain the
ability to not messages. | [
"Reconciles",
"the",
"appender",
"list",
"after",
"configuration",
"to",
"ensure",
"that",
"the",
"asynchrnous",
"appenders",
"are",
"not",
"left",
"over",
"after",
"the",
"configuration",
".",
"This",
"is",
"needed",
"because",
"the",
"appenders",
"are",
"not",... | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/NFAppenderAttachableImpl.java#L230-L237 | train |
Netflix/blitz4j | src/main/java/com/netflix/logging/messaging/BatcherFactory.java | BatcherFactory.getBatcher | public static MessageBatcher getBatcher(String name) {
MessageBatcher batcher = batcherMap.get(name);
return batcher;
} | java | public static MessageBatcher getBatcher(String name) {
MessageBatcher batcher = batcherMap.get(name);
return batcher;
} | [
"public",
"static",
"MessageBatcher",
"getBatcher",
"(",
"String",
"name",
")",
"{",
"MessageBatcher",
"batcher",
"=",
"batcherMap",
".",
"get",
"(",
"name",
")",
";",
"return",
"batcher",
";",
"}"
] | Get a batcher by name
@param name - The name of the batcher
@return - the batcher associated with the name | [
"Get",
"a",
"batcher",
"by",
"name"
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/logging/messaging/BatcherFactory.java#L49-L52 | train |
Netflix/blitz4j | src/main/java/com/netflix/logging/messaging/BatcherFactory.java | BatcherFactory.createBatcher | public static MessageBatcher createBatcher(String name,
MessageProcessor processor) {
MessageBatcher batcher = batcherMap.get(name);
if (batcher == null) {
synchronized (BatcherFactory.class) {
batcher = batcherMap.get(name);
if (batcher == null) {
batcher = new MessageBatcher(name, processor);
batcherMap.put(name, batcher);
}
}
}
return batcher;
} | java | public static MessageBatcher createBatcher(String name,
MessageProcessor processor) {
MessageBatcher batcher = batcherMap.get(name);
if (batcher == null) {
synchronized (BatcherFactory.class) {
batcher = batcherMap.get(name);
if (batcher == null) {
batcher = new MessageBatcher(name, processor);
batcherMap.put(name, batcher);
}
}
}
return batcher;
} | [
"public",
"static",
"MessageBatcher",
"createBatcher",
"(",
"String",
"name",
",",
"MessageProcessor",
"processor",
")",
"{",
"MessageBatcher",
"batcher",
"=",
"batcherMap",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"batcher",
"==",
"null",
")",
"{",
"sy... | Creates the batcher. The user needs to make sure another batcher already exists before
they create one.
@param name - The name of the batcher to be created
@param processor - The user override for actions to be performed on the batched messages.
@return | [
"Creates",
"the",
"batcher",
".",
"The",
"user",
"needs",
"to",
"make",
"sure",
"another",
"batcher",
"already",
"exists",
"before",
"they",
"create",
"one",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/logging/messaging/BatcherFactory.java#L63-L76 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggingContext.java | LoggingContext.getStackTraceElement | public StackTraceElement getStackTraceElement(Class stackClass) {
Stopwatch s = stackTraceTimer.start();
Throwable t = new Throwable();
StackTraceElement[] stArray = t.getStackTrace();
int stackSize = stArray.length;
StackTraceElement st = null;
for (int i = 0; i < stackSize; i++) {
boolean found = false;
while (stArray[i].getClassName().equals(stackClass.getName())) {
++i;
found = true;
}
if (found) {
st = stArray[i];
}
}
s.stop();
return st;
} | java | public StackTraceElement getStackTraceElement(Class stackClass) {
Stopwatch s = stackTraceTimer.start();
Throwable t = new Throwable();
StackTraceElement[] stArray = t.getStackTrace();
int stackSize = stArray.length;
StackTraceElement st = null;
for (int i = 0; i < stackSize; i++) {
boolean found = false;
while (stArray[i].getClassName().equals(stackClass.getName())) {
++i;
found = true;
}
if (found) {
st = stArray[i];
}
}
s.stop();
return st;
} | [
"public",
"StackTraceElement",
"getStackTraceElement",
"(",
"Class",
"stackClass",
")",
"{",
"Stopwatch",
"s",
"=",
"stackTraceTimer",
".",
"start",
"(",
")",
";",
"Throwable",
"t",
"=",
"new",
"Throwable",
"(",
")",
";",
"StackTraceElement",
"[",
"]",
"stArra... | Gets the starting calling stack trace element of a given stack which
matches the given class name. Given the wrapper class name, the match
continues until the last stack trace element of the wrapper class is
matched.
@param stackClass
- The class to be matched for. Get the last matching class
down the stack
@return - StackTraceElement which denotes the calling point of given
class or wrapper class | [
"Gets",
"the",
"starting",
"calling",
"stack",
"trace",
"element",
"of",
"a",
"given",
"stack",
"which",
"matches",
"the",
"given",
"class",
"name",
".",
"Given",
"the",
"wrapper",
"class",
"name",
"the",
"match",
"continues",
"until",
"the",
"last",
"stack"... | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggingContext.java#L82-L103 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggingContext.java | LoggingContext.getLocationInfo | public LocationInfo getLocationInfo(Class wrapperClassName) {
LocationInfo locationInfo = null;
try {
if (stackLocal.get() == null) {
stackLocal.set(this.getStackTraceElement(wrapperClassName));
}
locationInfo = new LocationInfo(stackLocal.get().getFileName(),
stackLocal.get().getClassName(), stackLocal.get()
.getMethodName(), stackLocal.get().getLineNumber()
+ "");
} catch (Throwable e) {
if (CONFIGURATION
.shouldPrintLoggingErrors()) {
e.printStackTrace();
}
}
return locationInfo;
} | java | public LocationInfo getLocationInfo(Class wrapperClassName) {
LocationInfo locationInfo = null;
try {
if (stackLocal.get() == null) {
stackLocal.set(this.getStackTraceElement(wrapperClassName));
}
locationInfo = new LocationInfo(stackLocal.get().getFileName(),
stackLocal.get().getClassName(), stackLocal.get()
.getMethodName(), stackLocal.get().getLineNumber()
+ "");
} catch (Throwable e) {
if (CONFIGURATION
.shouldPrintLoggingErrors()) {
e.printStackTrace();
}
}
return locationInfo;
} | [
"public",
"LocationInfo",
"getLocationInfo",
"(",
"Class",
"wrapperClassName",
")",
"{",
"LocationInfo",
"locationInfo",
"=",
"null",
";",
"try",
"{",
"if",
"(",
"stackLocal",
".",
"get",
"(",
")",
"==",
"null",
")",
"{",
"stackLocal",
".",
"set",
"(",
"th... | Get the location information of the calling class
@param wrapperClassName
- The wrapper that indicates the caller
@return the location information | [
"Get",
"the",
"location",
"information",
"of",
"the",
"calling",
"class"
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggingContext.java#L112-L131 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/LoggingContext.java | LoggingContext.generateLocationInfo | public LocationInfo generateLocationInfo(LoggingEvent event) {
// If the event is not the same, clear the cache
if (event != loggingEvent.get()) {
loggingEvent.set(event);
clearLocationInfo();
}
LocationInfo locationInfo = null;
try {
// We should only generate location info if the caller is using NFPatternLayout otherwise this is expensive and unused.
if (isUsingNFPatternLayout(event.getLogger())) {
locationInfo = LoggingContext
.getInstance()
.getLocationInfo(Class.forName(event.getFQNOfLoggerClass()));
if (locationInfo != null) {
MDC.put(LOCATION_INFO, locationInfo);
}
}
} catch (Throwable e) {
if (CONFIGURATION !=null && CONFIGURATION
.shouldPrintLoggingErrors()) {
e.printStackTrace();
}
}
return locationInfo;
} | java | public LocationInfo generateLocationInfo(LoggingEvent event) {
// If the event is not the same, clear the cache
if (event != loggingEvent.get()) {
loggingEvent.set(event);
clearLocationInfo();
}
LocationInfo locationInfo = null;
try {
// We should only generate location info if the caller is using NFPatternLayout otherwise this is expensive and unused.
if (isUsingNFPatternLayout(event.getLogger())) {
locationInfo = LoggingContext
.getInstance()
.getLocationInfo(Class.forName(event.getFQNOfLoggerClass()));
if (locationInfo != null) {
MDC.put(LOCATION_INFO, locationInfo);
}
}
} catch (Throwable e) {
if (CONFIGURATION !=null && CONFIGURATION
.shouldPrintLoggingErrors()) {
e.printStackTrace();
}
}
return locationInfo;
} | [
"public",
"LocationInfo",
"generateLocationInfo",
"(",
"LoggingEvent",
"event",
")",
"{",
"// If the event is not the same, clear the cache",
"if",
"(",
"event",
"!=",
"loggingEvent",
".",
"get",
"(",
")",
")",
"{",
"loggingEvent",
".",
"set",
"(",
"event",
")",
"... | Generate the location information of the given logging event and cache
it.
@param event
The logging event for which the location information needs to
be determined.
@return The location info object contains information about the logger. | [
"Generate",
"the",
"location",
"information",
"of",
"the",
"given",
"logging",
"event",
"and",
"cache",
"it",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/LoggingContext.java#L155-L179 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/AsyncAppender.java | AsyncAppender.initBatcher | private void initBatcher(String appenderName) {
MessageProcessor<LoggingEvent> messageProcessor = new MessageProcessor<LoggingEvent>() {
@Override
public void process(List<LoggingEvent> objects) {
processLoggingEvents(objects);
}
};
String batcherName = this.getClass().getName() + BATCHER_NAME_LIMITER
+ appenderName;
batcher = BatcherFactory.createBatcher(batcherName, messageProcessor);
batcher.setTarget(messageProcessor);
} | java | private void initBatcher(String appenderName) {
MessageProcessor<LoggingEvent> messageProcessor = new MessageProcessor<LoggingEvent>() {
@Override
public void process(List<LoggingEvent> objects) {
processLoggingEvents(objects);
}
};
String batcherName = this.getClass().getName() + BATCHER_NAME_LIMITER
+ appenderName;
batcher = BatcherFactory.createBatcher(batcherName, messageProcessor);
batcher.setTarget(messageProcessor);
} | [
"private",
"void",
"initBatcher",
"(",
"String",
"appenderName",
")",
"{",
"MessageProcessor",
"<",
"LoggingEvent",
">",
"messageProcessor",
"=",
"new",
"MessageProcessor",
"<",
"LoggingEvent",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"process",
"(... | Initialize the batcher that stores the messages and calls the underlying
appenders.
@param appenderName
- The name of the appender for which the batcher is created | [
"Initialize",
"the",
"batcher",
"that",
"stores",
"the",
"messages",
"and",
"calls",
"the",
"underlying",
"appenders",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/AsyncAppender.java#L140-L152 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/AsyncAppender.java | AsyncAppender.processLoggingEvents | private void processLoggingEvents(List<LoggingEvent> loggingEvents) {
// Lazy initialization of the appender. This is needed because the
// original appenders configuration may be available only after the
// complete
// log4j initialization.
while (appenders.getAllAppenders() == null) {
if ((batcher == null) || (batcher.isPaused())) {
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ignore) {
}
continue;
}
org.apache.log4j.Logger asyncLogger = LoggerCache.getInstance()
.getOrCreateLogger(LOGGER_ASYNC_APPENDER);
Appender originalAppender = asyncLogger
.getAppender(originalAppenderName);
if (originalAppender == null) {
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ignore) {
}
continue;
}
appenders.addAppender(originalAppender);
}
// First take the overflown summary events and put it back in the queue
for (Iterator<Entry<String, LogSummary>> iter = logSummaryMap
.entrySet().iterator(); iter.hasNext();) {
Entry<String, LogSummary> mapEntry = (Entry<String, LogSummary>) iter
.next();
// If the space is not available, then exit immediately
if (batcher.isSpaceAvailable()) {
LogSummary logSummary = mapEntry.getValue();
LoggingEvent event = logSummary.createEvent();
// Put the event in the queue and remove the event from the summary
if (batcher.process(event)) {
iter.remove();
} else {
break;
}
} else {
break;
}
}
// Process the events from the queue and call the underlying
// appender
for (LoggingEvent event : loggingEvents) {
appenders.appendLoopOnAppenders(event);
}
} | java | private void processLoggingEvents(List<LoggingEvent> loggingEvents) {
// Lazy initialization of the appender. This is needed because the
// original appenders configuration may be available only after the
// complete
// log4j initialization.
while (appenders.getAllAppenders() == null) {
if ((batcher == null) || (batcher.isPaused())) {
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ignore) {
}
continue;
}
org.apache.log4j.Logger asyncLogger = LoggerCache.getInstance()
.getOrCreateLogger(LOGGER_ASYNC_APPENDER);
Appender originalAppender = asyncLogger
.getAppender(originalAppenderName);
if (originalAppender == null) {
try {
Thread.sleep(SLEEP_TIME_MS);
} catch (InterruptedException ignore) {
}
continue;
}
appenders.addAppender(originalAppender);
}
// First take the overflown summary events and put it back in the queue
for (Iterator<Entry<String, LogSummary>> iter = logSummaryMap
.entrySet().iterator(); iter.hasNext();) {
Entry<String, LogSummary> mapEntry = (Entry<String, LogSummary>) iter
.next();
// If the space is not available, then exit immediately
if (batcher.isSpaceAvailable()) {
LogSummary logSummary = mapEntry.getValue();
LoggingEvent event = logSummary.createEvent();
// Put the event in the queue and remove the event from the summary
if (batcher.process(event)) {
iter.remove();
} else {
break;
}
} else {
break;
}
}
// Process the events from the queue and call the underlying
// appender
for (LoggingEvent event : loggingEvents) {
appenders.appendLoopOnAppenders(event);
}
} | [
"private",
"void",
"processLoggingEvents",
"(",
"List",
"<",
"LoggingEvent",
">",
"loggingEvents",
")",
"{",
"// Lazy initialization of the appender. This is needed because the",
"// original appenders configuration may be available only after the",
"// complete",
"// log4j initializatio... | Process the logging events. This is called by the batcher.
@param loggingEvents
- The logging events to be written to the underlying appender | [
"Process",
"the",
"logging",
"events",
".",
"This",
"is",
"called",
"by",
"the",
"batcher",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/AsyncAppender.java#L160-L216 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/AsyncAppender.java | AsyncAppender.initAndRegisterCounter | private Counter initAndRegisterCounter(String name) {
BasicCounter counter = new BasicCounter(MonitorConfig.builder(name).build());
DefaultMonitorRegistry.getInstance().register(counter);
return counter;
} | java | private Counter initAndRegisterCounter(String name) {
BasicCounter counter = new BasicCounter(MonitorConfig.builder(name).build());
DefaultMonitorRegistry.getInstance().register(counter);
return counter;
} | [
"private",
"Counter",
"initAndRegisterCounter",
"(",
"String",
"name",
")",
"{",
"BasicCounter",
"counter",
"=",
"new",
"BasicCounter",
"(",
"MonitorConfig",
".",
"builder",
"(",
"name",
")",
".",
"build",
"(",
")",
")",
";",
"DefaultMonitorRegistry",
".",
"ge... | Construct a new Counter, register it, and then return it.
@param name String
@return Counter | [
"Construct",
"a",
"new",
"Counter",
"register",
"it",
"and",
"then",
"return",
"it",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/AsyncAppender.java#L330-L334 | train |
Netflix/blitz4j | src/main/java/com/netflix/blitz4j/AsyncAppender.java | AsyncAppender.putInBuffer | private boolean putInBuffer(final LoggingEvent event) {
putInBufferCounter.increment();
Stopwatch t = putBufferTimeTracer.start();
boolean hasPut = false;
if (batcher.process(event)) {
hasPut = true;
} else {
hasPut = false;
}
t.stop();
return hasPut;
} | java | private boolean putInBuffer(final LoggingEvent event) {
putInBufferCounter.increment();
Stopwatch t = putBufferTimeTracer.start();
boolean hasPut = false;
if (batcher.process(event)) {
hasPut = true;
} else {
hasPut = false;
}
t.stop();
return hasPut;
} | [
"private",
"boolean",
"putInBuffer",
"(",
"final",
"LoggingEvent",
"event",
")",
"{",
"putInBufferCounter",
".",
"increment",
"(",
")",
";",
"Stopwatch",
"t",
"=",
"putBufferTimeTracer",
".",
"start",
"(",
")",
";",
"boolean",
"hasPut",
"=",
"false",
";",
"i... | Puts the logging events to the in-memory buffer.
@param event
- The event that needs to be put in the buffer.
@return - true, if the put was successful, false otherwise | [
"Puts",
"the",
"logging",
"events",
"to",
"the",
"in",
"-",
"memory",
"buffer",
"."
] | d03aaf4ede238dc204a4420c8d333565f86fc6f2 | https://github.com/Netflix/blitz4j/blob/d03aaf4ede238dc204a4420c8d333565f86fc6f2/src/main/java/com/netflix/blitz4j/AsyncAppender.java#L359-L370 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/EstimatedHistogram.java | EstimatedHistogram.add | public void add(long n)
{
int index = Arrays.binarySearch(bucketOffsets, n);
if (index < 0)
{
// inexact match, take the first bucket higher than n
index = -index - 1;
}
// else exact match; we're good
buckets.incrementAndGet(index);
} | java | public void add(long n)
{
int index = Arrays.binarySearch(bucketOffsets, n);
if (index < 0)
{
// inexact match, take the first bucket higher than n
index = -index - 1;
}
// else exact match; we're good
buckets.incrementAndGet(index);
} | [
"public",
"void",
"add",
"(",
"long",
"n",
")",
"{",
"int",
"index",
"=",
"Arrays",
".",
"binarySearch",
"(",
"bucketOffsets",
",",
"n",
")",
";",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"// inexact match, take the first bucket higher than n",
"index",
"=",
... | Increments the count of the bucket closest to n, rounding UP.
@param n | [
"Increments",
"the",
"count",
"of",
"the",
"bucket",
"closest",
"to",
"n",
"rounding",
"UP",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/EstimatedHistogram.java#L89-L99 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java | ConnectionPoolImpl.getConnectionForOperation | public <R> Connection<CL> getConnectionForOperation(BaseOperation<CL, R> baseOperation) {
return selectionStrategy.getConnection(baseOperation, cpConfiguration.getMaxTimeoutWhenExhausted(),
TimeUnit.MILLISECONDS);
} | java | public <R> Connection<CL> getConnectionForOperation(BaseOperation<CL, R> baseOperation) {
return selectionStrategy.getConnection(baseOperation, cpConfiguration.getMaxTimeoutWhenExhausted(),
TimeUnit.MILLISECONDS);
} | [
"public",
"<",
"R",
">",
"Connection",
"<",
"CL",
">",
"getConnectionForOperation",
"(",
"BaseOperation",
"<",
"CL",
",",
"R",
">",
"baseOperation",
")",
"{",
"return",
"selectionStrategy",
".",
"getConnection",
"(",
"baseOperation",
",",
"cpConfiguration",
".",... | Use with EXTREME CAUTION. Connection that is borrowed must be returned,
else we will have connection pool exhaustion
@param baseOperation
@return | [
"Use",
"with",
"EXTREME",
"CAUTION",
".",
"Connection",
"that",
"is",
"borrowed",
"must",
"be",
"returned",
"else",
"we",
"will",
"have",
"connection",
"pool",
"exhaustion"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/ConnectionPoolImpl.java#L454-L457 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/HostSelectionWithFallback.java | HostSelectionWithFallback.getConnectionForTokenOnRackNoFallback | private Connection<CL> getConnectionForTokenOnRackNoFallback(BaseOperation<CL, ?> op, Long token, String rack, int duration, TimeUnit unit, RetryPolicy retry)
throws NoAvailableHostsException, PoolExhaustedException, PoolTimeoutException, PoolOfflineException {
DynoConnectException lastEx = null;
// find the selector for that rack,
HostSelectionStrategy<CL> selector = findSelectorForRack(rack);
// get the host using that selector
HostConnectionPool<CL> hostPool = selector.getPoolForToken(token);
if (hostPool != null) {
try {
// Note that if a PoolExhaustedException is thrown it is caught by the calling
// ConnectionPoolImpl#executeXXX() method
return hostPool.borrowConnection(duration, unit);
} catch (PoolTimeoutException pte) {
lastEx = pte;
cpMonitor.incOperationFailure(null, pte);
}
}
if (lastEx == null) {
throw new PoolOfflineException(hostPool == null ? null : hostPool.getHost(), "host pool is offline and we are forcing no fallback");
} else {
throw lastEx;
}
} | java | private Connection<CL> getConnectionForTokenOnRackNoFallback(BaseOperation<CL, ?> op, Long token, String rack, int duration, TimeUnit unit, RetryPolicy retry)
throws NoAvailableHostsException, PoolExhaustedException, PoolTimeoutException, PoolOfflineException {
DynoConnectException lastEx = null;
// find the selector for that rack,
HostSelectionStrategy<CL> selector = findSelectorForRack(rack);
// get the host using that selector
HostConnectionPool<CL> hostPool = selector.getPoolForToken(token);
if (hostPool != null) {
try {
// Note that if a PoolExhaustedException is thrown it is caught by the calling
// ConnectionPoolImpl#executeXXX() method
return hostPool.borrowConnection(duration, unit);
} catch (PoolTimeoutException pte) {
lastEx = pte;
cpMonitor.incOperationFailure(null, pte);
}
}
if (lastEx == null) {
throw new PoolOfflineException(hostPool == null ? null : hostPool.getHost(), "host pool is offline and we are forcing no fallback");
} else {
throw lastEx;
}
} | [
"private",
"Connection",
"<",
"CL",
">",
"getConnectionForTokenOnRackNoFallback",
"(",
"BaseOperation",
"<",
"CL",
",",
"?",
">",
"op",
",",
"Long",
"token",
",",
"String",
"rack",
",",
"int",
"duration",
",",
"TimeUnit",
"unit",
",",
"RetryPolicy",
"retry",
... | Should be called when a connection is required on that particular zone with no fall backs what so ever | [
"Should",
"be",
"called",
"when",
"a",
"connection",
"is",
"required",
"on",
"that",
"particular",
"zone",
"with",
"no",
"fall",
"backs",
"what",
"so",
"ever"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/HostSelectionWithFallback.java#L159-L184 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/HostSelectionWithFallback.java | HostSelectionWithFallback.initWithHosts | public void initWithHosts(Map<Host, HostConnectionPool<CL>> hPools) {
// Get the list of tokens for these hosts
//tokenSupplier.initWithHosts(hPools.keySet());
List<HostToken> allHostTokens = tokenSupplier.getTokens(hPools.keySet());
Map<HostToken, HostConnectionPool<CL>> tokenPoolMap = new HashMap<HostToken, HostConnectionPool<CL>>();
// Update inner state with the host tokens.
for (HostToken hToken : allHostTokens) {
hostTokens.put(hToken.getHost(), hToken);
tokenPoolMap.put(hToken, hPools.get(hToken.getHost()));
}
// Initialize Local selector
Map<HostToken, HostConnectionPool<CL>> localPools = getHostPoolsForRack(tokenPoolMap, localRack);
localSelector.initWithHosts(localPools);
if (localSelector.isTokenAware() && localRack != null) {
replicationFactor.set(calculateReplicationFactor(allHostTokens));
}
// Initialize Remote selectors
Set<String> remoteRacks = new HashSet<String>();
for (Host host : hPools.keySet()) {
String rack = host.getRack();
if (localRack != null && !localRack.isEmpty() && rack != null && !rack.isEmpty() && !localRack.equals(rack)) {
remoteRacks.add(rack);
}
}
for (String rack : remoteRacks) {
Map<HostToken, HostConnectionPool<CL>> dcPools = getHostPoolsForRack(tokenPoolMap, rack);
HostSelectionStrategy<CL> remoteSelector = selectorFactory.vendPoolSelectionStrategy();
remoteSelector.initWithHosts(dcPools);
remoteRackSelectors.put(rack, remoteSelector);
}
remoteDCNames.swapWithList(remoteRackSelectors.keySet());
topology.set(createTokenPoolTopology(allHostTokens));
} | java | public void initWithHosts(Map<Host, HostConnectionPool<CL>> hPools) {
// Get the list of tokens for these hosts
//tokenSupplier.initWithHosts(hPools.keySet());
List<HostToken> allHostTokens = tokenSupplier.getTokens(hPools.keySet());
Map<HostToken, HostConnectionPool<CL>> tokenPoolMap = new HashMap<HostToken, HostConnectionPool<CL>>();
// Update inner state with the host tokens.
for (HostToken hToken : allHostTokens) {
hostTokens.put(hToken.getHost(), hToken);
tokenPoolMap.put(hToken, hPools.get(hToken.getHost()));
}
// Initialize Local selector
Map<HostToken, HostConnectionPool<CL>> localPools = getHostPoolsForRack(tokenPoolMap, localRack);
localSelector.initWithHosts(localPools);
if (localSelector.isTokenAware() && localRack != null) {
replicationFactor.set(calculateReplicationFactor(allHostTokens));
}
// Initialize Remote selectors
Set<String> remoteRacks = new HashSet<String>();
for (Host host : hPools.keySet()) {
String rack = host.getRack();
if (localRack != null && !localRack.isEmpty() && rack != null && !rack.isEmpty() && !localRack.equals(rack)) {
remoteRacks.add(rack);
}
}
for (String rack : remoteRacks) {
Map<HostToken, HostConnectionPool<CL>> dcPools = getHostPoolsForRack(tokenPoolMap, rack);
HostSelectionStrategy<CL> remoteSelector = selectorFactory.vendPoolSelectionStrategy();
remoteSelector.initWithHosts(dcPools);
remoteRackSelectors.put(rack, remoteSelector);
}
remoteDCNames.swapWithList(remoteRackSelectors.keySet());
topology.set(createTokenPoolTopology(allHostTokens));
} | [
"public",
"void",
"initWithHosts",
"(",
"Map",
"<",
"Host",
",",
"HostConnectionPool",
"<",
"CL",
">",
">",
"hPools",
")",
"{",
"// Get the list of tokens for these hosts",
"//tokenSupplier.initWithHosts(hPools.keySet());",
"List",
"<",
"HostToken",
">",
"allHostTokens",
... | hPools comes from discovery.
@param hPools | [
"hPools",
"comes",
"from",
"discovery",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/HostSelectionWithFallback.java#L345-L384 | train |
Netflix/dyno | dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java | DynoJedisPipeline.checkKey | private void checkKey(final byte[] key) {
if (theBinaryKey.get() != null) {
verifyKey(key);
} else {
boolean success = theBinaryKey.compareAndSet(null, key);
if (!success) {
// someone already beat us to it. that's fine, just verify
// that the key is the same
verifyKey(key);
} else {
pipelined(key);
}
}
} | java | private void checkKey(final byte[] key) {
if (theBinaryKey.get() != null) {
verifyKey(key);
} else {
boolean success = theBinaryKey.compareAndSet(null, key);
if (!success) {
// someone already beat us to it. that's fine, just verify
// that the key is the same
verifyKey(key);
} else {
pipelined(key);
}
}
} | [
"private",
"void",
"checkKey",
"(",
"final",
"byte",
"[",
"]",
"key",
")",
"{",
"if",
"(",
"theBinaryKey",
".",
"get",
"(",
")",
"!=",
"null",
")",
"{",
"verifyKey",
"(",
"key",
")",
";",
"}",
"else",
"{",
"boolean",
"success",
"=",
"theBinaryKey",
... | Checks that a pipeline is associated with a single key. Binary keys do not
support hashtags.
@param key | [
"Checks",
"that",
"a",
"pipeline",
"is",
"associated",
"with",
"a",
"single",
"key",
".",
"Binary",
"keys",
"do",
"not",
"support",
"hashtags",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java#L175-L188 | train |
Netflix/dyno | dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java | DynoJedisPipeline.checkKey | private void checkKey(final String key) {
/*
* Get hashtag from the first host of the active pool We cannot use the
* connection object because as of now we have not selected a connection. A
* connection is selected based on the key or hashtag respectively.
*/
String hashtag = connPool.getConfiguration().getHashtag();
if (hashtag == null || hashtag.isEmpty()) {
if (theKey.get() != null) {
verifyKey(key);
} else {
boolean success = theKey.compareAndSet(null, key);
if (!success) {
// someone already beat us to it. that's fine, just verify
// that the key is the same
verifyKey(key);
} else {
pipelined(key);
}
}
} else {
/*
* We have a identified a hashtag in the Host object. That means Dynomite has a
* defined hashtag. Producing the hashvalue out of the hashtag and using that as
* a reference to the pipeline
*/
String hashValue = StringUtils.substringBetween(key, Character.toString(hashtag.charAt(0)),
Character.toString(hashtag.charAt(1)));
if (Strings.isNullOrEmpty(hashValue)) {
hashValue = key;
}
checkHashtag(key, hashValue);
}
} | java | private void checkKey(final String key) {
/*
* Get hashtag from the first host of the active pool We cannot use the
* connection object because as of now we have not selected a connection. A
* connection is selected based on the key or hashtag respectively.
*/
String hashtag = connPool.getConfiguration().getHashtag();
if (hashtag == null || hashtag.isEmpty()) {
if (theKey.get() != null) {
verifyKey(key);
} else {
boolean success = theKey.compareAndSet(null, key);
if (!success) {
// someone already beat us to it. that's fine, just verify
// that the key is the same
verifyKey(key);
} else {
pipelined(key);
}
}
} else {
/*
* We have a identified a hashtag in the Host object. That means Dynomite has a
* defined hashtag. Producing the hashvalue out of the hashtag and using that as
* a reference to the pipeline
*/
String hashValue = StringUtils.substringBetween(key, Character.toString(hashtag.charAt(0)),
Character.toString(hashtag.charAt(1)));
if (Strings.isNullOrEmpty(hashValue)) {
hashValue = key;
}
checkHashtag(key, hashValue);
}
} | [
"private",
"void",
"checkKey",
"(",
"final",
"String",
"key",
")",
"{",
"/*\n\t\t * Get hashtag from the first host of the active pool We cannot use the\n\t\t * connection object because as of now we have not selected a connection. A\n\t\t * connection is selected based on the key or hashtag respe... | Checks that a pipeline is associated with a single key. If there is a hashtag
defined in the first host of the connectionpool then we check that first.
@param key | [
"Checks",
"that",
"a",
"pipeline",
"is",
"associated",
"with",
"a",
"single",
"key",
".",
"If",
"there",
"is",
"a",
"hashtag",
"defined",
"in",
"the",
"first",
"host",
"of",
"the",
"connectionpool",
"then",
"we",
"check",
"that",
"first",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java#L196-L230 | train |
Netflix/dyno | dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java | DynoJedisPipeline.verifyKey | private void verifyKey(final String key) {
if (!theKey.get().equals(key)) {
try {
throw new RuntimeException("Must have same key for Redis Pipeline in Dynomite. This key: " + key);
} finally {
discardPipelineAndReleaseConnection();
}
}
} | java | private void verifyKey(final String key) {
if (!theKey.get().equals(key)) {
try {
throw new RuntimeException("Must have same key for Redis Pipeline in Dynomite. This key: " + key);
} finally {
discardPipelineAndReleaseConnection();
}
}
} | [
"private",
"void",
"verifyKey",
"(",
"final",
"String",
"key",
")",
"{",
"if",
"(",
"!",
"theKey",
".",
"get",
"(",
")",
".",
"equals",
"(",
"key",
")",
")",
"{",
"try",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Must have same key for Redis Pipeline... | Verifies key with pipeline key | [
"Verifies",
"key",
"with",
"pipeline",
"key"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-jedis/src/main/java/com/netflix/dyno/jedis/DynoJedisPipeline.java#L248-L257 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java | Murmur2Hash.hash32 | public static int hash32(final byte[] data, int length, int seed) {
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
final int m = 0x5bd1e995;
final int r = 24;
// Initialize the hash to a random value
int h = seed^length;
int length4 = length/4;
for (int i=0; i<length4; i++) {
final int i4 = i*4;
int k = (data[i4+0]&0xff) +((data[i4+1]&0xff)<<8)
+((data[i4+2]&0xff)<<16) +((data[i4+3]&0xff)<<24);
k *= m;
k ^= k >>> r;
k *= m;
h *= m;
h ^= k;
}
// Handle the last few bytes of the input array
switch (length%4) {
case 3: h ^= (data[(length&~3) +2]&0xff) << 16;
case 2: h ^= (data[(length&~3) +1]&0xff) << 8;
case 1: h ^= (data[length&~3]&0xff);
h *= m;
}
h ^= h >>> 13;
h *= m;
h ^= h >>> 15;
return h;
} | java | public static int hash32(final byte[] data, int length, int seed) {
// 'm' and 'r' are mixing constants generated offline.
// They're not really 'magic', they just happen to work well.
final int m = 0x5bd1e995;
final int r = 24;
// Initialize the hash to a random value
int h = seed^length;
int length4 = length/4;
for (int i=0; i<length4; i++) {
final int i4 = i*4;
int k = (data[i4+0]&0xff) +((data[i4+1]&0xff)<<8)
+((data[i4+2]&0xff)<<16) +((data[i4+3]&0xff)<<24);
k *= m;
k ^= k >>> r;
k *= m;
h *= m;
h ^= k;
}
// Handle the last few bytes of the input array
switch (length%4) {
case 3: h ^= (data[(length&~3) +2]&0xff) << 16;
case 2: h ^= (data[(length&~3) +1]&0xff) << 8;
case 1: h ^= (data[length&~3]&0xff);
h *= m;
}
h ^= h >>> 13;
h *= m;
h ^= h >>> 15;
return h;
} | [
"public",
"static",
"int",
"hash32",
"(",
"final",
"byte",
"[",
"]",
"data",
",",
"int",
"length",
",",
"int",
"seed",
")",
"{",
"// 'm' and 'r' are mixing constants generated offline.",
"// They're not really 'magic', they just happen to work well.",
"final",
"int",
"m",... | Generates 32 bit hash from byte array of the given length and
seed.
@param data byte array to hash
@param length length of the array to hash
@param seed initial seed value
@return 32 bit hash of the given array | [
"Generates",
"32",
"bit",
"hash",
"from",
"byte",
"array",
"of",
"the",
"given",
"length",
"and",
"seed",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java#L48-L82 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java | Murmur2Hash.hash32 | public static int hash32(final String text) {
final byte[] bytes = text.getBytes();
return hash32(bytes, bytes.length);
} | java | public static int hash32(final String text) {
final byte[] bytes = text.getBytes();
return hash32(bytes, bytes.length);
} | [
"public",
"static",
"int",
"hash32",
"(",
"final",
"String",
"text",
")",
"{",
"final",
"byte",
"[",
"]",
"bytes",
"=",
"text",
".",
"getBytes",
"(",
")",
";",
"return",
"hash32",
"(",
"bytes",
",",
"bytes",
".",
"length",
")",
";",
"}"
] | Generates 32 bit hash from a string.
@param text string to hash
@return 32 bit hash of the given string | [
"Generates",
"32",
"bit",
"hash",
"from",
"a",
"string",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java#L101-L104 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java | Murmur2Hash.hash32 | public static int hash32(final String text, int from, int length) {
return hash32(text.substring( from, from+length));
} | java | public static int hash32(final String text, int from, int length) {
return hash32(text.substring( from, from+length));
} | [
"public",
"static",
"int",
"hash32",
"(",
"final",
"String",
"text",
",",
"int",
"from",
",",
"int",
"length",
")",
"{",
"return",
"hash32",
"(",
"text",
".",
"substring",
"(",
"from",
",",
"from",
"+",
"length",
")",
")",
";",
"}"
] | Generates 32 bit hash from a substring.
@param text string to hash
@param from starting index
@param length length of the substring to hash
@return 32 bit hash of the given string | [
"Generates",
"32",
"bit",
"hash",
"from",
"a",
"substring",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java#L114-L116 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java | Murmur2Hash.hash64 | public static long hash64(final String text) {
final byte[] bytes = text.getBytes();
return hash64(bytes, bytes.length);
} | java | public static long hash64(final String text) {
final byte[] bytes = text.getBytes();
return hash64(bytes, bytes.length);
} | [
"public",
"static",
"long",
"hash64",
"(",
"final",
"String",
"text",
")",
"{",
"final",
"byte",
"[",
"]",
"bytes",
"=",
"text",
".",
"getBytes",
"(",
")",
";",
"return",
"hash64",
"(",
"bytes",
",",
"bytes",
".",
"length",
")",
";",
"}"
] | Generates 64 bit hash from a string.
@param text string to hash
@return 64 bit hash of the given string | [
"Generates",
"64",
"bit",
"hash",
"from",
"a",
"string",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java#L184-L187 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java | Murmur2Hash.hash64 | public static long hash64(final String text, int from, int length) {
return hash64(text.substring( from, from+length));
} | java | public static long hash64(final String text, int from, int length) {
return hash64(text.substring( from, from+length));
} | [
"public",
"static",
"long",
"hash64",
"(",
"final",
"String",
"text",
",",
"int",
"from",
",",
"int",
"length",
")",
"{",
"return",
"hash64",
"(",
"text",
".",
"substring",
"(",
"from",
",",
"from",
"+",
"length",
")",
")",
";",
"}"
] | Generates 64 bit hash from a substring.
@param text string to hash
@param from starting index
@param length length of the substring to hash
@return 64 bit hash of the given array | [
"Generates",
"64",
"bit",
"hash",
"from",
"a",
"substring",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur2Hash.java#L197-L199 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java | ZipUtils.compressBytesNonBase64 | public static byte[] compressBytesNonBase64(byte[] value) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(value.length);
try (GZIPOutputStream gos = new GZIPOutputStream(baos)) {
gos.write(value);
}
byte[] compressed = baos.toByteArray();
baos.close();
return compressed;
} | java | public static byte[] compressBytesNonBase64(byte[] value) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(value.length);
try (GZIPOutputStream gos = new GZIPOutputStream(baos)) {
gos.write(value);
}
byte[] compressed = baos.toByteArray();
baos.close();
return compressed;
} | [
"public",
"static",
"byte",
"[",
"]",
"compressBytesNonBase64",
"(",
"byte",
"[",
"]",
"value",
")",
"throws",
"IOException",
"{",
"ByteArrayOutputStream",
"baos",
"=",
"new",
"ByteArrayOutputStream",
"(",
"value",
".",
"length",
")",
";",
"try",
"(",
"GZIPOut... | Encodes the given byte array and then GZIP compresses it.
@param value byte array input
@return compressed byte array output
@throws IOException | [
"Encodes",
"the",
"given",
"byte",
"array",
"and",
"then",
"GZIP",
"compresses",
"it",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java#L59-L67 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java | ZipUtils.decompressBytesNonBase64 | public static byte[] decompressBytesNonBase64(byte[] compressed) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(compressed);
try (InputStream gis = new GZIPInputStream(is)) {
return IOUtils.toByteArray(gis);
}
} | java | public static byte[] decompressBytesNonBase64(byte[] compressed) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(compressed);
try (InputStream gis = new GZIPInputStream(is)) {
return IOUtils.toByteArray(gis);
}
} | [
"public",
"static",
"byte",
"[",
"]",
"decompressBytesNonBase64",
"(",
"byte",
"[",
"]",
"compressed",
")",
"throws",
"IOException",
"{",
"ByteArrayInputStream",
"is",
"=",
"new",
"ByteArrayInputStream",
"(",
"compressed",
")",
";",
"try",
"(",
"InputStream",
"g... | Decompresses the given byte array without transforming it into a String
@param compressed byte array input
@return decompressed data in a byte array
@throws IOException | [
"Decompresses",
"the",
"given",
"byte",
"array",
"without",
"transforming",
"it",
"into",
"a",
"String"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java#L76-L81 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java | ZipUtils.decompressStringNonBase64 | public static String decompressStringNonBase64(byte[] compressed) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(compressed);
try (InputStream gis = new GZIPInputStream(is)) {
return new String(IOUtils.toByteArray(gis), StandardCharsets.UTF_8);
}
} | java | public static String decompressStringNonBase64(byte[] compressed) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(compressed);
try (InputStream gis = new GZIPInputStream(is)) {
return new String(IOUtils.toByteArray(gis), StandardCharsets.UTF_8);
}
} | [
"public",
"static",
"String",
"decompressStringNonBase64",
"(",
"byte",
"[",
"]",
"compressed",
")",
"throws",
"IOException",
"{",
"ByteArrayInputStream",
"is",
"=",
"new",
"ByteArrayInputStream",
"(",
"compressed",
")",
";",
"try",
"(",
"InputStream",
"gis",
"=",... | Decompresses the given byte array
@param compressed byte array input
@return decompressed data in string format
@throws IOException | [
"Decompresses",
"the",
"given",
"byte",
"array"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java#L90-L95 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java | ZipUtils.compressStringToBase64String | public static String compressStringToBase64String(String value) throws IOException {
return new String(Base64.encode(compressString(value)), StandardCharsets.UTF_8);
} | java | public static String compressStringToBase64String(String value) throws IOException {
return new String(Base64.encode(compressString(value)), StandardCharsets.UTF_8);
} | [
"public",
"static",
"String",
"compressStringToBase64String",
"(",
"String",
"value",
")",
"throws",
"IOException",
"{",
"return",
"new",
"String",
"(",
"Base64",
".",
"encode",
"(",
"compressString",
"(",
"value",
")",
")",
",",
"StandardCharsets",
".",
"UTF_8"... | Encodes the given string with Base64 encoding and then GZIP compresses it. Returns
result as a Base64 encoded string.
@param value input String
@return Base64 encoded compressed String
@throws IOException | [
"Encodes",
"the",
"given",
"string",
"with",
"Base64",
"encoding",
"and",
"then",
"GZIP",
"compresses",
"it",
".",
"Returns",
"result",
"as",
"a",
"Base64",
"encoded",
"string",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java#L105-L107 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java | ZipUtils.decompressString | public static String decompressString(byte[] compressed) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(compressed);
try (InputStream gis = new GZIPInputStream(is)) {
return new String(Base64.decode(IOUtils.toByteArray(gis)), StandardCharsets.UTF_8);
}
} | java | public static String decompressString(byte[] compressed) throws IOException {
ByteArrayInputStream is = new ByteArrayInputStream(compressed);
try (InputStream gis = new GZIPInputStream(is)) {
return new String(Base64.decode(IOUtils.toByteArray(gis)), StandardCharsets.UTF_8);
}
} | [
"public",
"static",
"String",
"decompressString",
"(",
"byte",
"[",
"]",
"compressed",
")",
"throws",
"IOException",
"{",
"ByteArrayInputStream",
"is",
"=",
"new",
"ByteArrayInputStream",
"(",
"compressed",
")",
";",
"try",
"(",
"InputStream",
"gis",
"=",
"new",... | Decompresses the given byte array and decodes with Base64 decoding
@param compressed byte array input
@return decompressed data in string format
@throws IOException | [
"Decompresses",
"the",
"given",
"byte",
"array",
"and",
"decodes",
"with",
"Base64",
"decoding"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java#L116-L121 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java | ZipUtils.decompressFromBase64String | public static String decompressFromBase64String(String compressed) throws IOException {
return decompressString(Base64.decode(compressed.getBytes(StandardCharsets.UTF_8)));
} | java | public static String decompressFromBase64String(String compressed) throws IOException {
return decompressString(Base64.decode(compressed.getBytes(StandardCharsets.UTF_8)));
} | [
"public",
"static",
"String",
"decompressFromBase64String",
"(",
"String",
"compressed",
")",
"throws",
"IOException",
"{",
"return",
"decompressString",
"(",
"Base64",
".",
"decode",
"(",
"compressed",
".",
"getBytes",
"(",
"StandardCharsets",
".",
"UTF_8",
")",
... | Given a Base64 encoded String, decompresses it.
@param compressed Compressed String
@return decompressed String
@throws IOException | [
"Given",
"a",
"Base64",
"encoded",
"String",
"decompresses",
"it",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java#L130-L132 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java | ZipUtils.isCompressed | public static boolean isCompressed(byte[] bytes) throws IOException {
return bytes != null && bytes.length >= 2 &&
bytes[0] == (byte) (GZIPInputStream.GZIP_MAGIC) && bytes[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8);
} | java | public static boolean isCompressed(byte[] bytes) throws IOException {
return bytes != null && bytes.length >= 2 &&
bytes[0] == (byte) (GZIPInputStream.GZIP_MAGIC) && bytes[1] == (byte) (GZIPInputStream.GZIP_MAGIC >> 8);
} | [
"public",
"static",
"boolean",
"isCompressed",
"(",
"byte",
"[",
"]",
"bytes",
")",
"throws",
"IOException",
"{",
"return",
"bytes",
"!=",
"null",
"&&",
"bytes",
".",
"length",
">=",
"2",
"&&",
"bytes",
"[",
"0",
"]",
"==",
"(",
"byte",
")",
"(",
"GZ... | Determines if a byte array is compressed. The java.util.zip GZip
implementation does not expose the GZip header so it is difficult to determine
if a string is compressed.
@param bytes an array of bytes
@return true if the array is compressed or false otherwise
@throws java.io.IOException if the byte array couldn't be read | [
"Determines",
"if",
"a",
"byte",
"array",
"is",
"compressed",
".",
"The",
"java",
".",
"util",
".",
"zip",
"GZip",
"implementation",
"does",
"not",
"expose",
"the",
"GZip",
"header",
"so",
"it",
"is",
"difficult",
"to",
"determine",
"if",
"a",
"string",
... | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java#L143-L146 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java | ZipUtils.isCompressed | public static boolean isCompressed(InputStream inputStream) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] data = new byte[2];
int nRead = inputStream.read(data, 0, 2);
buffer.write(data, 0, nRead);
buffer.flush();
return isCompressed(buffer.toByteArray());
} | java | public static boolean isCompressed(InputStream inputStream) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] data = new byte[2];
int nRead = inputStream.read(data, 0, 2);
buffer.write(data, 0, nRead);
buffer.flush();
return isCompressed(buffer.toByteArray());
} | [
"public",
"static",
"boolean",
"isCompressed",
"(",
"InputStream",
"inputStream",
")",
"throws",
"IOException",
"{",
"ByteArrayOutputStream",
"buffer",
"=",
"new",
"ByteArrayOutputStream",
"(",
")",
";",
"byte",
"[",
"]",
"data",
"=",
"new",
"byte",
"[",
"2",
... | Determines if an InputStream is compressed. The java.util.zip GZip
implementation does not expose the GZip header so it is difficult to determine
if a string is compressed.
@param inputStream an array of bytes
@return true if the stream is compressed or false otherwise
@throws java.io.IOException if the byte array couldn't be read | [
"Determines",
"if",
"an",
"InputStream",
"is",
"compressed",
".",
"The",
"java",
".",
"util",
".",
"zip",
"GZip",
"implementation",
"does",
"not",
"expose",
"the",
"GZip",
"header",
"so",
"it",
"is",
"difficult",
"to",
"determine",
"if",
"a",
"string",
"is... | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/utils/ZipUtils.java#L157-L167 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostStatusTracker.java | HostStatusTracker.inactiveSetChanged | public boolean inactiveSetChanged(Collection<Host> hostsUp, Collection<Host> hostsDown) {
boolean newInactiveHostsFound = false;
// Check for condition 1.
for (Host hostDown : hostsDown) {
if (activeHosts.contains(hostDown)) {
newInactiveHostsFound = true;
break;
}
}
// Check for condition 2.
Set<Host> prevActiveHosts = new HashSet<Host>(activeHosts);
prevActiveHosts.removeAll(hostsUp);
newInactiveHostsFound = !prevActiveHosts.isEmpty();
return newInactiveHostsFound;
} | java | public boolean inactiveSetChanged(Collection<Host> hostsUp, Collection<Host> hostsDown) {
boolean newInactiveHostsFound = false;
// Check for condition 1.
for (Host hostDown : hostsDown) {
if (activeHosts.contains(hostDown)) {
newInactiveHostsFound = true;
break;
}
}
// Check for condition 2.
Set<Host> prevActiveHosts = new HashSet<Host>(activeHosts);
prevActiveHosts.removeAll(hostsUp);
newInactiveHostsFound = !prevActiveHosts.isEmpty();
return newInactiveHostsFound;
} | [
"public",
"boolean",
"inactiveSetChanged",
"(",
"Collection",
"<",
"Host",
">",
"hostsUp",
",",
"Collection",
"<",
"Host",
">",
"hostsDown",
")",
"{",
"boolean",
"newInactiveHostsFound",
"=",
"false",
";",
"// Check for condition 1. ",
"for",
"(",
"Host",
"hostDow... | This check is more involved than the active set check. Here we 2 conditions to check for
1. We could have new hosts that were in the active set and have shown up in the inactive set.
2. We can also have the case where hosts from the active set have disappeared and also not in the provided inactive set.
This is where we have simply forgotten about some active host and that it needs to be shutdown
@param hostsUp
@param hostsDown
@return true/false indicating whether we have a host that has been shutdown | [
"This",
"check",
"is",
"more",
"involved",
"than",
"the",
"active",
"set",
"check",
".",
"Here",
"we",
"2",
"conditions",
"to",
"check",
"for"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostStatusTracker.java#L103-L122 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostStatusTracker.java | HostStatusTracker.computeNewHostStatus | public HostStatusTracker computeNewHostStatus(Collection<Host> hostsUp, Collection<Host> hostsDown) {
verifyMutuallyExclusive(hostsUp, hostsDown);
Set<Host> nextActiveHosts = new HashSet<Host>(hostsUp);
// Get the hosts that are currently down
Set<Host> nextInactiveHosts = new HashSet<Host>(hostsDown);
// add any previous hosts that were currently down iff they are still reported by the HostSupplier
Set<Host> union = new HashSet<>(hostsUp);
union.addAll(hostsDown);
if (!union.containsAll(inactiveHosts)) {
logger.info("REMOVING at least one inactive host from {} b/c it is no longer reported by HostSupplier",
inactiveHosts);
inactiveHosts.retainAll(union);
}
nextInactiveHosts.addAll(inactiveHosts);
// Now remove from the total set of inactive hosts any host that is currently up.
// This typically happens when a host moves from the inactive state to the active state.
// And hence it will be there in the prev inactive set, and will also be there in the new active set
// for this round.
for (Host host : nextActiveHosts) {
nextInactiveHosts.remove(host);
}
// Now add any host that is not in the new active hosts set and that was in the previous active set
Set<Host> prevActiveHosts = new HashSet<Host>(activeHosts);
prevActiveHosts.removeAll(hostsUp);
// If anyone is remaining in the prev set then add it to the inactive set, since it has gone away
nextInactiveHosts.addAll(prevActiveHosts);
for (Host host : nextActiveHosts) {
host.setStatus(Status.Up);
}
for (Host host : nextInactiveHosts) {
host.setStatus(Status.Down);
}
return new HostStatusTracker(nextActiveHosts, nextInactiveHosts);
} | java | public HostStatusTracker computeNewHostStatus(Collection<Host> hostsUp, Collection<Host> hostsDown) {
verifyMutuallyExclusive(hostsUp, hostsDown);
Set<Host> nextActiveHosts = new HashSet<Host>(hostsUp);
// Get the hosts that are currently down
Set<Host> nextInactiveHosts = new HashSet<Host>(hostsDown);
// add any previous hosts that were currently down iff they are still reported by the HostSupplier
Set<Host> union = new HashSet<>(hostsUp);
union.addAll(hostsDown);
if (!union.containsAll(inactiveHosts)) {
logger.info("REMOVING at least one inactive host from {} b/c it is no longer reported by HostSupplier",
inactiveHosts);
inactiveHosts.retainAll(union);
}
nextInactiveHosts.addAll(inactiveHosts);
// Now remove from the total set of inactive hosts any host that is currently up.
// This typically happens when a host moves from the inactive state to the active state.
// And hence it will be there in the prev inactive set, and will also be there in the new active set
// for this round.
for (Host host : nextActiveHosts) {
nextInactiveHosts.remove(host);
}
// Now add any host that is not in the new active hosts set and that was in the previous active set
Set<Host> prevActiveHosts = new HashSet<Host>(activeHosts);
prevActiveHosts.removeAll(hostsUp);
// If anyone is remaining in the prev set then add it to the inactive set, since it has gone away
nextInactiveHosts.addAll(prevActiveHosts);
for (Host host : nextActiveHosts) {
host.setStatus(Status.Up);
}
for (Host host : nextInactiveHosts) {
host.setStatus(Status.Down);
}
return new HostStatusTracker(nextActiveHosts, nextInactiveHosts);
} | [
"public",
"HostStatusTracker",
"computeNewHostStatus",
"(",
"Collection",
"<",
"Host",
">",
"hostsUp",
",",
"Collection",
"<",
"Host",
">",
"hostsDown",
")",
"{",
"verifyMutuallyExclusive",
"(",
"hostsUp",
",",
"hostsDown",
")",
";",
"Set",
"<",
"Host",
">",
"... | Helper method that actually changes the state of the class to reflect the new set of hosts up and down
Note that the new HostStatusTracker is returned that holds onto the new state. Calling classes must update their
references to use the new HostStatusTracker
@param hostsUp
@param hostsDown
@return | [
"Helper",
"method",
"that",
"actually",
"changes",
"the",
"state",
"of",
"the",
"class",
"to",
"reflect",
"the",
"new",
"set",
"of",
"hosts",
"up",
"and",
"down",
"Note",
"that",
"the",
"new",
"HostStatusTracker",
"is",
"returned",
"that",
"holds",
"onto",
... | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/HostStatusTracker.java#L154-L195 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java | CircularList.swapWithList | public void swapWithList(Collection<T> newList) {
InnerList newInnerList = new InnerList(newList);
ref.set(newInnerList);
} | java | public void swapWithList(Collection<T> newList) {
InnerList newInnerList = new InnerList(newList);
ref.set(newInnerList);
} | [
"public",
"void",
"swapWithList",
"(",
"Collection",
"<",
"T",
">",
"newList",
")",
"{",
"InnerList",
"newInnerList",
"=",
"new",
"InnerList",
"(",
"newList",
")",
";",
"ref",
".",
"set",
"(",
"newInnerList",
")",
";",
"}"
] | Swap the entire inner list with a new list
@param newList | [
"Swap",
"the",
"entire",
"inner",
"list",
"with",
"a",
"new",
"list"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java#L61-L64 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java | CircularList.addElement | public synchronized void addElement(T element) {
List<T> origList = ref.get().list;
boolean isPresent = origList.contains(element);
if (isPresent) {
return;
}
List<T> newList = new ArrayList<T>(origList);
newList.add(element);
swapWithList(newList);
} | java | public synchronized void addElement(T element) {
List<T> origList = ref.get().list;
boolean isPresent = origList.contains(element);
if (isPresent) {
return;
}
List<T> newList = new ArrayList<T>(origList);
newList.add(element);
swapWithList(newList);
} | [
"public",
"synchronized",
"void",
"addElement",
"(",
"T",
"element",
")",
"{",
"List",
"<",
"T",
">",
"origList",
"=",
"ref",
".",
"get",
"(",
")",
".",
"list",
";",
"boolean",
"isPresent",
"=",
"origList",
".",
"contains",
"(",
"element",
")",
";",
... | Add an element to the list. This causes the inner list to be swapped out
@param element | [
"Add",
"an",
"element",
"to",
"the",
"list",
".",
"This",
"causes",
"the",
"inner",
"list",
"to",
"be",
"swapped",
"out"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java#L70-L81 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java | CircularList.removeElement | public synchronized void removeElement(T element) {
List<T> origList = ref.get().list;
boolean isPresent = origList.contains(element);
if (!isPresent) {
return;
}
List<T> newList = new ArrayList<T>(origList);
newList.remove(element);
swapWithList(newList);
} | java | public synchronized void removeElement(T element) {
List<T> origList = ref.get().list;
boolean isPresent = origList.contains(element);
if (!isPresent) {
return;
}
List<T> newList = new ArrayList<T>(origList);
newList.remove(element);
swapWithList(newList);
} | [
"public",
"synchronized",
"void",
"removeElement",
"(",
"T",
"element",
")",
"{",
"List",
"<",
"T",
">",
"origList",
"=",
"ref",
".",
"get",
"(",
")",
".",
"list",
";",
"boolean",
"isPresent",
"=",
"origList",
".",
"contains",
"(",
"element",
")",
";",... | Remove an element from this list. This causes the inner list to be swapped out
@param element | [
"Remove",
"an",
"element",
"from",
"this",
"list",
".",
"This",
"causes",
"the",
"inner",
"list",
"to",
"be",
"swapped",
"out"
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java#L87-L98 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java | CircularList.getEntireList | public List<T> getEntireList() {
InnerList iList = ref.get();
return iList != null ? iList.getList() : null;
} | java | public List<T> getEntireList() {
InnerList iList = ref.get();
return iList != null ? iList.getList() : null;
} | [
"public",
"List",
"<",
"T",
">",
"getEntireList",
"(",
")",
"{",
"InnerList",
"iList",
"=",
"ref",
".",
"get",
"(",
")",
";",
"return",
"iList",
"!=",
"null",
"?",
"iList",
".",
"getList",
"(",
")",
":",
"null",
";",
"}"
] | Helpful utility to access the inner list. Must be used with care since the inner list can change.
@return List<T> | [
"Helpful",
"utility",
"to",
"access",
"the",
"inner",
"list",
".",
"Must",
"be",
"used",
"with",
"care",
"since",
"the",
"inner",
"list",
"can",
"change",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java#L104-L107 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java | CircularList.getSize | public int getSize() {
InnerList iList = ref.get();
return iList != null ? iList.getList().size() : 0;
} | java | public int getSize() {
InnerList iList = ref.get();
return iList != null ? iList.getList().size() : 0;
} | [
"public",
"int",
"getSize",
"(",
")",
"{",
"InnerList",
"iList",
"=",
"ref",
".",
"get",
"(",
")",
";",
"return",
"iList",
"!=",
"null",
"?",
"iList",
".",
"getList",
"(",
")",
".",
"size",
"(",
")",
":",
"0",
";",
"}"
] | Gets the size of the bounded list underneath. Note that this num can change if the inner list is swapped out.
@return | [
"Gets",
"the",
"size",
"of",
"the",
"bounded",
"list",
"underneath",
".",
"Note",
"that",
"this",
"num",
"can",
"change",
"if",
"the",
"inner",
"list",
"is",
"swapped",
"out",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/lb/CircularList.java#L113-L116 | train |
Netflix/dyno | dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur1Hash.java | Murmur1Hash.hash | public static int hash(byte[] data, int offset, int length, int seed) {
return hash(ByteBuffer.wrap(data, offset, length), seed);
} | java | public static int hash(byte[] data, int offset, int length, int seed) {
return hash(ByteBuffer.wrap(data, offset, length), seed);
} | [
"public",
"static",
"int",
"hash",
"(",
"byte",
"[",
"]",
"data",
",",
"int",
"offset",
",",
"int",
"length",
",",
"int",
"seed",
")",
"{",
"return",
"hash",
"(",
"ByteBuffer",
".",
"wrap",
"(",
"data",
",",
"offset",
",",
"length",
")",
",",
"seed... | Hashes bytes in part of an array.
@param data The data to hash.
@param offset Where to start munging.
@param length How many bytes to process.
@param seed The seed to start with.
@return The 32-bit hash of the data in question. | [
"Hashes",
"bytes",
"in",
"part",
"of",
"an",
"array",
"."
] | 158f807083ea8e9b09c8089cb07f98e954ad5b23 | https://github.com/Netflix/dyno/blob/158f807083ea8e9b09c8089cb07f98e954ad5b23/dyno-core/src/main/java/com/netflix/dyno/connectionpool/impl/hash/Murmur1Hash.java#L31-L33 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.