Skip to content

Commit

Permalink
Fix sofastack/issues/367 and remove unnecessary code. (sofastack#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojigang authored and leizhiyuan committed Nov 22, 2018
1 parent 01ae847 commit 3e8bbf6
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public interface Compressor {
* @param src 未压缩的字节数组
* @return 压缩后的字节数组
*/
public byte[] compress(byte[] src);
byte[] compress(byte[] src);

/**
* 字节数组解压缩
*
* @param src 压缩后的源字节数组
* @return 解压缩后的字节数组
*/
public byte[] deCompress(byte[] src);
byte[] deCompress(byte[] src);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface Serializer {
* @return 序列化后的对象
* @throws SofaRpcException 序列化异常
*/
public AbstractByteBuf encode(Object object, Map<String, String> context) throws SofaRpcException;
AbstractByteBuf encode(Object object, Map<String, String> context) throws SofaRpcException;

/**
* 反序列化,只有类型,返回对象
Expand All @@ -51,7 +51,7 @@ public interface Serializer {
* @return 反序列化后的对象
* @throws SofaRpcException 序列化异常
*/
public Object decode(AbstractByteBuf data, Class clazz, Map<String, String> context) throws SofaRpcException;
Object decode(AbstractByteBuf data, Class clazz, Map<String, String> context) throws SofaRpcException;

/**
* 反序列化,已有数据,填充字段
Expand All @@ -61,5 +61,5 @@ public interface Serializer {
* @param context 上下文
* @throws SofaRpcException 序列化异常
*/
public void decode(AbstractByteBuf data, Object template, Map<String, String> context) throws SofaRpcException;
void decode(AbstractByteBuf data, Object template, Map<String, String> context) throws SofaRpcException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ public interface Cache {
* @param args 方法参数
* @return 关键字,可以返回null
*/
public Object buildKey(String interfaceId, String methodName, Object[] args);
Object buildKey(String interfaceId, String methodName, Object[] args);

/**
* 放入缓存
*
* @param key 方法参数得到的关键字
* @param result 缓存的调用结果
*/
public void put(Object key, Object result);
void put(Object key, Object result);

/**
* 拿出缓存
*
* @param key 方法参数得到的关键字
* @return 缓存的调用结果
*/
public Object get(Object key);
Object get(Object key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public interface SendableResponseCallback<T> extends SofaResponseCallback<T> {
*
* @param appResponse 返回给A的值
*/
public void sendAppResponse(Object appResponse);
void sendAppResponse(Object appResponse);

/**
* A-&gt;B(当前)-&gt;C的场景下,B将异常异步返回给调用者A
*
* @param throwable 返回给A的异常
*/
public void sendAppException(Throwable throwable);
void sendAppException(Throwable throwable);

/**
* A-&gt;B(当前)-&gt;C的场景下,B将异常异步返回给调用者A
*
* @param exception 返回给A的异常
*/
public void sendSofaException(SofaRpcException exception);
void sendSofaException(SofaRpcException exception);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface SofaResponseCallback<T> {
* @param methodName the invoked method
* @param request the invoked request object
*/
public void onAppResponse(Object appResponse, String methodName, RequestBase request);
void onAppResponse(Object appResponse, String methodName, RequestBase request);

/**
* SOFA RPC will callback this method when server meet exception
Expand All @@ -41,7 +41,7 @@ public interface SofaResponseCallback<T> {
* @param methodName the invoked method
* @param request the invoked request
*/
public void onAppException(Throwable throwable, String methodName, RequestBase request);
void onAppException(Throwable throwable, String methodName, RequestBase request);

/**
* SOFA RPC will callback this method when framework meet exception
Expand All @@ -50,5 +50,5 @@ public interface SofaResponseCallback<T> {
* @param methodName the invoked method
* @param request the invoked request object
*/
public void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request);
void onSofaException(SofaRpcException sofaException, String methodName, RequestBase request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ protected void readLine(URL url, String line) {
String[] rejection = extensionClass.getRejection();
if (CommonUtils.isNotEmpty(rejection)) {
for (String rej : rejection) {
existed = all.get(rej);
if (existed == null || extensionClass.getOrder() < existed.getOrder()) {
continue;
}
ExtensionClass removed = all.remove(rej);
if (removed != null) {
if (LOGGER.isInfoEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public interface ExtensionLoaderListener<T> {
*
* @param extensionClass 扩展点类对象
*/
public void onLoad(ExtensionClass<T> extensionClass);
void onLoad(ExtensionClass<T> extensionClass);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public interface ClientHandler {
*
* @param result response
*/
public void onResponse(final Object result);
void onResponse(final Object result);

/**
* On exception caught.
*
* @param e exception
*/
public void onException(final Throwable e);
void onException(final Throwable e);

/**
* User defined executor.
*
* @return executor
*/
public Executor getExecutor();
Executor getExecutor();
}
37 changes: 37 additions & 0 deletions core/api/src/test/java/com/alipay/sofa/rpc/ext/RejectionLB1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.alipay.sofa.rpc.ext;

import com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap;
import com.alipay.sofa.rpc.client.LoadBalancer;
import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.core.exception.SofaRpcException;
import com.alipay.sofa.rpc.core.request.SofaRequest;

import java.util.List;

@Extension(value = "lb1", order = 1)
public class RejectionLB1 extends LoadBalancer {
public RejectionLB1(ConsumerBootstrap consumerBootstrap) {
super(consumerBootstrap);
}

@Override
public ProviderInfo select(SofaRequest request, List<ProviderInfo> providerInfos) throws SofaRpcException {
return null;
}
}
37 changes: 37 additions & 0 deletions core/api/src/test/java/com/alipay/sofa/rpc/ext/RejectionLB2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.alipay.sofa.rpc.ext;

import com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap;
import com.alipay.sofa.rpc.client.LoadBalancer;
import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.core.exception.SofaRpcException;
import com.alipay.sofa.rpc.core.request.SofaRequest;

import java.util.List;

@Extension(value = "lb2", order = 2, rejection = { "lb1", "lb3" })
public class RejectionLB2 extends LoadBalancer {
public RejectionLB2(ConsumerBootstrap consumerBootstrap) {
super(consumerBootstrap);
}

@Override
public ProviderInfo select(SofaRequest request, List<ProviderInfo> providerInfos) throws SofaRpcException {
return null;
}
}
37 changes: 37 additions & 0 deletions core/api/src/test/java/com/alipay/sofa/rpc/ext/RejectionLB3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.alipay.sofa.rpc.ext;

import com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap;
import com.alipay.sofa.rpc.client.LoadBalancer;
import com.alipay.sofa.rpc.client.ProviderInfo;
import com.alipay.sofa.rpc.core.exception.SofaRpcException;
import com.alipay.sofa.rpc.core.request.SofaRequest;

import java.util.List;

@Extension(value = "lb3", order = 3)
public class RejectionLB3 extends LoadBalancer {
public RejectionLB3(ConsumerBootstrap consumerBootstrap) {
super(consumerBootstrap);
}

@Override
public ProviderInfo select(SofaRequest request, List<ProviderInfo> providerInfos) throws SofaRpcException {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.alipay.sofa.rpc.ext;

import com.alipay.sofa.rpc.client.LoadBalancer;
import org.junit.Assert;
import org.junit.Test;

/**
* 测试 https://github.com/alipay/sofa-rpc/issues/367
*/
public class TestRejectionOrder {

@Test
public void testRejection() {
boolean error = true;
ExtensionLoader<LoadBalancer> loader = new ExtensionLoader<LoadBalancer>(LoadBalancer.class, false, null);
loader.loadFromFile("META-INF/ext5/");
try {
loader.getExtension("lb3");
} catch (Exception e) {
error = false;
}
Assert.assertTrue(error);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lb1=com.alipay.sofa.rpc.ext.RejectionLB1
lb3=com.alipay.sofa.rpc.ext.RejectionLB3
lb2=com.alipay.sofa.rpc.ext.RejectionLB2

0 comments on commit 3e8bbf6

Please sign in to comment.