提交 3c5d9e33 编写于 作者: oldratlee's avatar oldratlee 🔥

Merge remote-tracking branch 'origin/master'

......@@ -15,6 +15,7 @@
*/
package com.alibaba.dubbo.common;
import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern;
/**
......@@ -569,6 +570,10 @@ public class Constants {
public static final String OUTPUT_KEY = "output";
public static final String EXECUTOR_SERVICE_COMPONENT_KEY = ExecutorService.class.getName();
public static final String DEFAULT_EXECUTOR_SERVICE_KEY = "threadnotsafe";
/*
* private Constants(){ }
*/
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.common.store;
import com.alibaba.dubbo.common.extension.SPI;
/**
* @author <a href="mailto:gang.lvg@alibaba-inc.com">kimi</a>
*/
@SPI("threadnotsafe")
public interface DataStore {
Object get(String componentName, String key);
void put(String componentName, String key, Object value);
void remove(String componentName, String key);
}
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.common.store.support;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.common.store.DataStore;
/**
* @author <a href="mailto:gang.lvg@alibaba-inc.com">kimi</a>
*/
public class ThreadNotSafeDataStore implements DataStore {
// <组件类名或标识, <数据名, 数据值>>
private Map<String, Map<String, Object>> datas =
new HashMap<String, Map<String, Object>>();
@SuppressWarnings("unchecked")
public Object get(String componentName, String key) {
if (!datas.containsKey(componentName)) {
return null;
}
return datas.get(componentName).get(key);
}
public void put(String componentName, String key, Object value) {
Map<String, Object> componentDatas = null;
if (!datas.containsKey(componentName)) {
componentDatas = new HashMap<String, Object>();
} else {
componentDatas = datas.get(componentName);
}
componentDatas.put(key, value);
datas.put(componentName, componentDatas);
}
public void remove(String componentName, String key) {
if (!datas.containsKey(componentName)) {
return;
}
datas.get(componentName).remove(key);
}
}
......@@ -126,6 +126,7 @@ public class PojoUtils {
if (pojo.getClass().isArray()) {
int len = Array.getLength(pojo);
Object[] dest = new Object[len];
history.put(pojo, dest);
for (int i = 0; i < len; i ++) {
Object obj = Array.get(pojo, i);
dest[i] = generalize(obj, history);
......@@ -136,6 +137,7 @@ public class PojoUtils {
Collection<Object> src = (Collection<Object>)pojo;
int len = src.size();
Collection<Object> dest = (pojo instanceof List<?>) ? new ArrayList<Object>(len) : new HashSet<Object>(len);
history.put(pojo, dest);
for (Object obj : src) {
dest.add(generalize(obj, history));
}
......@@ -143,12 +145,12 @@ public class PojoUtils {
}
if (pojo instanceof Map<?, ?>) {
Map<Object, Object> src = (Map<Object, Object>)pojo;
Map<Object, Object> tmp = new HashMap<Object, Object>(src.size());
tmp.putAll(src);
for (Map.Entry<Object, Object> obj : tmp.entrySet()) {
src.put(generalize(obj.getKey(), history), generalize(obj.getValue(), history));
Map<Object, Object> dest= new HashMap<Object, Object>(src.size());
history.put(pojo, dest);
for (Map.Entry<Object, Object> obj : src.entrySet()) {
dest.put(generalize(obj.getKey(), history), generalize(obj.getValue(), history));
}
return src;
return dest;
}
Map<String, Object> map = new HashMap<String, Object>();
history.put(pojo, map);
......@@ -273,6 +275,7 @@ public class PojoUtils {
Class<?> ctype = pojo.getClass().getComponentType();
int len = Array.getLength(pojo);
Collection dest = createCollection(type, len);
history.put(pojo, dest);
for (int i = 0; i < len; i ++) {
Object obj = Array.get(pojo, i);
Object value = realize0(obj, ctype, null, history);
......@@ -283,6 +286,7 @@ public class PojoUtils {
Class<?> ctype = (type != null && type.isArray() ? type.getComponentType() : pojo.getClass().getComponentType());
int len = Array.getLength(pojo);
Object dest = Array.newInstance(ctype, len);
history.put(pojo, dest);
for (int i = 0; i < len; i ++) {
Object obj = Array.get(pojo, i);
Object value = realize0(obj, ctype, null, history);
......@@ -298,6 +302,7 @@ public class PojoUtils {
Collection<Object> src = (Collection<Object>)pojo;
int len = src.size();
Object dest = Array.newInstance(ctype, len);
history.put(pojo, dest);
int i = 0;
for (Object obj : src) {
Object value = realize0(obj, ctype, null, history);
......@@ -309,6 +314,7 @@ public class PojoUtils {
Collection<Object> src = (Collection<Object>)pojo;
int len = src.size();
Collection<Object> dest = createCollection(type, len);
history.put(pojo, dest);
for (Object obj : src) {
Type keyType = getGenericClassByIndex(genericType, 0);
Class<?> keyClazz = obj.getClass() ;
......@@ -324,7 +330,7 @@ public class PojoUtils {
if (pojo instanceof Map<?, ?> && type != null) {
Object className = ((Map<Object, Object>)pojo).get("class");
if (className instanceof String && ! Map.class.isAssignableFrom(type)) {
if (className instanceof String) {
try {
type = ClassHelper.forName((String)className);
} catch (ClassNotFoundException e) {
......@@ -346,9 +352,9 @@ public class PojoUtils {
}
if (Map.class.isAssignableFrom(type) || type == Object.class) {
final Map<Object, Object> tmp = new HashMap<Object, Object>(map.size());
tmp.putAll(map);
for (Map.Entry<Object, Object> entry : tmp.entrySet()) {
final Map<Object, Object> result = new HashMap<Object, Object>(map.size());
history.put(pojo, result);
for (Map.Entry<Object, Object> entry : map.entrySet()) {
Type keyType = getGenericClassByIndex(genericType, 0);
Type valueType = getGenericClassByIndex(genericType, 1);
Class<?> keyClazz;
......@@ -366,9 +372,9 @@ public class PojoUtils {
Object key = keyClazz == null ? entry.getKey() : realize0(entry.getKey(), keyClazz, keyType, history);
Object value = valueClazz == null ? entry.getValue() : realize0(entry.getValue(), valueClazz, valueType, history);
map.put(key, value);
result.put(key, value);
}
return map;
return result;
} else if (type.isInterface()) {
Object dest = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[]{type}, new PojoInvocationHandler(map));
history.put(pojo, dest);
......
......@@ -417,5 +417,28 @@ public class UrlUtils {
return value.startsWith(prefix) && value.endsWith(suffix);
}
}
public static boolean isServiceKeyMatch(URL pattern, URL value) {
return pattern.getParameter(Constants.INTERFACE_KEY).equals(
value.getParameter(Constants.INTERFACE_KEY))
&& isItemMatch(pattern.getParameter(Constants.GROUP_KEY),
value.getParameter(Constants.GROUP_KEY))
&& isItemMatch(pattern.getParameter(Constants.VERSION_KEY),
value.getParameter(Constants.VERSION_KEY));
}
/**
* 判断 value 是否匹配 pattern,pattern 支持 * 通配符.
*
* @param pattern pattern
* @param value value
* @return true if match otherwise false
*/
static boolean isItemMatch(String pattern, String value) {
if (pattern == null) {
return value == null;
} else {
return "*".equals(pattern) || pattern.equals(value);
}
}
}
\ No newline at end of file
threadnotsafe=com.alibaba.dubbo.common.store.support.ThreadNotSafeDataStore
\ No newline at end of file
......@@ -24,6 +24,8 @@ import static org.junit.Assert.assertTrue;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -292,7 +294,17 @@ public class PojoUtilsTest {
public String gender;
public int age;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
......@@ -348,10 +360,13 @@ public class PojoUtilsTest {
map.put("k", "v");
map.put("m", map);
assertSame(map, map.get("m"));
System.out.println(map);
Object generalize = PojoUtils.generalize(map);
System.out.println(generalize);
@SuppressWarnings("unchecked")
Map<String, Object> ret = (Map<String, Object>) PojoUtils.realize(generalize, Map.class);
System.out.println(ret);
assertEquals("v", ret.get("k"));
assertSame(ret, ret.get("m"));
......@@ -510,4 +525,73 @@ public class PojoUtilsTest {
Assert.assertEquals(parent.getEmail(), realizedParent.getEmail());
Assert.assertNull(realizedParent.email);
}
public static class TestData {
private Map<String, Child> children = new HashMap<String, Child>();
private List<Child> list = new ArrayList<Child>();
public List<Child> getList() {
return list;
}
public void setList(List<Child> list) {
if (list != null && !list.isEmpty()) {
this.list.addAll(list);
}
}
public Map<String, Child> getChildren() {
return children;
}
public void setChildren(Map<String, Child> children) {
if (children!= null && !children.isEmpty()) {
this.children.putAll(children);
}
}
public void addChild(Child child) {
this.children.put(child.getName(), child);
}
}
@Test
public void testMapField() throws Exception {
TestData data = new TestData();
Child child = newChild("first", 1);
data.addChild(child);
child = newChild("second", 2);
data.addChild(child);
child = newChild("third", 3);
data.addChild(child);
data.setList(Arrays.asList(newChild("forth", 4)));
Object obj = PojoUtils.generalize(data);
Assert.assertEquals(3, data.getChildren().size());
Assert.assertTrue(data.getChildren().get("first").getClass() == Child.class);
Assert.assertEquals(1, data.getList().size());
Assert.assertTrue(data.getList().get(0).getClass() == Child.class);
TestData realizadData = (TestData) PojoUtils.realize(obj, TestData.class);
Assert.assertEquals(data.getChildren().size(), realizadData.getChildren().size());
Assert.assertEquals(data.getChildren().keySet(), realizadData.getChildren().keySet());
for(Map.Entry<String, Child> entry : data.getChildren().entrySet()) {
Child c = realizadData.getChildren().get(entry.getKey());
Assert.assertNotNull(c);
Assert.assertEquals(entry.getValue().getName(), c.getName());
Assert.assertEquals(entry.getValue().getAge(), c.getAge());
}
Assert.assertEquals(1, realizadData.getList().size());
Assert.assertEquals(data.getList().get(0).getName(), realizadData.getList().get(0).getName());
Assert.assertEquals(data.getList().get(0).getAge(), realizadData.getList().get(0).getAge());
}
private static Child newChild(String name, int age) {
Child result = new Child();
result.setName(name);
result.setAge(age);
return result;
}
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ import java.util.Set;
import org.junit.Test;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
/**
......@@ -308,4 +309,32 @@ public class UrlUtilsTest {
URL providerUrl = URL.valueOf("http://127.0.0.1:8080/com.xxx.XxxService?version=1.0.0&group=test");
assertTrue(UrlUtils.isMatch(consumerUrl, providerUrl));
}
@Test
public void testIsItemMatch() throws Exception {
assertTrue(UrlUtils.isItemMatch(null, null));
assertTrue(!UrlUtils.isItemMatch("1", null));
assertTrue(!UrlUtils.isItemMatch(null, "1"));
assertTrue(UrlUtils.isItemMatch("1", "1"));
assertTrue(UrlUtils.isItemMatch("*", null));
assertTrue(UrlUtils.isItemMatch("*", "*"));
assertTrue(UrlUtils.isItemMatch("*", "1234"));
assertTrue(!UrlUtils.isItemMatch(null, "*"));
}
@Test
public void testIsServiceKeyMatch() throws Exception {
URL url = URL.valueOf("test://127.0.0.0");
URL pattern = url.addParameter(Constants.GROUP_KEY, "test")
.addParameter(Constants.INTERFACE_KEY, "test")
.addParameter(Constants.VERSION_KEY, "test");
URL value = pattern;
assertTrue(UrlUtils.isServiceKeyMatch(pattern, value));
pattern = pattern.addParameter(Constants.GROUP_KEY, "*");
assertTrue(UrlUtils.isServiceKeyMatch(pattern, value));
pattern = pattern.addParameter(Constants.VERSION_KEY, "*");
assertTrue(UrlUtils.isServiceKeyMatch(pattern, value));
}
}
\ No newline at end of file
......@@ -18,18 +18,17 @@ package com.alibaba.dubbo.remoting.transport.dispather;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.store.DataStore;
import com.alibaba.dubbo.common.threadpool.ThreadPool;
import com.alibaba.dubbo.common.utils.NamedThreadFactory;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.exchange.Request;
import com.alibaba.dubbo.remoting.exchange.Response;
import com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler;
import com.alibaba.dubbo.remoting.transport.ChannelHandlerDelegate;
public class WrappedChannelHandler implements ChannelHandlerDelegate {
......@@ -48,6 +47,8 @@ public class WrappedChannelHandler implements ChannelHandlerDelegate {
this.handler = handler;
this.url = url;
executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url);
ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension().put(
Constants.EXECUTOR_SERVICE_COMPONENT_KEY, Constants.DEFAULT_EXECUTOR_SERVICE_KEY, executor);
}
public void close() {
......
......@@ -15,19 +15,15 @@
*/
package com.alibaba.dubbo.rpc.protocol.dubbo.status;
import java.util.Collection;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.status.Status;
import com.alibaba.dubbo.common.status.StatusChecker;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.Server;
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
import com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeServer;
import com.alibaba.dubbo.remoting.transport.dispather.WrappedChannelHandler;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
import com.alibaba.dubbo.common.store.DataStore;
/**
* ThreadPoolStatusChecker
......@@ -38,29 +34,18 @@ import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
public class ThreadPoolStatusChecker implements StatusChecker {
public Status check() {
Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
if (servers == null || servers.size() == 0) {
return new Status(Status.Level.UNKNOWN);
}
for (Server server : servers) {
if (server instanceof HeaderExchangeServer) {
HeaderExchangeServer exchanger = (HeaderExchangeServer) server;
server = exchanger.getServer();
}
ChannelHandler handler = server.getChannelHandler();
if (handler instanceof WrappedChannelHandler) {
Executor executor = ((WrappedChannelHandler) handler).getExecutor();
if (executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor tp = (ThreadPoolExecutor)executor;
boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
return new Status(ok ? Status.Level.OK : Status.Level.WARN,
"max:" + tp.getMaximumPoolSize()
+ ",core:" + tp.getCorePoolSize()
+ ",largest:" + tp.getLargestPoolSize()
+ ",active:" + tp.getActiveCount()
+ ",task:" + tp.getTaskCount());
}
}
ExecutorService executor = (ExecutorService) ExtensionLoader
.getExtensionLoader(DataStore.class).getDefaultExtension()
.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY, Constants.DEFAULT_EXECUTOR_SERVICE_KEY);
if (executor != null && executor instanceof ThreadPoolExecutor) {
ThreadPoolExecutor tp = (ThreadPoolExecutor) executor;
boolean ok = tp.getActiveCount() < tp.getMaximumPoolSize() - 1;
return new Status(ok ? Status.Level.OK : Status.Level.WARN,
"max:" + tp.getMaximumPoolSize()
+ ",core:" + tp.getCorePoolSize()
+ ",largest:" + tp.getLargestPoolSize()
+ ",active:" + tp.getActiveCount()
+ ",task:" + tp.getTaskCount());
}
return new Status(Status.Level.UNKNOWN);
}
......
......@@ -19,6 +19,7 @@ import java.util.Map;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.common.utils.UrlUtils;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.RpcException;
......@@ -54,7 +55,7 @@ class InjvmInvoker<T> extends AbstractInvoker<T> {
}
public Result doInvoke(Invocation invocation) throws Throwable {
InjvmExporter<?> exporter = (InjvmExporter<?>) exporterMap.get(key);
Exporter<?> exporter = InjvmProtocol.getExporter(exporterMap, getUrl());
if (exporter == null) {
throw new RpcException("Service [" + key + "] not found.");
}
......
......@@ -15,9 +15,12 @@
*/
package com.alibaba.dubbo.rpc.protocol.injvm;
import java.util.Map;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.utils.UrlUtils;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
......@@ -60,9 +63,16 @@ public class InjvmProtocol extends AbstractProtocol implements Protocol {
public <T> Invoker<T> refer(Class<T> serviceType, URL url) throws RpcException {
return new InjvmInvoker<T>(serviceType, url, url.getServiceKey(), exporterMap);
}
private boolean isExported(String key) {
return exporterMap != null && exporterMap.containsKey(key);
static Exporter<?> getExporter(Map<String, Exporter<?>> map, URL key) {
if (map != null && !map.isEmpty()) {
for(Exporter<?> exporter : map.values()) {
if (UrlUtils.isServiceKeyMatch(key, exporter.getInvoker().getUrl())) {
return exporter;
}
}
}
return null;
}
public boolean isInjvmRefer(URL url) {
......@@ -74,14 +84,14 @@ public class InjvmProtocol extends AbstractProtocol implements Protocol {
} else if (Constants.SCOPE_LOCAL.equals(scope) || (url.getParameter("injvm", false))) {
//如果声明为本地引用
//scope=local || injvm=true 等价 injvm标签未来废弃掉.
isJvmRefer = true;
isJvmRefer = true;
} else if (Constants.SCOPE_REMOTE.equals(scope)){
//声明了是远程引用,则不做本地引用
isJvmRefer = false;
} else if (url.getParameter(Constants.GENERIC_KEY, false)){
//泛化调用不走本地
isJvmRefer = false;
} else if (isExported(url.getServiceKey())) {
} else if (getExporter(exporterMap, url) != null) {
//默认情况下如果本地有服务暴露,则引用本地服务.
isJvmRefer = true;
} else {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.protococol.injvm;
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.injvm;
import java.io.Serializable;
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.protococol.injvm;
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.injvm;
/**
* <code>TestService</code>
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.protococol.injvm;
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.injvm;
import com.alibaba.dubbo.rpc.RpcContext;
......
......@@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.protococol.injvm;
public interface IEcho {
String echo(String e);
package com.alibaba.dubbo.rpc.protocol.injvm;
public interface IEcho {
String echo(String e);
}
\ No newline at end of file
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.protococol.injvm;
import static junit.framework.Assert.assertEquals;
import org.junit.Test;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.injvm;
import java.util.ArrayList;
import java.util.List;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import org.junit.After;
import org.junit.Test;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
/**
* <code>ProxiesTest</code>
......@@ -33,15 +40,41 @@ public class InjvmProtocolTest
{
private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
private List<Exporter<?>> exporters = new ArrayList<Exporter<?>>();
@After
public void after() throws Exception {
for(Exporter<?> exporter : exporters) {
exporter.unexport();
}
exporters.clear();
}
@Test
public void testLocalProtocol() throws Exception
{
DemoService service = new DemoServiceImpl();
protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService")));
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService")));
Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.class.getName())));
exporters.add(exporter);
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, DemoService.class.getName())));
assertEquals(service.getSize(new String[]{"", "", ""}), 3);
service.invoke("injvm://127.0.0.1/TestService", "invoke");
}
@Test
public void testIsInjvmRefer() throws Exception {
DemoService service = new DemoServiceImpl();
URL url = URL.valueOf("injvm://127.0.0.1/TestService")
.addParameter(Constants.INTERFACE_KEY, DemoService.class.getName());
Exporter<?> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
exporters.add(exporter);
url = url.setProtocol("dubbo");
assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
url = url.addParameter(Constants.GROUP_KEY, "*")
.addParameter(Constants.VERSION_KEY, "*");
assertTrue(InjvmProtocol.getInjvmProtocol().isInjvmRefer(url));
}
}
\ No newline at end of file
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.protococol.injvm;
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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.injvm;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
......@@ -22,7 +22,7 @@ import static org.junit.matchers.JUnitMatchers.containsString;
import org.junit.Test;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
......@@ -40,7 +40,7 @@ public class ProtocolTest {
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getExtension("javassist");
URL url = URL.valueOf("injvm://localhost:0/com.alibaba.dubbo.rpc.support.IEcho");
URL url = URL.valueOf("injvm://localhost:0/com.alibaba.dubbo.rpc.support.IEcho?interface=com.alibaba.dubbo.rpc.support.IEcho");
Invoker<IEcho> invoker = proxyFactory.getInvoker(echo, IEcho.class, url);
......
......@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.protococol.injvm;
public enum Type
{
High, Normal, Lower
package com.alibaba.dubbo.rpc.protocol.injvm;
public enum Type
{
High, Normal, Lower
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册