Skip to content

Commit 228cc82

Browse files
authored
Merge pull request #3493 from HattoriHenzo/eventmesh-3491
[ISSUE #3491] Refactor class StandaloneAdmin and RocketMQAdmin
2 parents ca444b6 + 36b41e2 commit 228cc82

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

eventmesh-storage/eventmesh-storage-api/src/main/java/org/apache/eventmesh/api/admin/Admin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public interface Admin extends LifeCycle {
3737
/**
3838
* Initializes admin api service.
3939
*/
40-
void init(Properties keyValue) throws Exception;
40+
void init(Properties properties) throws Exception;
4141

4242
/**
4343
* Get the list of topics.

eventmesh-storage/eventmesh-storage-rocketmq/src/main/java/org/apache/eventmesh/storage/rocketmq/admin/RocketMQAdmin.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class RocketMQAdmin implements Admin {
5959
private int numOfQueue = 4;
6060
private int queuePermission = 6;
6161

62-
public RocketMQAdmin(Properties properties) {
62+
public RocketMQAdmin() {
6363
isStarted = new AtomicBoolean(false);
6464

6565
ConfigService configService = ConfigService.getInstance();
@@ -98,7 +98,8 @@ public void shutdown() {
9898
}
9999

100100
@Override
101-
public void init(Properties keyValue) throws Exception {
101+
public void init(Properties properties) {
102+
102103
}
103104

104105
@Override
@@ -163,11 +164,11 @@ public void deleteTopic(String topicName) throws Exception {
163164
}
164165

165166
@Override
166-
public List<CloudEvent> getEvent(String topicName, int offset, int length) throws Exception {
167+
public List<CloudEvent> getEvent(String topicName, int offset, int length) {
167168
return null;
168169
}
169170

170171
@Override
171-
public void publish(CloudEvent cloudEvent) throws Exception {
172+
public void publish(CloudEvent cloudEvent) {
172173
}
173174
}

eventmesh-storage/eventmesh-storage-rocketmq/src/main/java/org/apache/eventmesh/storage/rocketmq/admin/RocketMQAdminAdaptor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929

3030
public class RocketMQAdminAdaptor implements Admin {
3131

32-
private RocketMQAdmin admin;
32+
private final RocketMQAdmin admin;
3333

3434
public RocketMQAdminAdaptor() {
35+
admin = new RocketMQAdmin();
3536
}
3637

3738
@Override
@@ -55,8 +56,8 @@ public void shutdown() {
5556
}
5657

5758
@Override
58-
public void init(Properties keyValue) throws Exception {
59-
admin = new RocketMQAdmin(keyValue);
59+
public void init(Properties properties) throws Exception {
60+
admin.init(properties);
6061
}
6162

6263
@Override
@@ -75,12 +76,12 @@ public void deleteTopic(String topicName) throws Exception {
7576
}
7677

7778
@Override
78-
public List<CloudEvent> getEvent(String topicName, int offset, int length) throws Exception {
79+
public List<CloudEvent> getEvent(String topicName, int offset, int length) {
7980
return admin.getEvent(topicName, offset, length);
8081
}
8182

8283
@Override
83-
public void publish(CloudEvent cloudEvent) throws Exception {
84+
public void publish(CloudEvent cloudEvent) {
8485
admin.publish(cloudEvent);
8586
}
8687
}

eventmesh-storage/eventmesh-storage-standalone/src/main/java/org/apache/eventmesh/storage/standalone/admin/StandaloneAdmin.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737
public class StandaloneAdmin implements Admin {
3838

3939
private final AtomicBoolean isStarted;
40-
4140
private final StandaloneBroker standaloneBroker;
4241

43-
public StandaloneAdmin(Properties properties) {
42+
public StandaloneAdmin() {
4443
this.standaloneBroker = StandaloneBroker.getInstance();
4544
this.isStarted = new AtomicBoolean(false);
4645
}
@@ -66,20 +65,21 @@ public void shutdown() {
6665
}
6766

6867
@Override
69-
public void init(Properties keyValue) throws Exception {
68+
public void init(Properties properties) throws Exception {
69+
7070
}
7171

7272
@Override
7373
public List<TopicProperties> getTopic() throws Exception {
7474
ConcurrentHashMap<TopicMetadata, MessageQueue> messageContainer = this.standaloneBroker.getMessageContainer();
7575
List<TopicProperties> topicList = new ArrayList<>();
76-
for (TopicMetadata topicMetadata : messageContainer.keySet()) {
76+
messageContainer.keySet().forEach(topicMetadata -> {
7777
MessageQueue messageQueue = messageContainer.get(topicMetadata);
7878
topicList.add(new TopicProperties(
7979
topicMetadata.getTopicName(),
8080
messageQueue.getPutIndex() - messageQueue.getTakeIndex()
8181
));
82-
}
82+
});
8383
topicList.sort(Comparator.comparing(t -> t.name));
8484
return topicList;
8585
}

eventmesh-storage/eventmesh-storage-standalone/src/main/java/org/apache/eventmesh/storage/standalone/admin/StandaloneAdminAdaptor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929

3030
public class StandaloneAdminAdaptor implements Admin {
3131

32-
private StandaloneAdmin admin;
32+
private final StandaloneAdmin admin;
3333

3434
public StandaloneAdminAdaptor() {
35+
admin = new StandaloneAdmin();
3536
}
3637

3738
@Override
@@ -55,8 +56,8 @@ public void shutdown() {
5556
}
5657

5758
@Override
58-
public void init(Properties keyValue) throws Exception {
59-
admin = new StandaloneAdmin(keyValue);
59+
public void init(Properties properties) throws Exception {
60+
admin.init(properties);
6061
}
6162

6263
@Override

eventmesh-storage/eventmesh-storage-standalone/src/test/java/org/apache/eventmesh/storage/standalone/admin/StandaloneAdminTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.eventmesh.storage.standalone.broker.model.MessageEntity;
3131

3232
import java.util.List;
33-
import java.util.Properties;
3433

3534
import org.junit.Assert;
3635
import org.junit.Before;
@@ -115,7 +114,7 @@ private void initStaticInstance() {
115114
try (MockedStatic<StandaloneBroker> standaloneBrokerMockedStatic = Mockito.mockStatic(StandaloneBroker.class)) {
116115
standaloneBrokerMockedStatic.when(StandaloneBroker::getInstance).thenReturn(standaloneBroker);
117116
Mockito.when(standaloneBroker.getMessageContainer()).thenReturn(createDefaultMessageContainer());
118-
standaloneAdmin = new StandaloneAdmin(new Properties());
117+
standaloneAdmin = new StandaloneAdmin();
119118
}
120119
}
121120
}

0 commit comments

Comments
 (0)