import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;
+import java.util.logging.Level;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
private final Path storagePath;
private final ShardingStrategy shardingStrategy;
private final ObjectMapper mapper;
+ private final String loggingCategory = FilesStorageStrategy.class.getSimpleName();
+ private final Level loggingLevel;
+ private final boolean showOperatorLine;
@Override
- public void writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux)
+ public Flux<ChatRoomInfo> writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux)
{
Path path = chatroomsPath();
log.info("Writing chatrooms to {}", path);
.getFactory()
.createGenerator(Files.newBufferedWriter(path, CREATE, TRUNCATE_EXISTING));
- chatRoomInfoFlux
- .log()
+ return chatRoomInfoFlux
+ .log(
+ loggingCategory,
+ loggingLevel,
+ showOperatorLine)
.doFirst(() ->
{
try
throw new RuntimeException(e);
}
})
- .subscribe(chatRoomInfo ->
+ .map(chatRoomInfo ->
{
try
{
ChatRoomInfoTo chatRoomInfoTo = ChatRoomInfoTo.from(chatRoomInfo);
generator.writeObject(chatRoomInfoTo);
+ return chatRoomInfo;
}
catch (IOException e)
{
JavaType type = mapper.getTypeFactory().constructType(ChatRoomInfoTo.class);
return Flux
.from(new JsonFilePublisher<ChatRoomInfoTo>(chatroomsPath(), mapper, type))
- .log()
+ .log(
+ loggingCategory,
+ loggingLevel,
+ showOperatorLine)
.map(chatRoomInfoTo ->
{
UUID chatRoomId = chatRoomInfoTo.getId();
}
@Override
- public void writeChatRoomData(
+ public Flux<Message> writeChatRoomData(
UUID chatRoomId,
Flux<Message> messageFlux)
{
.getFactory()
.createGenerator(Files.newBufferedWriter(path, CREATE, TRUNCATE_EXISTING));
- messageFlux
- .log()
+ return messageFlux
+ .log(
+ loggingCategory,
+ loggingLevel,
+ showOperatorLine)
.doFirst(() ->
{
try
throw new RuntimeException(e);
}
})
- .subscribe(message ->
+ .map(message ->
{
try
{
MessageTo messageTo = MessageTo.from(message);
generator.writeObject(messageTo);
+ return message;
}
catch (IOException e)
{
JavaType type = mapper.getTypeFactory().constructType(MessageTo.class);
return Flux
.from(new JsonFilePublisher<MessageTo>(chatroomPath(chatRoomId), mapper, type))
- .log()
+ .log(
+ loggingCategory,
+ loggingLevel,
+ showOperatorLine)
.map(MessageTo::toMessage);
}