
com.couchbase.transactions.log.PersistedLogReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of couchbase-transactions Show documentation
Show all versions of couchbase-transactions Show documentation
Transaction Support for Couchbase on top of the Java SDK
The newest version!
/*
* Copyright 2021 Couchbase, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.couchbase.transactions.log;
import com.couchbase.client.core.annotation.Stability;
import com.couchbase.client.java.Collection;
import com.couchbase.client.java.json.JsonArray;
import com.couchbase.client.java.json.JsonObject;
import com.couchbase.client.java.kv.LookupInSpec;
import com.couchbase.transactions.error.internal.ErrorClasses;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import java.time.LocalDateTime;
import java.util.Arrays;
class LogEntry {
public final String clientUuid;
public final String value;
public final LocalDateTime clientTime;
public final String serverTime;
LogEntry(String clientUuid, String value, LocalDateTime clientTime, String serverTime) {
this.clientUuid = clientUuid;
this.value = value;
this.clientTime = clientTime;
this.serverTime = serverTime;
}
static public LogEntry create(JsonObject o) {
return new LogEntry(
o.getString("u"),
o.getString("v"),
LocalDateTime.parse(o.getString("t")),
o.getString("c"));
}
}
@Stability.Internal
public class PersistedLogReader {
public static Flux read(Collection collection) {
return collection.reactive().lookupIn(PersistedLogWriter.PERSISTED_LOG_DOC_ID,
Arrays.asList(
LookupInSpec.get("l.logs").xattr()
))
.onErrorResume(err -> {
ErrorClasses ec = ErrorClasses.classify(err);
if (ec == ErrorClasses.FAIL_DOC_NOT_FOUND) {
return Mono.empty();
}
else {
return Mono.error(err);
}
})
.flatMapMany(result -> {
JsonArray logs = result.contentAsArray(0);
return Flux.fromIterable(logs)
.map(log -> LogEntry.create((JsonObject) log));
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy