加强端口清理
git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@191 1a56cb94-b969-4eaa-88fa-be21384802f2
This commit is contained in:
parent
4a64a3abc2
commit
0a1ca0c06f
|
|
@ -15,36 +15,47 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.rpc.protocol.dubbo.support;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.alibaba.dubbo.common.ExtensionLoader;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
|
||||
import com.alibaba.dubbo.rpc.Exporter;
|
||||
import com.alibaba.dubbo.rpc.Protocol;
|
||||
import com.alibaba.dubbo.rpc.ProxyFactory;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
|
||||
|
||||
/**
|
||||
* TODO Comment of ProtocolUtils
|
||||
*
|
||||
* @author william.liangf
|
||||
*
|
||||
*/
|
||||
public class ProtocolUtils {
|
||||
|
||||
private static Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
|
||||
private static ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
|
||||
|
||||
private static Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
|
||||
private static ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
|
||||
|
||||
public static <T> T refer(Class<T> type, String url) {
|
||||
return refer(type, URL.valueOf(url));
|
||||
}
|
||||
|
||||
|
||||
public static <T> T refer(Class<T> type, URL url) {
|
||||
return proxy.getProxy(protocol.refer(type, url));
|
||||
}
|
||||
|
||||
|
||||
public static <T> Exporter<T> export(T instance, Class<T> type, String url) {
|
||||
return export(instance, type, URL.valueOf(url));
|
||||
}
|
||||
|
||||
|
||||
public static <T> Exporter<T> export(T instance, Class<T> type, URL url) {
|
||||
return protocol.export(proxy.getInvoker(instance, type, url));
|
||||
}
|
||||
|
||||
}
|
||||
public static void closeAll() {
|
||||
DubboProtocol.getDubboProtocol().destroy();
|
||||
Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
|
||||
for (ExchangeServer server : servers) {
|
||||
server.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ import org.junit.Test;
|
|||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.remoting.Channel;
|
||||
import com.alibaba.dubbo.remoting.RemotingException;
|
||||
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
|
||||
import com.alibaba.dubbo.remoting.telnet.TelnetHandler;
|
||||
import com.alibaba.dubbo.rpc.Invoker;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.support.ProtocolUtils;
|
||||
|
||||
/**
|
||||
* ChangeTelnetHandlerTest.java
|
||||
|
|
@ -69,11 +69,8 @@ public class ChangeTelnetHandlerTest {
|
|||
|
||||
@After
|
||||
public void after() {
|
||||
for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) {
|
||||
server.close();
|
||||
}
|
||||
ProtocolUtils.closeAll();
|
||||
EasyMock.reset(mockChannel, mockInvoker);
|
||||
DubboProtocol.getDubboProtocol().destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -18,19 +18,24 @@ package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.utils.NetUtils;
|
||||
import com.alibaba.dubbo.remoting.Channel;
|
||||
import com.alibaba.dubbo.remoting.RemotingException;
|
||||
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
|
||||
import com.alibaba.dubbo.remoting.telnet.TelnetHandler;
|
||||
import com.alibaba.dubbo.rpc.Invocation;
|
||||
import com.alibaba.dubbo.rpc.Invoker;
|
||||
import com.alibaba.dubbo.rpc.RpcResult;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.support.ProtocolUtils;
|
||||
|
||||
/**
|
||||
* CountTelnetHandlerTest.java
|
||||
|
|
@ -43,6 +48,11 @@ public class InvokerTelnetHandlerTest {
|
|||
private Channel mockChannel;
|
||||
private Invoker<DemoService> mockInvoker;
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
ProtocolUtils.closeAll();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testInvokeDefaultSService() throws RemotingException {
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -35,6 +35,7 @@ import com.alibaba.dubbo.rpc.Invoker;
|
|||
import com.alibaba.dubbo.rpc.RpcResult;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.support.DemoService;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.support.ProtocolUtils;
|
||||
|
||||
/**
|
||||
* CountTelnetHandlerTest.java
|
||||
|
|
@ -67,6 +68,11 @@ public class ListTelnetHandlerTest {
|
|||
detailMethods = buf.toString();
|
||||
methodsName = buf2.toString();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
ProtocolUtils.closeAll();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
|
|
@ -100,6 +106,7 @@ public class ListTelnetHandlerTest {
|
|||
EasyMock.reset(mockChannel, mockInvoker);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testList() throws RemotingException {
|
||||
mockInvoker = EasyMock.createMock(Invoker.class);
|
||||
|
|
@ -115,6 +122,7 @@ public class ListTelnetHandlerTest {
|
|||
EasyMock.reset(mockChannel);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testListDetail() throws RemotingException {
|
||||
mockInvoker = EasyMock.createMock(Invoker.class);
|
||||
|
|
@ -131,6 +139,7 @@ public class ListTelnetHandlerTest {
|
|||
EasyMock.reset(mockChannel);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testListDefault() throws RemotingException {
|
||||
mockInvoker = EasyMock.createMock(Invoker.class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue