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

fix zipkin compatible. #3728 #4368

Merged
merged 4 commits into from
Jun 26, 2019
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 @@ -237,12 +237,12 @@ private static void deserializeInternal(Object result, JavaBeanDescriptor beanDe
for (Map.Entry<Object, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -48,4 +55,12 @@ private static RpcContext newInstance(org.apache.dubbo.rpc.RpcContext rpcContext

return copy;
}

public <T> Future<T> getFuture() {
CompletableFuture completableFuture = FutureContext.getCompletableFuture();
if (completableFuture == null) {
return null;
}
return new FutureAdapter(completableFuture);
}
}
Original file line number Diff line number Diff line change
@@ -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<V> implements Future<V> {
private CompletableFuture<V> future;

public FutureAdapter(CompletableFuture<V> 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<AppResponse, ? super Throwable> biConsumer = new BiConsumer<AppResponse, Throwable>() {

@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);
chickenlj marked this conversation as resolved.
Show resolved Hide resolved
}

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-multicast</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-zookeeper</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-configcenter-zookeeper</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-dubbo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-multicast</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-zookeeper</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-configcenter-zookeeper</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-rpc-dubbo</artifactId>
Expand Down
Loading