Skip to content

Commit 6456630

Browse files
[#148] Throwables.propagate in deprecated for making runtime exception more verbose (#160)
1 parent a25ccd6 commit 6456630

File tree

14 files changed

+118
-63
lines changed

14 files changed

+118
-63
lines changed

src/main/java/org/apache/rocketmq/dashboard/service/AbstractCommonService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ protected final Set<String> changeToBrokerNameSet(Map<String, Set<String>> clust
3838
}
3939
}
4040
catch (Exception e) {
41-
throw Throwables.propagate(e);
41+
Throwables.throwIfUnchecked(e);
42+
throw new RuntimeException(e);
4243
}
4344
}
4445
if (CollectionUtils.isNotEmpty(brokerNameList)) {

src/main/java/org/apache/rocketmq/dashboard/service/client/MQAdminExtImpl.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,16 @@ public void createAndUpdateSubscriptionGroupConfig(String addr, SubscriptionGrou
140140
}
141141

142142
@Override
143-
public SubscriptionGroupConfig examineSubscriptionGroupConfig(String addr, String group) {
143+
public SubscriptionGroupConfig examineSubscriptionGroupConfig(String addr, String group) throws MQBrokerException {
144144
RemotingClient remotingClient = MQAdminInstance.threadLocalRemotingClient();
145145
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
146146
RemotingCommand response = null;
147147
try {
148148
response = remotingClient.invokeSync(addr, request, 3000);
149149
}
150150
catch (Exception err) {
151-
throw Throwables.propagate(err);
151+
Throwables.throwIfUnchecked(err);
152+
throw new RuntimeException(err);
152153
}
153154
assert response != null;
154155
switch (response.getCode()) {
@@ -157,28 +158,29 @@ public SubscriptionGroupConfig examineSubscriptionGroupConfig(String addr, Strin
157158
return subscriptionGroupWrapper.getSubscriptionGroupTable().get(group);
158159
}
159160
default:
160-
throw Throwables.propagate(new MQBrokerException(response.getCode(), response.getRemark()));
161+
throw new MQBrokerException(response.getCode(), response.getRemark());
161162
}
162163
}
163164

164165
@Override
165-
public TopicConfig examineTopicConfig(String addr, String topic) {
166+
public TopicConfig examineTopicConfig(String addr, String topic) throws MQBrokerException {
166167
RemotingClient remotingClient = MQAdminInstance.threadLocalRemotingClient();
167168
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null);
168169
RemotingCommand response = null;
169170
try {
170171
response = remotingClient.invokeSync(addr, request, 3000);
171172
}
172173
catch (Exception err) {
173-
throw Throwables.propagate(err);
174+
Throwables.throwIfUnchecked(err);
175+
throw new RuntimeException(err);
174176
}
175177
switch (response.getCode()) {
176178
case ResponseCode.SUCCESS: {
177179
TopicConfigSerializeWrapper topicConfigSerializeWrapper = decode(response.getBody(), TopicConfigSerializeWrapper.class);
178180
return topicConfigSerializeWrapper.getTopicConfigTable().get(topic);
179181
}
180182
default:
181-
throw Throwables.propagate(new MQBrokerException(response.getCode(), response.getRemark()));
183+
throw new MQBrokerException(response.getCode(), response.getRemark());
182184
}
183185
}
184186

src/main/java/org/apache/rocketmq/dashboard/service/impl/AclServiceImpl.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public AclConfig getAclConfig(boolean excludeSecretKey) {
6868
}
6969
} catch (Exception e) {
7070
log.error("getAclConfig error.", e);
71-
throw Throwables.propagate(e);
71+
Throwables.throwIfUnchecked(e);
72+
throw new RuntimeException(e);
7273
}
7374
AclConfig aclConfig = new AclConfig();
7475
aclConfig.setGlobalWhiteAddrs(Collections.emptyList());
@@ -100,7 +101,8 @@ public void addAclConfig(PlainAccessConfig config) {
100101
mqAdminExt.createAndUpdatePlainAccessConfig(addr, config);
101102
}
102103
} catch (Exception e) {
103-
throw Throwables.propagate(e);
104+
Throwables.throwIfUnchecked(e);
105+
throw new RuntimeException(e);
104106
}
105107

106108
}
@@ -116,7 +118,8 @@ public void deleteAclConfig(PlainAccessConfig config) {
116118
log.info("Delete acl [{}] from broker [{}] complete", config.getAccessKey(), addr);
117119
}
118120
} catch (Exception e) {
119-
throw Throwables.propagate(e);
121+
Throwables.throwIfUnchecked(e);
122+
throw new RuntimeException(e);
120123
}
121124
}
122125

@@ -142,7 +145,8 @@ public void updateAclConfig(PlainAccessConfig config) {
142145
mqAdminExt.createAndUpdatePlainAccessConfig(addr, config);
143146
}
144147
} catch (Exception e) {
145-
throw Throwables.propagate(e);
148+
Throwables.throwIfUnchecked(e);
149+
throw new RuntimeException(e);
146150
}
147151
}
148152

@@ -174,7 +178,8 @@ public void addOrUpdateAclTopicConfig(AclRequest request) {
174178
}
175179
}
176180
} catch (Exception e) {
177-
throw Throwables.propagate(e);
181+
Throwables.throwIfUnchecked(e);
182+
throw new RuntimeException(e);
178183
}
179184
}
180185

@@ -206,7 +211,8 @@ public void addOrUpdateAclGroupConfig(AclRequest request) {
206211
}
207212
}
208213
} catch (Exception e) {
209-
throw Throwables.propagate(e);
214+
Throwables.throwIfUnchecked(e);
215+
throw new RuntimeException(e);
210216
}
211217
}
212218

@@ -249,7 +255,8 @@ public void deletePermConfig(AclRequest request) {
249255
}
250256
}
251257
} catch (Exception e) {
252-
throw Throwables.propagate(e);
258+
Throwables.throwIfUnchecked(e);
259+
throw new RuntimeException(e);
253260
}
254261

255262
}
@@ -261,7 +268,8 @@ public void syncData(PlainAccessConfig config) {
261268
mqAdminExt.createAndUpdatePlainAccessConfig(addr, config);
262269
}
263270
} catch (Exception e) {
264-
throw Throwables.propagate(e);
271+
Throwables.throwIfUnchecked(e);
272+
throw new RuntimeException(e);
265273
}
266274
}
267275

@@ -281,7 +289,8 @@ public void addWhiteList(List<String> whiteList) {
281289
mqAdminExt.updateGlobalWhiteAddrConfig(addr, StringUtils.join(aclConfig.getGlobalWhiteAddrs(), ","));
282290
}
283291
} catch (Exception e) {
284-
throw Throwables.propagate(e);
292+
Throwables.throwIfUnchecked(e);
293+
throw new RuntimeException(e);
285294
}
286295
}
287296

@@ -297,7 +306,8 @@ public void deleteWhiteAddr(String deleteAddr) {
297306
mqAdminExt.updateGlobalWhiteAddrConfig(addr, StringUtils.join(aclConfig.getGlobalWhiteAddrs(), ","));
298307
}
299308
} catch (Exception e) {
300-
throw Throwables.propagate(e);
309+
Throwables.throwIfUnchecked(e);
310+
throw new RuntimeException(e);
301311
}
302312
}
303313

@@ -311,7 +321,8 @@ public void synchronizeWhiteList(List<String> whiteList) {
311321
mqAdminExt.updateGlobalWhiteAddrConfig(addr, StringUtils.join(whiteList, ","));
312322
}
313323
} catch (Exception e) {
314-
throw Throwables.propagate(e);
324+
Throwables.throwIfUnchecked(e);
325+
throw new RuntimeException(e);
315326
}
316327
}
317328

src/main/java/org/apache/rocketmq/dashboard/service/impl/ClusterServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public Map<String, Object> list() {
5959
return resultMap;
6060
}
6161
catch (Exception err) {
62-
throw Throwables.propagate(err);
62+
Throwables.throwIfUnchecked(err);
63+
throw new RuntimeException(err);
6364
}
6465
}
6566

@@ -70,7 +71,8 @@ public Properties getBrokerConfig(String brokerAddr) {
7071
return mqAdminExt.getBrokerConfig(brokerAddr);
7172
}
7273
catch (Exception e) {
73-
throw Throwables.propagate(e);
74+
Throwables.throwIfUnchecked(e);
75+
throw new RuntimeException(e);
7476
}
7577
}
7678
}

src/main/java/org/apache/rocketmq/dashboard/service/impl/ConsumerServiceImpl.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@
7373
import org.springframework.beans.factory.InitializingBean;
7474
import org.springframework.stereotype.Service;
7575

76-
import static com.google.common.base.Throwables.propagate;
77-
7876
@Service
7977
public class ConsumerServiceImpl extends AbstractCommonService implements ConsumerService, InitializingBean, DisposableBean {
8078
private Logger logger = LoggerFactory.getLogger(ConsumerServiceImpl.class);
@@ -131,7 +129,8 @@ public List<GroupConsumeInfo> queryGroupList(boolean skipSysGroup) {
131129
}
132130
}
133131
catch (Exception err) {
134-
throw Throwables.propagate(err);
132+
Throwables.throwIfUnchecked(err);
133+
throw new RuntimeException(err);
135134
}
136135
List<GroupConsumeInfo> groupConsumeInfoList = Collections.synchronizedList(Lists.newArrayList());
137136
CountDownLatch countDownLatch = new CountDownLatch(consumerGroupSet.size());
@@ -218,7 +217,8 @@ public List<TopicConsumerInfo> queryConsumeStatsList(final String topic, String
218217
consumeStats = mqAdminExt.examineConsumeStats(groupName, topic);
219218
}
220219
catch (Exception e) {
221-
throw propagate(e);
220+
Throwables.throwIfUnchecked(e);
221+
throw new RuntimeException(e);
222222
}
223223
List<MessageQueue> mqList = Lists.newArrayList(Iterables.filter(consumeStats.getOffsetTable().keySet(), new Predicate<MessageQueue>() {
224224
@Override
@@ -278,7 +278,8 @@ private Map<MessageQueue, String> getClientConnection(String groupName) {
278278
return group2ConsumerInfoMap;
279279
}
280280
catch (Exception e) {
281-
throw propagate(e);
281+
Throwables.throwIfUnchecked(e);
282+
throw new RuntimeException(e);
282283
}
283284
}
284285

@@ -341,7 +342,8 @@ public List<ConsumerConfigInfo> examineSubscriptionGroupConfig(String group) {
341342
}
342343
}
343344
catch (Exception e) {
344-
throw propagate(e);
345+
Throwables.throwIfUnchecked(e);
346+
throw new RuntimeException(e);
345347
}
346348
return consumerConfigInfoList;
347349
}
@@ -366,7 +368,8 @@ public boolean deleteSubGroup(DeleteSubGroupRequest deleteSubGroupRequest) {
366368
}
367369
}
368370
catch (Exception e) {
369-
throw propagate(e);
371+
Throwables.throwIfUnchecked(e);
372+
throw new RuntimeException(e);
370373
}
371374
return true;
372375
}
@@ -393,7 +396,8 @@ public boolean createAndUpdateSubscriptionGroupConfig(ConsumerConfigInfo consume
393396
}
394397
}
395398
catch (Exception err) {
396-
throw Throwables.propagate(err);
399+
Throwables.throwIfUnchecked(err);
400+
throw new RuntimeException(err);
397401
}
398402
return true;
399403
}
@@ -408,7 +412,8 @@ public Set<String> fetchBrokerNameSetBySubscriptionGroup(String group) {
408412
}
409413
}
410414
catch (Exception e) {
411-
throw Throwables.propagate(e);
415+
Throwables.throwIfUnchecked(e);
416+
throw new RuntimeException(e);
412417
}
413418
return brokerNameSet;
414419

@@ -420,7 +425,8 @@ public ConsumerConnection getConsumerConnection(String consumerGroup) {
420425
return mqAdminExt.examineConsumerConnectionInfo(consumerGroup);
421426
}
422427
catch (Exception e) {
423-
throw Throwables.propagate(e);
428+
Throwables.throwIfUnchecked(e);
429+
throw new RuntimeException(e);
424430
}
425431
}
426432

@@ -430,7 +436,8 @@ public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String c
430436
return mqAdminExt.getConsumerRunningInfo(consumerGroup, clientId, jstack);
431437
}
432438
catch (Exception e) {
433-
throw Throwables.propagate(e);
439+
Throwables.throwIfUnchecked(e);
440+
throw new RuntimeException(e);
434441
}
435442
}
436443
}

src/main/java/org/apache/rocketmq/dashboard/service/impl/DashboardCollectServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public Map<String, List<String>> jsonDataFile2map(File file) {
107107
strings = Files.readLines(file, Charsets.UTF_8);
108108
}
109109
catch (IOException e) {
110-
throw Throwables.propagate(e);
110+
Throwables.throwIfUnchecked(e);
111+
throw new RuntimeException(e);
111112
}
112113
StringBuffer sb = new StringBuffer();
113114
for (String string : strings) {

src/main/java/org/apache/rocketmq/dashboard/service/impl/DlqMessageServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ public MessagePage queryDlqMessageByPage(MessageQuery query) {
6262
&& e.getResponseCode() == ResponseCode.TOPIC_NOT_EXIST) {
6363
return new MessagePage(new PageImpl<>(messageViews, page, 0), query.getTaskId());
6464
} else {
65-
throw Throwables.propagate(e);
65+
Throwables.throwIfUnchecked(e);
66+
throw new RuntimeException(e);
6667
}
6768
} catch (Exception e) {
68-
throw Throwables.propagate(e);
69+
Throwables.throwIfUnchecked(e);
70+
throw new RuntimeException(e);
6971
}
7072
return messageService.queryMessageByPage(query);
7173
}

src/main/java/org/apache/rocketmq/dashboard/service/impl/MessageServiceImpl.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public MessageView apply(MessageExt messageExt) {
115115
if (err instanceof MQClientException) {
116116
throw new ServiceException(-1, ((MQClientException) err).getErrorMessage());
117117
}
118-
throw Throwables.propagate(err);
118+
Throwables.throwIfUnchecked(err);
119+
throw new RuntimeException(err);
119120
}
120121
}
121122

@@ -185,7 +186,8 @@ public int compare(MessageView o1, MessageView o2) {
185186
});
186187
return messageViewList;
187188
} catch (Exception e) {
188-
throw Throwables.propagate(e);
189+
Throwables.throwIfUnchecked(e);
190+
throw new RuntimeException(e);
189191
} finally {
190192
consumer.shutdown();
191193
}
@@ -209,7 +211,8 @@ public ConsumeMessageDirectlyResult consumeMessageDirectly(String topic, String
209211
try {
210212
return mqAdminExt.consumeMessageDirectly(consumerGroup, clientId, topic, msgId);
211213
} catch (Exception e) {
212-
throw Throwables.propagate(e);
214+
Throwables.throwIfUnchecked(e);
215+
throw new RuntimeException(e);
213216
}
214217
}
215218

@@ -223,7 +226,8 @@ public ConsumeMessageDirectlyResult consumeMessageDirectly(String topic, String
223226
return mqAdminExt.consumeMessageDirectly(consumerGroup, connection.getClientId(), topic, msgId);
224227
}
225228
} catch (Exception e) {
226-
throw Throwables.propagate(e);
229+
Throwables.throwIfUnchecked(e);
230+
throw new RuntimeException(e);
227231
}
228232
throw new IllegalStateException("NO CONSUMER");
229233

@@ -388,7 +392,8 @@ private MessagePageTask queryFirstMessagePage(MessageQueryByPage query) {
388392
PageImpl<MessageView> page = new PageImpl<>(messageViews, query.page(), total);
389393
return new MessagePageTask(page, queueOffsetInfos);
390394
} catch (Exception e) {
391-
throw Throwables.propagate(e);
395+
Throwables.throwIfUnchecked(e);
396+
throw new RuntimeException(e);
392397
} finally {
393398
consumer.shutdown();
394399
}
@@ -455,7 +460,8 @@ private Page<MessageView> queryMessageByTaskPage(MessageQueryByPage query, List<
455460
}
456461
return new PageImpl<>(messageViews, query.page(), total);
457462
} catch (Exception e) {
458-
throw Throwables.propagate(e);
463+
Throwables.throwIfUnchecked(e);
464+
throw new RuntimeException(e);
459465
} finally {
460466
consumer.shutdown();
461467
}

src/main/java/org/apache/rocketmq/dashboard/service/impl/MonitorServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ private void writeDataJsonToFile(String path, String dataStr) {
8282
MixAll.string2File(dataStr, path);
8383
}
8484
catch (Exception e) {
85-
throw Throwables.propagate(e);
85+
Throwables.throwIfUnchecked(e);
86+
throw new RuntimeException(e);
8687
}
8788
}
8889

src/main/java/org/apache/rocketmq/dashboard/service/impl/ProducerServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public ProducerConnection getProducerConnection(String producerGroup, String top
3535
return mqAdminExt.examineProducerConnectionInfo(producerGroup, topic);
3636
}
3737
catch (Exception e) {
38-
throw Throwables.propagate(e);
38+
Throwables.throwIfUnchecked(e);
39+
throw new RuntimeException(e);
3940
}
4041
}
4142
}

0 commit comments

Comments
 (0)