Skip to content

Commit

Permalink
refactor: remove unnecessary code (apache#1490)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyqian authored and zjinlei committed Aug 20, 2019
1 parent f61382a commit dd04c87
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ private static ConsulClient getConsulClient() {
* @param configFuture
*/
private void complete(Response response, ConfigFuture configFuture) {
Object value = response.getValue();
if (null != response && null != value) {
if (null != response && null != response.getValue()) {
Object value = response.getValue();
if (value instanceof GetValue) {
configFuture.setResult(((GetValue) response.getValue()).getDecodedValue());
configFuture.setResult(((GetValue) value).getDecodedValue());
} else {
configFuture.setResult(response.getValue());
configFuture.setResult(value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Duration getDuration(String dataId, Duration defaultValue) {

@Override
public Duration getDuration(String dataId, Duration defaultValue, long timeoutMills) {
String result = getConfig(dataId, String.valueOf(defaultValue.toMillis() + "ms"), timeoutMills);
String result = getConfig(dataId, defaultValue.toMillis() + "ms", timeoutMills);
return DurationUtil.parse(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public boolean isTimeout() {
* Get object.
*
* @return the object
* @throws InterruptedException the interrupted exception
*/
public Object get() {
return get(this.timeoutMills, TimeUnit.MILLISECONDS);
Expand All @@ -89,7 +88,6 @@ public Object get() {
* @param timeout the timeout
* @param unit the unit
* @return the object
* @throws InterruptedException the interrupted exception
*/
public Object get(long timeout, TimeUnit unit) {
this.timeoutMills = unit.toMillis(timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public String getConfig(String dataId, String defaultValue, long timeoutMills) {
value = configService.getConfig(dataId, SEATA_GROUP, timeoutMills);
} catch (NacosException exx) {
LOGGER.error(exx.getErrMsg());
value = defaultValue;
}
return value == null ? defaultValue : value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,10 @@ public String getConfig(String dataId, String defaultValue, long timeoutMills) {
}
FutureTask<String> future = new FutureTask<String>(new Callable<String>() {
@Override
public String call() throws Exception {
public String call() {
String path = ROOT_PATH + ZK_PATH_SPLIT_CHAR + dataId;
String value = zkClient.readData(path);
if (StringUtils.isNullOrEmpty(value)) {
return defaultValue;
}
return value;
return StringUtils.isNullOrEmpty(value) ? defaultValue : value;
}
});
CONFIG_EXECUTOR.execute(future);
Expand All @@ -112,7 +109,7 @@ public String call() throws Exception {
public boolean putConfig(String dataId, String content, long timeoutMills) {
FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
public Boolean call() {
String path = ROOT_PATH + ZK_PATH_SPLIT_CHAR + dataId;
if (!zkClient.exists(path)) {
zkClient.create(path, content, CreateMode.PERSISTENT);
Expand Down Expand Up @@ -140,7 +137,7 @@ public boolean putConfigIfAbsent(String dataId, String content, long timeoutMill
public boolean removeConfig(String dataId, long timeoutMills) {
FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
public Boolean call() {
String path = ROOT_PATH + ZK_PATH_SPLIT_CHAR + dataId;
return zkClient.delete(path);
}
Expand Down

0 comments on commit dd04c87

Please sign in to comment.