Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #148] Throwables.propagate is deprecated for making runtime exception more verbose #160

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ protected final Set<String> changeToBrokerNameSet(Map<String, Set<String>> clust
}
}
catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
if (CollectionUtils.isNotEmpty(brokerNameList)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ public void createAndUpdateSubscriptionGroupConfig(String addr, SubscriptionGrou
}

@Override
public SubscriptionGroupConfig examineSubscriptionGroupConfig(String addr, String group) {
public SubscriptionGroupConfig examineSubscriptionGroupConfig(String addr, String group) throws MQBrokerException {
RemotingClient remotingClient = MQAdminInstance.threadLocalRemotingClient();
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_SUBSCRIPTIONGROUP_CONFIG, null);
RemotingCommand response = null;
try {
response = remotingClient.invokeSync(addr, request, 3000);
}
catch (Exception err) {
throw Throwables.propagate(err);
Throwables.throwIfUnchecked(err);
throw new RuntimeException(err);
}
assert response != null;
switch (response.getCode()) {
Expand All @@ -157,28 +158,29 @@ public SubscriptionGroupConfig examineSubscriptionGroupConfig(String addr, Strin
return subscriptionGroupWrapper.getSubscriptionGroupTable().get(group);
}
default:
throw Throwables.propagate(new MQBrokerException(response.getCode(), response.getRemark()));
throw new MQBrokerException(response.getCode(), response.getRemark());
}
}

@Override
public TopicConfig examineTopicConfig(String addr, String topic) {
public TopicConfig examineTopicConfig(String addr, String topic) throws MQBrokerException {
RemotingClient remotingClient = MQAdminInstance.threadLocalRemotingClient();
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_ALL_TOPIC_CONFIG, null);
RemotingCommand response = null;
try {
response = remotingClient.invokeSync(addr, request, 3000);
}
catch (Exception err) {
throw Throwables.propagate(err);
Throwables.throwIfUnchecked(err);
throw new RuntimeException(err);
}
switch (response.getCode()) {
case ResponseCode.SUCCESS: {
TopicConfigSerializeWrapper topicConfigSerializeWrapper = decode(response.getBody(), TopicConfigSerializeWrapper.class);
return topicConfigSerializeWrapper.getTopicConfigTable().get(topic);
}
default:
throw Throwables.propagate(new MQBrokerException(response.getCode(), response.getRemark()));
throw new MQBrokerException(response.getCode(), response.getRemark());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public AclConfig getAclConfig(boolean excludeSecretKey) {
}
} catch (Exception e) {
log.error("getAclConfig error.", e);
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
AclConfig aclConfig = new AclConfig();
aclConfig.setGlobalWhiteAddrs(Collections.emptyList());
Expand Down Expand Up @@ -100,7 +101,8 @@ public void addAclConfig(PlainAccessConfig config) {
mqAdminExt.createAndUpdatePlainAccessConfig(addr, config);
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}

}
Expand All @@ -116,7 +118,8 @@ public void deleteAclConfig(PlainAccessConfig config) {
log.info("Delete acl [{}] from broker [{}] complete", config.getAccessKey(), addr);
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand All @@ -142,7 +145,8 @@ public void updateAclConfig(PlainAccessConfig config) {
mqAdminExt.createAndUpdatePlainAccessConfig(addr, config);
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -174,7 +178,8 @@ public void addOrUpdateAclTopicConfig(AclRequest request) {
}
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -206,7 +211,8 @@ public void addOrUpdateAclGroupConfig(AclRequest request) {
}
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -249,7 +255,8 @@ public void deletePermConfig(AclRequest request) {
}
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}

}
Expand All @@ -261,7 +268,8 @@ public void syncData(PlainAccessConfig config) {
mqAdminExt.createAndUpdatePlainAccessConfig(addr, config);
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand All @@ -281,7 +289,8 @@ public void addWhiteList(List<String> whiteList) {
mqAdminExt.updateGlobalWhiteAddrConfig(addr, StringUtils.join(aclConfig.getGlobalWhiteAddrs(), ","));
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand All @@ -297,7 +306,8 @@ public void deleteWhiteAddr(String deleteAddr) {
mqAdminExt.updateGlobalWhiteAddrConfig(addr, StringUtils.join(aclConfig.getGlobalWhiteAddrs(), ","));
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand All @@ -311,7 +321,8 @@ public void synchronizeWhiteList(List<String> whiteList) {
mqAdminExt.updateGlobalWhiteAddrConfig(addr, StringUtils.join(whiteList, ","));
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public Map<String, Object> list() {
return resultMap;
}
catch (Exception err) {
throw Throwables.propagate(err);
Throwables.throwIfUnchecked(err);
throw new RuntimeException(err);
}
}

Expand All @@ -70,7 +71,8 @@ public Properties getBrokerConfig(String brokerAddr) {
return mqAdminExt.getBrokerConfig(brokerAddr);
}
catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import static com.google.common.base.Throwables.propagate;

@Service
public class ConsumerServiceImpl extends AbstractCommonService implements ConsumerService, InitializingBean, DisposableBean {
private Logger logger = LoggerFactory.getLogger(ConsumerServiceImpl.class);
Expand Down Expand Up @@ -131,7 +129,8 @@ public List<GroupConsumeInfo> queryGroupList(boolean skipSysGroup) {
}
}
catch (Exception err) {
throw Throwables.propagate(err);
Throwables.throwIfUnchecked(err);
throw new RuntimeException(err);
}
List<GroupConsumeInfo> groupConsumeInfoList = Collections.synchronizedList(Lists.newArrayList());
CountDownLatch countDownLatch = new CountDownLatch(consumerGroupSet.size());
Expand Down Expand Up @@ -218,7 +217,8 @@ public List<TopicConsumerInfo> queryConsumeStatsList(final String topic, String
consumeStats = mqAdminExt.examineConsumeStats(groupName, topic);
}
catch (Exception e) {
throw propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
List<MessageQueue> mqList = Lists.newArrayList(Iterables.filter(consumeStats.getOffsetTable().keySet(), new Predicate<MessageQueue>() {
@Override
Expand Down Expand Up @@ -278,7 +278,8 @@ private Map<MessageQueue, String> getClientConnection(String groupName) {
return group2ConsumerInfoMap;
}
catch (Exception e) {
throw propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -341,7 +342,8 @@ public List<ConsumerConfigInfo> examineSubscriptionGroupConfig(String group) {
}
}
catch (Exception e) {
throw propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
return consumerConfigInfoList;
}
Expand All @@ -366,7 +368,8 @@ public boolean deleteSubGroup(DeleteSubGroupRequest deleteSubGroupRequest) {
}
}
catch (Exception e) {
throw propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
return true;
}
Expand All @@ -393,7 +396,8 @@ public boolean createAndUpdateSubscriptionGroupConfig(ConsumerConfigInfo consume
}
}
catch (Exception err) {
throw Throwables.propagate(err);
Throwables.throwIfUnchecked(err);
throw new RuntimeException(err);
}
return true;
}
Expand All @@ -408,7 +412,8 @@ public Set<String> fetchBrokerNameSetBySubscriptionGroup(String group) {
}
}
catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
return brokerNameSet;

Expand All @@ -420,7 +425,8 @@ public ConsumerConnection getConsumerConnection(String consumerGroup) {
return mqAdminExt.examineConsumerConnectionInfo(consumerGroup);
}
catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand All @@ -430,7 +436,8 @@ public ConsumerRunningInfo getConsumerRunningInfo(String consumerGroup, String c
return mqAdminExt.getConsumerRunningInfo(consumerGroup, clientId, jstack);
}
catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public Map<String, List<String>> jsonDataFile2map(File file) {
strings = Files.readLines(file, Charsets.UTF_8);
}
catch (IOException e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
StringBuffer sb = new StringBuffer();
for (String string : strings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public MessagePage queryDlqMessageByPage(MessageQuery query) {
&& e.getResponseCode() == ResponseCode.TOPIC_NOT_EXIST) {
return new MessagePage(new PageImpl<>(messageViews, page, 0), query.getTaskId());
} else {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
return messageService.queryMessageByPage(query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public MessageView apply(MessageExt messageExt) {
if (err instanceof MQClientException) {
throw new ServiceException(-1, ((MQClientException) err).getErrorMessage());
}
throw Throwables.propagate(err);
Throwables.throwIfUnchecked(err);
throw new RuntimeException(err);
}
}

Expand Down Expand Up @@ -185,7 +186,8 @@ public int compare(MessageView o1, MessageView o2) {
});
return messageViewList;
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
} finally {
consumer.shutdown();
}
Expand All @@ -209,7 +211,8 @@ public ConsumeMessageDirectlyResult consumeMessageDirectly(String topic, String
try {
return mqAdminExt.consumeMessageDirectly(consumerGroup, clientId, topic, msgId);
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand All @@ -223,7 +226,8 @@ public ConsumeMessageDirectlyResult consumeMessageDirectly(String topic, String
return mqAdminExt.consumeMessageDirectly(consumerGroup, connection.getClientId(), topic, msgId);
}
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
throw new IllegalStateException("NO CONSUMER");

Expand Down Expand Up @@ -388,7 +392,8 @@ private MessagePageTask queryFirstMessagePage(MessageQueryByPage query) {
PageImpl<MessageView> page = new PageImpl<>(messageViews, query.page(), total);
return new MessagePageTask(page, queueOffsetInfos);
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
} finally {
consumer.shutdown();
}
Expand Down Expand Up @@ -455,7 +460,8 @@ private Page<MessageView> queryMessageByTaskPage(MessageQueryByPage query, List<
}
return new PageImpl<>(messageViews, query.page(), total);
} catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
} finally {
consumer.shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ private void writeDataJsonToFile(String path, String dataStr) {
MixAll.string2File(dataStr, path);
}
catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public ProducerConnection getProducerConnection(String producerGroup, String top
return mqAdminExt.examineProducerConnectionInfo(producerGroup, topic);
}
catch (Exception e) {
throw Throwables.propagate(e);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
}
Loading