Skip to content

Commit d0fa61b

Browse files
feat: apply Spotless plugin for code style consistency
- Implement Google Java Format (AOSP style) - Organize imports and remove unused ones - Add spotlessApply dependency to JavaCompile tasks - Apply trailing whitespace removal and ensure files end with newline
1 parent 5fa83a1 commit d0fa61b

100 files changed

Lines changed: 607 additions & 538 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
plugins {
99
// Apply the java-library plugin for API and implementation separation.
1010
id 'java-library'
11+
id 'com.diffplug.spotless' version '6.23.3' // Spotless 플러그인 (코드 포맷팅)
1112
}
1213

1314
repositories {
@@ -29,6 +30,21 @@ dependencies {
2930
implementation 'com.google.code.gson:gson:2.10.1'
3031
}
3132

33+
spotless {
34+
java {
35+
// Google Java format.
36+
googleJavaFormat().aosp()
37+
// import ordering
38+
importOrder('java', 'javax', 'jakarta', 'org', 'com')
39+
// remove unused imports
40+
removeUnusedImports()
41+
// trim trailing whitespace
42+
trimTrailingWhitespace()
43+
// end with newline
44+
endWithNewline()
45+
}
46+
}
47+
3248
// Apply a specific Java toolchain to ease working on different environments.
3349
java {
3450
toolchain {
@@ -38,6 +54,7 @@ java {
3854

3955
tasks.withType(JavaCompile) {
4056
options.encoding = 'UTF-8'
57+
dependsOn 'spotlessApply'
4158
}
4259
test {
4360
// 테스트 로그를 표준 출력으로 리다이렉트

lib/src/main/java/com/github/getcurrentthread/soopapi/client/IChatMessageObserver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
public interface IChatMessageObserver {
66
void notify(Message message);
7-
}
7+
}
Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
package com.github.getcurrentthread.soopapi.client;
22

3-
import com.github.getcurrentthread.soopapi.config.SOOPChatConfig;
4-
import com.github.getcurrentthread.soopapi.connection.ConnectionManager;
5-
import com.github.getcurrentthread.soopapi.model.Message;
6-
import com.github.getcurrentthread.soopapi.util.SOOPChatUtils;
7-
83
import java.util.List;
94
import java.util.concurrent.CompletableFuture;
105
import java.util.concurrent.CompletionException;
116
import java.util.concurrent.CopyOnWriteArrayList;
127
import java.util.logging.Level;
138
import java.util.logging.Logger;
149

10+
import com.github.getcurrentthread.soopapi.config.SOOPChatConfig;
11+
import com.github.getcurrentthread.soopapi.connection.ConnectionManager;
12+
import com.github.getcurrentthread.soopapi.model.Message;
13+
import com.github.getcurrentthread.soopapi.util.SOOPChatUtils;
14+
1515
public class SOOPChatClient implements AutoCloseable {
1616
private static final Logger LOGGER = Logger.getLogger(SOOPChatClient.class.getName());
17-
17+
1818
private final SOOPChatConfig config;
1919
private final ConnectionManager connectionManager;
2020
private final List<IChatMessageObserver> observers;
2121
private volatile boolean isConnected;
22-
22+
2323
public SOOPChatClient(SOOPChatConfig config) {
2424
this.config = validateConfig(config);
2525
this.connectionManager = ConnectionManager.getInstance();
2626
this.observers = new CopyOnWriteArrayList<>();
2727
}
28-
28+
2929
private SOOPChatConfig validateConfig(SOOPChatConfig config) {
3030
if (config.getBno() == null) {
3131
String bno = SOOPChatUtils.getBnoFromBid(config.getBid());
3232
return new SOOPChatConfig.Builder()
33-
.bid(config.getBid())
34-
.bno(bno)
35-
.sslContext(config.getSSLContext())
36-
.build();
33+
.bid(config.getBid())
34+
.bno(bno)
35+
.sslContext(config.getSSLContext())
36+
.build();
3737
}
3838
return config;
3939
}
40-
40+
4141
public void addObserver(IChatMessageObserver observer) {
4242
observers.add(observer);
4343
}
44-
44+
4545
public void removeObserver(IChatMessageObserver observer) {
4646
observers.remove(observer);
4747
}
48-
48+
4949
private void notifyObservers(Message message) {
5050
for (IChatMessageObserver observer : observers) {
5151
try {
@@ -55,50 +55,54 @@ private void notifyObservers(Message message) {
5555
}
5656
}
5757
}
58-
58+
5959
public CompletableFuture<Void> connectToChat() {
6060
if (isConnected) {
6161
return CompletableFuture.completedFuture(null);
6262
}
63-
64-
return CompletableFuture.runAsync(() -> {
65-
try {
66-
connectionManager.connect(config, this::notifyObservers)
67-
.thenRun(() -> isConnected = true)
68-
.exceptionally(throwable -> {
69-
LOGGER.log(Level.SEVERE, "Failed to connect", throwable);
70-
return null;
71-
})
72-
.join();
73-
} catch (Exception e) {
74-
throw new CompletionException("Failed to connect to chat", e);
75-
}
76-
});
63+
64+
return CompletableFuture.runAsync(
65+
() -> {
66+
try {
67+
connectionManager
68+
.connect(config, this::notifyObservers)
69+
.thenRun(() -> isConnected = true)
70+
.exceptionally(
71+
throwable -> {
72+
LOGGER.log(
73+
Level.SEVERE, "Failed to connect", throwable);
74+
return null;
75+
})
76+
.join();
77+
} catch (Exception e) {
78+
throw new CompletionException("Failed to connect to chat", e);
79+
}
80+
});
7781
}
78-
82+
7983
public void disconnect() {
8084
if (!isConnected) {
8185
return;
8286
}
83-
87+
8488
try {
8589
connectionManager.disconnect(config.getBid());
8690
isConnected = false;
8791
} catch (Exception e) {
8892
LOGGER.log(Level.WARNING, "Error during disconnect", e);
8993
}
9094
}
91-
95+
9296
@Override
9397
public void close() {
9498
disconnect();
9599
}
96-
100+
97101
public boolean isConnected() {
98102
return isConnected;
99103
}
100-
104+
101105
public String getBid() {
102106
return config.getBid();
103107
}
104-
}
108+
}

lib/src/main/java/com/github/getcurrentthread/soopapi/config/SOOPChatConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ public SOOPChatConfig build() {
4949
return new SOOPChatConfig(this);
5050
}
5151
}
52-
}
52+
}

lib/src/main/java/com/github/getcurrentthread/soopapi/connection/ConnectionManager.java

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.github.getcurrentthread.soopapi.connection;
22

3-
import com.github.getcurrentthread.soopapi.client.IChatMessageObserver;
4-
import com.github.getcurrentthread.soopapi.config.SOOPChatConfig;
5-
63
import java.util.Map;
74
import java.util.concurrent.*;
85
import java.util.logging.Logger;
96

7+
import com.github.getcurrentthread.soopapi.client.IChatMessageObserver;
8+
import com.github.getcurrentthread.soopapi.config.SOOPChatConfig;
9+
1010
public class ConnectionManager {
1111
private static final Logger LOGGER = Logger.getLogger(ConnectionManager.class.getName());
1212
private static final int CORE_POOL_SIZE = Runtime.getRuntime().availableProcessors();
@@ -21,13 +21,14 @@ private static class InstanceHolder {
2121
}
2222

2323
private ConnectionManager() {
24-
this.messageProcessorPool = new ThreadPoolExecutor(
25-
CORE_POOL_SIZE,
26-
MAX_POOL_SIZE,
27-
60L, TimeUnit.SECONDS,
28-
new LinkedBlockingQueue<>(5000),
29-
new ThreadPoolExecutor.CallerRunsPolicy()
30-
);
24+
this.messageProcessorPool =
25+
new ThreadPoolExecutor(
26+
CORE_POOL_SIZE,
27+
MAX_POOL_SIZE,
28+
60L,
29+
TimeUnit.SECONDS,
30+
new LinkedBlockingQueue<>(5000),
31+
new ThreadPoolExecutor.CallerRunsPolicy());
3132

3233
this.sharedScheduler = Executors.newScheduledThreadPool(2);
3334
this.connections = new ConcurrentHashMap<>();
@@ -37,17 +38,23 @@ public static ConnectionManager getInstance() {
3738
return InstanceHolder.INSTANCE;
3839
}
3940

40-
public CompletableFuture<SOOPConnection> connect(SOOPChatConfig config, IChatMessageObserver observer) {
41+
public CompletableFuture<SOOPConnection> connect(
42+
SOOPChatConfig config, IChatMessageObserver observer) {
4143
String bid = config.getBid();
4244

43-
return CompletableFuture.supplyAsync(() -> {
44-
SOOPConnection connection = connections.computeIfAbsent(bid,
45-
k -> new SOOPConnection(config, messageProcessorPool, sharedScheduler));
45+
return CompletableFuture.supplyAsync(
46+
() -> {
47+
SOOPConnection connection =
48+
connections.computeIfAbsent(
49+
bid,
50+
k ->
51+
new SOOPConnection(
52+
config, messageProcessorPool, sharedScheduler));
4653

47-
connection.addObserver(observer);
48-
connection.connect().join();
49-
return connection;
50-
});
54+
connection.addObserver(observer);
55+
connection.connect().join();
56+
return connection;
57+
});
5158
}
5259

5360
public void disconnect(String bid) {
@@ -75,4 +82,4 @@ public void shutdown() {
7582
Thread.currentThread().interrupt();
7683
}
7784
}
78-
}
85+
}

lib/src/main/java/com/github/getcurrentthread/soopapi/connection/SOOPConnection.java

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.github.getcurrentthread.soopapi.connection;
22

3+
import java.util.List;
4+
import java.util.concurrent.*;
5+
import java.util.logging.Level;
6+
import java.util.logging.Logger;
7+
38
import com.github.getcurrentthread.soopapi.client.IChatMessageObserver;
49
import com.github.getcurrentthread.soopapi.config.SOOPChatConfig;
510
import com.github.getcurrentthread.soopapi.decoder.MessageDispatcher;
@@ -10,11 +15,6 @@
1015
import com.github.getcurrentthread.soopapi.websocket.WebSocketListener;
1116
import com.github.getcurrentthread.soopapi.websocket.WebSocketManager;
1217

13-
import java.util.List;
14-
import java.util.concurrent.*;
15-
import java.util.logging.Level;
16-
import java.util.logging.Logger;
17-
1818
public class SOOPConnection {
1919
private static final Logger LOGGER = Logger.getLogger(SOOPConnection.class.getName());
2020

@@ -26,45 +26,50 @@ public class SOOPConnection {
2626
private final WebSocketManager webSocketManager;
2727
private volatile boolean isConnected;
2828

29-
public SOOPConnection(SOOPChatConfig config,
30-
ExecutorService messageProcessor,
31-
ScheduledExecutorService scheduler) {
29+
public SOOPConnection(
30+
SOOPChatConfig config,
31+
ExecutorService messageProcessor,
32+
ScheduledExecutorService scheduler) {
3233
this.config = config;
3334
this.messageProcessor = messageProcessor;
3435
this.scheduler = scheduler;
3536
this.observers = new CopyOnWriteArrayList<>();
3637

3738
// MessageDispatcher 초기화
38-
this.messageDispatcher = new MessageDispatcher(
39-
new DefaultMessageDecoderFactory().createDecoders(),
40-
messageProcessor
41-
);
39+
this.messageDispatcher =
40+
new MessageDispatcher(
41+
new DefaultMessageDecoderFactory().createDecoders(), messageProcessor);
4242

4343
// 메시지 핸들러 설정
4444
this.messageDispatcher.setMessageHandler(this::notifyObservers);
4545

4646
// WebSocketManager 초기화
4747
WebSocketListener listener = new WebSocketListener(messageDispatcher);
48-
this.webSocketManager = new WebSocketManager(config, config.getSSLContext(), scheduler, listener);
48+
this.webSocketManager =
49+
new WebSocketManager(config, config.getSSLContext(), scheduler, listener);
4950
}
5051

5152
public CompletableFuture<Void> connect() {
52-
return CompletableFuture.runAsync(() -> {
53-
try {
54-
LOGGER.info("Fetching channel info for BID: " + config.getBid());
55-
String bno = config.getBno() != null ? config.getBno() :
56-
SOOPChatUtils.getBnoFromBid(config.getBid());
57-
58-
ChannelInfo channelInfo = SOOPChatUtils.getPlayerLive(bno, config.getBid());
59-
LOGGER.info("Channel info received: " + channelInfo);
60-
61-
webSocketManager.connect(channelInfo).join();
62-
isConnected = true;
63-
} catch (Exception e) {
64-
LOGGER.log(Level.SEVERE, "Connection failed", e);
65-
throw new CompletionException(e);
66-
}
67-
}, scheduler);
53+
return CompletableFuture.runAsync(
54+
() -> {
55+
try {
56+
LOGGER.info("Fetching channel info for BID: " + config.getBid());
57+
String bno =
58+
config.getBno() != null
59+
? config.getBno()
60+
: SOOPChatUtils.getBnoFromBid(config.getBid());
61+
62+
ChannelInfo channelInfo = SOOPChatUtils.getPlayerLive(bno, config.getBid());
63+
LOGGER.info("Channel info received: " + channelInfo);
64+
65+
webSocketManager.connect(channelInfo).join();
66+
isConnected = true;
67+
} catch (Exception e) {
68+
LOGGER.log(Level.SEVERE, "Connection failed", e);
69+
throw new CompletionException(e);
70+
}
71+
},
72+
scheduler);
6873
}
6974

7075
private void notifyObservers(Message message) {
@@ -107,4 +112,4 @@ public void disconnect() {
107112
public boolean isConnected() {
108113
return isConnected && webSocketManager.isConnected();
109114
}
110-
}
115+
}

lib/src/main/java/com/github/getcurrentthread/soopapi/constant/SOOPConstants.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ public class SOOPConstants {
44
public static final String F = "\u000c";
55
public static final String ESC = "\u001b\t";
66

7-
private SOOPConstants() {
8-
}
9-
}
7+
private SOOPConstants() {}
8+
}

0 commit comments

Comments
 (0)