diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java b/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java index 995965ac74a..1ce5c455cf5 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/beanutil/JavaBeanSerializeUtil.java @@ -237,12 +237,12 @@ private static void deserializeInternal(Object result, JavaBeanDescriptor beanDe for (Map.Entry entry : beanDescriptor) { Object key = entry.getKey(); Object value = entry.getValue(); - if (key != null && key instanceof JavaBeanDescriptor) { + if (key instanceof JavaBeanDescriptor) { JavaBeanDescriptor keyDescriptor = (JavaBeanDescriptor) entry.getKey(); key = instantiateForDeserialize(keyDescriptor, loader, cache); deserializeInternal(key, keyDescriptor, loader, cache); } - if (value != null && value instanceof JavaBeanDescriptor) { + if (value instanceof JavaBeanDescriptor) { JavaBeanDescriptor valueDescriptor = (JavaBeanDescriptor) entry.getValue(); value = instantiateForDeserialize(valueDescriptor, loader, cache); deserializeInternal(value, valueDescriptor, loader, cache); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java index f5e039c3be8..a75bedbdd40 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java @@ -47,7 +47,7 @@ public Object get(int index) { */ public boolean getBoolean(int index, boolean def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Boolean ? ((Boolean) tmp).booleanValue() : def; + return tmp instanceof Boolean ? ((Boolean) tmp).booleanValue() : def; } /** @@ -59,7 +59,7 @@ public boolean getBoolean(int index, boolean def) { */ public int getInt(int index, int def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Number ? ((Number) tmp).intValue() : def; + return tmp instanceof Number ? ((Number) tmp).intValue() : def; } /** @@ -71,7 +71,7 @@ public int getInt(int index, int def) { */ public long getLong(int index, long def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Number ? ((Number) tmp).longValue() : def; + return tmp instanceof Number ? ((Number) tmp).longValue() : def; } /** @@ -83,7 +83,7 @@ public long getLong(int index, long def) { */ public float getFloat(int index, float def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Number ? ((Number) tmp).floatValue() : def; + return tmp instanceof Number ? ((Number) tmp).floatValue() : def; } /** @@ -95,7 +95,7 @@ public float getFloat(int index, float def) { */ public double getDouble(int index, double def) { Object tmp = mArray.get(index); - return tmp != null && tmp instanceof Number ? ((Number) tmp).doubleValue() : def; + return tmp instanceof Number ? ((Number) tmp).doubleValue() : def; } /** diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java index 052f35269dd..c04d4e14050 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java @@ -47,7 +47,7 @@ public Object get(String key) { */ public boolean getBoolean(String key, boolean def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Boolean ? (Boolean) tmp : def; + return tmp instanceof Boolean ? (Boolean) tmp : def; } /** @@ -59,7 +59,7 @@ public boolean getBoolean(String key, boolean def) { */ public int getInt(String key, int def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Number ? ((Number) tmp).intValue() : def; + return tmp instanceof Number ? ((Number) tmp).intValue() : def; } /** @@ -71,7 +71,7 @@ public int getInt(String key, int def) { */ public long getLong(String key, long def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Number ? ((Number) tmp).longValue() : def; + return tmp instanceof Number ? ((Number) tmp).longValue() : def; } /** @@ -83,7 +83,7 @@ public long getLong(String key, long def) { */ public float getFloat(String key, float def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Number ? ((Number) tmp).floatValue() : def; + return tmp instanceof Number ? ((Number) tmp).floatValue() : def; } /** @@ -95,7 +95,7 @@ public float getFloat(String key, float def) { */ public double getDouble(String key, double def) { Object tmp = mMap.get(key); - return tmp != null && tmp instanceof Number ? ((Number) tmp).doubleValue() : def; + return tmp instanceof Number ? ((Number) tmp).doubleValue() : def; } /** diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/RemotingException.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/RemotingException.java index 32d6fcd4d20..c863a510347 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/RemotingException.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/RemotingException.java @@ -47,4 +47,8 @@ public RemotingException(Channel channel, String message, Throwable cause) { public RemotingException(InetSocketAddress localAddress, InetSocketAddress remoteAddress, String message, Throwable cause) { super(localAddress, remoteAddress, message, cause); } + + public RemotingException(Exception e){ + super(null, e.getMessage()); + } } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/exchange/ResponseCallback.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/exchange/ResponseCallback.java new file mode 100644 index 00000000000..30a71afdf14 --- /dev/null +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/exchange/ResponseCallback.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.remoting.exchange; + +/** + * 2019-06-20 + */ +@Deprecated +public interface ResponseCallback { + /** + * done. + * + * @param response + */ + void done(Object response); + + /** + * caught exception. + * + * @param exception + */ + void caught(Throwable exception); + +} diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/exchange/ResponseFuture.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/exchange/ResponseFuture.java new file mode 100644 index 00000000000..c7083a6058b --- /dev/null +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/remoting/exchange/ResponseFuture.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.remoting.exchange; + + +import com.alibaba.dubbo.remoting.RemotingException; + +/** + * 2019-06-20 + */ +@Deprecated +public interface ResponseFuture { + /** + * get result. + * + * @return result. + */ + Object get() throws RemotingException; + + /** + * get result with the specified timeout. + * + * @param timeoutInMillis timeout. + * @return result. + */ + Object get(int timeoutInMillis) throws RemotingException; + + /** + * set callback. + * + * @param callback + */ + void setCallback(ResponseCallback callback); + + /** + * check is done. + * + * @return done or not. + */ + boolean isDone(); +} diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java index 28ae5f1757a..010eae86017 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java @@ -17,6 +17,13 @@ package com.alibaba.dubbo.rpc; +import org.apache.dubbo.rpc.FutureContext; + +import com.alibaba.dubbo.rpc.protocol.dubbo.FutureAdapter; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; + @Deprecated public class RpcContext extends org.apache.dubbo.rpc.RpcContext { @@ -48,4 +55,12 @@ private static RpcContext newInstance(org.apache.dubbo.rpc.RpcContext rpcContext return copy; } + + public Future getFuture() { + CompletableFuture completableFuture = FutureContext.getCompletableFuture(); + if (completableFuture == null) { + return null; + } + return new FutureAdapter(completableFuture); + } } diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/FutureAdapter.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/FutureAdapter.java new file mode 100644 index 00000000000..58a62a4cd4d --- /dev/null +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/FutureAdapter.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.rpc.protocol.dubbo; + +import org.apache.dubbo.rpc.AppResponse; + +import com.alibaba.dubbo.remoting.RemotingException; +import com.alibaba.dubbo.remoting.exchange.ResponseCallback; +import com.alibaba.dubbo.remoting.exchange.ResponseFuture; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.function.BiConsumer; + +/** + * 2019-06-20 + */ +@Deprecated +public class FutureAdapter implements Future { + private CompletableFuture future; + + public FutureAdapter(CompletableFuture future) { + this.future = future; + + } + + public ResponseFuture getFuture() { + return new ResponseFuture() { + @Override + public Object get() throws RemotingException { + try { + return FutureAdapter.this.get(); + } catch (InterruptedException e) { + throw new RemotingException(e); + } catch (ExecutionException e) { + throw new RemotingException(e); + } + } + + @Override + public Object get(int timeoutInMillis) throws RemotingException { + try { + return FutureAdapter.this.get(timeoutInMillis, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + throw new RemotingException(e); + } catch (ExecutionException e) { + throw new RemotingException(e); + } catch (TimeoutException e) { + throw new RemotingException(e); + } + } + + @Override + public void setCallback(ResponseCallback callback) { + FutureAdapter.this.setCallback(callback); + } + + @Override + public boolean isDone() { + return FutureAdapter.this.isDone(); + } + }; + } + + void setCallback(ResponseCallback callback) { + if (!(future instanceof org.apache.dubbo.rpc.protocol.dubbo.FutureAdapter)) { + return; + } + org.apache.dubbo.rpc.protocol.dubbo.FutureAdapter futureAdapter = (org.apache.dubbo.rpc.protocol.dubbo.FutureAdapter) future; + BiConsumer biConsumer = new BiConsumer() { + + @Override + public void accept(AppResponse appResponse, Throwable t) { + if (t != null) { + if (t instanceof CompletionException) { + t = t.getCause(); + } + callback.caught(t); + } else { + if (appResponse.hasException()) { + callback.caught(appResponse.getException()); + } else { + callback.done((V) appResponse.getValue()); + } + } + } + }; + futureAdapter.getAppResponseFuture().whenComplete(biConsumer); + } + + public boolean cancel(boolean mayInterruptIfRunning) { + return future.cancel(mayInterruptIfRunning); + } + + public boolean isCancelled() { + return future.isCancelled(); + } + + public boolean isDone() { + return future.isDone(); + } + + @SuppressWarnings("unchecked") + public V get() throws InterruptedException, ExecutionException { + return future.get(); + } + + @SuppressWarnings("unchecked") + public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + return future.get(timeout, unit); + } +} diff --git a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml index c13bc265bc2..c8f9d9d50e1 100644 --- a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-consumer/pom.xml @@ -42,6 +42,14 @@ org.apache.dubbo dubbo-registry-multicast + + org.apache.dubbo + dubbo-registry-zookeeper + + + org.apache.dubbo + dubbo-configcenter-zookeeper + org.apache.dubbo dubbo-rpc-dubbo diff --git a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml index 4f164bce61e..02d0248e431 100644 --- a/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml +++ b/dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/pom.xml @@ -43,6 +43,14 @@ org.apache.dubbo dubbo-registry-multicast + + org.apache.dubbo + dubbo-registry-zookeeper + + + org.apache.dubbo + dubbo-configcenter-zookeeper + org.apache.dubbo dubbo-rpc-dubbo diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml index 4dfde790cfa..5720551e7db 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-consumer/pom.xml @@ -38,6 +38,14 @@ org.apache.dubbo dubbo-registry-multicast + + org.apache.dubbo + dubbo-registry-zookeeper + + + org.apache.dubbo + dubbo-configcenter-zookeeper + org.apache.dubbo dubbo-config-spring diff --git a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml index a93c41ccf00..c683235834a 100644 --- a/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml +++ b/dubbo-demo/dubbo-demo-xml/dubbo-demo-xml-provider/pom.xml @@ -40,6 +40,14 @@ org.apache.dubbo dubbo-registry-multicast + + org.apache.dubbo + dubbo-registry-zookeeper + + + org.apache.dubbo + dubbo-configcenter-zookeeper + org.apache.dubbo dubbo-rpc-dubbo diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java index ce079b743e4..a1eaad3410d 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderInvokerWrapper.java @@ -90,7 +90,7 @@ public void setReg(boolean reg) { @Override public boolean equals(Object o) { - if (o == null || !(o instanceof ProviderInvokerWrapper)) { + if (!(o instanceof ProviderInvokerWrapper)) { return false; } ProviderInvokerWrapper other = (ProviderInvokerWrapper) o; diff --git a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java index ec73094ce95..64f41b2daef 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyHelper.java @@ -27,7 +27,7 @@ final class NettyHelper { public static void setNettyLoggerFactory() { InternalLoggerFactory factory = InternalLoggerFactory.getDefaultFactory(); - if (factory == null || !(factory instanceof DubboLoggerFactory)) { + if (!(factory instanceof DubboLoggerFactory)) { InternalLoggerFactory.setDefaultFactory(new DubboLoggerFactory()); } } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/FutureAdapter.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/FutureAdapter.java index 03954d1b345..7c88776542d 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/FutureAdapter.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/FutureAdapter.java @@ -90,4 +90,7 @@ public V get(long timeout, TimeUnit unit) throws InterruptedException, Execution } } + public CompletableFuture getAppResponseFuture() { + return appResponseFuture; + } } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/decode/DubboTelnetDecodeTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/decode/DubboTelnetDecodeTest.java index e54d2e6508a..28c49cce497 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/decode/DubboTelnetDecodeTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/org/apache/dubbo/rpc/protocol/dubbo/decode/DubboTelnetDecodeTest.java @@ -452,7 +452,7 @@ private ByteBuf createDubboByteBuf() throws IOException { } private static boolean checkTelnetDecoded(Object msg) { - if (msg != null && msg instanceof String && !msg.toString().contains("Unsupported command:")) { + if (msg instanceof String && !msg.toString().contains("Unsupported command:")) { return true; } return false;