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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
lift/framework | core/common/src/main/java/net/liftweb/common/Func.java | Func.lift | public static<A, B, Z> Function2<A, B, Z> lift(Func2<A, B, Z> f) {
return bridge.lift(f);
} | java | public static<A, B, Z> Function2<A, B, Z> lift(Func2<A, B, Z> f) {
return bridge.lift(f);
} | [
"public",
"static",
"<",
"A",
",",
"B",
",",
"Z",
">",
"Function2",
"<",
"A",
",",
"B",
",",
"Z",
">",
"lift",
"(",
"Func2",
"<",
"A",
",",
"B",
",",
"Z",
">",
"f",
")",
"{",
"return",
"bridge",
".",
"lift",
"(",
"f",
")",
";",
"}"
] | Lift a Java Func2 to a Scala Function2
@param f the function to lift
@returns the Scala function | [
"Lift",
"a",
"Java",
"Func2",
"to",
"a",
"Scala",
"Function2"
] | 975aa115e0a8e2450dd4905a17ebd19830ae97b2 | https://github.com/lift/framework/blob/975aa115e0a8e2450dd4905a17ebd19830ae97b2/core/common/src/main/java/net/liftweb/common/Func.java#L59-L61 | train |
lift/framework | core/common/src/main/java/net/liftweb/common/Func.java | Func.lift | public static<A, B, C, Z> Function3<A, B, C, Z> lift(Func3<A, B, C, Z> f) {
return bridge.lift(f);
} | java | public static<A, B, C, Z> Function3<A, B, C, Z> lift(Func3<A, B, C, Z> f) {
return bridge.lift(f);
} | [
"public",
"static",
"<",
"A",
",",
"B",
",",
"C",
",",
"Z",
">",
"Function3",
"<",
"A",
",",
"B",
",",
"C",
",",
"Z",
">",
"lift",
"(",
"Func3",
"<",
"A",
",",
"B",
",",
"C",
",",
"Z",
">",
"f",
")",
"{",
"return",
"bridge",
".",
"lift",
... | Lift a Java Func3 to a Scala Function3
@param f the function to lift
@returns the Scala function | [
"Lift",
"a",
"Java",
"Func3",
"to",
"a",
"Scala",
"Function3"
] | 975aa115e0a8e2450dd4905a17ebd19830ae97b2 | https://github.com/lift/framework/blob/975aa115e0a8e2450dd4905a17ebd19830ae97b2/core/common/src/main/java/net/liftweb/common/Func.java#L70-L72 | train |
lift/framework | core/common/src/main/java/net/liftweb/common/Func.java | Func.lift | public static<A, B, C, D, Z> Function4<A, B, C, D, Z> lift(Func4<A, B, C, D, Z> f) {
return bridge.lift(f);
} | java | public static<A, B, C, D, Z> Function4<A, B, C, D, Z> lift(Func4<A, B, C, D, Z> f) {
return bridge.lift(f);
} | [
"public",
"static",
"<",
"A",
",",
"B",
",",
"C",
",",
"D",
",",
"Z",
">",
"Function4",
"<",
"A",
",",
"B",
",",
"C",
",",
"D",
",",
"Z",
">",
"lift",
"(",
"Func4",
"<",
"A",
",",
"B",
",",
"C",
",",
"D",
",",
"Z",
">",
"f",
")",
"{",... | Lift a Java Func4 to a Scala Function4
@param f the function to lift
@returns the Scala function | [
"Lift",
"a",
"Java",
"Func4",
"to",
"a",
"Scala",
"Function4"
] | 975aa115e0a8e2450dd4905a17ebd19830ae97b2 | https://github.com/lift/framework/blob/975aa115e0a8e2450dd4905a17ebd19830ae97b2/core/common/src/main/java/net/liftweb/common/Func.java#L81-L83 | train |
lift/framework | core/common/src/main/java/net/liftweb/common/Func.java | Func.lift | public static<Z> Function0<Z> lift(Callable<Z> f) {
return bridge.lift(f);
} | java | public static<Z> Function0<Z> lift(Callable<Z> f) {
return bridge.lift(f);
} | [
"public",
"static",
"<",
"Z",
">",
"Function0",
"<",
"Z",
">",
"lift",
"(",
"Callable",
"<",
"Z",
">",
"f",
")",
"{",
"return",
"bridge",
".",
"lift",
"(",
"f",
")",
";",
"}"
] | Lift a Java Callable to a Scala Function0
@param f the function to lift
@returns the Scala function | [
"Lift",
"a",
"Java",
"Callable",
"to",
"a",
"Scala",
"Function0"
] | 975aa115e0a8e2450dd4905a17ebd19830ae97b2 | https://github.com/lift/framework/blob/975aa115e0a8e2450dd4905a17ebd19830ae97b2/core/common/src/main/java/net/liftweb/common/Func.java#L92-L94 | train |
lift/framework | core/util/src/main/java/net/liftweb/util/Css.java | Css.sel | public static CssSel sel(String selector, String value) {
return j.sel(selector, value);
} | java | public static CssSel sel(String selector, String value) {
return j.sel(selector, value);
} | [
"public",
"static",
"CssSel",
"sel",
"(",
"String",
"selector",
",",
"String",
"value",
")",
"{",
"return",
"j",
".",
"sel",
"(",
"selector",
",",
"value",
")",
";",
"}"
] | Create a Css Selector Transform | [
"Create",
"a",
"Css",
"Selector",
"Transform"
] | 975aa115e0a8e2450dd4905a17ebd19830ae97b2 | https://github.com/lift/framework/blob/975aa115e0a8e2450dd4905a17ebd19830ae97b2/core/util/src/main/java/net/liftweb/util/Css.java#L31-L33 | train |
lift/framework | core/util/src/main/java/net/liftweb/util/VendorJ.java | VendorJ.vendor | public static<T> Vendor<T> vendor(Func0<T> f) {
return j.vendor(f);
} | java | public static<T> Vendor<T> vendor(Func0<T> f) {
return j.vendor(f);
} | [
"public",
"static",
"<",
"T",
">",
"Vendor",
"<",
"T",
">",
"vendor",
"(",
"Func0",
"<",
"T",
">",
"f",
")",
"{",
"return",
"j",
".",
"vendor",
"(",
"f",
")",
";",
"}"
] | Create a Vendor from a Func0 | [
"Create",
"a",
"Vendor",
"from",
"a",
"Func0"
] | 975aa115e0a8e2450dd4905a17ebd19830ae97b2 | https://github.com/lift/framework/blob/975aa115e0a8e2450dd4905a17ebd19830ae97b2/core/util/src/main/java/net/liftweb/util/VendorJ.java#L31-L33 | train |
lift/framework | core/util/src/main/java/net/liftweb/util/VendorJ.java | VendorJ.vendor | public static<T> Vendor<T> vendor(Callable<T> f) {
return j.vendor(f);
} | java | public static<T> Vendor<T> vendor(Callable<T> f) {
return j.vendor(f);
} | [
"public",
"static",
"<",
"T",
">",
"Vendor",
"<",
"T",
">",
"vendor",
"(",
"Callable",
"<",
"T",
">",
"f",
")",
"{",
"return",
"j",
".",
"vendor",
"(",
"f",
")",
";",
"}"
] | Create a Vendor from a Callable | [
"Create",
"a",
"Vendor",
"from",
"a",
"Callable"
] | 975aa115e0a8e2450dd4905a17ebd19830ae97b2 | https://github.com/lift/framework/blob/975aa115e0a8e2450dd4905a17ebd19830ae97b2/core/util/src/main/java/net/liftweb/util/VendorJ.java#L38-L40 | train |
lift/framework | web/webkit/src/main/java/net/liftweb/http/VarsJ.java | VarsJ.vendSessionVar | public static<T> SessionVar<T> vendSessionVar(T defValue) {
return (new VarsJBridge()).vendSessionVar(defValue, new Exception());
} | java | public static<T> SessionVar<T> vendSessionVar(T defValue) {
return (new VarsJBridge()).vendSessionVar(defValue, new Exception());
} | [
"public",
"static",
"<",
"T",
">",
"SessionVar",
"<",
"T",
">",
"vendSessionVar",
"(",
"T",
"defValue",
")",
"{",
"return",
"(",
"new",
"VarsJBridge",
"(",
")",
")",
".",
"vendSessionVar",
"(",
"defValue",
",",
"new",
"Exception",
"(",
")",
")",
";",
... | Vend a SessionVar with the default value | [
"Vend",
"a",
"SessionVar",
"with",
"the",
"default",
"value"
] | 975aa115e0a8e2450dd4905a17ebd19830ae97b2 | https://github.com/lift/framework/blob/975aa115e0a8e2450dd4905a17ebd19830ae97b2/web/webkit/src/main/java/net/liftweb/http/VarsJ.java#L33-L35 | train |
lift/framework | web/webkit/src/main/java/net/liftweb/http/VarsJ.java | VarsJ.vendSessionVar | public static<T> SessionVar<T> vendSessionVar(Callable<T> defFunc) {
return (new VarsJBridge()).vendSessionVar(defFunc, new Exception());
} | java | public static<T> SessionVar<T> vendSessionVar(Callable<T> defFunc) {
return (new VarsJBridge()).vendSessionVar(defFunc, new Exception());
} | [
"public",
"static",
"<",
"T",
">",
"SessionVar",
"<",
"T",
">",
"vendSessionVar",
"(",
"Callable",
"<",
"T",
">",
"defFunc",
")",
"{",
"return",
"(",
"new",
"VarsJBridge",
"(",
")",
")",
".",
"vendSessionVar",
"(",
"defFunc",
",",
"new",
"Exception",
"... | Vend a SessionVar with the function to create the default value | [
"Vend",
"a",
"SessionVar",
"with",
"the",
"function",
"to",
"create",
"the",
"default",
"value"
] | 975aa115e0a8e2450dd4905a17ebd19830ae97b2 | https://github.com/lift/framework/blob/975aa115e0a8e2450dd4905a17ebd19830ae97b2/web/webkit/src/main/java/net/liftweb/http/VarsJ.java#L40-L42 | train |
vlingo/vlingo-actors | src/main/java/io/vlingo/actors/Router.java | Router.dispatchCommand | protected <T1> void dispatchCommand(final BiConsumer<P, T1> action, final T1 routable1) {
routingFor(routable1)
.routees()
.forEach(routee -> routee.receiveCommand(action, routable1));
} | java | protected <T1> void dispatchCommand(final BiConsumer<P, T1> action, final T1 routable1) {
routingFor(routable1)
.routees()
.forEach(routee -> routee.receiveCommand(action, routable1));
} | [
"protected",
"<",
"T1",
">",
"void",
"dispatchCommand",
"(",
"final",
"BiConsumer",
"<",
"P",
",",
"T1",
">",
"action",
",",
"final",
"T1",
"routable1",
")",
"{",
"routingFor",
"(",
"routable1",
")",
".",
"routees",
"(",
")",
".",
"forEach",
"(",
"rout... | DISPATCHING - COMMANDS | [
"DISPATCHING",
"-",
"COMMANDS"
] | c7d046fd139c0490cf0fd2588d7dc2f792f13493 | https://github.com/vlingo/vlingo-actors/blob/c7d046fd139c0490cf0fd2588d7dc2f792f13493/src/main/java/io/vlingo/actors/Router.java#L97-L101 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncMongoIterableImpl.java | CoreSyncMongoIterableImpl.first | @Nullable
public ResultT first() {
final CoreRemoteMongoCursor<ResultT> cursor = iterator();
if (!cursor.hasNext()) {
return null;
}
return cursor.next();
} | java | @Nullable
public ResultT first() {
final CoreRemoteMongoCursor<ResultT> cursor = iterator();
if (!cursor.hasNext()) {
return null;
}
return cursor.next();
} | [
"@",
"Nullable",
"public",
"ResultT",
"first",
"(",
")",
"{",
"final",
"CoreRemoteMongoCursor",
"<",
"ResultT",
">",
"cursor",
"=",
"iterator",
"(",
")",
";",
"if",
"(",
"!",
"cursor",
".",
"hasNext",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"... | Helper to return the first item in the iterator or null.
@return T the first item or null. | [
"Helper",
"to",
"return",
"the",
"first",
"item",
"in",
"the",
"iterator",
"or",
"null",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncMongoIterableImpl.java#L76-L83 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncMongoIterableImpl.java | CoreSyncMongoIterableImpl.map | public <U> CoreRemoteMongoIterable<U> map(final Function<ResultT, U> mapper) {
return new CoreRemoteMappingIterable<>(this, mapper);
} | java | public <U> CoreRemoteMongoIterable<U> map(final Function<ResultT, U> mapper) {
return new CoreRemoteMappingIterable<>(this, mapper);
} | [
"public",
"<",
"U",
">",
"CoreRemoteMongoIterable",
"<",
"U",
">",
"map",
"(",
"final",
"Function",
"<",
"ResultT",
",",
"U",
">",
"mapper",
")",
"{",
"return",
"new",
"CoreRemoteMappingIterable",
"<>",
"(",
"this",
",",
"mapper",
")",
";",
"}"
] | Maps this iterable from the source document type to the target document type.
@param mapper a function that maps from the source to the target document type
@param <U> the target document type
@return an iterable which maps T to U | [
"Maps",
"this",
"iterable",
"from",
"the",
"source",
"document",
"type",
"to",
"the",
"target",
"document",
"type",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncMongoIterableImpl.java#L92-L94 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncMongoIterableImpl.java | CoreSyncMongoIterableImpl.into | public <A extends Collection<? super ResultT>> A into(final A target) {
forEach(new Block<ResultT>() {
@Override
public void apply(@Nonnull final ResultT t) {
target.add(t);
}
});
return target;
} | java | public <A extends Collection<? super ResultT>> A into(final A target) {
forEach(new Block<ResultT>() {
@Override
public void apply(@Nonnull final ResultT t) {
target.add(t);
}
});
return target;
} | [
"public",
"<",
"A",
"extends",
"Collection",
"<",
"?",
"super",
"ResultT",
">",
">",
"A",
"into",
"(",
"final",
"A",
"target",
")",
"{",
"forEach",
"(",
"new",
"Block",
"<",
"ResultT",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"void",
"apply",
... | Iterates over all the documents, adding each to the given target.
@param target the collection to insert into
@param <A> the collection type
@return the target | [
"Iterates",
"over",
"all",
"the",
"documents",
"adding",
"each",
"to",
"the",
"given",
"target",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreSyncMongoIterableImpl.java#L116-L124 | train |
mongodb/stitch-android-sdk | android/services/aws/src/main/java/com/mongodb/stitch/android/services/aws/internal/AwsServiceClientImpl.java | AwsServiceClientImpl.withCodecRegistry | public AwsServiceClient withCodecRegistry(@Nonnull final CodecRegistry codecRegistry) {
return new AwsServiceClientImpl(proxy.withCodecRegistry(codecRegistry), dispatcher);
} | java | public AwsServiceClient withCodecRegistry(@Nonnull final CodecRegistry codecRegistry) {
return new AwsServiceClientImpl(proxy.withCodecRegistry(codecRegistry), dispatcher);
} | [
"public",
"AwsServiceClient",
"withCodecRegistry",
"(",
"@",
"Nonnull",
"final",
"CodecRegistry",
"codecRegistry",
")",
"{",
"return",
"new",
"AwsServiceClientImpl",
"(",
"proxy",
".",
"withCodecRegistry",
"(",
"codecRegistry",
")",
",",
"dispatcher",
")",
";",
"}"
... | Create a new AwsServiceClient instance with a different codec registry.
@param codecRegistry the new {@link CodecRegistry} for the client.
@return a new AwsServiceClient instance with the different codec registry | [
"Create",
"a",
"new",
"AwsServiceClient",
"instance",
"with",
"a",
"different",
"codec",
"registry",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/services/aws/src/main/java/com/mongodb/stitch/android/services/aws/internal/AwsServiceClientImpl.java#L243-L245 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/CoreStitchAppClient.java | CoreStitchAppClient.callFunction | public void callFunction(
final String name,
final List<?> args,
final @Nullable Long requestTimeout) {
this.functionService.callFunction(name, args, requestTimeout);
} | java | public void callFunction(
final String name,
final List<?> args,
final @Nullable Long requestTimeout) {
this.functionService.callFunction(name, args, requestTimeout);
} | [
"public",
"void",
"callFunction",
"(",
"final",
"String",
"name",
",",
"final",
"List",
"<",
"?",
">",
"args",
",",
"final",
"@",
"Nullable",
"Long",
"requestTimeout",
")",
"{",
"this",
".",
"functionService",
".",
"callFunction",
"(",
"name",
",",
"args",... | Calls the specified Stitch function.
@param name the name of the Stitch function to call.
@param args the arguments to pass to the Stitch function.
@param requestTimeout the number of milliseconds the client should wait for a response from the
server before failing with an error. | [
"Calls",
"the",
"specified",
"Stitch",
"function",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/CoreStitchAppClient.java#L57-L62 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/CoreStitchAppClient.java | CoreStitchAppClient.callFunction | public <T> T callFunction(
final String name,
final List<?> args,
final @Nullable Long requestTimeout,
final Class<T> resultClass,
final CodecRegistry codecRegistry
) {
return this.functionService
.withCodecRegistry(codecRegistry)
.callFunction(name, args, requestTimeout, resultClass);
} | java | public <T> T callFunction(
final String name,
final List<?> args,
final @Nullable Long requestTimeout,
final Class<T> resultClass,
final CodecRegistry codecRegistry
) {
return this.functionService
.withCodecRegistry(codecRegistry)
.callFunction(name, args, requestTimeout, resultClass);
} | [
"public",
"<",
"T",
">",
"T",
"callFunction",
"(",
"final",
"String",
"name",
",",
"final",
"List",
"<",
"?",
">",
"args",
",",
"final",
"@",
"Nullable",
"Long",
"requestTimeout",
",",
"final",
"Class",
"<",
"T",
">",
"resultClass",
",",
"final",
"Code... | Calls the specified Stitch function, and decodes the response into an instance of the specified
type. The response will be decoded using the codec registry given.
@param name the name of the Stitch function to call.
@param args the arguments to pass to the Stitch function.
@param requestTimeout the number of milliseconds the client should wait for a response from the
server before failing with an error.
@param resultClass the class that the Stitch response should be decoded as.
@param <T> the type into which the Stitch response will be decoded.
@param codecRegistry the codec registry that will be used to encode/decode the function call.
@return the decoded value. | [
"Calls",
"the",
"specified",
"Stitch",
"function",
"and",
"decodes",
"the",
"response",
"into",
"an",
"instance",
"of",
"the",
"specified",
"type",
".",
"The",
"response",
"will",
"be",
"decoded",
"using",
"the",
"codec",
"registry",
"given",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/CoreStitchAppClient.java#L120-L130 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java | InstanceChangeStreamListenerImpl.start | public void start() {
instanceLock.writeLock().lock();
try {
for (final Map.Entry<MongoNamespace, NamespaceChangeStreamListener> streamerEntry :
nsStreamers.entrySet()) {
streamerEntry.getValue().start();
}
} finally {
instanceLock.writeLock().unlock();
}
} | java | public void start() {
instanceLock.writeLock().lock();
try {
for (final Map.Entry<MongoNamespace, NamespaceChangeStreamListener> streamerEntry :
nsStreamers.entrySet()) {
streamerEntry.getValue().start();
}
} finally {
instanceLock.writeLock().unlock();
}
} | [
"public",
"void",
"start",
"(",
")",
"{",
"instanceLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"for",
"(",
"final",
"Map",
".",
"Entry",
"<",
"MongoNamespace",
",",
"NamespaceChangeStreamListener",
">",
"streamerEntry",
":",
... | Starts all streams. | [
"Starts",
"all",
"streams",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java#L79-L89 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java | InstanceChangeStreamListenerImpl.stop | public void stop() {
instanceLock.writeLock().lock();
try {
for (final NamespaceChangeStreamListener streamer : nsStreamers.values()) {
streamer.stop();
}
} finally {
instanceLock.writeLock().unlock();
}
} | java | public void stop() {
instanceLock.writeLock().lock();
try {
for (final NamespaceChangeStreamListener streamer : nsStreamers.values()) {
streamer.stop();
}
} finally {
instanceLock.writeLock().unlock();
}
} | [
"public",
"void",
"stop",
"(",
")",
"{",
"instanceLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"for",
"(",
"final",
"NamespaceChangeStreamListener",
"streamer",
":",
"nsStreamers",
".",
"values",
"(",
")",
")",
"{",
"streame... | Stops all streams. | [
"Stops",
"all",
"streams",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java#L105-L114 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java | InstanceChangeStreamListenerImpl.addNamespace | public void addNamespace(final MongoNamespace namespace) {
this.instanceLock.writeLock().lock();
try {
if (this.nsStreamers.containsKey(namespace)) {
return;
}
final NamespaceChangeStreamListener streamer =
new NamespaceChangeStreamListener(
namespace,
instanceConfig.getNamespaceConfig(namespace),
service,
networkMonitor,
authMonitor,
getLockForNamespace(namespace));
this.nsStreamers.put(namespace, streamer);
} finally {
this.instanceLock.writeLock().unlock();
}
} | java | public void addNamespace(final MongoNamespace namespace) {
this.instanceLock.writeLock().lock();
try {
if (this.nsStreamers.containsKey(namespace)) {
return;
}
final NamespaceChangeStreamListener streamer =
new NamespaceChangeStreamListener(
namespace,
instanceConfig.getNamespaceConfig(namespace),
service,
networkMonitor,
authMonitor,
getLockForNamespace(namespace));
this.nsStreamers.put(namespace, streamer);
} finally {
this.instanceLock.writeLock().unlock();
}
} | [
"public",
"void",
"addNamespace",
"(",
"final",
"MongoNamespace",
"namespace",
")",
"{",
"this",
".",
"instanceLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"this",
".",
"nsStreamers",
".",
"containsKey",
"(",
"nam... | Requests that the given namespace be started listening to for change events.
@param namespace the namespace to listen for change events on. | [
"Requests",
"that",
"the",
"given",
"namespace",
"be",
"started",
"listening",
"to",
"for",
"change",
"events",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java#L172-L190 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java | InstanceChangeStreamListenerImpl.removeNamespace | @Override
public void removeNamespace(final MongoNamespace namespace) {
this.instanceLock.writeLock().lock();
try {
if (!this.nsStreamers.containsKey(namespace)) {
return;
}
final NamespaceChangeStreamListener streamer = this.nsStreamers.get(namespace);
streamer.stop();
this.nsStreamers.remove(namespace);
} finally {
this.instanceLock.writeLock().unlock();
}
} | java | @Override
public void removeNamespace(final MongoNamespace namespace) {
this.instanceLock.writeLock().lock();
try {
if (!this.nsStreamers.containsKey(namespace)) {
return;
}
final NamespaceChangeStreamListener streamer = this.nsStreamers.get(namespace);
streamer.stop();
this.nsStreamers.remove(namespace);
} finally {
this.instanceLock.writeLock().unlock();
}
} | [
"@",
"Override",
"public",
"void",
"removeNamespace",
"(",
"final",
"MongoNamespace",
"namespace",
")",
"{",
"this",
".",
"instanceLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"!",
"this",
".",
"nsStreamers",
".",... | Requests that the given namespace stopped being listened to for change events.
@param namespace the namespace to stop listening for change events on. | [
"Requests",
"that",
"the",
"given",
"namespace",
"stopped",
"being",
"listened",
"to",
"for",
"change",
"events",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java#L197-L210 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java | InstanceChangeStreamListenerImpl.getEventsForNamespace | public Map<BsonValue, ChangeEvent<BsonDocument>> getEventsForNamespace(
final MongoNamespace namespace
) {
this.instanceLock.readLock().lock();
final NamespaceChangeStreamListener streamer;
try {
streamer = nsStreamers.get(namespace);
} finally {
this.instanceLock.readLock().unlock();
}
if (streamer == null) {
return new HashMap<>();
}
return streamer.getEvents();
} | java | public Map<BsonValue, ChangeEvent<BsonDocument>> getEventsForNamespace(
final MongoNamespace namespace
) {
this.instanceLock.readLock().lock();
final NamespaceChangeStreamListener streamer;
try {
streamer = nsStreamers.get(namespace);
} finally {
this.instanceLock.readLock().unlock();
}
if (streamer == null) {
return new HashMap<>();
}
return streamer.getEvents();
} | [
"public",
"Map",
"<",
"BsonValue",
",",
"ChangeEvent",
"<",
"BsonDocument",
">",
">",
"getEventsForNamespace",
"(",
"final",
"MongoNamespace",
"namespace",
")",
"{",
"this",
".",
"instanceLock",
".",
"readLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"final",... | Returns the latest change events for a given namespace.
@param namespace the namespace to get events for.
@return the latest change events for a given namespace. | [
"Returns",
"the",
"latest",
"change",
"events",
"for",
"a",
"given",
"namespace",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java#L218-L232 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java | InstanceChangeStreamListenerImpl.getUnprocessedEventForDocumentId | public @Nullable ChangeEvent<BsonDocument> getUnprocessedEventForDocumentId(
final MongoNamespace namespace,
final BsonValue documentId
) {
this.instanceLock.readLock().lock();
final NamespaceChangeStreamListener streamer;
try {
streamer = nsStreamers.get(namespace);
} finally {
this.instanceLock.readLock().unlock();
}
if (streamer == null) {
return null;
}
return streamer.getUnprocessedEventForDocumentId(documentId);
} | java | public @Nullable ChangeEvent<BsonDocument> getUnprocessedEventForDocumentId(
final MongoNamespace namespace,
final BsonValue documentId
) {
this.instanceLock.readLock().lock();
final NamespaceChangeStreamListener streamer;
try {
streamer = nsStreamers.get(namespace);
} finally {
this.instanceLock.readLock().unlock();
}
if (streamer == null) {
return null;
}
return streamer.getUnprocessedEventForDocumentId(documentId);
} | [
"public",
"@",
"Nullable",
"ChangeEvent",
"<",
"BsonDocument",
">",
"getUnprocessedEventForDocumentId",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"BsonValue",
"documentId",
")",
"{",
"this",
".",
"instanceLock",
".",
"readLock",
"(",
")",
".",
"lo... | If there is an unprocessed change event for a particular document ID, fetch it from the
appropriate namespace change stream listener, and remove it. By reading the event here, we are
assuming it will be processed by the consumer.
@return the latest unprocessed change event for the given document ID and namespace, or null
if none exists. | [
"If",
"there",
"is",
"an",
"unprocessed",
"change",
"event",
"for",
"a",
"particular",
"document",
"ID",
"fetch",
"it",
"from",
"the",
"appropriate",
"namespace",
"change",
"stream",
"listener",
"and",
"remove",
"it",
".",
"By",
"reading",
"the",
"event",
"h... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/InstanceChangeStreamListenerImpl.java#L258-L275 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfig.java | CoreDocumentSynchronizationConfig.setPaused | void setPaused(final boolean isPaused) {
docLock.writeLock().lock();
try {
docsColl.updateOne(
getDocFilter(namespace, documentId),
new BsonDocument("$set",
new BsonDocument(
ConfigCodec.Fields.IS_PAUSED,
new BsonBoolean(isPaused))));
this.isPaused = isPaused;
} catch (IllegalStateException e) {
// eat this
} finally {
docLock.writeLock().unlock();
}
} | java | void setPaused(final boolean isPaused) {
docLock.writeLock().lock();
try {
docsColl.updateOne(
getDocFilter(namespace, documentId),
new BsonDocument("$set",
new BsonDocument(
ConfigCodec.Fields.IS_PAUSED,
new BsonBoolean(isPaused))));
this.isPaused = isPaused;
} catch (IllegalStateException e) {
// eat this
} finally {
docLock.writeLock().unlock();
}
} | [
"void",
"setPaused",
"(",
"final",
"boolean",
"isPaused",
")",
"{",
"docLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"docsColl",
".",
"updateOne",
"(",
"getDocFilter",
"(",
"namespace",
",",
"documentId",
")",
",",
"new",
... | A document that is paused no longer has remote updates applied to it.
Any local updates to this document cause it to be thawed. An example of pausing a document
is when a conflict is being resolved for that document and the handler throws an exception.
@param isPaused whether or not this config is frozen | [
"A",
"document",
"that",
"is",
"paused",
"no",
"longer",
"has",
"remote",
"updates",
"applied",
"to",
"it",
".",
"Any",
"local",
"updates",
"to",
"this",
"document",
"cause",
"it",
"to",
"be",
"thawed",
".",
"An",
"example",
"of",
"pausing",
"a",
"docume... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfig.java#L160-L175 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfig.java | CoreDocumentSynchronizationConfig.setSomePendingWritesAndSave | public void setSomePendingWritesAndSave(
final long atTime,
final ChangeEvent<BsonDocument> changeEvent
) {
docLock.writeLock().lock();
try {
// if we were frozen
if (isPaused) {
// unfreeze the document due to the local write
setPaused(false);
// and now the unfrozen document is now stale
setStale(true);
}
this.lastUncommittedChangeEvent =
coalesceChangeEvents(this.lastUncommittedChangeEvent, changeEvent);
this.lastResolution = atTime;
docsColl.replaceOne(
getDocFilter(namespace, documentId),
this);
} finally {
docLock.writeLock().unlock();
}
} | java | public void setSomePendingWritesAndSave(
final long atTime,
final ChangeEvent<BsonDocument> changeEvent
) {
docLock.writeLock().lock();
try {
// if we were frozen
if (isPaused) {
// unfreeze the document due to the local write
setPaused(false);
// and now the unfrozen document is now stale
setStale(true);
}
this.lastUncommittedChangeEvent =
coalesceChangeEvents(this.lastUncommittedChangeEvent, changeEvent);
this.lastResolution = atTime;
docsColl.replaceOne(
getDocFilter(namespace, documentId),
this);
} finally {
docLock.writeLock().unlock();
}
} | [
"public",
"void",
"setSomePendingWritesAndSave",
"(",
"final",
"long",
"atTime",
",",
"final",
"ChangeEvent",
"<",
"BsonDocument",
">",
"changeEvent",
")",
"{",
"docLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"// if we were froze... | Sets that there are some pending writes that occurred at a time for an associated
locally emitted change event. This variant maintains the last version set.
@param atTime the time at which the write occurred.
@param changeEvent the description of the write/change. | [
"Sets",
"that",
"there",
"are",
"some",
"pending",
"writes",
"that",
"occurred",
"at",
"a",
"time",
"for",
"an",
"associated",
"locally",
"emitted",
"change",
"event",
".",
"This",
"variant",
"maintains",
"the",
"last",
"version",
"set",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfig.java#L188-L211 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfig.java | CoreDocumentSynchronizationConfig.coalesceChangeEvents | private static ChangeEvent<BsonDocument> coalesceChangeEvents(
final ChangeEvent<BsonDocument> lastUncommittedChangeEvent,
final ChangeEvent<BsonDocument> newestChangeEvent
) {
if (lastUncommittedChangeEvent == null) {
return newestChangeEvent;
}
switch (lastUncommittedChangeEvent.getOperationType()) {
case INSERT:
switch (newestChangeEvent.getOperationType()) {
// Coalesce replaces/updates to inserts since we believe at some point a document did not
// exist remotely and that this replace or update should really be an insert if we are
// still in an uncommitted state.
case REPLACE:
case UPDATE:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.INSERT,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
null,
newestChangeEvent.hasUncommittedWrites()
);
default:
break;
}
break;
case DELETE:
switch (newestChangeEvent.getOperationType()) {
// Coalesce inserts to replaces since we believe at some point a document existed
// remotely and that this insert should really be an replace if we are still in an
// uncommitted state.
case INSERT:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.REPLACE,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
null,
newestChangeEvent.hasUncommittedWrites()
);
default:
break;
}
break;
case UPDATE:
switch (newestChangeEvent.getOperationType()) {
case UPDATE:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.UPDATE,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
lastUncommittedChangeEvent.getUpdateDescription() != null
? lastUncommittedChangeEvent
.getUpdateDescription()
.merge(newestChangeEvent.getUpdateDescription())
: newestChangeEvent.getUpdateDescription(),
newestChangeEvent.hasUncommittedWrites()
);
case REPLACE:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.REPLACE,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
null,
newestChangeEvent.hasUncommittedWrites()
);
default:
break;
}
break;
case REPLACE:
switch (newestChangeEvent.getOperationType()) {
case UPDATE:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.REPLACE,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
null,
newestChangeEvent.hasUncommittedWrites()
);
default:
break;
}
break;
default:
break;
}
return newestChangeEvent;
} | java | private static ChangeEvent<BsonDocument> coalesceChangeEvents(
final ChangeEvent<BsonDocument> lastUncommittedChangeEvent,
final ChangeEvent<BsonDocument> newestChangeEvent
) {
if (lastUncommittedChangeEvent == null) {
return newestChangeEvent;
}
switch (lastUncommittedChangeEvent.getOperationType()) {
case INSERT:
switch (newestChangeEvent.getOperationType()) {
// Coalesce replaces/updates to inserts since we believe at some point a document did not
// exist remotely and that this replace or update should really be an insert if we are
// still in an uncommitted state.
case REPLACE:
case UPDATE:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.INSERT,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
null,
newestChangeEvent.hasUncommittedWrites()
);
default:
break;
}
break;
case DELETE:
switch (newestChangeEvent.getOperationType()) {
// Coalesce inserts to replaces since we believe at some point a document existed
// remotely and that this insert should really be an replace if we are still in an
// uncommitted state.
case INSERT:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.REPLACE,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
null,
newestChangeEvent.hasUncommittedWrites()
);
default:
break;
}
break;
case UPDATE:
switch (newestChangeEvent.getOperationType()) {
case UPDATE:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.UPDATE,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
lastUncommittedChangeEvent.getUpdateDescription() != null
? lastUncommittedChangeEvent
.getUpdateDescription()
.merge(newestChangeEvent.getUpdateDescription())
: newestChangeEvent.getUpdateDescription(),
newestChangeEvent.hasUncommittedWrites()
);
case REPLACE:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.REPLACE,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
null,
newestChangeEvent.hasUncommittedWrites()
);
default:
break;
}
break;
case REPLACE:
switch (newestChangeEvent.getOperationType()) {
case UPDATE:
return new ChangeEvent<>(
newestChangeEvent.getId(),
OperationType.REPLACE,
newestChangeEvent.getFullDocument(),
newestChangeEvent.getNamespace(),
newestChangeEvent.getDocumentKey(),
null,
newestChangeEvent.hasUncommittedWrites()
);
default:
break;
}
break;
default:
break;
}
return newestChangeEvent;
} | [
"private",
"static",
"ChangeEvent",
"<",
"BsonDocument",
">",
"coalesceChangeEvents",
"(",
"final",
"ChangeEvent",
"<",
"BsonDocument",
">",
"lastUncommittedChangeEvent",
",",
"final",
"ChangeEvent",
"<",
"BsonDocument",
">",
"newestChangeEvent",
")",
"{",
"if",
"(",
... | Possibly coalesces the newest change event to match the user's original intent. For example,
an unsynchronized insert and update is still an insert.
@param lastUncommittedChangeEvent the last change event known about for a document.
@param newestChangeEvent the newest change event known about for a document.
@return the possibly coalesced change event. | [
"Possibly",
"coalesces",
"the",
"newest",
"change",
"event",
"to",
"match",
"the",
"user",
"s",
"original",
"intent",
".",
"For",
"example",
"an",
"unsynchronized",
"insert",
"and",
"update",
"is",
"still",
"an",
"insert",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreDocumentSynchronizationConfig.java#L373-L470 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java | DocumentVersionInfo.getRemoteVersionInfo | static DocumentVersionInfo getRemoteVersionInfo(final BsonDocument remoteDocument) {
final BsonDocument version = getDocumentVersionDoc(remoteDocument);
return new DocumentVersionInfo(
version,
remoteDocument != null
? BsonUtils.getDocumentId(remoteDocument) : null
);
} | java | static DocumentVersionInfo getRemoteVersionInfo(final BsonDocument remoteDocument) {
final BsonDocument version = getDocumentVersionDoc(remoteDocument);
return new DocumentVersionInfo(
version,
remoteDocument != null
? BsonUtils.getDocumentId(remoteDocument) : null
);
} | [
"static",
"DocumentVersionInfo",
"getRemoteVersionInfo",
"(",
"final",
"BsonDocument",
"remoteDocument",
")",
"{",
"final",
"BsonDocument",
"version",
"=",
"getDocumentVersionDoc",
"(",
"remoteDocument",
")",
";",
"return",
"new",
"DocumentVersionInfo",
"(",
"version",
... | Returns the current version info for a provided remote document.
@param remoteDocument the remote BSON document from which to extract version info
@return a DocumentVersionInfo | [
"Returns",
"the",
"current",
"version",
"info",
"for",
"a",
"provided",
"remote",
"document",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java#L185-L192 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java | DocumentVersionInfo.getFreshVersionDocument | static BsonDocument getFreshVersionDocument() {
final BsonDocument versionDoc = new BsonDocument();
versionDoc.append(Fields.SYNC_PROTOCOL_VERSION_FIELD, new BsonInt32(1));
versionDoc.append(Fields.INSTANCE_ID_FIELD, new BsonString(UUID.randomUUID().toString()));
versionDoc.append(Fields.VERSION_COUNTER_FIELD, new BsonInt64(0L));
return versionDoc;
} | java | static BsonDocument getFreshVersionDocument() {
final BsonDocument versionDoc = new BsonDocument();
versionDoc.append(Fields.SYNC_PROTOCOL_VERSION_FIELD, new BsonInt32(1));
versionDoc.append(Fields.INSTANCE_ID_FIELD, new BsonString(UUID.randomUUID().toString()));
versionDoc.append(Fields.VERSION_COUNTER_FIELD, new BsonInt64(0L));
return versionDoc;
} | [
"static",
"BsonDocument",
"getFreshVersionDocument",
"(",
")",
"{",
"final",
"BsonDocument",
"versionDoc",
"=",
"new",
"BsonDocument",
"(",
")",
";",
"versionDoc",
".",
"append",
"(",
"Fields",
".",
"SYNC_PROTOCOL_VERSION_FIELD",
",",
"new",
"BsonInt32",
"(",
"1",... | Returns a BSON version document representing a new version with a new instance ID, and
version counter of zero.
@return a BsonDocument representing a synchronization version | [
"Returns",
"a",
"BSON",
"version",
"document",
"representing",
"a",
"new",
"version",
"with",
"a",
"new",
"instance",
"ID",
"and",
"version",
"counter",
"of",
"zero",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java#L210-L218 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java | DocumentVersionInfo.getDocumentVersionDoc | static BsonDocument getDocumentVersionDoc(final BsonDocument document) {
if (document == null || !document.containsKey(DOCUMENT_VERSION_FIELD)) {
return null;
}
return document.getDocument(DOCUMENT_VERSION_FIELD, null);
} | java | static BsonDocument getDocumentVersionDoc(final BsonDocument document) {
if (document == null || !document.containsKey(DOCUMENT_VERSION_FIELD)) {
return null;
}
return document.getDocument(DOCUMENT_VERSION_FIELD, null);
} | [
"static",
"BsonDocument",
"getDocumentVersionDoc",
"(",
"final",
"BsonDocument",
"document",
")",
"{",
"if",
"(",
"document",
"==",
"null",
"||",
"!",
"document",
".",
"containsKey",
"(",
"DOCUMENT_VERSION_FIELD",
")",
")",
"{",
"return",
"null",
";",
"}",
"re... | Returns the version document of the given document, if any; returns null otherwise.
@param document the document to get the version from.
@return the version of the given document, if any; returns null otherwise. | [
"Returns",
"the",
"version",
"document",
"of",
"the",
"given",
"document",
"if",
"any",
";",
"returns",
"null",
"otherwise",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java#L225-L230 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java | DocumentVersionInfo.getVersionedFilter | static BsonDocument getVersionedFilter(
@Nonnull final BsonValue documentId,
@Nullable final BsonValue version
) {
final BsonDocument filter = new BsonDocument("_id", documentId);
if (version == null) {
filter.put(DOCUMENT_VERSION_FIELD, new BsonDocument("$exists", BsonBoolean.FALSE));
} else {
filter.put(DOCUMENT_VERSION_FIELD, version);
}
return filter;
} | java | static BsonDocument getVersionedFilter(
@Nonnull final BsonValue documentId,
@Nullable final BsonValue version
) {
final BsonDocument filter = new BsonDocument("_id", documentId);
if (version == null) {
filter.put(DOCUMENT_VERSION_FIELD, new BsonDocument("$exists", BsonBoolean.FALSE));
} else {
filter.put(DOCUMENT_VERSION_FIELD, version);
}
return filter;
} | [
"static",
"BsonDocument",
"getVersionedFilter",
"(",
"@",
"Nonnull",
"final",
"BsonValue",
"documentId",
",",
"@",
"Nullable",
"final",
"BsonValue",
"version",
")",
"{",
"final",
"BsonDocument",
"filter",
"=",
"new",
"BsonDocument",
"(",
"\"_id\"",
",",
"documentI... | Returns a query filter for the given document _id and version. The version is allowed to be
null. The query will match only if there is either no version on the document in the database
in question if we have no reference of the version or if the version matches the database's
version.
@param documentId the _id of the document.
@param version the expected version of the document, if any.
@return a query filter for the given document _id and version for a remote operation. | [
"Returns",
"a",
"query",
"filter",
"for",
"the",
"given",
"document",
"_id",
"and",
"version",
".",
"The",
"version",
"is",
"allowed",
"to",
"be",
"null",
".",
"The",
"query",
"will",
"match",
"only",
"if",
"there",
"is",
"either",
"no",
"version",
"on",... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java#L242-L253 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java | DocumentVersionInfo.getNextVersion | BsonDocument getNextVersion() {
if (!this.hasVersion() || this.getVersionDoc() == null) {
return getFreshVersionDocument();
}
final BsonDocument nextVersion = BsonUtils.copyOfDocument(this.getVersionDoc());
nextVersion.put(
Fields.VERSION_COUNTER_FIELD,
new BsonInt64(this.getVersion().getVersionCounter() + 1));
return nextVersion;
} | java | BsonDocument getNextVersion() {
if (!this.hasVersion() || this.getVersionDoc() == null) {
return getFreshVersionDocument();
}
final BsonDocument nextVersion = BsonUtils.copyOfDocument(this.getVersionDoc());
nextVersion.put(
Fields.VERSION_COUNTER_FIELD,
new BsonInt64(this.getVersion().getVersionCounter() + 1));
return nextVersion;
} | [
"BsonDocument",
"getNextVersion",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"hasVersion",
"(",
")",
"||",
"this",
".",
"getVersionDoc",
"(",
")",
"==",
"null",
")",
"{",
"return",
"getFreshVersionDocument",
"(",
")",
";",
"}",
"final",
"BsonDocument",
... | Given a DocumentVersionInfo, returns a BSON document representing the next version. This means
and incremented version count for a non-empty version, or a fresh version document for an
empty version.
@return a BsonDocument representing a synchronization version | [
"Given",
"a",
"DocumentVersionInfo",
"returns",
"a",
"BSON",
"document",
"representing",
"the",
"next",
"version",
".",
"This",
"means",
"and",
"incremented",
"version",
"count",
"for",
"a",
"non",
"-",
"empty",
"version",
"or",
"a",
"fresh",
"version",
"docum... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DocumentVersionInfo.java#L261-L270 | train |
mongodb/stitch-android-sdk | android/services/mongodb-remote/src/main/java/com/mongodb/stitch/android/services/mongodb/remote/internal/RemoteMongoDatabaseImpl.java | RemoteMongoDatabaseImpl.getCollection | public RemoteMongoCollection<Document> getCollection(final String collectionName) {
return new RemoteMongoCollectionImpl<>(proxy.getCollection(collectionName), dispatcher);
} | java | public RemoteMongoCollection<Document> getCollection(final String collectionName) {
return new RemoteMongoCollectionImpl<>(proxy.getCollection(collectionName), dispatcher);
} | [
"public",
"RemoteMongoCollection",
"<",
"Document",
">",
"getCollection",
"(",
"final",
"String",
"collectionName",
")",
"{",
"return",
"new",
"RemoteMongoCollectionImpl",
"<>",
"(",
"proxy",
".",
"getCollection",
"(",
"collectionName",
")",
",",
"dispatcher",
")",
... | Gets a collection.
@param collectionName the name of the collection to return
@return the collection | [
"Gets",
"a",
"collection",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/services/mongodb-remote/src/main/java/com/mongodb/stitch/android/services/mongodb/remote/internal/RemoteMongoDatabaseImpl.java#L54-L56 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/StitchEvent.java | StitchEvent.fromEvent | static <T> StitchEvent<T> fromEvent(final Event event,
final Decoder<T> decoder) {
return new StitchEvent<>(event.getEventName(), event.getData(), decoder);
} | java | static <T> StitchEvent<T> fromEvent(final Event event,
final Decoder<T> decoder) {
return new StitchEvent<>(event.getEventName(), event.getData(), decoder);
} | [
"static",
"<",
"T",
">",
"StitchEvent",
"<",
"T",
">",
"fromEvent",
"(",
"final",
"Event",
"event",
",",
"final",
"Decoder",
"<",
"T",
">",
"decoder",
")",
"{",
"return",
"new",
"StitchEvent",
"<>",
"(",
"event",
".",
"getEventName",
"(",
")",
",",
"... | Convert a SSE to a Stitch SSE
@param event SSE to convert
@param decoder decoder for decoding data
@param <T> type to decode data to
@return a Stitch server-sent event | [
"Convert",
"a",
"SSE",
"to",
"a",
"Stitch",
"SSE"
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/StitchEvent.java#L142-L145 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/EventStreamReader.java | EventStreamReader.processEvent | protected final Event processEvent() throws IOException {
while (true) {
String line;
try {
line = readLine();
} catch (final EOFException ex) {
if (doneOnce) {
throw ex;
}
doneOnce = true;
line = "";
}
// If the line is empty (a blank line), Dispatch the event, as defined below.
if (line.isEmpty()) {
// If the data buffer is an empty string, set the data buffer and the event name buffer to
// the empty string and abort these steps.
if (dataBuffer.length() == 0) {
eventName = "";
continue;
}
// If the event name buffer is not the empty string but is also not a valid NCName,
// set the data buffer and the event name buffer to the empty string and abort these steps.
// NOT IMPLEMENTED
final Event.Builder eventBuilder = new Event.Builder();
eventBuilder.withEventName(eventName.isEmpty() ? Event.MESSAGE_EVENT : eventName);
eventBuilder.withData(dataBuffer.toString());
// Set the data buffer and the event name buffer to the empty string.
dataBuffer = new StringBuilder();
eventName = "";
return eventBuilder.build();
// If the line starts with a U+003A COLON character (':')
} else if (line.startsWith(":")) {
// ignore the line
// If the line contains a U+003A COLON character (':') character
} else if (line.contains(":")) {
// Collect the characters on the line before the first U+003A COLON character (':'),
// and let field be that string.
final int colonIdx = line.indexOf(":");
final String field = line.substring(0, colonIdx);
// Collect the characters on the line after the first U+003A COLON character (':'),
// and let value be that string.
// If value starts with a single U+0020 SPACE character, remove it from value.
String value = line.substring(colonIdx + 1);
value = value.startsWith(" ") ? value.substring(1) : value;
processField(field, value);
// Otherwise, the string is not empty but does not contain a U+003A COLON character (':')
// character
} else {
processField(line, "");
}
}
} | java | protected final Event processEvent() throws IOException {
while (true) {
String line;
try {
line = readLine();
} catch (final EOFException ex) {
if (doneOnce) {
throw ex;
}
doneOnce = true;
line = "";
}
// If the line is empty (a blank line), Dispatch the event, as defined below.
if (line.isEmpty()) {
// If the data buffer is an empty string, set the data buffer and the event name buffer to
// the empty string and abort these steps.
if (dataBuffer.length() == 0) {
eventName = "";
continue;
}
// If the event name buffer is not the empty string but is also not a valid NCName,
// set the data buffer and the event name buffer to the empty string and abort these steps.
// NOT IMPLEMENTED
final Event.Builder eventBuilder = new Event.Builder();
eventBuilder.withEventName(eventName.isEmpty() ? Event.MESSAGE_EVENT : eventName);
eventBuilder.withData(dataBuffer.toString());
// Set the data buffer and the event name buffer to the empty string.
dataBuffer = new StringBuilder();
eventName = "";
return eventBuilder.build();
// If the line starts with a U+003A COLON character (':')
} else if (line.startsWith(":")) {
// ignore the line
// If the line contains a U+003A COLON character (':') character
} else if (line.contains(":")) {
// Collect the characters on the line before the first U+003A COLON character (':'),
// and let field be that string.
final int colonIdx = line.indexOf(":");
final String field = line.substring(0, colonIdx);
// Collect the characters on the line after the first U+003A COLON character (':'),
// and let value be that string.
// If value starts with a single U+0020 SPACE character, remove it from value.
String value = line.substring(colonIdx + 1);
value = value.startsWith(" ") ? value.substring(1) : value;
processField(field, value);
// Otherwise, the string is not empty but does not contain a U+003A COLON character (':')
// character
} else {
processField(line, "");
}
}
} | [
"protected",
"final",
"Event",
"processEvent",
"(",
")",
"throws",
"IOException",
"{",
"while",
"(",
"true",
")",
"{",
"String",
"line",
";",
"try",
"{",
"line",
"=",
"readLine",
"(",
")",
";",
"}",
"catch",
"(",
"final",
"EOFException",
"ex",
")",
"{"... | Process the next event in a given stream.
@return the fully processed event
@throws IOException if a stream is in the wrong state, IO errors can be thrown | [
"Process",
"the",
"next",
"event",
"in",
"a",
"given",
"stream",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/EventStreamReader.java#L86-L144 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/StitchError.java | StitchError.handleRichError | private static String handleRichError(final Response response, final String body) {
if (!response.getHeaders().containsKey(Headers.CONTENT_TYPE)
|| !response.getHeaders().get(Headers.CONTENT_TYPE).equals(ContentTypes.APPLICATION_JSON)) {
return body;
}
final Document doc;
try {
doc = BsonUtils.parseValue(body, Document.class);
} catch (Exception e) {
return body;
}
if (!doc.containsKey(Fields.ERROR)) {
return body;
}
final String errorMsg = doc.getString(Fields.ERROR);
if (!doc.containsKey(Fields.ERROR_CODE)) {
return errorMsg;
}
final String errorCode = doc.getString(Fields.ERROR_CODE);
throw new StitchServiceException(errorMsg, StitchServiceErrorCode.fromCodeName(errorCode));
} | java | private static String handleRichError(final Response response, final String body) {
if (!response.getHeaders().containsKey(Headers.CONTENT_TYPE)
|| !response.getHeaders().get(Headers.CONTENT_TYPE).equals(ContentTypes.APPLICATION_JSON)) {
return body;
}
final Document doc;
try {
doc = BsonUtils.parseValue(body, Document.class);
} catch (Exception e) {
return body;
}
if (!doc.containsKey(Fields.ERROR)) {
return body;
}
final String errorMsg = doc.getString(Fields.ERROR);
if (!doc.containsKey(Fields.ERROR_CODE)) {
return errorMsg;
}
final String errorCode = doc.getString(Fields.ERROR_CODE);
throw new StitchServiceException(errorMsg, StitchServiceErrorCode.fromCodeName(errorCode));
} | [
"private",
"static",
"String",
"handleRichError",
"(",
"final",
"Response",
"response",
",",
"final",
"String",
"body",
")",
"{",
"if",
"(",
"!",
"response",
".",
"getHeaders",
"(",
")",
".",
"containsKey",
"(",
"Headers",
".",
"CONTENT_TYPE",
")",
"||",
"... | Private helper method which decodes the Stitch error from the body of an HTTP `Response`
object. If the error is successfully decoded, this function will throw the error for the end
user to eventually consume. If the error cannot be decoded, this is likely not an error from
the Stitch server, and this function will return an error message that the calling function
should use as the message of a StitchServiceException with an unknown code. | [
"Private",
"helper",
"method",
"which",
"decodes",
"the",
"Stitch",
"error",
"from",
"the",
"body",
"of",
"an",
"HTTP",
"Response",
"object",
".",
"If",
"the",
"error",
"is",
"successfully",
"decoded",
"this",
"function",
"will",
"throw",
"the",
"error",
"fo... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/StitchError.java#L72-L95 | train |
mongodb/stitch-android-sdk | android/core/src/main/java/com/mongodb/stitch/android/core/Stitch.java | Stitch.initialize | public static void initialize(final Context context) {
if (!initialized.compareAndSet(false, true)) {
return;
}
applicationContext = context.getApplicationContext();
final String packageName = applicationContext.getPackageName();
localAppName = packageName;
final PackageManager manager = applicationContext.getPackageManager();
try {
final PackageInfo pkgInfo = manager.getPackageInfo(packageName, 0);
localAppVersion = pkgInfo.versionName;
} catch (final NameNotFoundException e) {
Log.d(TAG, "Failed to get version of application, will not send in device info.");
}
Log.d(TAG, "Initialized android SDK");
} | java | public static void initialize(final Context context) {
if (!initialized.compareAndSet(false, true)) {
return;
}
applicationContext = context.getApplicationContext();
final String packageName = applicationContext.getPackageName();
localAppName = packageName;
final PackageManager manager = applicationContext.getPackageManager();
try {
final PackageInfo pkgInfo = manager.getPackageInfo(packageName, 0);
localAppVersion = pkgInfo.versionName;
} catch (final NameNotFoundException e) {
Log.d(TAG, "Failed to get version of application, will not send in device info.");
}
Log.d(TAG, "Initialized android SDK");
} | [
"public",
"static",
"void",
"initialize",
"(",
"final",
"Context",
"context",
")",
"{",
"if",
"(",
"!",
"initialized",
".",
"compareAndSet",
"(",
"false",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"applicationContext",
"=",
"context",
".",
"getApplic... | Initializes the Stitch SDK so that app clients can be created.
@param context An Android context value. | [
"Initializes",
"the",
"Stitch",
"SDK",
"so",
"that",
"app",
"clients",
"can",
"be",
"created",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/core/src/main/java/com/mongodb/stitch/android/core/Stitch.java#L62-L81 | train |
mongodb/stitch-android-sdk | android/core/src/main/java/com/mongodb/stitch/android/core/Stitch.java | Stitch.getAppClient | public static StitchAppClient getAppClient(
@Nonnull final String clientAppId
) {
ensureInitialized();
synchronized (Stitch.class) {
if (!appClients.containsKey(clientAppId)) {
throw new IllegalStateException(
String.format("client for app '%s' has not yet been initialized", clientAppId));
}
return appClients.get(clientAppId);
}
} | java | public static StitchAppClient getAppClient(
@Nonnull final String clientAppId
) {
ensureInitialized();
synchronized (Stitch.class) {
if (!appClients.containsKey(clientAppId)) {
throw new IllegalStateException(
String.format("client for app '%s' has not yet been initialized", clientAppId));
}
return appClients.get(clientAppId);
}
} | [
"public",
"static",
"StitchAppClient",
"getAppClient",
"(",
"@",
"Nonnull",
"final",
"String",
"clientAppId",
")",
"{",
"ensureInitialized",
"(",
")",
";",
"synchronized",
"(",
"Stitch",
".",
"class",
")",
"{",
"if",
"(",
"!",
"appClients",
".",
"containsKey",... | Gets an app client by its client app id if it has been initialized; throws if none can be
found.
@param clientAppId the client app id of the app client to get.
@return the app client associated with the client app id. | [
"Gets",
"an",
"app",
"client",
"by",
"its",
"client",
"app",
"id",
"if",
"it",
"has",
"been",
"initialized",
";",
"throws",
"if",
"none",
"can",
"be",
"found",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/core/src/main/java/com/mongodb/stitch/android/core/Stitch.java#L114-L126 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java | NamespaceChangeStreamListener.start | public void start() {
nsLock.writeLock().lock();
try {
if (runnerThread != null) {
return;
}
runnerThread =
new Thread(new NamespaceChangeStreamRunner(
new WeakReference<>(this), networkMonitor, logger));
runnerThread.start();
} finally {
nsLock.writeLock().unlock();
}
} | java | public void start() {
nsLock.writeLock().lock();
try {
if (runnerThread != null) {
return;
}
runnerThread =
new Thread(new NamespaceChangeStreamRunner(
new WeakReference<>(this), networkMonitor, logger));
runnerThread.start();
} finally {
nsLock.writeLock().unlock();
}
} | [
"public",
"void",
"start",
"(",
")",
"{",
"nsLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"runnerThread",
"!=",
"null",
")",
"{",
"return",
";",
"}",
"runnerThread",
"=",
"new",
"Thread",
"(",
"new",
"Namesp... | Opens the stream in a background thread. | [
"Opens",
"the",
"stream",
"in",
"a",
"background",
"thread",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java#L91-L104 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java | NamespaceChangeStreamListener.stop | public void stop() {
if (runnerThread == null) {
return;
}
runnerThread.interrupt();
nsLock.writeLock().lock();
try {
if (runnerThread == null) {
return;
}
this.cancel();
this.close();
while (runnerThread.isAlive()) {
runnerThread.interrupt();
try {
runnerThread.join(1000);
} catch (final Exception e) {
e.printStackTrace();
return;
}
}
runnerThread = null;
} catch (Exception e) {
e.printStackTrace();
} finally {
nsLock.writeLock().unlock();
}
} | java | public void stop() {
if (runnerThread == null) {
return;
}
runnerThread.interrupt();
nsLock.writeLock().lock();
try {
if (runnerThread == null) {
return;
}
this.cancel();
this.close();
while (runnerThread.isAlive()) {
runnerThread.interrupt();
try {
runnerThread.join(1000);
} catch (final Exception e) {
e.printStackTrace();
return;
}
}
runnerThread = null;
} catch (Exception e) {
e.printStackTrace();
} finally {
nsLock.writeLock().unlock();
}
} | [
"public",
"void",
"stop",
"(",
")",
"{",
"if",
"(",
"runnerThread",
"==",
"null",
")",
"{",
"return",
";",
"}",
"runnerThread",
".",
"interrupt",
"(",
")",
";",
"nsLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"... | Stops the background stream thread. | [
"Stops",
"the",
"background",
"stream",
"thread",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java#L109-L140 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java | NamespaceChangeStreamListener.openStream | boolean openStream() throws InterruptedException, IOException {
logger.info("stream START");
final boolean isOpen;
final Set<BsonValue> idsToWatch = nsConfig.getSynchronizedDocumentIds();
if (!networkMonitor.isConnected()) {
logger.info("stream END - Network disconnected");
return false;
}
if (idsToWatch.isEmpty()) {
logger.info("stream END - No synchronized documents");
return false;
}
nsLock.writeLock().lockInterruptibly();
try {
if (!authMonitor.isLoggedIn()) {
logger.info("stream END - Logged out");
return false;
}
final Document args = new Document();
args.put("database", namespace.getDatabaseName());
args.put("collection", namespace.getCollectionName());
args.put("ids", idsToWatch);
currentStream =
service.streamFunction(
"watch",
Collections.singletonList(args),
ResultDecoders.changeEventDecoder(BSON_DOCUMENT_CODEC));
if (currentStream != null && currentStream.isOpen()) {
this.nsConfig.setStale(true);
isOpen = true;
} else {
isOpen = false;
}
} finally {
nsLock.writeLock().unlock();
}
return isOpen;
} | java | boolean openStream() throws InterruptedException, IOException {
logger.info("stream START");
final boolean isOpen;
final Set<BsonValue> idsToWatch = nsConfig.getSynchronizedDocumentIds();
if (!networkMonitor.isConnected()) {
logger.info("stream END - Network disconnected");
return false;
}
if (idsToWatch.isEmpty()) {
logger.info("stream END - No synchronized documents");
return false;
}
nsLock.writeLock().lockInterruptibly();
try {
if (!authMonitor.isLoggedIn()) {
logger.info("stream END - Logged out");
return false;
}
final Document args = new Document();
args.put("database", namespace.getDatabaseName());
args.put("collection", namespace.getCollectionName());
args.put("ids", idsToWatch);
currentStream =
service.streamFunction(
"watch",
Collections.singletonList(args),
ResultDecoders.changeEventDecoder(BSON_DOCUMENT_CODEC));
if (currentStream != null && currentStream.isOpen()) {
this.nsConfig.setStale(true);
isOpen = true;
} else {
isOpen = false;
}
} finally {
nsLock.writeLock().unlock();
}
return isOpen;
} | [
"boolean",
"openStream",
"(",
")",
"throws",
"InterruptedException",
",",
"IOException",
"{",
"logger",
".",
"info",
"(",
"\"stream START\"",
")",
";",
"final",
"boolean",
"isOpen",
";",
"final",
"Set",
"<",
"BsonValue",
">",
"idsToWatch",
"=",
"nsConfig",
"."... | Open the event stream
@return true if successfully opened, false if not | [
"Open",
"the",
"event",
"stream"
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java#L193-L236 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java | NamespaceChangeStreamListener.getEvents | @SuppressWarnings("unchecked")
public Map<BsonValue, ChangeEvent<BsonDocument>> getEvents() {
nsLock.readLock().lock();
final Map<BsonValue, ChangeEvent<BsonDocument>> events;
try {
events = new HashMap<>(this.events);
} finally {
nsLock.readLock().unlock();
}
nsLock.writeLock().lock();
try {
this.events.clear();
return events;
} finally {
nsLock.writeLock().unlock();
}
} | java | @SuppressWarnings("unchecked")
public Map<BsonValue, ChangeEvent<BsonDocument>> getEvents() {
nsLock.readLock().lock();
final Map<BsonValue, ChangeEvent<BsonDocument>> events;
try {
events = new HashMap<>(this.events);
} finally {
nsLock.readLock().unlock();
}
nsLock.writeLock().lock();
try {
this.events.clear();
return events;
} finally {
nsLock.writeLock().unlock();
}
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"Map",
"<",
"BsonValue",
",",
"ChangeEvent",
"<",
"BsonDocument",
">",
">",
"getEvents",
"(",
")",
"{",
"nsLock",
".",
"readLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"final",
"Map",
"<",
... | Returns the latest change events, and clears them from the change stream listener.
@return the latest change events. | [
"Returns",
"the",
"latest",
"change",
"events",
"and",
"clears",
"them",
"from",
"the",
"change",
"stream",
"listener",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java#L301-L318 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java | NamespaceChangeStreamListener.getUnprocessedEventForDocumentId | public @Nullable ChangeEvent<BsonDocument> getUnprocessedEventForDocumentId(
final BsonValue documentId
) {
final ChangeEvent<BsonDocument> event;
nsLock.readLock().lock();
try {
event = this.events.get(documentId);
} finally {
nsLock.readLock().unlock();
}
nsLock.writeLock().lock();
try {
this.events.remove(documentId);
return event;
} finally {
nsLock.writeLock().unlock();
}
} | java | public @Nullable ChangeEvent<BsonDocument> getUnprocessedEventForDocumentId(
final BsonValue documentId
) {
final ChangeEvent<BsonDocument> event;
nsLock.readLock().lock();
try {
event = this.events.get(documentId);
} finally {
nsLock.readLock().unlock();
}
nsLock.writeLock().lock();
try {
this.events.remove(documentId);
return event;
} finally {
nsLock.writeLock().unlock();
}
} | [
"public",
"@",
"Nullable",
"ChangeEvent",
"<",
"BsonDocument",
">",
"getUnprocessedEventForDocumentId",
"(",
"final",
"BsonValue",
"documentId",
")",
"{",
"final",
"ChangeEvent",
"<",
"BsonDocument",
">",
"event",
";",
"nsLock",
".",
"readLock",
"(",
")",
".",
"... | If there is an unprocessed change event for a particular document ID, fetch it from the
change stream listener, and remove it. By reading the event here, we are assuming it will be
processed by the consumer.
@return the latest unprocessed change event for the given document ID, or null if none exists. | [
"If",
"there",
"is",
"an",
"unprocessed",
"change",
"event",
"for",
"a",
"particular",
"document",
"ID",
"fetch",
"it",
"from",
"the",
"change",
"stream",
"listener",
"and",
"remove",
"it",
".",
"By",
"reading",
"the",
"event",
"here",
"we",
"are",
"assumi... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/NamespaceChangeStreamListener.java#L327-L345 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/HashUtils.java | HashUtils.hash | public static long hash(final BsonDocument doc) {
if (doc == null) {
return 0L;
}
final byte[] docBytes = toBytes(doc);
long hashValue = FNV_64BIT_OFFSET_BASIS;
for (int offset = 0; offset < docBytes.length; offset++) {
hashValue ^= (0xFF & docBytes[offset]);
hashValue *= FNV_64BIT_PRIME;
}
return hashValue;
} | java | public static long hash(final BsonDocument doc) {
if (doc == null) {
return 0L;
}
final byte[] docBytes = toBytes(doc);
long hashValue = FNV_64BIT_OFFSET_BASIS;
for (int offset = 0; offset < docBytes.length; offset++) {
hashValue ^= (0xFF & docBytes[offset]);
hashValue *= FNV_64BIT_PRIME;
}
return hashValue;
} | [
"public",
"static",
"long",
"hash",
"(",
"final",
"BsonDocument",
"doc",
")",
"{",
"if",
"(",
"doc",
"==",
"null",
")",
"{",
"return",
"0L",
";",
"}",
"final",
"byte",
"[",
"]",
"docBytes",
"=",
"toBytes",
"(",
"doc",
")",
";",
"long",
"hashValue",
... | Implementation of FNV-1a hash algorithm.
@see <a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function">
ttps://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function</a>
@param doc the document to hash
@return | [
"Implementation",
"of",
"FNV",
"-",
"1a",
"hash",
"algorithm",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/HashUtils.java#L45-L59 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/SyncMongoClientFactory.java | SyncMongoClientFactory.deleteDatabase | public static boolean deleteDatabase(final StitchAppClientInfo appInfo,
final String serviceName,
final EmbeddedMongoClientFactory clientFactory,
final String userId) {
final String dataDir = appInfo.getDataDirectory();
if (dataDir == null) {
throw new IllegalArgumentException("StitchAppClient not configured with a data directory");
}
final String instanceKey = String.format(
"%s-%s_sync_%s_%s", appInfo.getClientAppId(), dataDir, serviceName, userId);
final String dbPath = String.format(
"%s/%s/sync_mongodb_%s/%s/0/", dataDir, appInfo.getClientAppId(), serviceName, userId);
final MongoClient client =
clientFactory.getClient(instanceKey, dbPath, appInfo.getCodecRegistry());
for (final String listDatabaseName : client.listDatabaseNames()) {
try {
client.getDatabase(listDatabaseName).drop();
} catch (Exception e) {
// do nothing
}
}
client.close();
clientFactory.removeClient(instanceKey);
return new File(dbPath).delete();
} | java | public static boolean deleteDatabase(final StitchAppClientInfo appInfo,
final String serviceName,
final EmbeddedMongoClientFactory clientFactory,
final String userId) {
final String dataDir = appInfo.getDataDirectory();
if (dataDir == null) {
throw new IllegalArgumentException("StitchAppClient not configured with a data directory");
}
final String instanceKey = String.format(
"%s-%s_sync_%s_%s", appInfo.getClientAppId(), dataDir, serviceName, userId);
final String dbPath = String.format(
"%s/%s/sync_mongodb_%s/%s/0/", dataDir, appInfo.getClientAppId(), serviceName, userId);
final MongoClient client =
clientFactory.getClient(instanceKey, dbPath, appInfo.getCodecRegistry());
for (final String listDatabaseName : client.listDatabaseNames()) {
try {
client.getDatabase(listDatabaseName).drop();
} catch (Exception e) {
// do nothing
}
}
client.close();
clientFactory.removeClient(instanceKey);
return new File(dbPath).delete();
} | [
"public",
"static",
"boolean",
"deleteDatabase",
"(",
"final",
"StitchAppClientInfo",
"appInfo",
",",
"final",
"String",
"serviceName",
",",
"final",
"EmbeddedMongoClientFactory",
"clientFactory",
",",
"final",
"String",
"userId",
")",
"{",
"final",
"String",
"dataDir... | Delete a database for a given path and userId.
@param appInfo the info for this application
@param serviceName the name of the associated service
@param clientFactory the associated factory that creates clients
@param userId the id of the user's to delete
@return true if successfully deleted, false if not | [
"Delete",
"a",
"database",
"for",
"a",
"given",
"path",
"and",
"userId",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/SyncMongoClientFactory.java#L53-L81 | train |
mongodb/stitch-android-sdk | android/services/mongodb-remote/src/main/java/com/mongodb/stitch/android/services/mongodb/remote/internal/RemoteMongoCollectionImpl.java | RemoteMongoCollectionImpl.count | public Task<Long> count() {
return dispatcher.dispatchTask(new Callable<Long>() {
@Override
public Long call() {
return proxy.count();
}
});
} | java | public Task<Long> count() {
return dispatcher.dispatchTask(new Callable<Long>() {
@Override
public Long call() {
return proxy.count();
}
});
} | [
"public",
"Task",
"<",
"Long",
">",
"count",
"(",
")",
"{",
"return",
"dispatcher",
".",
"dispatchTask",
"(",
"new",
"Callable",
"<",
"Long",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Long",
"call",
"(",
")",
"{",
"return",
"proxy",
".",
"count... | Counts the number of documents in the collection.
@return a task containing the number of documents in the collection | [
"Counts",
"the",
"number",
"of",
"documents",
"in",
"the",
"collection",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/services/mongodb-remote/src/main/java/com/mongodb/stitch/android/services/mongodb/remote/internal/RemoteMongoCollectionImpl.java#L106-L113 | train |
mongodb/stitch-android-sdk | android/services/mongodb-remote/src/main/java/com/mongodb/stitch/android/services/mongodb/remote/internal/RemoteMongoCollectionImpl.java | RemoteMongoCollectionImpl.insertOne | public Task<RemoteInsertOneResult> insertOne(final DocumentT document) {
return dispatcher.dispatchTask(new Callable<RemoteInsertOneResult>() {
@Override
public RemoteInsertOneResult call() {
return proxy.insertOne(document);
}
});
} | java | public Task<RemoteInsertOneResult> insertOne(final DocumentT document) {
return dispatcher.dispatchTask(new Callable<RemoteInsertOneResult>() {
@Override
public RemoteInsertOneResult call() {
return proxy.insertOne(document);
}
});
} | [
"public",
"Task",
"<",
"RemoteInsertOneResult",
">",
"insertOne",
"(",
"final",
"DocumentT",
"document",
")",
"{",
"return",
"dispatcher",
".",
"dispatchTask",
"(",
"new",
"Callable",
"<",
"RemoteInsertOneResult",
">",
"(",
")",
"{",
"@",
"Override",
"public",
... | Inserts the provided document. If the document is missing an identifier, the client should
generate one.
@param document the document to insert
@return a task containing the result of the insert one operation | [
"Inserts",
"the",
"provided",
"document",
".",
"If",
"the",
"document",
"is",
"missing",
"an",
"identifier",
"the",
"client",
"should",
"generate",
"one",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/services/mongodb-remote/src/main/java/com/mongodb/stitch/android/services/mongodb/remote/internal/RemoteMongoCollectionImpl.java#L324-L331 | train |
mongodb/stitch-android-sdk | android/core/src/main/java/com/mongodb/stitch/android/core/auth/providers/userpassword/internal/UserPasswordAuthProviderClientImpl.java | UserPasswordAuthProviderClientImpl.registerWithEmail | public Task<Void> registerWithEmail(@NonNull final String email, @NonNull final String password) {
return dispatcher.dispatchTask(
new Callable<Void>() {
@Override
public Void call() {
registerWithEmailInternal(email, password);
return null;
}
});
} | java | public Task<Void> registerWithEmail(@NonNull final String email, @NonNull final String password) {
return dispatcher.dispatchTask(
new Callable<Void>() {
@Override
public Void call() {
registerWithEmailInternal(email, password);
return null;
}
});
} | [
"public",
"Task",
"<",
"Void",
">",
"registerWithEmail",
"(",
"@",
"NonNull",
"final",
"String",
"email",
",",
"@",
"NonNull",
"final",
"String",
"password",
")",
"{",
"return",
"dispatcher",
".",
"dispatchTask",
"(",
"new",
"Callable",
"<",
"Void",
">",
"... | Registers a new user with the given email and password.
@param email the email to register with. This will be the username used during log in.
@param password the password to associated with the email. The password must be between
6 and 128 characters long.
@return A {@link Task} that completes when registration completes/fails. | [
"Registers",
"a",
"new",
"user",
"with",
"the",
"given",
"email",
"and",
"password",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/core/src/main/java/com/mongodb/stitch/android/core/auth/providers/userpassword/internal/UserPasswordAuthProviderClientImpl.java#L62-L71 | train |
mongodb/stitch-android-sdk | android/core/src/main/java/com/mongodb/stitch/android/core/auth/providers/userpassword/internal/UserPasswordAuthProviderClientImpl.java | UserPasswordAuthProviderClientImpl.confirmUser | public Task<Void> confirmUser(@NonNull final String token, @NonNull final String tokenId) {
return dispatcher.dispatchTask(
new Callable<Void>() {
@Override
public Void call() {
confirmUserInternal(token, tokenId);
return null;
}
});
} | java | public Task<Void> confirmUser(@NonNull final String token, @NonNull final String tokenId) {
return dispatcher.dispatchTask(
new Callable<Void>() {
@Override
public Void call() {
confirmUserInternal(token, tokenId);
return null;
}
});
} | [
"public",
"Task",
"<",
"Void",
">",
"confirmUser",
"(",
"@",
"NonNull",
"final",
"String",
"token",
",",
"@",
"NonNull",
"final",
"String",
"tokenId",
")",
"{",
"return",
"dispatcher",
".",
"dispatchTask",
"(",
"new",
"Callable",
"<",
"Void",
">",
"(",
"... | Confirms a user with the given token and token id.
@param token the confirmation token.
@param tokenId the id of the confirmation token.
@return A {@link Task} that completes when confirmation completes/fails. | [
"Confirms",
"a",
"user",
"with",
"the",
"given",
"token",
"and",
"token",
"id",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/core/src/main/java/com/mongodb/stitch/android/core/auth/providers/userpassword/internal/UserPasswordAuthProviderClientImpl.java#L80-L89 | train |
mongodb/stitch-android-sdk | android/core/src/main/java/com/mongodb/stitch/android/core/auth/providers/userpassword/internal/UserPasswordAuthProviderClientImpl.java | UserPasswordAuthProviderClientImpl.resendConfirmationEmail | public Task<Void> resendConfirmationEmail(@NonNull final String email) {
return dispatcher.dispatchTask(
new Callable<Void>() {
@Override
public Void call() {
resendConfirmationEmailInternal(email);
return null;
}
});
} | java | public Task<Void> resendConfirmationEmail(@NonNull final String email) {
return dispatcher.dispatchTask(
new Callable<Void>() {
@Override
public Void call() {
resendConfirmationEmailInternal(email);
return null;
}
});
} | [
"public",
"Task",
"<",
"Void",
">",
"resendConfirmationEmail",
"(",
"@",
"NonNull",
"final",
"String",
"email",
")",
"{",
"return",
"dispatcher",
".",
"dispatchTask",
"(",
"new",
"Callable",
"<",
"Void",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Void... | Resend the confirmation for a user to the given email.
@param email the email of the user.
@return A {@link Task} that completes when the resend request completes/fails. | [
"Resend",
"the",
"confirmation",
"for",
"a",
"user",
"to",
"the",
"given",
"email",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/core/src/main/java/com/mongodb/stitch/android/core/auth/providers/userpassword/internal/UserPasswordAuthProviderClientImpl.java#L97-L106 | train |
mongodb/stitch-android-sdk | android/core/src/main/java/com/mongodb/stitch/android/core/auth/providers/userpassword/internal/UserPasswordAuthProviderClientImpl.java | UserPasswordAuthProviderClientImpl.sendResetPasswordEmail | public Task<Void> sendResetPasswordEmail(@NonNull final String email) {
return dispatcher.dispatchTask(
new Callable<Void>() {
@Override
public Void call() {
sendResetPasswordEmailInternal(email);
return null;
}
});
} | java | public Task<Void> sendResetPasswordEmail(@NonNull final String email) {
return dispatcher.dispatchTask(
new Callable<Void>() {
@Override
public Void call() {
sendResetPasswordEmailInternal(email);
return null;
}
});
} | [
"public",
"Task",
"<",
"Void",
">",
"sendResetPasswordEmail",
"(",
"@",
"NonNull",
"final",
"String",
"email",
")",
"{",
"return",
"dispatcher",
".",
"dispatchTask",
"(",
"new",
"Callable",
"<",
"Void",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"Void"... | Sends a user a password reset email for the given email.
@param email the email of the user.
@return A {@link Task} that completes when the reqest request completes/fails. | [
"Sends",
"a",
"user",
"a",
"password",
"reset",
"email",
"for",
"the",
"given",
"email",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/core/src/main/java/com/mongodb/stitch/android/core/auth/providers/userpassword/internal/UserPasswordAuthProviderClientImpl.java#L135-L144 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreRemoteMongoCollectionWriteModelContainer.java | CoreRemoteMongoCollectionWriteModelContainer.commit | @Override
public boolean commit() {
final CoreRemoteMongoCollection<DocumentT> collection = getCollection();
final List<WriteModel<DocumentT>> writeModels = getBulkWriteModels();
// define success as any one operation succeeding for now
boolean success = true;
for (final WriteModel<DocumentT> write : writeModels) {
if (write instanceof ReplaceOneModel) {
final ReplaceOneModel<DocumentT> replaceModel = ((ReplaceOneModel) write);
final RemoteUpdateResult result =
collection.updateOne(replaceModel.getFilter(), (Bson) replaceModel.getReplacement());
success = success
&& (result != null && result.getModifiedCount() == result.getMatchedCount());
} else if (write instanceof UpdateOneModel) {
final UpdateOneModel<DocumentT> updateModel = ((UpdateOneModel) write);
final RemoteUpdateResult result =
collection.updateOne(updateModel.getFilter(), updateModel.getUpdate());
success = success
&& (result != null && result.getModifiedCount() == result.getMatchedCount());
} else if (write instanceof UpdateManyModel) {
final UpdateManyModel<DocumentT> updateModel = ((UpdateManyModel) write);
final RemoteUpdateResult result =
collection.updateMany(updateModel.getFilter(), updateModel.getUpdate());
success = success
&& (result != null && result.getModifiedCount() == result.getMatchedCount());
}
}
return success;
} | java | @Override
public boolean commit() {
final CoreRemoteMongoCollection<DocumentT> collection = getCollection();
final List<WriteModel<DocumentT>> writeModels = getBulkWriteModels();
// define success as any one operation succeeding for now
boolean success = true;
for (final WriteModel<DocumentT> write : writeModels) {
if (write instanceof ReplaceOneModel) {
final ReplaceOneModel<DocumentT> replaceModel = ((ReplaceOneModel) write);
final RemoteUpdateResult result =
collection.updateOne(replaceModel.getFilter(), (Bson) replaceModel.getReplacement());
success = success
&& (result != null && result.getModifiedCount() == result.getMatchedCount());
} else if (write instanceof UpdateOneModel) {
final UpdateOneModel<DocumentT> updateModel = ((UpdateOneModel) write);
final RemoteUpdateResult result =
collection.updateOne(updateModel.getFilter(), updateModel.getUpdate());
success = success
&& (result != null && result.getModifiedCount() == result.getMatchedCount());
} else if (write instanceof UpdateManyModel) {
final UpdateManyModel<DocumentT> updateModel = ((UpdateManyModel) write);
final RemoteUpdateResult result =
collection.updateMany(updateModel.getFilter(), updateModel.getUpdate());
success = success
&& (result != null && result.getModifiedCount() == result.getMatchedCount());
}
}
return success;
} | [
"@",
"Override",
"public",
"boolean",
"commit",
"(",
")",
"{",
"final",
"CoreRemoteMongoCollection",
"<",
"DocumentT",
">",
"collection",
"=",
"getCollection",
"(",
")",
";",
"final",
"List",
"<",
"WriteModel",
"<",
"DocumentT",
">",
">",
"writeModels",
"=",
... | Commits the writes to the remote collection. | [
"Commits",
"the",
"writes",
"to",
"the",
"remote",
"collection",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/CoreRemoteMongoCollectionWriteModelContainer.java#L47-L76 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/StitchAppRequestClientImpl.java | StitchAppRequestClientImpl.doRequest | @Override
public Response doRequest(final StitchRequest stitchReq) {
initAppMetadata(clientAppId);
return super.doRequestUrl(stitchReq, getHostname());
} | java | @Override
public Response doRequest(final StitchRequest stitchReq) {
initAppMetadata(clientAppId);
return super.doRequestUrl(stitchReq, getHostname());
} | [
"@",
"Override",
"public",
"Response",
"doRequest",
"(",
"final",
"StitchRequest",
"stitchReq",
")",
"{",
"initAppMetadata",
"(",
"clientAppId",
")",
";",
"return",
"super",
".",
"doRequestUrl",
"(",
"stitchReq",
",",
"getHostname",
"(",
")",
")",
";",
"}"
] | Performs a request against a Stitch app server determined by the deployment model
of the underlying app. Throws a Stitch specific exception if the request fails.
@param stitchReq the request to perform.
@return a {@link Response} to the request. | [
"Performs",
"a",
"request",
"against",
"a",
"Stitch",
"app",
"server",
"determined",
"by",
"the",
"deployment",
"model",
"of",
"the",
"underlying",
"app",
".",
"Throws",
"a",
"Stitch",
"specific",
"exception",
"if",
"the",
"request",
"fails",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/StitchAppRequestClientImpl.java#L51-L56 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/StitchAppRequestClientImpl.java | StitchAppRequestClientImpl.doStreamRequest | @Override
public EventStream doStreamRequest(final StitchRequest stitchReq) {
initAppMetadata(clientAppId);
return super.doStreamRequestUrl(stitchReq, getHostname());
} | java | @Override
public EventStream doStreamRequest(final StitchRequest stitchReq) {
initAppMetadata(clientAppId);
return super.doStreamRequestUrl(stitchReq, getHostname());
} | [
"@",
"Override",
"public",
"EventStream",
"doStreamRequest",
"(",
"final",
"StitchRequest",
"stitchReq",
")",
"{",
"initAppMetadata",
"(",
"clientAppId",
")",
";",
"return",
"super",
".",
"doStreamRequestUrl",
"(",
"stitchReq",
",",
"getHostname",
"(",
")",
")",
... | Performs a streaming request against a Stitch app server determined by the deployment model
of the underlying app. Throws a Stitch specific exception if the request fails.
@param stitchReq the request to perform.
@return an {@link EventStream} that will provide response events. | [
"Performs",
"a",
"streaming",
"request",
"against",
"a",
"Stitch",
"app",
"server",
"determined",
"by",
"the",
"deployment",
"model",
"of",
"the",
"underlying",
"app",
".",
"Throws",
"a",
"Stitch",
"specific",
"exception",
"if",
"the",
"request",
"fails",
"."
... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/StitchAppRequestClientImpl.java#L65-L70 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/UpdateDescription.java | UpdateDescription.toUpdateDocument | public BsonDocument toUpdateDocument() {
final List<BsonElement> unsets = new ArrayList<>();
for (final String removedField : this.removedFields) {
unsets.add(new BsonElement(removedField, new BsonBoolean(true)));
}
final BsonDocument updateDocument = new BsonDocument();
if (this.updatedFields.size() > 0) {
updateDocument.append("$set", this.updatedFields);
}
if (unsets.size() > 0) {
updateDocument.append("$unset", new BsonDocument(unsets));
}
return updateDocument;
} | java | public BsonDocument toUpdateDocument() {
final List<BsonElement> unsets = new ArrayList<>();
for (final String removedField : this.removedFields) {
unsets.add(new BsonElement(removedField, new BsonBoolean(true)));
}
final BsonDocument updateDocument = new BsonDocument();
if (this.updatedFields.size() > 0) {
updateDocument.append("$set", this.updatedFields);
}
if (unsets.size() > 0) {
updateDocument.append("$unset", new BsonDocument(unsets));
}
return updateDocument;
} | [
"public",
"BsonDocument",
"toUpdateDocument",
"(",
")",
"{",
"final",
"List",
"<",
"BsonElement",
">",
"unsets",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"final",
"String",
"removedField",
":",
"this",
".",
"removedFields",
")",
"{",
"unse... | Convert this update description to an update document.
@return an update document with the appropriate $set and $unset documents. | [
"Convert",
"this",
"update",
"description",
"to",
"an",
"update",
"document",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/UpdateDescription.java#L84-L100 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/UpdateDescription.java | UpdateDescription.toBsonDocument | public BsonDocument toBsonDocument() {
final BsonDocument updateDescDoc = new BsonDocument();
updateDescDoc.put(
Fields.UPDATED_FIELDS_FIELD,
this.getUpdatedFields());
final BsonArray removedFields = new BsonArray();
for (final String field : this.getRemovedFields()) {
removedFields.add(new BsonString(field));
}
updateDescDoc.put(
Fields.REMOVED_FIELDS_FIELD,
removedFields);
return updateDescDoc;
} | java | public BsonDocument toBsonDocument() {
final BsonDocument updateDescDoc = new BsonDocument();
updateDescDoc.put(
Fields.UPDATED_FIELDS_FIELD,
this.getUpdatedFields());
final BsonArray removedFields = new BsonArray();
for (final String field : this.getRemovedFields()) {
removedFields.add(new BsonString(field));
}
updateDescDoc.put(
Fields.REMOVED_FIELDS_FIELD,
removedFields);
return updateDescDoc;
} | [
"public",
"BsonDocument",
"toBsonDocument",
"(",
")",
"{",
"final",
"BsonDocument",
"updateDescDoc",
"=",
"new",
"BsonDocument",
"(",
")",
";",
"updateDescDoc",
".",
"put",
"(",
"Fields",
".",
"UPDATED_FIELDS_FIELD",
",",
"this",
".",
"getUpdatedFields",
"(",
")... | Converts this update description to its document representation as it would appear in a
MongoDB Change Event.
@return the update description document as it would appear in a change event | [
"Converts",
"this",
"update",
"description",
"to",
"its",
"document",
"representation",
"as",
"it",
"would",
"appear",
"in",
"a",
"MongoDB",
"Change",
"Event",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/UpdateDescription.java#L108-L123 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/UpdateDescription.java | UpdateDescription.fromBsonDocument | public static UpdateDescription fromBsonDocument(final BsonDocument document) {
keyPresent(Fields.UPDATED_FIELDS_FIELD, document);
keyPresent(Fields.REMOVED_FIELDS_FIELD, document);
final BsonArray removedFieldsArr =
document.getArray(Fields.REMOVED_FIELDS_FIELD);
final Set<String> removedFields = new HashSet<>(removedFieldsArr.size());
for (final BsonValue field : removedFieldsArr) {
removedFields.add(field.asString().getValue());
}
return new UpdateDescription(document.getDocument(Fields.UPDATED_FIELDS_FIELD), removedFields);
} | java | public static UpdateDescription fromBsonDocument(final BsonDocument document) {
keyPresent(Fields.UPDATED_FIELDS_FIELD, document);
keyPresent(Fields.REMOVED_FIELDS_FIELD, document);
final BsonArray removedFieldsArr =
document.getArray(Fields.REMOVED_FIELDS_FIELD);
final Set<String> removedFields = new HashSet<>(removedFieldsArr.size());
for (final BsonValue field : removedFieldsArr) {
removedFields.add(field.asString().getValue());
}
return new UpdateDescription(document.getDocument(Fields.UPDATED_FIELDS_FIELD), removedFields);
} | [
"public",
"static",
"UpdateDescription",
"fromBsonDocument",
"(",
"final",
"BsonDocument",
"document",
")",
"{",
"keyPresent",
"(",
"Fields",
".",
"UPDATED_FIELDS_FIELD",
",",
"document",
")",
";",
"keyPresent",
"(",
"Fields",
".",
"REMOVED_FIELDS_FIELD",
",",
"docu... | Converts an update description BSON document from a MongoDB Change Event into an
UpdateDescription object.
@param document the
@return the converted UpdateDescription | [
"Converts",
"an",
"update",
"description",
"BSON",
"document",
"from",
"a",
"MongoDB",
"Change",
"Event",
"into",
"an",
"UpdateDescription",
"object",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/UpdateDescription.java#L132-L144 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/UpdateDescription.java | UpdateDescription.merge | public UpdateDescription merge(@Nullable final UpdateDescription otherDescription) {
if (otherDescription != null) {
for (final Map.Entry<String, BsonValue> entry : this.updatedFields.entrySet()) {
if (otherDescription.removedFields.contains(entry.getKey())) {
this.updatedFields.remove(entry.getKey());
}
}
for (final String removedField : this.removedFields) {
if (otherDescription.updatedFields.containsKey(removedField)) {
this.removedFields.remove(removedField);
}
}
this.removedFields.addAll(otherDescription.removedFields);
this.updatedFields.putAll(otherDescription.updatedFields);
}
return this;
} | java | public UpdateDescription merge(@Nullable final UpdateDescription otherDescription) {
if (otherDescription != null) {
for (final Map.Entry<String, BsonValue> entry : this.updatedFields.entrySet()) {
if (otherDescription.removedFields.contains(entry.getKey())) {
this.updatedFields.remove(entry.getKey());
}
}
for (final String removedField : this.removedFields) {
if (otherDescription.updatedFields.containsKey(removedField)) {
this.removedFields.remove(removedField);
}
}
this.removedFields.addAll(otherDescription.removedFields);
this.updatedFields.putAll(otherDescription.updatedFields);
}
return this;
} | [
"public",
"UpdateDescription",
"merge",
"(",
"@",
"Nullable",
"final",
"UpdateDescription",
"otherDescription",
")",
"{",
"if",
"(",
"otherDescription",
"!=",
"null",
")",
"{",
"for",
"(",
"final",
"Map",
".",
"Entry",
"<",
"String",
",",
"BsonValue",
">",
"... | Unilaterally merge an update description into this update description.
@param otherDescription the update description to merge into this
@return this merged update description | [
"Unilaterally",
"merge",
"an",
"update",
"description",
"into",
"this",
"update",
"description",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/UpdateDescription.java#L151-L169 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionImpl.java | CoreRemoteMongoCollectionImpl.watch | @Override
@SuppressWarnings("unchecked")
public Stream<ChangeEvent<DocumentT>> watch(final BsonValue... ids)
throws InterruptedException, IOException {
return operations.watch(
new HashSet<>(Arrays.asList(ids)),
false,
documentClass
).execute(service);
} | java | @Override
@SuppressWarnings("unchecked")
public Stream<ChangeEvent<DocumentT>> watch(final BsonValue... ids)
throws InterruptedException, IOException {
return operations.watch(
new HashSet<>(Arrays.asList(ids)),
false,
documentClass
).execute(service);
} | [
"@",
"Override",
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"Stream",
"<",
"ChangeEvent",
"<",
"DocumentT",
">",
">",
"watch",
"(",
"final",
"BsonValue",
"...",
"ids",
")",
"throws",
"InterruptedException",
",",
"IOException",
"{",
"return",
... | Watches specified IDs in a collection.
@param ids the ids to watch.
@return the stream of change events. | [
"Watches",
"specified",
"IDs",
"in",
"a",
"collection",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/internal/CoreRemoteMongoCollectionImpl.java#L709-L718 | train |
mongodb/stitch-android-sdk | android/services/mongodb-remote/src/main/java/com/mongodb/stitch/android/services/mongodb/remote/internal/SyncImpl.java | SyncImpl.updateSyncFrequency | public Task<Void> updateSyncFrequency(@NonNull final SyncFrequency syncFrequency) {
return this.dispatcher.dispatchTask(new Callable<Void>() {
@Override
public Void call() throws Exception {
SyncImpl.this.proxy.updateSyncFrequency(syncFrequency);
return null;
}
});
} | java | public Task<Void> updateSyncFrequency(@NonNull final SyncFrequency syncFrequency) {
return this.dispatcher.dispatchTask(new Callable<Void>() {
@Override
public Void call() throws Exception {
SyncImpl.this.proxy.updateSyncFrequency(syncFrequency);
return null;
}
});
} | [
"public",
"Task",
"<",
"Void",
">",
"updateSyncFrequency",
"(",
"@",
"NonNull",
"final",
"SyncFrequency",
"syncFrequency",
")",
"{",
"return",
"this",
".",
"dispatcher",
".",
"dispatchTask",
"(",
"new",
"Callable",
"<",
"Void",
">",
"(",
")",
"{",
"@",
"Ov... | Sets the SyncFrequency on this collection.
@param syncFrequency the SyncFrequency that contains all the desired options
@return A Task that completes when the SyncFrequency has been updated | [
"Sets",
"the",
"SyncFrequency",
"on",
"this",
"collection",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/services/mongodb-remote/src/main/java/com/mongodb/stitch/android/services/mongodb/remote/internal/SyncImpl.java#L95-L103 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/EventDispatcher.java | EventDispatcher.emitEvent | public void emitEvent(
final NamespaceSynchronizationConfig nsConfig,
final ChangeEvent<BsonDocument> event) {
listenersLock.lock();
try {
if (nsConfig.getNamespaceListenerConfig() == null) {
return;
}
final NamespaceListenerConfig namespaceListener =
nsConfig.getNamespaceListenerConfig();
eventDispatcher.dispatch(() -> {
try {
if (namespaceListener.getEventListener() != null) {
namespaceListener.getEventListener().onEvent(
BsonUtils.getDocumentId(event.getDocumentKey()),
ChangeEvents.transformChangeEventForUser(
event, namespaceListener.getDocumentCodec()));
}
} catch (final Exception ex) {
logger.error(String.format(
Locale.US,
"emitEvent ns=%s documentId=%s emit exception: %s",
event.getNamespace(),
BsonUtils.getDocumentId(event.getDocumentKey()),
ex), ex);
}
return null;
});
} finally {
listenersLock.unlock();
}
} | java | public void emitEvent(
final NamespaceSynchronizationConfig nsConfig,
final ChangeEvent<BsonDocument> event) {
listenersLock.lock();
try {
if (nsConfig.getNamespaceListenerConfig() == null) {
return;
}
final NamespaceListenerConfig namespaceListener =
nsConfig.getNamespaceListenerConfig();
eventDispatcher.dispatch(() -> {
try {
if (namespaceListener.getEventListener() != null) {
namespaceListener.getEventListener().onEvent(
BsonUtils.getDocumentId(event.getDocumentKey()),
ChangeEvents.transformChangeEventForUser(
event, namespaceListener.getDocumentCodec()));
}
} catch (final Exception ex) {
logger.error(String.format(
Locale.US,
"emitEvent ns=%s documentId=%s emit exception: %s",
event.getNamespace(),
BsonUtils.getDocumentId(event.getDocumentKey()),
ex), ex);
}
return null;
});
} finally {
listenersLock.unlock();
}
} | [
"public",
"void",
"emitEvent",
"(",
"final",
"NamespaceSynchronizationConfig",
"nsConfig",
",",
"final",
"ChangeEvent",
"<",
"BsonDocument",
">",
"event",
")",
"{",
"listenersLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"nsConfig",
".",
"getNamesp... | Emits a change event for the given document id.
@param nsConfig the configuration for the namespace to which the
document referred to by the change event belongs.
@param event the change event. | [
"Emits",
"a",
"change",
"event",
"for",
"the",
"given",
"document",
"id",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/EventDispatcher.java#L50-L81 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/ChangeEvents.java | ChangeEvents.changeEventForLocalInsert | static ChangeEvent<BsonDocument> changeEventForLocalInsert(
final MongoNamespace namespace,
final BsonDocument document,
final boolean writePending
) {
final BsonValue docId = BsonUtils.getDocumentId(document);
return new ChangeEvent<>(
new BsonDocument(),
OperationType.INSERT,
document,
namespace,
new BsonDocument("_id", docId),
null,
writePending);
} | java | static ChangeEvent<BsonDocument> changeEventForLocalInsert(
final MongoNamespace namespace,
final BsonDocument document,
final boolean writePending
) {
final BsonValue docId = BsonUtils.getDocumentId(document);
return new ChangeEvent<>(
new BsonDocument(),
OperationType.INSERT,
document,
namespace,
new BsonDocument("_id", docId),
null,
writePending);
} | [
"static",
"ChangeEvent",
"<",
"BsonDocument",
">",
"changeEventForLocalInsert",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"BsonDocument",
"document",
",",
"final",
"boolean",
"writePending",
")",
"{",
"final",
"BsonValue",
"docId",
"=",
"BsonUtils",
... | Generates a change event for a local insert of the given document in the given namespace.
@param namespace the namespace where the document was inserted.
@param document the document that was inserted.
@return a change event for a local insert of the given document in the given namespace. | [
"Generates",
"a",
"change",
"event",
"for",
"a",
"local",
"insert",
"of",
"the",
"given",
"document",
"in",
"the",
"given",
"namespace",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/ChangeEvents.java#L40-L54 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/ChangeEvents.java | ChangeEvents.changeEventForLocalUpdate | static ChangeEvent<BsonDocument> changeEventForLocalUpdate(
final MongoNamespace namespace,
final BsonValue documentId,
final UpdateDescription update,
final BsonDocument fullDocumentAfterUpdate,
final boolean writePending
) {
return new ChangeEvent<>(
new BsonDocument(),
OperationType.UPDATE,
fullDocumentAfterUpdate,
namespace,
new BsonDocument("_id", documentId),
update,
writePending);
} | java | static ChangeEvent<BsonDocument> changeEventForLocalUpdate(
final MongoNamespace namespace,
final BsonValue documentId,
final UpdateDescription update,
final BsonDocument fullDocumentAfterUpdate,
final boolean writePending
) {
return new ChangeEvent<>(
new BsonDocument(),
OperationType.UPDATE,
fullDocumentAfterUpdate,
namespace,
new BsonDocument("_id", documentId),
update,
writePending);
} | [
"static",
"ChangeEvent",
"<",
"BsonDocument",
">",
"changeEventForLocalUpdate",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"BsonValue",
"documentId",
",",
"final",
"UpdateDescription",
"update",
",",
"final",
"BsonDocument",
"fullDocumentAfterUpdate",
",",... | Generates a change event for a local update of a document in the given namespace referring
to the given document _id.
@param namespace the namespace where the document was inserted.
@param documentId the _id of the document that was updated.
@param update the update specifier.
@return a change event for a local update of a document in the given namespace referring
to the given document _id. | [
"Generates",
"a",
"change",
"event",
"for",
"a",
"local",
"update",
"of",
"a",
"document",
"in",
"the",
"given",
"namespace",
"referring",
"to",
"the",
"given",
"document",
"_id",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/ChangeEvents.java#L66-L81 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/ChangeEvents.java | ChangeEvents.changeEventForLocalReplace | static ChangeEvent<BsonDocument> changeEventForLocalReplace(
final MongoNamespace namespace,
final BsonValue documentId,
final BsonDocument document,
final boolean writePending
) {
return new ChangeEvent<>(
new BsonDocument(),
OperationType.REPLACE,
document,
namespace,
new BsonDocument("_id", documentId),
null,
writePending);
} | java | static ChangeEvent<BsonDocument> changeEventForLocalReplace(
final MongoNamespace namespace,
final BsonValue documentId,
final BsonDocument document,
final boolean writePending
) {
return new ChangeEvent<>(
new BsonDocument(),
OperationType.REPLACE,
document,
namespace,
new BsonDocument("_id", documentId),
null,
writePending);
} | [
"static",
"ChangeEvent",
"<",
"BsonDocument",
">",
"changeEventForLocalReplace",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"BsonValue",
"documentId",
",",
"final",
"BsonDocument",
"document",
",",
"final",
"boolean",
"writePending",
")",
"{",
"return"... | Generates a change event for a local replacement of a document in the given namespace referring
to the given document _id.
@param namespace the namespace where the document was inserted.
@param documentId the _id of the document that was updated.
@param document the replacement document.
@return a change event for a local replacement of a document in the given namespace referring
to the given document _id. | [
"Generates",
"a",
"change",
"event",
"for",
"a",
"local",
"replacement",
"of",
"a",
"document",
"in",
"the",
"given",
"namespace",
"referring",
"to",
"the",
"given",
"document",
"_id",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/ChangeEvents.java#L93-L107 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/ChangeEvents.java | ChangeEvents.changeEventForLocalDelete | static ChangeEvent<BsonDocument> changeEventForLocalDelete(
final MongoNamespace namespace,
final BsonValue documentId,
final boolean writePending
) {
return new ChangeEvent<>(
new BsonDocument(),
OperationType.DELETE,
null,
namespace,
new BsonDocument("_id", documentId),
null,
writePending);
} | java | static ChangeEvent<BsonDocument> changeEventForLocalDelete(
final MongoNamespace namespace,
final BsonValue documentId,
final boolean writePending
) {
return new ChangeEvent<>(
new BsonDocument(),
OperationType.DELETE,
null,
namespace,
new BsonDocument("_id", documentId),
null,
writePending);
} | [
"static",
"ChangeEvent",
"<",
"BsonDocument",
">",
"changeEventForLocalDelete",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"BsonValue",
"documentId",
",",
"final",
"boolean",
"writePending",
")",
"{",
"return",
"new",
"ChangeEvent",
"<>",
"(",
"new",... | Generates a change event for a local deletion of a document in the given namespace referring
to the given document _id.
@param namespace the namespace where the document was inserted.
@param documentId the _id of the document that was updated.
@return a change event for a local deletion of a document in the given namespace referring
to the given document _id. | [
"Generates",
"a",
"change",
"event",
"for",
"a",
"local",
"deletion",
"of",
"a",
"document",
"in",
"the",
"given",
"namespace",
"referring",
"to",
"the",
"given",
"document",
"_id",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/ChangeEvents.java#L118-L131 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/Assertions.java | Assertions.notNull | public static <T> void notNull(final String name, final T value) {
if (value == null) {
throw new IllegalArgumentException(name + " can not be null");
}
} | java | public static <T> void notNull(final String name, final T value) {
if (value == null) {
throw new IllegalArgumentException(name + " can not be null");
}
} | [
"public",
"static",
"<",
"T",
">",
"void",
"notNull",
"(",
"final",
"String",
"name",
",",
"final",
"T",
"value",
")",
"{",
"if",
"(",
"value",
"==",
"null",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"name",
"+",
"\" can not be null\"",
... | Throw IllegalArgumentException if the value is null.
@param name the parameter name.
@param value the value that should not be null.
@param <T> the value type.
@throws IllegalArgumentException if value is null. | [
"Throw",
"IllegalArgumentException",
"if",
"the",
"value",
"is",
"null",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/Assertions.java#L30-L34 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/Assertions.java | Assertions.keyPresent | public static void keyPresent(final String key, final Map<String, ?> map) {
if (!map.containsKey(key)) {
throw new IllegalStateException(
String.format("expected %s to be present", key));
}
} | java | public static void keyPresent(final String key, final Map<String, ?> map) {
if (!map.containsKey(key)) {
throw new IllegalStateException(
String.format("expected %s to be present", key));
}
} | [
"public",
"static",
"void",
"keyPresent",
"(",
"final",
"String",
"key",
",",
"final",
"Map",
"<",
"String",
",",
"?",
">",
"map",
")",
"{",
"if",
"(",
"!",
"map",
".",
"containsKey",
"(",
"key",
")",
")",
"{",
"throw",
"new",
"IllegalStateException",
... | Throw IllegalStateException if key is not present in map.
@param key the key to expect.
@param map the map to search.
@throws IllegalArgumentException if key is not in map. | [
"Throw",
"IllegalStateException",
"if",
"key",
"is",
"not",
"present",
"in",
"map",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/Assertions.java#L42-L47 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/BsonUtils.java | BsonUtils.copyOfDocument | public static BsonDocument copyOfDocument(final BsonDocument document) {
final BsonDocument newDocument = new BsonDocument();
for (final Map.Entry<String, BsonValue> kv : document.entrySet()) {
newDocument.put(kv.getKey(), kv.getValue());
}
return newDocument;
} | java | public static BsonDocument copyOfDocument(final BsonDocument document) {
final BsonDocument newDocument = new BsonDocument();
for (final Map.Entry<String, BsonValue> kv : document.entrySet()) {
newDocument.put(kv.getKey(), kv.getValue());
}
return newDocument;
} | [
"public",
"static",
"BsonDocument",
"copyOfDocument",
"(",
"final",
"BsonDocument",
"document",
")",
"{",
"final",
"BsonDocument",
"newDocument",
"=",
"new",
"BsonDocument",
"(",
")",
";",
"for",
"(",
"final",
"Map",
".",
"Entry",
"<",
"String",
",",
"BsonValu... | Returns a copy of the given document.
@param document the document to copy.
@return a copy of the given document. | [
"Returns",
"a",
"copy",
"of",
"the",
"given",
"document",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/BsonUtils.java#L150-L156 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/DefaultSyncConflictResolvers.java | DefaultSyncConflictResolvers.localWins | public static <T> ConflictHandler<T> localWins() {
return new ConflictHandler<T>() {
@Override
public T resolveConflict(
final BsonValue documentId,
final ChangeEvent<T> localEvent,
final ChangeEvent<T> remoteEvent
) {
return localEvent.getFullDocument();
}
};
} | java | public static <T> ConflictHandler<T> localWins() {
return new ConflictHandler<T>() {
@Override
public T resolveConflict(
final BsonValue documentId,
final ChangeEvent<T> localEvent,
final ChangeEvent<T> remoteEvent
) {
return localEvent.getFullDocument();
}
};
} | [
"public",
"static",
"<",
"T",
">",
"ConflictHandler",
"<",
"T",
">",
"localWins",
"(",
")",
"{",
"return",
"new",
"ConflictHandler",
"<",
"T",
">",
"(",
")",
"{",
"@",
"Override",
"public",
"T",
"resolveConflict",
"(",
"final",
"BsonValue",
"documentId",
... | The local event will decide the next state of the document in question.
@param <T> the type of class represented by the document in the change event.
@return the local full document which may be null. | [
"The",
"local",
"event",
"will",
"decide",
"the",
"next",
"state",
"of",
"the",
"document",
"in",
"question",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/DefaultSyncConflictResolvers.java#L53-L64 | train |
mongodb/stitch-android-sdk | android/examples/todo/src/main/java/com/mongodb/stitch/android/examples/todo/TodoItem.java | TodoItem.isTodoItem | public static boolean isTodoItem(final Document todoItemDoc) {
return todoItemDoc.containsKey(ID_KEY)
&& todoItemDoc.containsKey(TASK_KEY)
&& todoItemDoc.containsKey(CHECKED_KEY);
} | java | public static boolean isTodoItem(final Document todoItemDoc) {
return todoItemDoc.containsKey(ID_KEY)
&& todoItemDoc.containsKey(TASK_KEY)
&& todoItemDoc.containsKey(CHECKED_KEY);
} | [
"public",
"static",
"boolean",
"isTodoItem",
"(",
"final",
"Document",
"todoItemDoc",
")",
"{",
"return",
"todoItemDoc",
".",
"containsKey",
"(",
"ID_KEY",
")",
"&&",
"todoItemDoc",
".",
"containsKey",
"(",
"TASK_KEY",
")",
"&&",
"todoItemDoc",
".",
"containsKey... | Returns if a MongoDB document is a todo item. | [
"Returns",
"if",
"a",
"MongoDB",
"document",
"is",
"a",
"todo",
"item",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/examples/todo/src/main/java/com/mongodb/stitch/android/examples/todo/TodoItem.java#L49-L53 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.recover | void recover() {
final List<NamespaceSynchronizationConfig> nsConfigs = new ArrayList<>();
for (final MongoNamespace ns : this.syncConfig.getSynchronizedNamespaces()) {
nsConfigs.add(this.syncConfig.getNamespaceConfig(ns));
}
for (final NamespaceSynchronizationConfig nsConfig : nsConfigs) {
nsConfig.getLock().writeLock().lock();
}
try {
for (final NamespaceSynchronizationConfig nsConfig : nsConfigs) {
nsConfig.getLock().writeLock().lock();
try {
recoverNamespace(nsConfig);
} finally {
nsConfig.getLock().writeLock().unlock();
}
}
} finally {
for (final NamespaceSynchronizationConfig nsConfig : nsConfigs) {
nsConfig.getLock().writeLock().unlock();
}
}
} | java | void recover() {
final List<NamespaceSynchronizationConfig> nsConfigs = new ArrayList<>();
for (final MongoNamespace ns : this.syncConfig.getSynchronizedNamespaces()) {
nsConfigs.add(this.syncConfig.getNamespaceConfig(ns));
}
for (final NamespaceSynchronizationConfig nsConfig : nsConfigs) {
nsConfig.getLock().writeLock().lock();
}
try {
for (final NamespaceSynchronizationConfig nsConfig : nsConfigs) {
nsConfig.getLock().writeLock().lock();
try {
recoverNamespace(nsConfig);
} finally {
nsConfig.getLock().writeLock().unlock();
}
}
} finally {
for (final NamespaceSynchronizationConfig nsConfig : nsConfigs) {
nsConfig.getLock().writeLock().unlock();
}
}
} | [
"void",
"recover",
"(",
")",
"{",
"final",
"List",
"<",
"NamespaceSynchronizationConfig",
">",
"nsConfigs",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"final",
"MongoNamespace",
"ns",
":",
"this",
".",
"syncConfig",
".",
"getSynchronizedNamespac... | Recovers the state of synchronization in case a system failure happened. The goal is to revert
to a known, good state. | [
"Recovers",
"the",
"state",
"of",
"synchronization",
"in",
"case",
"a",
"system",
"failure",
"happened",
".",
"The",
"goal",
"is",
"to",
"revert",
"to",
"a",
"known",
"good",
"state",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L197-L220 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.recoverNamespace | private void recoverNamespace(final NamespaceSynchronizationConfig nsConfig) {
final MongoCollection<BsonDocument> undoCollection =
getUndoCollection(nsConfig.getNamespace());
final MongoCollection<BsonDocument> localCollection =
getLocalCollection(nsConfig.getNamespace());
final List<BsonDocument> undoDocs = undoCollection.find().into(new ArrayList<>());
final Set<BsonValue> recoveredIds = new HashSet<>();
// Replace local docs with undo docs. Presence of an undo doc implies we had a system failure
// during a write. This covers updates and deletes.
for (final BsonDocument undoDoc : undoDocs) {
final BsonValue documentId = BsonUtils.getDocumentId(undoDoc);
final BsonDocument filter = getDocumentIdFilter(documentId);
localCollection.findOneAndReplace(
filter, undoDoc, new FindOneAndReplaceOptions().upsert(true));
recoveredIds.add(documentId);
}
// If we recovered a document, but its pending writes are set to do something else, then the
// failure occurred after the pending writes were set, but before the undo document was
// deleted. In this case, we should restore the document to the state that the pending
// write indicates. There is a possibility that the pending write is from before the failed
// operation, but in that case, the findOneAndReplace or delete is a no-op since restoring
// the document to the state of the change event would be the same as recovering the undo
// document.
for (final CoreDocumentSynchronizationConfig docConfig : nsConfig.getSynchronizedDocuments()) {
final BsonValue documentId = docConfig.getDocumentId();
final BsonDocument filter = getDocumentIdFilter(documentId);
if (recoveredIds.contains(docConfig.getDocumentId())) {
final ChangeEvent<BsonDocument> pendingWrite = docConfig.getLastUncommittedChangeEvent();
if (pendingWrite != null) {
switch (pendingWrite.getOperationType()) {
case INSERT:
case UPDATE:
case REPLACE:
localCollection.findOneAndReplace(
filter,
pendingWrite.getFullDocument(),
new FindOneAndReplaceOptions().upsert(true)
);
break;
case DELETE:
localCollection.deleteOne(filter);
break;
default:
// There should never be pending writes with an unknown event type, but if someone
// is messing with the config collection we want to stop the synchronizer to prevent
// further data corruption.
throw new IllegalStateException(
"there should not be a pending write with an unknown event type"
);
}
}
}
}
// Delete all of our undo documents. If we've reached this point, we've recovered the local
// collection to the state we want with respect to all of our undo documents. If we fail before
// these deletes or while carrying out the deletes, but after recovering the documents to
// their desired state, that's okay because the next recovery pass will be effectively a no-op
// up to this point.
for (final BsonValue recoveredId : recoveredIds) {
undoCollection.deleteOne(getDocumentIdFilter(recoveredId));
}
// Find local documents for which there are no document configs and delete them. This covers
// inserts, upserts, and desync deletes. This will occur on any recovery pass regardless of
// the documents in the undo collection, so it's fine that we do this after deleting the undo
// documents.
localCollection.deleteMany(new BsonDocument(
"_id",
new BsonDocument(
"$nin",
new BsonArray(new ArrayList<>(
this.syncConfig.getSynchronizedDocumentIds(nsConfig.getNamespace()))))));
} | java | private void recoverNamespace(final NamespaceSynchronizationConfig nsConfig) {
final MongoCollection<BsonDocument> undoCollection =
getUndoCollection(nsConfig.getNamespace());
final MongoCollection<BsonDocument> localCollection =
getLocalCollection(nsConfig.getNamespace());
final List<BsonDocument> undoDocs = undoCollection.find().into(new ArrayList<>());
final Set<BsonValue> recoveredIds = new HashSet<>();
// Replace local docs with undo docs. Presence of an undo doc implies we had a system failure
// during a write. This covers updates and deletes.
for (final BsonDocument undoDoc : undoDocs) {
final BsonValue documentId = BsonUtils.getDocumentId(undoDoc);
final BsonDocument filter = getDocumentIdFilter(documentId);
localCollection.findOneAndReplace(
filter, undoDoc, new FindOneAndReplaceOptions().upsert(true));
recoveredIds.add(documentId);
}
// If we recovered a document, but its pending writes are set to do something else, then the
// failure occurred after the pending writes were set, but before the undo document was
// deleted. In this case, we should restore the document to the state that the pending
// write indicates. There is a possibility that the pending write is from before the failed
// operation, but in that case, the findOneAndReplace or delete is a no-op since restoring
// the document to the state of the change event would be the same as recovering the undo
// document.
for (final CoreDocumentSynchronizationConfig docConfig : nsConfig.getSynchronizedDocuments()) {
final BsonValue documentId = docConfig.getDocumentId();
final BsonDocument filter = getDocumentIdFilter(documentId);
if (recoveredIds.contains(docConfig.getDocumentId())) {
final ChangeEvent<BsonDocument> pendingWrite = docConfig.getLastUncommittedChangeEvent();
if (pendingWrite != null) {
switch (pendingWrite.getOperationType()) {
case INSERT:
case UPDATE:
case REPLACE:
localCollection.findOneAndReplace(
filter,
pendingWrite.getFullDocument(),
new FindOneAndReplaceOptions().upsert(true)
);
break;
case DELETE:
localCollection.deleteOne(filter);
break;
default:
// There should never be pending writes with an unknown event type, but if someone
// is messing with the config collection we want to stop the synchronizer to prevent
// further data corruption.
throw new IllegalStateException(
"there should not be a pending write with an unknown event type"
);
}
}
}
}
// Delete all of our undo documents. If we've reached this point, we've recovered the local
// collection to the state we want with respect to all of our undo documents. If we fail before
// these deletes or while carrying out the deletes, but after recovering the documents to
// their desired state, that's okay because the next recovery pass will be effectively a no-op
// up to this point.
for (final BsonValue recoveredId : recoveredIds) {
undoCollection.deleteOne(getDocumentIdFilter(recoveredId));
}
// Find local documents for which there are no document configs and delete them. This covers
// inserts, upserts, and desync deletes. This will occur on any recovery pass regardless of
// the documents in the undo collection, so it's fine that we do this after deleting the undo
// documents.
localCollection.deleteMany(new BsonDocument(
"_id",
new BsonDocument(
"$nin",
new BsonArray(new ArrayList<>(
this.syncConfig.getSynchronizedDocumentIds(nsConfig.getNamespace()))))));
} | [
"private",
"void",
"recoverNamespace",
"(",
"final",
"NamespaceSynchronizationConfig",
"nsConfig",
")",
"{",
"final",
"MongoCollection",
"<",
"BsonDocument",
">",
"undoCollection",
"=",
"getUndoCollection",
"(",
"nsConfig",
".",
"getNamespace",
"(",
")",
")",
";",
"... | Recovers the state of synchronization for a namespace in case a system failure happened.
The goal is to revert the namespace to a known, good state. This method itself is resilient
to failures, since it doesn't delete any documents from the undo collection until the
collection is in the desired state with respect to those documents. | [
"Recovers",
"the",
"state",
"of",
"synchronization",
"for",
"a",
"namespace",
"in",
"case",
"a",
"system",
"failure",
"happened",
".",
"The",
"goal",
"is",
"to",
"revert",
"the",
"namespace",
"to",
"a",
"known",
"good",
"state",
".",
"This",
"method",
"its... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L228-L305 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.wipeInMemorySettings | public void wipeInMemorySettings() {
this.waitUntilInitialized();
syncLock.lock();
try {
this.instanceChangeStreamListener.stop();
if (instancesColl.find().first() == null) {
throw new IllegalStateException("expected to find instance configuration");
}
this.syncConfig = new InstanceSynchronizationConfig(configDb);
this.instanceChangeStreamListener = new InstanceChangeStreamListenerImpl(
syncConfig,
service,
networkMonitor,
authMonitor
);
this.isConfigured = false;
this.stop();
} finally {
syncLock.unlock();
}
} | java | public void wipeInMemorySettings() {
this.waitUntilInitialized();
syncLock.lock();
try {
this.instanceChangeStreamListener.stop();
if (instancesColl.find().first() == null) {
throw new IllegalStateException("expected to find instance configuration");
}
this.syncConfig = new InstanceSynchronizationConfig(configDb);
this.instanceChangeStreamListener = new InstanceChangeStreamListenerImpl(
syncConfig,
service,
networkMonitor,
authMonitor
);
this.isConfigured = false;
this.stop();
} finally {
syncLock.unlock();
}
} | [
"public",
"void",
"wipeInMemorySettings",
"(",
")",
"{",
"this",
".",
"waitUntilInitialized",
"(",
")",
";",
"syncLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"this",
".",
"instanceChangeStreamListener",
".",
"stop",
"(",
")",
";",
"if",
"(",
"instancesC... | Reloads the synchronization config. This wipes all in-memory synchronization settings. | [
"Reloads",
"the",
"synchronization",
"config",
".",
"This",
"wipes",
"all",
"in",
"-",
"memory",
"synchronization",
"settings",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L337-L358 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.start | public void start() {
syncLock.lock();
try {
if (!this.isConfigured) {
return;
}
instanceChangeStreamListener.stop();
if (listenersEnabled) {
instanceChangeStreamListener.start();
}
if (syncThread == null) {
syncThread = new Thread(
new DataSynchronizerRunner(
new WeakReference<>(this),
networkMonitor,
logger
),
"dataSynchronizerRunnerThread"
);
}
if (syncThreadEnabled && !isRunning) {
syncThread.start();
isRunning = true;
}
} finally {
syncLock.unlock();
}
} | java | public void start() {
syncLock.lock();
try {
if (!this.isConfigured) {
return;
}
instanceChangeStreamListener.stop();
if (listenersEnabled) {
instanceChangeStreamListener.start();
}
if (syncThread == null) {
syncThread = new Thread(
new DataSynchronizerRunner(
new WeakReference<>(this),
networkMonitor,
logger
),
"dataSynchronizerRunnerThread"
);
}
if (syncThreadEnabled && !isRunning) {
syncThread.start();
isRunning = true;
}
} finally {
syncLock.unlock();
}
} | [
"public",
"void",
"start",
"(",
")",
"{",
"syncLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"!",
"this",
".",
"isConfigured",
")",
"{",
"return",
";",
"}",
"instanceChangeStreamListener",
".",
"stop",
"(",
")",
";",
"if",
"(",
"listeners... | Starts data synchronization in a background thread. | [
"Starts",
"data",
"synchronization",
"in",
"a",
"background",
"thread",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L541-L569 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.stop | public void stop() {
syncLock.lock();
try {
if (syncThread == null) {
return;
}
instanceChangeStreamListener.stop();
syncThread.interrupt();
try {
syncThread.join();
} catch (final InterruptedException e) {
return;
}
syncThread = null;
isRunning = false;
} finally {
syncLock.unlock();
}
} | java | public void stop() {
syncLock.lock();
try {
if (syncThread == null) {
return;
}
instanceChangeStreamListener.stop();
syncThread.interrupt();
try {
syncThread.join();
} catch (final InterruptedException e) {
return;
}
syncThread = null;
isRunning = false;
} finally {
syncLock.unlock();
}
} | [
"public",
"void",
"stop",
"(",
")",
"{",
"syncLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"syncThread",
"==",
"null",
")",
"{",
"return",
";",
"}",
"instanceChangeStreamListener",
".",
"stop",
"(",
")",
";",
"syncThread",
".",
"interrupt"... | Stops the background data synchronization thread. | [
"Stops",
"the",
"background",
"data",
"synchronization",
"thread",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L592-L610 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.close | public void close() {
this.waitUntilInitialized();
this.ongoingOperationsGroup.blockAndWait();
syncLock.lock();
try {
if (this.networkMonitor != null) {
this.networkMonitor.removeNetworkStateListener(this);
}
this.dispatcher.close();
stop();
this.localClient.close();
} finally {
syncLock.unlock();
}
} | java | public void close() {
this.waitUntilInitialized();
this.ongoingOperationsGroup.blockAndWait();
syncLock.lock();
try {
if (this.networkMonitor != null) {
this.networkMonitor.removeNetworkStateListener(this);
}
this.dispatcher.close();
stop();
this.localClient.close();
} finally {
syncLock.unlock();
}
} | [
"public",
"void",
"close",
"(",
")",
"{",
"this",
".",
"waitUntilInitialized",
"(",
")",
";",
"this",
".",
"ongoingOperationsGroup",
".",
"blockAndWait",
"(",
")",
";",
"syncLock",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"this",
".",
"networ... | Stops the background data synchronization thread and releases the local client. | [
"Stops",
"the",
"background",
"data",
"synchronization",
"thread",
"and",
"releases",
"the",
"local",
"client",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L615-L631 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.doSyncPass | public boolean doSyncPass() {
if (!this.isConfigured || !syncLock.tryLock()) {
return false;
}
try {
if (logicalT == Long.MAX_VALUE) {
if (logger.isInfoEnabled()) {
logger.info("reached max logical time; resetting back to 0");
}
logicalT = 0;
}
logicalT++;
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass START",
logicalT));
}
if (networkMonitor == null || !networkMonitor.isConnected()) {
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass END - Network disconnected",
logicalT));
}
return false;
}
if (authMonitor == null || !authMonitor.tryIsLoggedIn()) {
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass END - Logged out",
logicalT));
}
return false;
}
syncRemoteToLocal();
syncLocalToRemote();
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass END",
logicalT));
}
} catch (InterruptedException e) {
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass INTERRUPTED",
logicalT));
}
return false;
} finally {
syncLock.unlock();
}
return true;
} | java | public boolean doSyncPass() {
if (!this.isConfigured || !syncLock.tryLock()) {
return false;
}
try {
if (logicalT == Long.MAX_VALUE) {
if (logger.isInfoEnabled()) {
logger.info("reached max logical time; resetting back to 0");
}
logicalT = 0;
}
logicalT++;
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass START",
logicalT));
}
if (networkMonitor == null || !networkMonitor.isConnected()) {
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass END - Network disconnected",
logicalT));
}
return false;
}
if (authMonitor == null || !authMonitor.tryIsLoggedIn()) {
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass END - Logged out",
logicalT));
}
return false;
}
syncRemoteToLocal();
syncLocalToRemote();
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass END",
logicalT));
}
} catch (InterruptedException e) {
if (logger.isInfoEnabled()) {
logger.info(String.format(
Locale.US,
"t='%d': doSyncPass INTERRUPTED",
logicalT));
}
return false;
} finally {
syncLock.unlock();
}
return true;
} | [
"public",
"boolean",
"doSyncPass",
"(",
")",
"{",
"if",
"(",
"!",
"this",
".",
"isConfigured",
"||",
"!",
"syncLock",
".",
"tryLock",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"if",
"(",
"logicalT",
"==",
"Long",
".",
"MAX_VALUE",
... | Performs a single synchronization pass in both the local and remote directions; the order
of which does not matter. If switching the order produces different results after one pass,
then there is a bug.
@return whether or not the synchronization pass was successful. | [
"Performs",
"a",
"single",
"synchronization",
"pass",
"in",
"both",
"the",
"local",
"and",
"remote",
"directions",
";",
"the",
"order",
"of",
"which",
"does",
"not",
"matter",
".",
"If",
"switching",
"the",
"order",
"produces",
"different",
"results",
"after",... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L642-L701 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.resolveConflict | @CheckReturnValue
private LocalSyncWriteModelContainer resolveConflict(
final NamespaceSynchronizationConfig nsConfig,
final CoreDocumentSynchronizationConfig docConfig,
final ChangeEvent<BsonDocument> remoteEvent
) {
return resolveConflict(nsConfig, docConfig, docConfig.getLastUncommittedChangeEvent(),
remoteEvent);
} | java | @CheckReturnValue
private LocalSyncWriteModelContainer resolveConflict(
final NamespaceSynchronizationConfig nsConfig,
final CoreDocumentSynchronizationConfig docConfig,
final ChangeEvent<BsonDocument> remoteEvent
) {
return resolveConflict(nsConfig, docConfig, docConfig.getLastUncommittedChangeEvent(),
remoteEvent);
} | [
"@",
"CheckReturnValue",
"private",
"LocalSyncWriteModelContainer",
"resolveConflict",
"(",
"final",
"NamespaceSynchronizationConfig",
"nsConfig",
",",
"final",
"CoreDocumentSynchronizationConfig",
"docConfig",
",",
"final",
"ChangeEvent",
"<",
"BsonDocument",
">",
"remoteEvent... | Resolves a conflict between a synchronized document's local and remote state. The resolution
will result in either the document being desynchronized or being replaced with some resolved
state based on the conflict resolver specified for the document. Uses the last uncommitted
local event as the local state.
@param nsConfig the namespace synchronization config of the namespace where the document
lives.
@param docConfig the configuration of the document that describes the resolver and current
state.
@param remoteEvent the remote change event that is conflicting. | [
"Resolves",
"a",
"conflict",
"between",
"a",
"synchronized",
"document",
"s",
"local",
"and",
"remote",
"state",
".",
"The",
"resolution",
"will",
"result",
"in",
"either",
"the",
"document",
"being",
"desynchronized",
"or",
"being",
"replaced",
"with",
"some",
... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L1681-L1689 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.resolveConflictWithResolver | @SuppressWarnings("unchecked")
private static Object resolveConflictWithResolver(
final ConflictHandler conflictResolver,
final BsonValue documentId,
final ChangeEvent localEvent,
final ChangeEvent remoteEvent
) {
return conflictResolver.resolveConflict(
documentId,
localEvent,
remoteEvent);
} | java | @SuppressWarnings("unchecked")
private static Object resolveConflictWithResolver(
final ConflictHandler conflictResolver,
final BsonValue documentId,
final ChangeEvent localEvent,
final ChangeEvent remoteEvent
) {
return conflictResolver.resolveConflict(
documentId,
localEvent,
remoteEvent);
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"private",
"static",
"Object",
"resolveConflictWithResolver",
"(",
"final",
"ConflictHandler",
"conflictResolver",
",",
"final",
"BsonValue",
"documentId",
",",
"final",
"ChangeEvent",
"localEvent",
",",
"final",
"Chan... | Returns the resolution of resolving the conflict between a local and remote event using
the given conflict resolver.
@param conflictResolver the conflict resolver to use.
@param documentId the document id related to the conflicted events.
@param localEvent the conflicted local event.
@param remoteEvent the conflicted remote event.
@return the resolution to the conflict. | [
"Returns",
"the",
"resolution",
"of",
"resolving",
"the",
"conflict",
"between",
"a",
"local",
"and",
"remote",
"event",
"using",
"the",
"given",
"conflict",
"resolver",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L1853-L1864 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.addWatcher | public void addWatcher(final MongoNamespace namespace,
final Callback<ChangeEvent<BsonDocument>, Object> watcher) {
instanceChangeStreamListener.addWatcher(namespace, watcher);
} | java | public void addWatcher(final MongoNamespace namespace,
final Callback<ChangeEvent<BsonDocument>, Object> watcher) {
instanceChangeStreamListener.addWatcher(namespace, watcher);
} | [
"public",
"void",
"addWatcher",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"Callback",
"<",
"ChangeEvent",
"<",
"BsonDocument",
">",
",",
"Object",
">",
"watcher",
")",
"{",
"instanceChangeStreamListener",
".",
"addWatcher",
"(",
"namespace",
",",
... | Queues up a callback to be removed and invoked on the next change event. | [
"Queues",
"up",
"a",
"callback",
"to",
"be",
"removed",
"and",
"invoked",
"on",
"the",
"next",
"change",
"event",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L1907-L1910 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.getSynchronizedDocuments | public Set<CoreDocumentSynchronizationConfig> getSynchronizedDocuments(
final MongoNamespace namespace
) {
this.waitUntilInitialized();
try {
ongoingOperationsGroup.enter();
return this.syncConfig.getSynchronizedDocuments(namespace);
} finally {
ongoingOperationsGroup.exit();
}
} | java | public Set<CoreDocumentSynchronizationConfig> getSynchronizedDocuments(
final MongoNamespace namespace
) {
this.waitUntilInitialized();
try {
ongoingOperationsGroup.enter();
return this.syncConfig.getSynchronizedDocuments(namespace);
} finally {
ongoingOperationsGroup.exit();
}
} | [
"public",
"Set",
"<",
"CoreDocumentSynchronizationConfig",
">",
"getSynchronizedDocuments",
"(",
"final",
"MongoNamespace",
"namespace",
")",
"{",
"this",
".",
"waitUntilInitialized",
"(",
")",
";",
"try",
"{",
"ongoingOperationsGroup",
".",
"enter",
"(",
")",
";",
... | Returns the set of synchronized documents in a namespace.
@param namespace the namespace to get synchronized documents for.
@return the set of synchronized documents in a namespace. | [
"Returns",
"the",
"set",
"of",
"synchronized",
"documents",
"in",
"a",
"namespace",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L1944-L1954 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.getPausedDocumentIds | public Set<BsonValue> getPausedDocumentIds(final MongoNamespace namespace) {
this.waitUntilInitialized();
try {
ongoingOperationsGroup.enter();
final Set<BsonValue> pausedDocumentIds = new HashSet<>();
for (final CoreDocumentSynchronizationConfig config :
this.syncConfig.getSynchronizedDocuments(namespace)) {
if (config.isPaused()) {
pausedDocumentIds.add(config.getDocumentId());
}
}
return pausedDocumentIds;
} finally {
ongoingOperationsGroup.exit();
}
} | java | public Set<BsonValue> getPausedDocumentIds(final MongoNamespace namespace) {
this.waitUntilInitialized();
try {
ongoingOperationsGroup.enter();
final Set<BsonValue> pausedDocumentIds = new HashSet<>();
for (final CoreDocumentSynchronizationConfig config :
this.syncConfig.getSynchronizedDocuments(namespace)) {
if (config.isPaused()) {
pausedDocumentIds.add(config.getDocumentId());
}
}
return pausedDocumentIds;
} finally {
ongoingOperationsGroup.exit();
}
} | [
"public",
"Set",
"<",
"BsonValue",
">",
"getPausedDocumentIds",
"(",
"final",
"MongoNamespace",
"namespace",
")",
"{",
"this",
".",
"waitUntilInitialized",
"(",
")",
";",
"try",
"{",
"ongoingOperationsGroup",
".",
"enter",
"(",
")",
";",
"final",
"Set",
"<",
... | Return the set of synchronized document _ids in a namespace
that have been paused due to an irrecoverable error.
@param namespace the namespace to get paused document _ids for.
@return the set of paused document _ids in a namespace | [
"Return",
"the",
"set",
"of",
"synchronized",
"document",
"_ids",
"in",
"a",
"namespace",
"that",
"have",
"been",
"paused",
"due",
"to",
"an",
"irrecoverable",
"error",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L1979-L1997 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.resumeSyncForDocument | boolean resumeSyncForDocument(
final MongoNamespace namespace,
final BsonValue documentId
) {
if (namespace == null || documentId == null) {
return false;
}
final NamespaceSynchronizationConfig namespaceSynchronizationConfig;
final CoreDocumentSynchronizationConfig config;
if ((namespaceSynchronizationConfig = syncConfig.getNamespaceConfig(namespace)) == null
|| (config = namespaceSynchronizationConfig.getSynchronizedDocument(documentId)) == null) {
return false;
}
config.setPaused(false);
return !config.isPaused();
} | java | boolean resumeSyncForDocument(
final MongoNamespace namespace,
final BsonValue documentId
) {
if (namespace == null || documentId == null) {
return false;
}
final NamespaceSynchronizationConfig namespaceSynchronizationConfig;
final CoreDocumentSynchronizationConfig config;
if ((namespaceSynchronizationConfig = syncConfig.getNamespaceConfig(namespace)) == null
|| (config = namespaceSynchronizationConfig.getSynchronizedDocument(documentId)) == null) {
return false;
}
config.setPaused(false);
return !config.isPaused();
} | [
"boolean",
"resumeSyncForDocument",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"BsonValue",
"documentId",
")",
"{",
"if",
"(",
"namespace",
"==",
"null",
"||",
"documentId",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"final",
"Namespa... | A document that is paused no longer has remote updates applied to it.
Any local updates to this document cause it to be resumed. An example of pausing a document
is when a conflict is being resolved for that document and the handler throws an exception.
This method allows you to resume sync for a document.
@param namespace namespace for the document
@param documentId the id of the document to resume syncing
@return true if successfully resumed, false if the document
could not be found or there was an error resuming | [
"A",
"document",
"that",
"is",
"paused",
"no",
"longer",
"has",
"remote",
"updates",
"applied",
"to",
"it",
".",
"Any",
"local",
"updates",
"to",
"this",
"document",
"cause",
"it",
"to",
"be",
"resumed",
".",
"An",
"example",
"of",
"pausing",
"a",
"docum... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L2083-L2101 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.insertOne | void insertOne(final MongoNamespace namespace, final BsonDocument document) {
this.waitUntilInitialized();
try {
ongoingOperationsGroup.enter();
// Remove forbidden fields from the document before inserting it into the local collection.
final BsonDocument docForStorage = sanitizeDocument(document);
final NamespaceSynchronizationConfig nsConfig =
this.syncConfig.getNamespaceConfig(namespace);
final Lock lock = nsConfig.getLock().writeLock();
lock.lock();
final ChangeEvent<BsonDocument> event;
final BsonValue documentId;
try {
getLocalCollection(namespace).insertOne(docForStorage);
documentId = BsonUtils.getDocumentId(docForStorage);
event = ChangeEvents.changeEventForLocalInsert(namespace, docForStorage, true);
final CoreDocumentSynchronizationConfig config = syncConfig.addAndGetSynchronizedDocument(
namespace,
documentId
);
config.setSomePendingWritesAndSave(logicalT, event);
} finally {
lock.unlock();
}
checkAndInsertNamespaceListener(namespace);
eventDispatcher.emitEvent(nsConfig, event);
} finally {
ongoingOperationsGroup.exit();
}
} | java | void insertOne(final MongoNamespace namespace, final BsonDocument document) {
this.waitUntilInitialized();
try {
ongoingOperationsGroup.enter();
// Remove forbidden fields from the document before inserting it into the local collection.
final BsonDocument docForStorage = sanitizeDocument(document);
final NamespaceSynchronizationConfig nsConfig =
this.syncConfig.getNamespaceConfig(namespace);
final Lock lock = nsConfig.getLock().writeLock();
lock.lock();
final ChangeEvent<BsonDocument> event;
final BsonValue documentId;
try {
getLocalCollection(namespace).insertOne(docForStorage);
documentId = BsonUtils.getDocumentId(docForStorage);
event = ChangeEvents.changeEventForLocalInsert(namespace, docForStorage, true);
final CoreDocumentSynchronizationConfig config = syncConfig.addAndGetSynchronizedDocument(
namespace,
documentId
);
config.setSomePendingWritesAndSave(logicalT, event);
} finally {
lock.unlock();
}
checkAndInsertNamespaceListener(namespace);
eventDispatcher.emitEvent(nsConfig, event);
} finally {
ongoingOperationsGroup.exit();
}
} | [
"void",
"insertOne",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"BsonDocument",
"document",
")",
"{",
"this",
".",
"waitUntilInitialized",
"(",
")",
";",
"try",
"{",
"ongoingOperationsGroup",
".",
"enter",
"(",
")",
";",
"// Remove forbidden fields... | Inserts a single document locally and being to synchronize it based on its _id. Inserting
a document with the same _id twice will result in a duplicate key exception.
@param namespace the namespace to put the document in.
@param document the document to insert. | [
"Inserts",
"a",
"single",
"document",
"locally",
"and",
"being",
"to",
"synchronize",
"it",
"based",
"on",
"its",
"_id",
".",
"Inserting",
"a",
"document",
"with",
"the",
"same",
"_id",
"twice",
"will",
"result",
"in",
"a",
"duplicate",
"key",
"exception",
... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L2247-L2278 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.deleteMany | DeleteResult deleteMany(final MongoNamespace namespace,
final Bson filter) {
this.waitUntilInitialized();
try {
ongoingOperationsGroup.enter();
final List<ChangeEvent<BsonDocument>> eventsToEmit = new ArrayList<>();
final DeleteResult result;
final NamespaceSynchronizationConfig nsConfig = this.syncConfig.getNamespaceConfig(namespace);
final Lock lock = nsConfig.getLock().writeLock();
lock.lock();
try {
final MongoCollection<BsonDocument> localCollection = getLocalCollection(namespace);
final MongoCollection<BsonDocument> undoCollection = getUndoCollection(namespace);
final Set<BsonValue> idsToDelete =
localCollection
.find(filter)
.map(new Function<BsonDocument, BsonValue>() {
@Override
@NonNull
public BsonValue apply(@NonNull final BsonDocument bsonDocument) {
undoCollection.insertOne(bsonDocument);
return BsonUtils.getDocumentId(bsonDocument);
}
}).into(new HashSet<>());
result = localCollection.deleteMany(filter);
for (final BsonValue documentId : idsToDelete) {
final CoreDocumentSynchronizationConfig config =
syncConfig.getSynchronizedDocument(namespace, documentId);
if (config == null) {
continue;
}
final ChangeEvent<BsonDocument> event =
ChangeEvents.changeEventForLocalDelete(namespace, documentId, true);
// this block is to trigger coalescence for a delete after insert
if (config.getLastUncommittedChangeEvent() != null
&& config.getLastUncommittedChangeEvent().getOperationType()
== OperationType.INSERT) {
desyncDocumentsFromRemote(nsConfig, config.getDocumentId())
.commitAndClear();
undoCollection.deleteOne(getDocumentIdFilter(documentId));
continue;
}
config.setSomePendingWritesAndSave(logicalT, event);
undoCollection.deleteOne(getDocumentIdFilter(documentId));
eventsToEmit.add(event);
}
checkAndDeleteNamespaceListener(namespace);
} finally {
lock.unlock();
}
for (final ChangeEvent<BsonDocument> event : eventsToEmit) {
eventDispatcher.emitEvent(nsConfig, event);
}
return result;
} finally {
ongoingOperationsGroup.exit();
}
} | java | DeleteResult deleteMany(final MongoNamespace namespace,
final Bson filter) {
this.waitUntilInitialized();
try {
ongoingOperationsGroup.enter();
final List<ChangeEvent<BsonDocument>> eventsToEmit = new ArrayList<>();
final DeleteResult result;
final NamespaceSynchronizationConfig nsConfig = this.syncConfig.getNamespaceConfig(namespace);
final Lock lock = nsConfig.getLock().writeLock();
lock.lock();
try {
final MongoCollection<BsonDocument> localCollection = getLocalCollection(namespace);
final MongoCollection<BsonDocument> undoCollection = getUndoCollection(namespace);
final Set<BsonValue> idsToDelete =
localCollection
.find(filter)
.map(new Function<BsonDocument, BsonValue>() {
@Override
@NonNull
public BsonValue apply(@NonNull final BsonDocument bsonDocument) {
undoCollection.insertOne(bsonDocument);
return BsonUtils.getDocumentId(bsonDocument);
}
}).into(new HashSet<>());
result = localCollection.deleteMany(filter);
for (final BsonValue documentId : idsToDelete) {
final CoreDocumentSynchronizationConfig config =
syncConfig.getSynchronizedDocument(namespace, documentId);
if (config == null) {
continue;
}
final ChangeEvent<BsonDocument> event =
ChangeEvents.changeEventForLocalDelete(namespace, documentId, true);
// this block is to trigger coalescence for a delete after insert
if (config.getLastUncommittedChangeEvent() != null
&& config.getLastUncommittedChangeEvent().getOperationType()
== OperationType.INSERT) {
desyncDocumentsFromRemote(nsConfig, config.getDocumentId())
.commitAndClear();
undoCollection.deleteOne(getDocumentIdFilter(documentId));
continue;
}
config.setSomePendingWritesAndSave(logicalT, event);
undoCollection.deleteOne(getDocumentIdFilter(documentId));
eventsToEmit.add(event);
}
checkAndDeleteNamespaceListener(namespace);
} finally {
lock.unlock();
}
for (final ChangeEvent<BsonDocument> event : eventsToEmit) {
eventDispatcher.emitEvent(nsConfig, event);
}
return result;
} finally {
ongoingOperationsGroup.exit();
}
} | [
"DeleteResult",
"deleteMany",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"Bson",
"filter",
")",
"{",
"this",
".",
"waitUntilInitialized",
"(",
")",
";",
"try",
"{",
"ongoingOperationsGroup",
".",
"enter",
"(",
")",
";",
"final",
"List",
"<",
... | Removes all documents from the collection that match the given query filter. If no documents
match, the collection is not modified.
@param filter the query filter to apply the the delete operation
@return the result of the remove many operation | [
"Removes",
"all",
"documents",
"from",
"the",
"collection",
"that",
"match",
"the",
"given",
"query",
"filter",
".",
"If",
"no",
"documents",
"match",
"the",
"collection",
"is",
"not",
"modified",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L2782-L2846 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.getUndoCollection | MongoCollection<BsonDocument> getUndoCollection(final MongoNamespace namespace) {
return localClient
.getDatabase(String.format("sync_undo_%s", namespace.getDatabaseName()))
.getCollection(namespace.getCollectionName(), BsonDocument.class)
.withCodecRegistry(MongoClientSettings.getDefaultCodecRegistry());
} | java | MongoCollection<BsonDocument> getUndoCollection(final MongoNamespace namespace) {
return localClient
.getDatabase(String.format("sync_undo_%s", namespace.getDatabaseName()))
.getCollection(namespace.getCollectionName(), BsonDocument.class)
.withCodecRegistry(MongoClientSettings.getDefaultCodecRegistry());
} | [
"MongoCollection",
"<",
"BsonDocument",
">",
"getUndoCollection",
"(",
"final",
"MongoNamespace",
"namespace",
")",
"{",
"return",
"localClient",
".",
"getDatabase",
"(",
"String",
".",
"format",
"(",
"\"sync_undo_%s\"",
",",
"namespace",
".",
"getDatabaseName",
"("... | Returns the undo collection representing the given namespace for recording documents that
may need to be reverted after a system failure.
@param namespace the namespace referring to the undo collection.
@return the undo collection representing the given namespace for recording documents that
may need to be reverted after a system failure. | [
"Returns",
"the",
"undo",
"collection",
"representing",
"the",
"given",
"namespace",
"for",
"recording",
"documents",
"that",
"may",
"need",
"to",
"be",
"reverted",
"after",
"a",
"system",
"failure",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L3022-L3027 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.getLocalCollection | private <T> MongoCollection<T> getLocalCollection(
final MongoNamespace namespace,
final Class<T> resultClass,
final CodecRegistry codecRegistry
) {
return localClient
.getDatabase(String.format("sync_user_%s", namespace.getDatabaseName()))
.getCollection(namespace.getCollectionName(), resultClass)
.withCodecRegistry(codecRegistry);
} | java | private <T> MongoCollection<T> getLocalCollection(
final MongoNamespace namespace,
final Class<T> resultClass,
final CodecRegistry codecRegistry
) {
return localClient
.getDatabase(String.format("sync_user_%s", namespace.getDatabaseName()))
.getCollection(namespace.getCollectionName(), resultClass)
.withCodecRegistry(codecRegistry);
} | [
"private",
"<",
"T",
">",
"MongoCollection",
"<",
"T",
">",
"getLocalCollection",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"Class",
"<",
"T",
">",
"resultClass",
",",
"final",
"CodecRegistry",
"codecRegistry",
")",
"{",
"return",
"localClient",... | Returns the local collection representing the given namespace.
@param namespace the namespace referring to the local collection.
@param resultClass the {@link Class} that represents documents in the collection.
@param <T> the type documents in the collection.
@return the local collection representing the given namespace. | [
"Returns",
"the",
"local",
"collection",
"representing",
"the",
"given",
"namespace",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L3037-L3046 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.getLocalCollection | MongoCollection<BsonDocument> getLocalCollection(final MongoNamespace namespace) {
return getLocalCollection(
namespace,
BsonDocument.class,
MongoClientSettings.getDefaultCodecRegistry());
} | java | MongoCollection<BsonDocument> getLocalCollection(final MongoNamespace namespace) {
return getLocalCollection(
namespace,
BsonDocument.class,
MongoClientSettings.getDefaultCodecRegistry());
} | [
"MongoCollection",
"<",
"BsonDocument",
">",
"getLocalCollection",
"(",
"final",
"MongoNamespace",
"namespace",
")",
"{",
"return",
"getLocalCollection",
"(",
"namespace",
",",
"BsonDocument",
".",
"class",
",",
"MongoClientSettings",
".",
"getDefaultCodecRegistry",
"("... | Returns the local collection representing the given namespace for raw document operations.
@param namespace the namespace referring to the local collection.
@return the local collection representing the given namespace for raw document operations. | [
"Returns",
"the",
"local",
"collection",
"representing",
"the",
"given",
"namespace",
"for",
"raw",
"document",
"operations",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L3054-L3059 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.getRemoteCollection | private <T> CoreRemoteMongoCollection<T> getRemoteCollection(
final MongoNamespace namespace,
final Class<T> resultClass
) {
return remoteClient
.getDatabase(namespace.getDatabaseName())
.getCollection(namespace.getCollectionName(), resultClass);
} | java | private <T> CoreRemoteMongoCollection<T> getRemoteCollection(
final MongoNamespace namespace,
final Class<T> resultClass
) {
return remoteClient
.getDatabase(namespace.getDatabaseName())
.getCollection(namespace.getCollectionName(), resultClass);
} | [
"private",
"<",
"T",
">",
"CoreRemoteMongoCollection",
"<",
"T",
">",
"getRemoteCollection",
"(",
"final",
"MongoNamespace",
"namespace",
",",
"final",
"Class",
"<",
"T",
">",
"resultClass",
")",
"{",
"return",
"remoteClient",
".",
"getDatabase",
"(",
"namespace... | Returns the remote collection representing the given namespace.
@param namespace the namespace referring to the remote collection.
@param resultClass the {@link Class} that represents documents in the collection.
@param <T> the type documents in the collection.
@return the remote collection representing the given namespace. | [
"Returns",
"the",
"remote",
"collection",
"representing",
"the",
"given",
"namespace",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L3069-L3076 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.sanitizeDocument | static BsonDocument sanitizeDocument(final BsonDocument document) {
if (document == null) {
return null;
}
if (document.containsKey(DOCUMENT_VERSION_FIELD)) {
final BsonDocument clonedDoc = document.clone();
clonedDoc.remove(DOCUMENT_VERSION_FIELD);
return clonedDoc;
}
return document;
} | java | static BsonDocument sanitizeDocument(final BsonDocument document) {
if (document == null) {
return null;
}
if (document.containsKey(DOCUMENT_VERSION_FIELD)) {
final BsonDocument clonedDoc = document.clone();
clonedDoc.remove(DOCUMENT_VERSION_FIELD);
return clonedDoc;
}
return document;
} | [
"static",
"BsonDocument",
"sanitizeDocument",
"(",
"final",
"BsonDocument",
"document",
")",
"{",
"if",
"(",
"document",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"document",
".",
"containsKey",
"(",
"DOCUMENT_VERSION_FIELD",
")",
")",
"... | Given a BSON document, remove any forbidden fields and return the document. If no changes are
made, the original document reference is returned. If changes are made, a cloned copy of the
document with the changes will be returned.
@param document the document from which to remove forbidden fields
@return a BsonDocument without any forbidden fields. | [
"Given",
"a",
"BSON",
"document",
"remove",
"any",
"forbidden",
"fields",
"and",
"return",
"the",
"document",
".",
"If",
"no",
"changes",
"are",
"made",
"the",
"original",
"document",
"reference",
"is",
"returned",
".",
"If",
"changes",
"are",
"made",
"a",
... | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L3169-L3180 | train |
mongodb/stitch-android-sdk | core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java | DataSynchronizer.withNewVersion | private static BsonDocument withNewVersion(
final BsonDocument document,
final BsonDocument newVersion
) {
final BsonDocument newDocument = BsonUtils.copyOfDocument(document);
newDocument.put(DOCUMENT_VERSION_FIELD, newVersion);
return newDocument;
} | java | private static BsonDocument withNewVersion(
final BsonDocument document,
final BsonDocument newVersion
) {
final BsonDocument newDocument = BsonUtils.copyOfDocument(document);
newDocument.put(DOCUMENT_VERSION_FIELD, newVersion);
return newDocument;
} | [
"private",
"static",
"BsonDocument",
"withNewVersion",
"(",
"final",
"BsonDocument",
"document",
",",
"final",
"BsonDocument",
"newVersion",
")",
"{",
"final",
"BsonDocument",
"newDocument",
"=",
"BsonUtils",
".",
"copyOfDocument",
"(",
"document",
")",
";",
"newDoc... | Adds and returns a document with a new version to the given document.
@param document the document to attach a new version to.
@param newVersion the version to attach to the document
@return a document with a new version to the given document. | [
"Adds",
"and",
"returns",
"a",
"document",
"with",
"a",
"new",
"version",
"to",
"the",
"given",
"document",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/services/mongodb-remote/src/main/java/com/mongodb/stitch/core/services/mongodb/remote/sync/internal/DataSynchronizer.java#L3189-L3196 | train |
mongodb/stitch-android-sdk | android/services/mongodb-local/src/main/java/com/mongodb/stitch/android/services/mongodb/local/LocalMongoDbService.java | LocalMongoDbService.clearallLocalDBs | public static void clearallLocalDBs() {
for (final Map.Entry<MongoClient, Boolean> entry : localInstances.entrySet()) {
for (final String dbName : entry.getKey().listDatabaseNames()) {
entry.getKey().getDatabase(dbName).drop();
}
}
} | java | public static void clearallLocalDBs() {
for (final Map.Entry<MongoClient, Boolean> entry : localInstances.entrySet()) {
for (final String dbName : entry.getKey().listDatabaseNames()) {
entry.getKey().getDatabase(dbName).drop();
}
}
} | [
"public",
"static",
"void",
"clearallLocalDBs",
"(",
")",
"{",
"for",
"(",
"final",
"Map",
".",
"Entry",
"<",
"MongoClient",
",",
"Boolean",
">",
"entry",
":",
"localInstances",
".",
"entrySet",
"(",
")",
")",
"{",
"for",
"(",
"final",
"String",
"dbName"... | Helper function that drops all local databases for every client. | [
"Helper",
"function",
"that",
"drops",
"all",
"local",
"databases",
"for",
"every",
"client",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/android/services/mongodb-local/src/main/java/com/mongodb/stitch/android/services/mongodb/local/LocalMongoDbService.java#L62-L68 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/StitchObjectMapper.java | StitchObjectMapper.withCodecRegistry | public StitchObjectMapper withCodecRegistry(final CodecRegistry codecRegistry) {
// We can't detect if their codecRegistry has any duplicate providers. There's also a chance
// that putting ours first may prevent decoding of some of their classes if for example they
// have their own way of decoding an Integer.
final CodecRegistry newReg =
CodecRegistries.fromRegistries(BsonUtils.DEFAULT_CODEC_REGISTRY, codecRegistry);
return new StitchObjectMapper(this, newReg);
} | java | public StitchObjectMapper withCodecRegistry(final CodecRegistry codecRegistry) {
// We can't detect if their codecRegistry has any duplicate providers. There's also a chance
// that putting ours first may prevent decoding of some of their classes if for example they
// have their own way of decoding an Integer.
final CodecRegistry newReg =
CodecRegistries.fromRegistries(BsonUtils.DEFAULT_CODEC_REGISTRY, codecRegistry);
return new StitchObjectMapper(this, newReg);
} | [
"public",
"StitchObjectMapper",
"withCodecRegistry",
"(",
"final",
"CodecRegistry",
"codecRegistry",
")",
"{",
"// We can't detect if their codecRegistry has any duplicate providers. There's also a chance",
"// that putting ours first may prevent decoding of some of their classes if for example ... | Applies the given codec registry to be used alongside the default codec registry.
@param codecRegistry the codec registry to merge in.
@return an {@link StitchObjectMapper} with the merged codec registries. | [
"Applies",
"the",
"given",
"codec",
"registry",
"to",
"be",
"used",
"alongside",
"the",
"default",
"codec",
"registry",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/common/StitchObjectMapper.java#L107-L114 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/Stream.java | Stream.nextEvent | public StitchEvent<T> nextEvent() throws IOException {
final Event nextEvent = eventStream.nextEvent();
if (nextEvent == null) {
return null;
}
return StitchEvent.fromEvent(nextEvent, this.decoder);
} | java | public StitchEvent<T> nextEvent() throws IOException {
final Event nextEvent = eventStream.nextEvent();
if (nextEvent == null) {
return null;
}
return StitchEvent.fromEvent(nextEvent, this.decoder);
} | [
"public",
"StitchEvent",
"<",
"T",
">",
"nextEvent",
"(",
")",
"throws",
"IOException",
"{",
"final",
"Event",
"nextEvent",
"=",
"eventStream",
".",
"nextEvent",
"(",
")",
";",
"if",
"(",
"nextEvent",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
... | Fetch the next event from a given stream
@return the next event
@throws IOException any io exception that could occur | [
"Fetch",
"the",
"next",
"event",
"from",
"a",
"given",
"stream"
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/internal/net/Stream.java#L52-L59 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/auth/internal/CoreStitchAuth.java | CoreStitchAuth.getUser | @Nullable
public StitchUserT getUser() {
authLock.readLock().lock();
try {
return activeUser;
} finally {
authLock.readLock().unlock();
}
} | java | @Nullable
public StitchUserT getUser() {
authLock.readLock().lock();
try {
return activeUser;
} finally {
authLock.readLock().unlock();
}
} | [
"@",
"Nullable",
"public",
"StitchUserT",
"getUser",
"(",
")",
"{",
"authLock",
".",
"readLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"return",
"activeUser",
";",
"}",
"finally",
"{",
"authLock",
".",
"readLock",
"(",
")",
".",
"unlock",
... | Returns the active logged in user. | [
"Returns",
"the",
"active",
"logged",
"in",
"user",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/auth/internal/CoreStitchAuth.java#L196-L204 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/auth/internal/CoreStitchAuth.java | CoreStitchAuth.doAuthenticatedRequest | private synchronized Response doAuthenticatedRequest(
final StitchAuthRequest stitchReq,
final AuthInfo authInfo
) {
try {
return requestClient.doRequest(prepareAuthRequest(stitchReq, authInfo));
} catch (final StitchServiceException ex) {
return handleAuthFailure(ex, stitchReq);
}
} | java | private synchronized Response doAuthenticatedRequest(
final StitchAuthRequest stitchReq,
final AuthInfo authInfo
) {
try {
return requestClient.doRequest(prepareAuthRequest(stitchReq, authInfo));
} catch (final StitchServiceException ex) {
return handleAuthFailure(ex, stitchReq);
}
} | [
"private",
"synchronized",
"Response",
"doAuthenticatedRequest",
"(",
"final",
"StitchAuthRequest",
"stitchReq",
",",
"final",
"AuthInfo",
"authInfo",
")",
"{",
"try",
"{",
"return",
"requestClient",
".",
"doRequest",
"(",
"prepareAuthRequest",
"(",
"stitchReq",
",",
... | Internal method which performs the authenticated request by preparing the auth request with
the provided auth info and request. | [
"Internal",
"method",
"which",
"performs",
"the",
"authenticated",
"request",
"by",
"preparing",
"the",
"auth",
"request",
"with",
"the",
"provided",
"auth",
"info",
"and",
"request",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/auth/internal/CoreStitchAuth.java#L234-L243 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/auth/internal/CoreStitchAuth.java | CoreStitchAuth.tryRefreshAccessToken | private void tryRefreshAccessToken(final Long reqStartedAt) {
authLock.writeLock().lock();
try {
if (!isLoggedIn()) {
throw new StitchClientException(StitchClientErrorCode.LOGGED_OUT_DURING_REQUEST);
}
try {
final Jwt jwt = Jwt.fromEncoded(getAuthInfo().getAccessToken());
if (jwt.getIssuedAt() >= reqStartedAt) {
return;
}
} catch (final IOException e) {
// Swallow
}
// retry
refreshAccessToken();
} finally {
authLock.writeLock().unlock();
}
} | java | private void tryRefreshAccessToken(final Long reqStartedAt) {
authLock.writeLock().lock();
try {
if (!isLoggedIn()) {
throw new StitchClientException(StitchClientErrorCode.LOGGED_OUT_DURING_REQUEST);
}
try {
final Jwt jwt = Jwt.fromEncoded(getAuthInfo().getAccessToken());
if (jwt.getIssuedAt() >= reqStartedAt) {
return;
}
} catch (final IOException e) {
// Swallow
}
// retry
refreshAccessToken();
} finally {
authLock.writeLock().unlock();
}
} | [
"private",
"void",
"tryRefreshAccessToken",
"(",
"final",
"Long",
"reqStartedAt",
")",
"{",
"authLock",
".",
"writeLock",
"(",
")",
".",
"lock",
"(",
")",
";",
"try",
"{",
"if",
"(",
"!",
"isLoggedIn",
"(",
")",
")",
"{",
"throw",
"new",
"StitchClientExc... | prevent too many refreshes happening one after the other. | [
"prevent",
"too",
"many",
"refreshes",
"happening",
"one",
"after",
"the",
"other",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/auth/internal/CoreStitchAuth.java#L570-L591 | train |
mongodb/stitch-android-sdk | core/sdk/src/main/java/com/mongodb/stitch/core/auth/internal/CoreStitchAuth.java | CoreStitchAuth.doLogin | private StitchUserT doLogin(final StitchCredential credential, final boolean asLinkRequest) {
final Response response = doLoginRequest(credential, asLinkRequest);
final StitchUserT previousUser = activeUser;
final StitchUserT user = processLoginResponse(credential, response, asLinkRequest);
if (asLinkRequest) {
onUserLinked(user);
} else {
onUserLoggedIn(user);
onActiveUserChanged(activeUser, previousUser);
}
return user;
} | java | private StitchUserT doLogin(final StitchCredential credential, final boolean asLinkRequest) {
final Response response = doLoginRequest(credential, asLinkRequest);
final StitchUserT previousUser = activeUser;
final StitchUserT user = processLoginResponse(credential, response, asLinkRequest);
if (asLinkRequest) {
onUserLinked(user);
} else {
onUserLoggedIn(user);
onActiveUserChanged(activeUser, previousUser);
}
return user;
} | [
"private",
"StitchUserT",
"doLogin",
"(",
"final",
"StitchCredential",
"credential",
",",
"final",
"boolean",
"asLinkRequest",
")",
"{",
"final",
"Response",
"response",
"=",
"doLoginRequest",
"(",
"credential",
",",
"asLinkRequest",
")",
";",
"final",
"StitchUserT"... | callers of doLogin should be serialized before calling in. | [
"callers",
"of",
"doLogin",
"should",
"be",
"serialized",
"before",
"calling",
"in",
"."
] | 159b9334b1f1a827285544be5ee20cdf7b04e4cc | https://github.com/mongodb/stitch-android-sdk/blob/159b9334b1f1a827285544be5ee20cdf7b04e4cc/core/sdk/src/main/java/com/mongodb/stitch/core/auth/internal/CoreStitchAuth.java#L631-L645 | train |
ThreeTen/threeten-extra | src/main/java/org/threeten/extra/Interval.java | Interval.parseStartExtended | private static Interval parseStartExtended(CharSequence startStr, CharSequence endStr) {
Instant start = Instant.parse(startStr);
if (endStr.length() > 0) {
char c = endStr.charAt(0);
if (c == 'P' || c == 'p') {
PeriodDuration amount = PeriodDuration.parse(endStr);
// addition of PeriodDuration only supported by OffsetDateTime,
// but to make that work need to move point being added to closer to EPOCH
long move = start.isBefore(Instant.EPOCH) ? 1000 * 86400 : -1000 * 86400;
Instant end = start.plusSeconds(move).atOffset(ZoneOffset.UTC).plus(amount).toInstant().minusSeconds(move);
return Interval.of(start, end);
}
}
// infer offset from start if not specified by end
return parseEndDateTime(start, ZoneOffset.UTC, endStr);
} | java | private static Interval parseStartExtended(CharSequence startStr, CharSequence endStr) {
Instant start = Instant.parse(startStr);
if (endStr.length() > 0) {
char c = endStr.charAt(0);
if (c == 'P' || c == 'p') {
PeriodDuration amount = PeriodDuration.parse(endStr);
// addition of PeriodDuration only supported by OffsetDateTime,
// but to make that work need to move point being added to closer to EPOCH
long move = start.isBefore(Instant.EPOCH) ? 1000 * 86400 : -1000 * 86400;
Instant end = start.plusSeconds(move).atOffset(ZoneOffset.UTC).plus(amount).toInstant().minusSeconds(move);
return Interval.of(start, end);
}
}
// infer offset from start if not specified by end
return parseEndDateTime(start, ZoneOffset.UTC, endStr);
} | [
"private",
"static",
"Interval",
"parseStartExtended",
"(",
"CharSequence",
"startStr",
",",
"CharSequence",
"endStr",
")",
"{",
"Instant",
"start",
"=",
"Instant",
".",
"parse",
"(",
"startStr",
")",
";",
"if",
"(",
"endStr",
".",
"length",
"(",
")",
">",
... | handle case where Instant is outside the bounds of OffsetDateTime | [
"handle",
"case",
"where",
"Instant",
"is",
"outside",
"the",
"bounds",
"of",
"OffsetDateTime"
] | e94ecd3592ef70e54d6eea21095239ea9ffbab78 | https://github.com/ThreeTen/threeten-extra/blob/e94ecd3592ef70e54d6eea21095239ea9ffbab78/src/main/java/org/threeten/extra/Interval.java#L203-L218 | train |
ThreeTen/threeten-extra | src/main/java/org/threeten/extra/Interval.java | Interval.parseEndDateTime | private static Interval parseEndDateTime(Instant start, ZoneOffset offset, CharSequence endStr) {
try {
TemporalAccessor temporal = DateTimeFormatter.ISO_DATE_TIME.parseBest(endStr, OffsetDateTime::from, LocalDateTime::from);
if (temporal instanceof OffsetDateTime) {
OffsetDateTime odt = (OffsetDateTime) temporal;
return Interval.of(start, odt.toInstant());
} else {
// infer offset from start if not specified by end
LocalDateTime ldt = (LocalDateTime) temporal;
return Interval.of(start, ldt.toInstant(offset));
}
} catch (DateTimeParseException ex) {
Instant end = Instant.parse(endStr);
return Interval.of(start, end);
}
} | java | private static Interval parseEndDateTime(Instant start, ZoneOffset offset, CharSequence endStr) {
try {
TemporalAccessor temporal = DateTimeFormatter.ISO_DATE_TIME.parseBest(endStr, OffsetDateTime::from, LocalDateTime::from);
if (temporal instanceof OffsetDateTime) {
OffsetDateTime odt = (OffsetDateTime) temporal;
return Interval.of(start, odt.toInstant());
} else {
// infer offset from start if not specified by end
LocalDateTime ldt = (LocalDateTime) temporal;
return Interval.of(start, ldt.toInstant(offset));
}
} catch (DateTimeParseException ex) {
Instant end = Instant.parse(endStr);
return Interval.of(start, end);
}
} | [
"private",
"static",
"Interval",
"parseEndDateTime",
"(",
"Instant",
"start",
",",
"ZoneOffset",
"offset",
",",
"CharSequence",
"endStr",
")",
"{",
"try",
"{",
"TemporalAccessor",
"temporal",
"=",
"DateTimeFormatter",
".",
"ISO_DATE_TIME",
".",
"parseBest",
"(",
"... | parse when there are two date-times | [
"parse",
"when",
"there",
"are",
"two",
"date",
"-",
"times"
] | e94ecd3592ef70e54d6eea21095239ea9ffbab78 | https://github.com/ThreeTen/threeten-extra/blob/e94ecd3592ef70e54d6eea21095239ea9ffbab78/src/main/java/org/threeten/extra/Interval.java#L221-L236 | train |
ThreeTen/threeten-extra | src/main/java/org/threeten/extra/chrono/AccountingChronology.java | AccountingChronology.date | @Override
public AccountingDate date(int prolepticYear, int month, int dayOfMonth) {
return AccountingDate.of(this, prolepticYear, month, dayOfMonth);
} | java | @Override
public AccountingDate date(int prolepticYear, int month, int dayOfMonth) {
return AccountingDate.of(this, prolepticYear, month, dayOfMonth);
} | [
"@",
"Override",
"public",
"AccountingDate",
"date",
"(",
"int",
"prolepticYear",
",",
"int",
"month",
",",
"int",
"dayOfMonth",
")",
"{",
"return",
"AccountingDate",
".",
"of",
"(",
"this",
",",
"prolepticYear",
",",
"month",
",",
"dayOfMonth",
")",
";",
... | Obtains a local date in Accounting calendar system from the
proleptic-year, month-of-year and day-of-month fields.
@param prolepticYear the proleptic-year
@param month the month-of-year
@param dayOfMonth the day-of-month
@return the Accounting local date, not null
@throws DateTimeException if unable to create the date | [
"Obtains",
"a",
"local",
"date",
"in",
"Accounting",
"calendar",
"system",
"from",
"the",
"proleptic",
"-",
"year",
"month",
"-",
"of",
"-",
"year",
"and",
"day",
"-",
"of",
"-",
"month",
"fields",
"."
] | e94ecd3592ef70e54d6eea21095239ea9ffbab78 | https://github.com/ThreeTen/threeten-extra/blob/e94ecd3592ef70e54d6eea21095239ea9ffbab78/src/main/java/org/threeten/extra/chrono/AccountingChronology.java#L307-L310 | train |
ThreeTen/threeten-extra | src/main/java/org/threeten/extra/chrono/AccountingChronology.java | AccountingChronology.dateYearDay | @Override
public AccountingDate dateYearDay(Era era, int yearOfEra, int dayOfYear) {
return dateYearDay(prolepticYear(era, yearOfEra), dayOfYear);
} | java | @Override
public AccountingDate dateYearDay(Era era, int yearOfEra, int dayOfYear) {
return dateYearDay(prolepticYear(era, yearOfEra), dayOfYear);
} | [
"@",
"Override",
"public",
"AccountingDate",
"dateYearDay",
"(",
"Era",
"era",
",",
"int",
"yearOfEra",
",",
"int",
"dayOfYear",
")",
"{",
"return",
"dateYearDay",
"(",
"prolepticYear",
"(",
"era",
",",
"yearOfEra",
")",
",",
"dayOfYear",
")",
";",
"}"
] | Obtains a local date in Accounting calendar system from the
era, year-of-era and day-of-year fields.
@param era the Accounting era, not null
@param yearOfEra the year-of-era
@param dayOfYear the day-of-year
@return the Accounting local date, not null
@throws DateTimeException if unable to create the date
@throws ClassCastException if the {@code era} is not a {@code AccountingEra} | [
"Obtains",
"a",
"local",
"date",
"in",
"Accounting",
"calendar",
"system",
"from",
"the",
"era",
"year",
"-",
"of",
"-",
"era",
"and",
"day",
"-",
"of",
"-",
"year",
"fields",
"."
] | e94ecd3592ef70e54d6eea21095239ea9ffbab78 | https://github.com/ThreeTen/threeten-extra/blob/e94ecd3592ef70e54d6eea21095239ea9ffbab78/src/main/java/org/threeten/extra/chrono/AccountingChronology.java#L323-L326 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.