[ROCKETMQ-206] Catch the IOException when call the file2String method.
Project: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/commit/aced0de7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/tree/aced0de7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/diff/aced0de7 Branch: refs/heads/master Commit: aced0de7d8f98a01d9d109dd592a6cb31fd174d9 Parents: ceeef8e Author: yukon <yu...@apache.org> Authored: Sat May 27 11:34:44 2017 +0800 Committer: yukon <yu...@apache.org> Committed: Sat May 27 11:34:44 2017 +0800 ---------------------------------------------------------------------- .../client/consumer/store/LocalFileOffsetStore.java | 14 ++++++++++++-- .../apache/rocketmq/example/benchmark/Consumer.java | 3 ++- .../org/apache/rocketmq/example/filter/Consumer.java | 3 ++- .../rocketmq/namesrv/kvconfig/KVConfigManager.java | 7 ++++++- 4 files changed, 22 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/aced0de7/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java ---------------------------------------------------------------------- diff --git a/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java b/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java index 2cde5f8..6c81516 100644 --- a/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java +++ b/client/src/main/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStore.java @@ -180,7 +180,12 @@ public class LocalFileOffsetStore implements OffsetStore { } private OffsetSerializeWrapper readLocalOffset() throws MQClientException { - String content = MixAll.file2String(this.storePath); + String content = null; + try { + content = MixAll.file2String(this.storePath); + } catch (IOException e) { + log.warn("Load local offset store file exception", e); + } if (null == content || content.length() == 0) { return this.readLocalOffsetBak(); } else { @@ -198,7 +203,12 @@ public class LocalFileOffsetStore implements OffsetStore { } private OffsetSerializeWrapper readLocalOffsetBak() throws MQClientException { - String content = MixAll.file2String(this.storePath + ".bak"); + String content = null; + try { + content = MixAll.file2String(this.storePath + ".bak"); + } catch (IOException e) { + log.warn("Load local offset store bak file exception", e); + } if (content != null && content.length() > 0) { OffsetSerializeWrapper offsetSerializeWrapper = null; try { http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/aced0de7/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java ---------------------------------------------------------------------- diff --git a/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java index 3e1b79b..d431d3e 100644 --- a/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/benchmark/Consumer.java @@ -17,6 +17,7 @@ package org.apache.rocketmq.example.benchmark; +import java.io.IOException; import java.util.LinkedList; import java.util.List; import java.util.Timer; @@ -39,7 +40,7 @@ import org.apache.rocketmq.srvutil.ServerUtil; public class Consumer { - public static void main(String[] args) throws MQClientException { + public static void main(String[] args) throws MQClientException, IOException { Options options = ServerUtil.buildCommandlineOptions(new Options()); CommandLine commandLine = ServerUtil.parseCmdLine("benchmarkConsumer", args, buildCommandlineOptions(options), new PosixParser()); if (null == commandLine) { http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/aced0de7/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java ---------------------------------------------------------------------- diff --git a/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java b/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java index d63435b..0be8e1d 100644 --- a/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java +++ b/example/src/main/java/org/apache/rocketmq/example/filter/Consumer.java @@ -17,6 +17,7 @@ package org.apache.rocketmq.example.filter; import java.io.File; +import java.io.IOException; import java.util.List; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; @@ -28,7 +29,7 @@ import org.apache.rocketmq.common.message.MessageExt; public class Consumer { - public static void main(String[] args) throws InterruptedException, MQClientException { + public static void main(String[] args) throws InterruptedException, MQClientException, IOException { DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4"); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); http://git-wip-us.apache.org/repos/asf/incubator-rocketmq/blob/aced0de7/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java ---------------------------------------------------------------------- diff --git a/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java b/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java index 69afcad..be13bd6 100644 --- a/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java +++ b/namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java @@ -43,7 +43,12 @@ public class KVConfigManager { } public void load() { - String content = MixAll.file2String(this.namesrvController.getNamesrvConfig().getKvConfigPath()); + String content = null; + try { + content = MixAll.file2String(this.namesrvController.getNamesrvConfig().getKvConfigPath()); + } catch (IOException e) { + log.warn("Load KV config table exception", e); + } if (content != null) { KVConfigSerializeWrapper kvConfigSerializeWrapper = KVConfigSerializeWrapper.fromJson(content, KVConfigSerializeWrapper.class);