projects
/
demos
/
kafka
/
chat
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: DRY for logging-category from io.projectreactor
[demos/kafka/chat]
/
src
/
main
/
java
/
de
/
juplo
/
kafka
/
chat
/
backend
/
storage
/
files
/
FilesStorageStrategy.java
diff --git
a/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java
b/src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java
index
7e04a96
..
7c1fef0
100644
(file)
--- a/
src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java
+++ b/
src/main/java/de/juplo/kafka/chat/backend/storage/files/FilesStorageStrategy.java
@@
-17,6
+17,7
@@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.UUID;
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;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
@@
-32,10
+33,13
@@
public class FilesStorageStrategy implements StorageStrategy
private final Path storagePath;
private final ShardingStrategy shardingStrategy;
private final ObjectMapper mapper;
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
@Override
- public
void
writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux)
+ public
Flux<ChatRoomInfo>
writeChatRoomInfo(Flux<ChatRoomInfo> chatRoomInfoFlux)
{
Path path = chatroomsPath();
log.info("Writing chatrooms to {}", path);
{
Path path = chatroomsPath();
log.info("Writing chatrooms to {}", path);
@@
-48,8
+52,11
@@
public class FilesStorageStrategy implements StorageStrategy
.getFactory()
.createGenerator(Files.newBufferedWriter(path, CREATE, TRUNCATE_EXISTING));
.getFactory()
.createGenerator(Files.newBufferedWriter(path, CREATE, TRUNCATE_EXISTING));
- chatRoomInfoFlux
- .log()
+ return chatRoomInfoFlux
+ .log(
+ loggingCategory,
+ loggingLevel,
+ showOperatorLine)
.doFirst(() ->
{
try
.doFirst(() ->
{
try
@@
-86,8
+93,7
@@
public class FilesStorageStrategy implements StorageStrategy
{
throw new RuntimeException(e);
}
{
throw new RuntimeException(e);
}
- })
- .subscribe();
+ });
}
catch (IOException e)
{
}
catch (IOException e)
{
@@
-101,7
+107,10
@@
public class FilesStorageStrategy implements StorageStrategy
JavaType type = mapper.getTypeFactory().constructType(ChatRoomInfoTo.class);
return Flux
.from(new JsonFilePublisher<ChatRoomInfoTo>(chatroomsPath(), mapper, type))
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();
.map(chatRoomInfoTo ->
{
UUID chatRoomId = chatRoomInfoTo.getId();
@@
-121,7
+130,7
@@
public class FilesStorageStrategy implements StorageStrategy
}
@Override
}
@Override
- public
void
writeChatRoomData(
+ public
Flux<Message>
writeChatRoomData(
UUID chatRoomId,
Flux<Message> messageFlux)
{
UUID chatRoomId,
Flux<Message> messageFlux)
{
@@
-136,8
+145,11
@@
public class FilesStorageStrategy implements StorageStrategy
.getFactory()
.createGenerator(Files.newBufferedWriter(path, CREATE, TRUNCATE_EXISTING));
.getFactory()
.createGenerator(Files.newBufferedWriter(path, CREATE, TRUNCATE_EXISTING));
- messageFlux
- .log()
+ return messageFlux
+ .log(
+ loggingCategory,
+ loggingLevel,
+ showOperatorLine)
.doFirst(() ->
{
try
.doFirst(() ->
{
try
@@
-174,8
+186,7
@@
public class FilesStorageStrategy implements StorageStrategy
{
throw new RuntimeException(e);
}
{
throw new RuntimeException(e);
}
- })
- .subscribe();
+ });
}
catch (IOException e)
{
}
catch (IOException e)
{
@@
-189,7
+200,10
@@
public class FilesStorageStrategy implements StorageStrategy
JavaType type = mapper.getTypeFactory().constructType(MessageTo.class);
return Flux
.from(new JsonFilePublisher<MessageTo>(chatroomPath(chatRoomId), mapper, type))
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);
}
.map(MessageTo::toMessage);
}