拆分模块
git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@64 1a56cb94-b969-4eaa-88fa-be21384802f2
This commit is contained in:
parent
8dc5a686f3
commit
6501a54860
|
|
@ -19,6 +19,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.script.Bindings;
|
||||
import javax.script.Compilable;
|
||||
|
|
@ -27,8 +28,6 @@ import javax.script.ScriptEngine;
|
|||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import org.jboss.netty.util.internal.ConcurrentHashMap;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ package com.alibaba.dubbo.rpc.cluster.loadbalance;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.jboss.netty.util.internal.ConcurrentHashMap;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ package com.alibaba.dubbo.rpc.cluster.support;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.jboss.netty.util.internal.ConcurrentHashMap;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,11 @@
|
|||
<artifactId>dubbo-monitor</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo-remoting</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring</artifactId>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
package com.alibaba.dubbo.monitor.dubbo;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
|
@ -23,8 +24,6 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.jboss.netty.util.internal.ConcurrentHashMap;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
import com.alibaba.dubbo.common.logger.LoggerFactory;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry;
|
||||
package com.alibaba.dubbo.registry.dubbo;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.registry;
|
||||
package com.alibaba.dubbo.registry.dubbo;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Map;
|
||||
|
|
@ -21,7 +21,6 @@ import org.junit.Test;
|
|||
|
||||
import com.alibaba.dubbo.common.ExtensionLoader;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.registry.MockedClient;
|
||||
import com.alibaba.dubbo.registry.RegistryFactory;
|
||||
import com.alibaba.dubbo.registry.support.RegistryProtocol;
|
||||
import com.alibaba.dubbo.registry.support.SimpleRegistryExporter;
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ package com.alibaba.dubbo.remoting.p2p.exchange.support;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.netty.util.internal.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ package com.alibaba.dubbo.remoting.p2p.support;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.netty.util.internal.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.common.logger.Logger;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import com.alibaba.dubbo.rpc.RpcContext;
|
|||
import com.alibaba.dubbo.rpc.RpcException;
|
||||
import com.alibaba.dubbo.rpc.RpcInvocation;
|
||||
import com.alibaba.dubbo.rpc.protocol.AbstractInvoker;
|
||||
import com.alibaba.dubbo.rpc.protocol.FutureAdapter;
|
||||
|
||||
/**
|
||||
* DubboInvoker
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.rpc.protocol;
|
||||
package com.alibaba.dubbo.rpc.protocol.dubbo;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.rpc.filter;
|
||||
package com.alibaba.dubbo.rpc.protocol.dubbo.filter;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
|
@ -33,17 +33,17 @@ import com.alibaba.dubbo.rpc.RpcConstants;
|
|||
import com.alibaba.dubbo.rpc.RpcContext;
|
||||
import com.alibaba.dubbo.rpc.RpcException;
|
||||
import com.alibaba.dubbo.rpc.StaticContext;
|
||||
import com.alibaba.dubbo.rpc.protocol.FutureAdapter;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.FutureAdapter;
|
||||
|
||||
/**
|
||||
* EventFilter
|
||||
* @author chao.liuc
|
||||
* @author william.liangf
|
||||
*/
|
||||
@Extension("event")
|
||||
public class EventFilter implements Filter {
|
||||
@Extension("future")
|
||||
public class FutureFilter implements Filter {
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(EventFilter.class);
|
||||
protected static final Logger logger = LoggerFactory.getLogger(FutureFilter.class);
|
||||
|
||||
public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
|
||||
fireInvokeCallback(invoker, invocation);
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.rpc.filter;
|
||||
package com.alibaba.dubbo.rpc.protocol.dubbo.filter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
|
@ -24,8 +24,8 @@ import com.alibaba.dubbo.remoting.telnet.TelnetHandler;
|
|||
import com.alibaba.dubbo.remoting.telnet.support.Help;
|
||||
import com.alibaba.dubbo.rpc.Exporter;
|
||||
import com.alibaba.dubbo.rpc.Invoker;
|
||||
import com.alibaba.dubbo.rpc.filter.TraceFilter;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
|
||||
import com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter;
|
||||
|
||||
/**
|
||||
* TraceTelnetHandler
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter
|
||||
com.alibaba.dubbo.rpc.protocol.dubbo.filter.FutureFilter
|
||||
|
|
@ -13,10 +13,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.dubbo.rpc.filter;
|
||||
package com.alibaba.dubbo.rpc.protocol.dubbo.filter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.BeforeClass;
|
||||
|
|
@ -38,8 +37,8 @@ import com.alibaba.dubbo.rpc.support.DemoService;
|
|||
* @author tony.chenl
|
||||
* TODO 暂时依赖callback集成测试,后续补充
|
||||
*/
|
||||
public class EventFilterTest {
|
||||
Filter eventFilter = new EventFilter();
|
||||
public class FutureFilterTest {
|
||||
Filter eventFilter = new FutureFilter();
|
||||
private static Invocation invocation;
|
||||
|
||||
@BeforeClass
|
||||
|
|
@ -27,7 +27,7 @@ import java.util.List;
|
|||
public final class RpcConstants {
|
||||
|
||||
public static final List<String> DEFAULT_REFERENCE_FILTERS = Collections.unmodifiableList(Arrays.asList(new String[] {
|
||||
"consumercontext", "compatible", "deprecated", "collect", "genericimpl", "activelimit", "monitor", "event" }));
|
||||
"consumercontext", "compatible", "deprecated", "collect", "genericimpl", "activelimit", "monitor", "future" }));
|
||||
|
||||
public static final List<String> DEFAULT_SERVICE_FILTERS = Collections.unmodifiableList(Arrays.asList(new String[] {
|
||||
"ready", "context", "token", "exception", "echo", "generic", "accesslog", "trace", "classloader", "executelimit", "monitor" ,"timeout"}));
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ com.alibaba.dubbo.rpc.filter.ConsumerContextFilter
|
|||
com.alibaba.dubbo.rpc.filter.ExceptionFilter
|
||||
com.alibaba.dubbo.rpc.filter.ExecuteLimitFilter
|
||||
com.alibaba.dubbo.rpc.filter.DeprecatedFilter
|
||||
com.alibaba.dubbo.rpc.filter.TraceFilter
|
||||
com.alibaba.dubbo.rpc.filter.CompatibleFilter
|
||||
com.alibaba.dubbo.rpc.filter.ReadyFilter
|
||||
com.alibaba.dubbo.rpc.filter.TimeoutFilter
|
||||
com.alibaba.dubbo.rpc.filter.EventFilter
|
||||
com.alibaba.dubbo.rpc.filter.TimeoutFilter
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
/*
|
||||
* 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.proxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.dubbo.common.Extension;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
import com.alibaba.dubbo.remoting.RemotingException;
|
||||
import com.alibaba.dubbo.remoting.exchange.ExchangeChannel;
|
||||
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
|
||||
import com.alibaba.dubbo.remoting.exchange.Exchangers;
|
||||
import com.alibaba.dubbo.remoting.exchange.support.Replier;
|
||||
import com.alibaba.dubbo.rpc.Exporter;
|
||||
import com.alibaba.dubbo.rpc.Invocation;
|
||||
import com.alibaba.dubbo.rpc.Invoker;
|
||||
import com.alibaba.dubbo.rpc.RpcException;
|
||||
import com.alibaba.dubbo.rpc.RpcInvocation;
|
||||
import com.alibaba.dubbo.rpc.protocol.AbstractExporter;
|
||||
import com.alibaba.dubbo.rpc.protocol.AbstractInvoker;
|
||||
import com.alibaba.dubbo.rpc.protocol.AbstractProtocol;
|
||||
|
||||
/**
|
||||
* TestProtocolSupport.
|
||||
*
|
||||
* @author qian.lei
|
||||
*/
|
||||
@Extension("demo")
|
||||
public class DemoRpcProtocol extends AbstractProtocol {
|
||||
|
||||
private final Map<String, ExchangeChannel> mClientMap = new HashMap<String, ExchangeChannel>(); // <remote ip:remote port,Client>
|
||||
|
||||
private final Map<Integer, ExchangeServer> mServerMap = new HashMap<Integer, ExchangeServer>(); // <port,Server>
|
||||
|
||||
private final Map<String, InternalExporter<?>> mServiceMap = new HashMap<String, InternalExporter<?>>(); // <service name@port,service instance>
|
||||
|
||||
private final Replier<DemoRequest> mHandler = new InternalHandler();
|
||||
|
||||
public int getDefaultPort() {
|
||||
return 123456;
|
||||
}
|
||||
|
||||
public <T> Invoker<T> refer(Class<T> serviceType, URL url) throws RpcException
|
||||
{
|
||||
ExchangeChannel client = mClientMap.get(url.getHost() + ':' + url.getPort());
|
||||
if( client == null )
|
||||
{
|
||||
// create client.
|
||||
try {
|
||||
client = Exchangers.connect(url);
|
||||
} catch (RemotingException e) {
|
||||
throw new RpcException(e.getMessage(), e);
|
||||
}
|
||||
mClientMap.put(url.getHost() + ':' + url.getPort(),client);
|
||||
}
|
||||
final ExchangeChannel fc = client;
|
||||
return new AbstractInvoker<T>(serviceType, url){
|
||||
public Object doInvoke(Invocation invocation) throws Throwable
|
||||
{
|
||||
DemoRequest req = new DemoRequest(getUrl().getPath(), invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments());
|
||||
int timeout = getUrl().getMethodIntParameter(invocation.getMethodName(), "timeout");
|
||||
if( timeout > 0 )
|
||||
return fc.request(req, timeout).get();
|
||||
return fc.request(req).get();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
|
||||
URL url = invoker.getUrl();
|
||||
if( !mServerMap.containsKey(url.getPort()) )
|
||||
{
|
||||
ExchangeServer server;
|
||||
try {
|
||||
server = Exchangers.bind(url, mHandler);
|
||||
} catch (RemotingException e) {
|
||||
throw new RpcException(e.getMessage(), e);
|
||||
}
|
||||
mServerMap.put(url.getPort(),server);
|
||||
}
|
||||
InternalExporter<T> exporter = new InternalExporter<T>(invoker);
|
||||
mServiceMap.put(url.getPath()+'@'+url.getPort(), exporter);
|
||||
return exporter;
|
||||
}
|
||||
|
||||
public void destroy()
|
||||
{
|
||||
for (String key : new ArrayList<String>(mServiceMap.keySet())) {
|
||||
InternalExporter<?> exporter = mServiceMap.remove(key);
|
||||
if (exporter != null) {
|
||||
try {
|
||||
exporter.unexport();
|
||||
} catch (Throwable t) {
|
||||
logger.warn(t.getMessage(), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Integer key : new ArrayList<Integer>(mServerMap.keySet())) {
|
||||
ExchangeServer server = mServerMap.remove(key);
|
||||
if (server != null) {
|
||||
try {
|
||||
server.close();
|
||||
} catch (Throwable t) {
|
||||
logger.warn(t.getMessage(), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String key : new ArrayList<String>(mClientMap.keySet())) {
|
||||
ExchangeChannel client = mClientMap.remove(key);
|
||||
if (client != null) {
|
||||
try {
|
||||
client.close();
|
||||
} catch (Throwable t) {
|
||||
logger.warn(t.getMessage(), t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class InternalExporter<T> extends AbstractExporter<T>
|
||||
{
|
||||
public InternalExporter(Invoker<T> invoker)
|
||||
{
|
||||
super(invoker);
|
||||
}
|
||||
}
|
||||
|
||||
private class InternalHandler implements Replier<DemoRequest> {
|
||||
public Object reply(ExchangeChannel channel, DemoRequest msg) throws RemotingException {
|
||||
// find service instance.
|
||||
int port = channel.getLocalAddress().getPort();
|
||||
String serviceName = msg.getServiceName();
|
||||
InternalExporter<?> exporter = mServiceMap.get(serviceName+'@'+port);
|
||||
if( exporter == null )
|
||||
throw new RemotingException(channel, "Service " + serviceName + " not found.");
|
||||
try {
|
||||
return exporter.invoke(new RpcInvocation(msg.getMethodName(), msg.getParameterTypes(), msg.getArguments()), channel.getRemoteAddress()).recreate();
|
||||
} catch (RpcException e) {
|
||||
throw new RemotingException(channel, e.getMessage(), e);
|
||||
} catch (Throwable e) {
|
||||
throw new RemotingException(channel, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue