拆分模块

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@48 1a56cb94-b969-4eaa-88fa-be21384802f2
This commit is contained in:
william.liangf 2011-10-26 01:41:28 +00:00
parent a65e71c7d9
commit 65bcf57464
115 changed files with 2385 additions and 132 deletions

View File

@ -28,9 +28,9 @@ import com.alibaba.dubbo.registry.RegistryService;
import com.alibaba.dubbo.registry.support.UrlUtils;
import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.InvokerListener;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.cluster.Cluster;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
/**
* AbstractDefaultConfig

View File

@ -38,15 +38,15 @@ import com.alibaba.dubbo.common.utils.ReflectUtils;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.StaticContext;
import com.alibaba.dubbo.rpc.cluster.Cluster;
import com.alibaba.dubbo.rpc.cluster.directory.StaticDirectory;
import com.alibaba.dubbo.rpc.cluster.support.AvailableCluster;
import com.alibaba.dubbo.rpc.cluster.support.ClusterUtils;
import com.alibaba.dubbo.rpc.injvm.InjvmProtocol;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.alibaba.dubbo.rpc.protocol.injvm.InjvmProtocol;
import com.alibaba.dubbo.service.GenericService;
/**
* ReferenceConfig

View File

@ -39,10 +39,10 @@ import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.RpcStatus;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.alibaba.dubbo.service.GenericService;
/**
* ServiceConfig

View File

@ -31,7 +31,7 @@ import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.rpc.injvm.InjvmProtocol;
import com.alibaba.dubbo.rpc.protocol.injvm.InjvmProtocol;
/**
* ReferenceFactoryBean

View File

@ -19,7 +19,7 @@ import com.alibaba.dubbo.common.ExtensionLoader;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
import com.alibaba.dubbo.rpc.ProxyFactory;
public class Client {
private static ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();

View File

@ -20,8 +20,8 @@ import com.alibaba.dubbo.common.ExtensionLoader;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.dubbo.DubboCodec;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboCodec;
public class Server {
private static ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();

View File

@ -28,7 +28,7 @@ import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.util.MyException;
import com.alibaba.dubbo.rpc.util.MyService;
import com.alibaba.dubbo.rpc.util.MyServiceImpl;

View File

@ -20,7 +20,7 @@ import java.util.Map;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.alibaba.dubbo.service.GenericService;
public class GenericConsumer {

View File

@ -19,8 +19,8 @@ import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.service.GenericException;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.alibaba.dubbo.service.GenericException;
import com.alibaba.dubbo.service.GenericService;
/**
* DemoServiceGenericeImpl

View File

@ -0,0 +1,39 @@
<!--
- 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.0.8-SNAPSHOT</version>
</parent>
<artifactId>dubbo-monitor-default</artifactId>
<packaging>jar</packaging>
<name>Dubbo Default Monitor Module</name>
<description>The default monitor module of dubbo project</description>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-monitor</artifactId>
<version>${project.parent.version}</version>
</dependency>
<!--<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
</dependency>-->
</dependencies>
</project>

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.monitor.support.dubbo;
package com.alibaba.dubbo.monitor.dubbo;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.monitor.support.dubbo;
package com.alibaba.dubbo.monitor.dubbo;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.Extension;
@ -23,7 +23,7 @@ import com.alibaba.dubbo.monitor.MonitorService;
import com.alibaba.dubbo.monitor.support.AbstractMonitorFactroy;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
import com.alibaba.dubbo.rpc.ProxyFactory;
/**
* DefaultMonitorFactroy

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.monitor.support.dubbo;
package com.alibaba.dubbo.monitor.dubbo;
import java.io.Serializable;

View File

@ -0,0 +1 @@
com.alibaba.dubbo.monitor.dubbo.DubboMonitorFactroy

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.monitor.filter.support.dubbo;
package com.alibaba.dubbo.monitor.dubbo;
import junit.framework.Assert;
@ -21,7 +21,6 @@ import org.junit.Test;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.monitor.MonitorService;
import com.alibaba.dubbo.monitor.support.dubbo.DubboMonitor;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;

35
dubbo-monitor-jmx/pom.xml Normal file
View File

@ -0,0 +1,35 @@
<!--
- 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.0.8-SNAPSHOT</version>
</parent>
<artifactId>dubbo-monitor-jmx</artifactId>
<packaging>jar</packaging>
<name>Dubbo JMX Monitor Module</name>
<description>The jmx monitor module of dubbo project</description>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-monitor</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.monitor.filter;
package com.alibaba.dubbo.monitor.support;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

View File

@ -1 +0,0 @@
com.alibaba.dubbo.monitor.support.dubbo.DubboMonitorFactroy

View File

@ -1 +1 @@
com.alibaba.dubbo.monitor.filter.MonitorFilter
com.alibaba.dubbo.monitor.support.MonitorFilter

View File

@ -28,6 +28,7 @@ import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.monitor.Monitor;
import com.alibaba.dubbo.monitor.MonitorFactory;
import com.alibaba.dubbo.monitor.MonitorService;
import com.alibaba.dubbo.monitor.support.MonitorFilter;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;

View File

@ -0,0 +1,35 @@
<!--
- 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.0.8-SNAPSHOT</version>
</parent>
<artifactId>dubbo-registry-default</artifactId>
<packaging>jar</packaging>
<name>Dubbo Default Registry Module</name>
<description>The default registry module of dubbo project</description>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-registry</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.registry.support.dubbo;
package com.alibaba.dubbo.registry.dubbo;
import java.util.HashMap;
import java.util.HashSet;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.registry.support.dubbo;
package com.alibaba.dubbo.registry.dubbo;
import java.util.ArrayList;
import java.util.Arrays;
@ -27,13 +27,13 @@ import com.alibaba.dubbo.common.bytecode.Wrapper;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.RegistryService;
import com.alibaba.dubbo.registry.directory.RegistryDirectory;
import com.alibaba.dubbo.registry.support.AbstractRegistryFactory;
import com.alibaba.dubbo.registry.support.RegistryDirectory;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.cluster.Cluster;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
/**
* DubboRegistryFactory

View File

@ -0,0 +1 @@
com.alibaba.dubbo.registry.dubbo.DubboRegistryFactory

View File

@ -0,0 +1,35 @@
<!--
- 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.0.8-SNAPSHOT</version>
</parent>
<artifactId>dubbo-registry-jndi</artifactId>
<packaging>jar</packaging>
<name>Dubbo JNDI Registry Module</name>
<description>The jndi registry module of dubbo project</description>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-registry</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,160 @@
/*
* 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.registry.multicast;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.registry.NotifyListener;
import com.alibaba.dubbo.registry.support.AbstractRegistry;
/**
* MulticastRegistry
*
* @author william.liangf
*/
public class MulticastRegistry extends AbstractRegistry {
// 日志输出
private static final Logger logger = LoggerFactory.getLogger(MulticastRegistry.class);
private InetAddress mutilcastAddress;
private MulticastSocket mutilcastSocket;
public MulticastRegistry(URL url) {
super(url);
if (! isMulticastAddress(url.getHost())) {
throw new IllegalArgumentException("Invalid multicast address " + url.getHost() + ", scope: 224.0.0.0 - 239.255.255.255");
}
try {
mutilcastAddress = InetAddress.getByName(url.getHost());
mutilcastSocket = new MulticastSocket(url.getPort());
mutilcastSocket.setLoopbackMode(false);
mutilcastSocket.joinGroup(mutilcastAddress);
Thread thread = new Thread(new Runnable() {
public void run() {
byte[] buf = new byte[1024];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
while (true) {
try {
mutilcastSocket.receive(recv);
MulticastRegistry.this.receive(new String(recv.getData()).trim(), (InetSocketAddress) recv.getSocketAddress());
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
}, "MulticastRegistry");
thread.setDaemon(true);
thread.start();
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
private static boolean isMulticastAddress(String ip) {
int i = ip.indexOf('.');
if (i > 0) {
String prefix = ip.substring(0, i);
if (StringUtils.isInteger(prefix)) {
int p = Integer.parseInt(prefix);
return p >= 224 && p <= 239;
}
}
return false;
}
private void receive(String msg, InetSocketAddress remoteAddress) {
if (msg.startsWith("register")) {
String[] parts = msg.split("\\s+");
String service = parts[1];
if (getSubscribed().containsKey(service)) {
URL url = URL.valueOf(parts[2]);
List<URL> urls = new ArrayList<URL>();
List<URL> notified = getNotified().get(service);
if (notified != null) {
urls.addAll(notified);
}
if (! urls.contains(url)) {
urls.add(url);
}
notify(service, urls);
}
} else if (msg.startsWith("subscribe")) {
String[] parts = msg.split("\\s+");
String service = parts[1];
if (getRegistered().containsKey(service)) {
for (URL url : getRegistered().get(service)) {
send("register " + service + " " + url.toString());
}
}
}
}
private void send(String msg) {
DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(), mutilcastAddress, mutilcastSocket.getLocalPort());
try {
mutilcastSocket.send(hi);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
public void register(String service, URL url) {
super.register(service, url);
send("register " + service + " " + url);
}
public void unregister(String service, URL url) {
send("unregister " + service + " " + url);
}
public void subscribe(String service, Map<String, String> parameters, NotifyListener listener) {
super.subscribe(service, parameters, listener);
send("subscribe " + service + " " + StringUtils.toQueryString(parameters));
synchronized (this) {
try {
this.wait(5000);
} catch (InterruptedException e) {
}
}
}
public void unsubscribe(String service, Map<String, String> query, NotifyListener listener) {
send("unsubscribe " + service + " " + StringUtils.toQueryString(query));
}
public boolean isAvailable() {
return mutilcastSocket.isConnected();
}
@Override
public void destroy() {
mutilcastSocket.close();
}
}

View File

@ -0,0 +1,35 @@
/*
* 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.registry.multicast;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.RegistryFactory;
/**
* MulticastRegistryLocator
*
* @author william.liangf
*/
@Extension("multicast")
public class MulticastRegistryFactory implements RegistryFactory {
public Registry getRegistry(URL url) {
return new MulticastRegistry(url);
}
}

View File

@ -0,0 +1 @@
com.alibaba.dubbo.registry.multicast.MulticastRegistryFactory

View File

@ -0,0 +1,167 @@
/*
* 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.registry.zookeeper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.Watcher.Event.EventType;
import org.apache.zookeeper.ZooDefs.Ids;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.registry.NotifyListener;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.rpc.RpcException;
/**
* ZookeeperRegistry
*
* @author william.liangf
*/
public class ZookeeperRegistry implements Registry {
private final static Logger logger = LoggerFactory.getLogger(ZookeeperRegistry.class);
private final URL url;
private final ZooKeeper zookeeper;
public ZookeeperRegistry(URL url) {
this.url = url;
try {
this.zookeeper = new ZooKeeper(url.getAddress(), url.getPositiveIntParameter(
Constants.TIMEOUT_KEY, 5000), new Watcher() {
public void process(WatchedEvent event) {
}
});
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
public URL getUrl() {
return url;
}
public boolean isAvailable() {
return zookeeper.getState().isAlive();
}
public void destroy() {
try {
zookeeper.close();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
}
public void register(URL url) {
try {
String service = "/" + URL.encode(url.getServiceKey());
if (zookeeper.exists(service, false) == null) {
zookeeper.create(service, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
}
String provider = service + "/" + URL.encode(url.toIdentityString());
if (zookeeper.exists(provider, false) == null) {
zookeeper.create(provider, url.toParameterString().getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
}
} catch (Exception e) {
throw new RpcException(e.getMessage(), e);
}
}
public void unregister(URL url) {
try {
String service = "/" + URL.encode(url.getServiceKey());
String provider = service + "/" + URL.encode(url.toIdentityString());
zookeeper.delete(provider, -1);
} catch (Exception e) {
throw new RpcException(e.getMessage(), e);
}
}
public void subscribe(URL url, NotifyListener listener) {
try {
String service = "/" + URL.encode(url.getServiceKey());
List<String> providers = zookeeper.getChildren(service, new NotifyWatcher(url, listener));
listener.notify(toUrls(service, providers));
} catch (Exception e) {
throw new RpcException(e.getMessage(), e);
}
}
public void unsubscribe(URL url, NotifyListener listener) {
}
public List<URL> lookup(URL url) {
try {
String service = "/" + URL.encode(url.getServiceKey());
List<String> providers = zookeeper.getChildren(service, false);
return toUrls(service, providers);
} catch (Exception e) {
throw new RpcException(e.getMessage(), e);
}
}
private List<URL> toUrls(String service, List<String> providers) throws KeeperException, InterruptedException {
List<URL> urls = new ArrayList<URL>();
for (String provider : providers) {
String path = service + provider;
String query = "";
Stat stat = zookeeper.exists(path, false);
if (stat != null) {
byte[] data = zookeeper.getData(path, false, stat);
if (data != null && data.length > 0) {
query = "?" + new String(data);
}
}
urls.add(URL.valueOf(URL.decode(provider + query)));
}
return urls;
}
private class NotifyWatcher implements Watcher {
private final URL url;
private final NotifyListener listener;
public NotifyWatcher(URL url, NotifyListener listener) {
this.url = url;
this.listener = listener;
}
public void process(WatchedEvent event) {
if (event.getType() == EventType.NodeChildrenChanged) {
listener.notify(lookup(url));
} else if (event.getType() == EventType.NodeDataChanged) {
listener.notify(lookup(url));
}
}
}
}

View File

@ -0,0 +1,35 @@
/*
* 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.registry.zookeeper;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.support.AbstractRegistryFactory;
/**
* ZookeeperRegistryFactory.
*
* @author william.liangf
*/
@Extension("zookeeper")
public class ZookeeperRegistryFactory extends AbstractRegistryFactory {
public Registry createRegistry(URL url) {
return new ZookeeperRegistry(url);
}
}

View File

@ -0,0 +1 @@
com.alibaba.dubbo.registry.zookeeper.ZookeeperRegistryFactory

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.registry.directory;
package com.alibaba.dubbo.registry.support;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.registry.protocol;
package com.alibaba.dubbo.registry.support;
import java.util.ArrayList;
import java.util.List;
@ -25,14 +25,13 @@ import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.RegistryFactory;
import com.alibaba.dubbo.registry.directory.RegistryDirectory;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.cluster.Cluster;
import com.alibaba.dubbo.rpc.support.InvokerWrapper;
import com.alibaba.dubbo.rpc.protocol.InvokerWrapper;
/**
* RegistryProtocol

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.registry.status;
package com.alibaba.dubbo.registry.support;
import java.util.Collection;
@ -21,7 +21,6 @@ import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.status.Status;
import com.alibaba.dubbo.common.status.StatusChecker;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.support.AbstractRegistryFactory;
/**
* RegistryStatusChecker

View File

@ -25,8 +25,8 @@ import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.registry.RegistryService;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
/**
* SimpleRegistryExporter

View File

@ -1 +1 @@
com.alibaba.dubbo.registry.status.RegistryStatusChecker
com.alibaba.dubbo.registry.support.RegistryStatusChecker

View File

@ -1 +0,0 @@
com.alibaba.dubbo.registry.support.dubbo.DubboRegistryFactory

View File

@ -1 +1 @@
com.alibaba.dubbo.registry.protocol.RegistryProtocol
com.alibaba.dubbo.registry.support.RegistryProtocol

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.registry.protocol;
package com.alibaba.dubbo.registry.support;
/**
* <code>TestService</code>

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.registry.directory;
package com.alibaba.dubbo.registry.support;
import static org.junit.Assert.fail;
@ -29,6 +29,7 @@ import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.ExtensionLoader;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.registry.RegistryFactory;
import com.alibaba.dubbo.registry.support.RegistryDirectory;
import com.alibaba.dubbo.registry.support.SimpleRegistryExporter;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.registry.protocol;
package com.alibaba.dubbo.registry.support;
import static org.junit.Assert.assertEquals;
@ -23,6 +23,7 @@ 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;
import com.alibaba.dubbo.remoting.exchange.ExchangeClient;
import com.alibaba.dubbo.rpc.Exporter;
@ -30,8 +31,8 @@ import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.cluster.support.FailfastCluster;
import com.alibaba.dubbo.rpc.dubbo.DubboInvoker;
import com.alibaba.dubbo.rpc.dubbo.DubboProtocol;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
/**
* RegistryProtocolTest

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.registry.status;
package com.alibaba.dubbo.registry.support;
import static org.junit.Assert.assertEquals;
@ -25,6 +25,7 @@ import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.status.Status;
import com.alibaba.dubbo.registry.RegistryFactory;
import com.alibaba.dubbo.registry.support.AbstractRegistryFactory;
import com.alibaba.dubbo.registry.support.RegistryStatusChecker;
import com.alibaba.dubbo.registry.support.SimpleRegistryExporter;
/**

View File

@ -31,5 +31,11 @@
<artifactId>dubbo-remoting</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-core</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,178 @@
/*
* 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.remoting.transport.grizzly;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.Grizzly;
import org.glassfish.grizzly.GrizzlyFuture;
import org.glassfish.grizzly.attributes.Attribute;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.transport.support.AbstractChannel;
/**
* GrizzlyChannel
*
* @author william.liangf
*/
final class GrizzlyChannel extends AbstractChannel {
private static final Logger logger = LoggerFactory.getLogger(GrizzlyChannel.class);
private static final String CHANNEL_KEY = GrizzlyChannel.class.getName() + ".CHANNEL";
private static final Attribute<GrizzlyChannel> ATTRIBUTE = Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(CHANNEL_KEY);
private final Connection<?> connection;
/**
* @param connection
* @param url
* @param handler
*/
private GrizzlyChannel(Connection<?> connection, URL url, ChannelHandler handler){
super(url, handler);
if (connection == null) {
throw new IllegalArgumentException("grizzly connection == null");
}
this.connection = connection;
}
static GrizzlyChannel getOrAddChannel(Connection<?> connection, URL url, ChannelHandler handler) {
if (connection == null) {
return null;
}
GrizzlyChannel ret = ATTRIBUTE.get(connection);
if (ret == null) {
ret = new GrizzlyChannel(connection, url, handler);
if (connection.isOpen()) {
ATTRIBUTE.set(connection, ret);
}
}
return ret;
}
static void removeChannelIfDisconnectd(Connection<?> connection) {
if (connection != null && ! connection.isOpen()) {
ATTRIBUTE.remove(connection);
}
}
public InetSocketAddress getRemoteAddress() {
return (InetSocketAddress) connection.getPeerAddress();
}
public boolean isConnected() {
return connection.isOpen();
}
public InetSocketAddress getLocalAddress() {
return (InetSocketAddress) connection.getLocalAddress();
}
@SuppressWarnings("rawtypes")
public void send(Object message, boolean sent) throws RemotingException {
super.send(message, sent);
int timeout = 0;
try {
GrizzlyFuture future = connection.write(message);
if (sent) {
timeout = getUrl().getPositiveIntParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
future.get(timeout, TimeUnit.MILLISECONDS);
}
}
catch (TimeoutException e) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress()
+ "in timeout(" + timeout + "ms) limit", e);
}
catch (Throwable e) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
}
}
public void close() {
try {
super.close();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
try {
removeChannelIfDisconnectd(connection);
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
try {
if (logger.isInfoEnabled()) {
logger.info("Close grizzly channel " + connection);
}
connection.close();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
}
public boolean hasAttribute(String key) {
return getAttribute(key) == null;
}
public Object getAttribute(String key) {
return Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(key).get(connection);
}
public void setAttribute(String key, Object value) {
Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(key).set(connection, value);
}
public void removeAttribute(String key) {
Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(key).remove(connection);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((connection == null) ? 0 : connection.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
GrizzlyChannel other = (GrizzlyChannel) obj;
if (connection == null) {
if (other.connection != null) return false;
} else if (!connection.equals(other.connection)) return false;
return true;
}
@Override
public String toString() {
return "GrizzlyChannel [connection=" + connection + "]";
}
}

View File

@ -0,0 +1,105 @@
/*
* 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.remoting.transport.grizzly;
import java.util.concurrent.TimeUnit;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.filterchain.TransportFilter;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder;
import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.transport.support.AbstractClient;
/**
* GrizzlyClient
*
* @author william.liangf
*/
public class GrizzlyClient extends AbstractClient {
private TCPNIOTransport transport;
private volatile Connection<?> connection; // volatile, please copy reference to use
public GrizzlyClient(URL url, ChannelHandler handler) throws RemotingException {
super(url, handler);
}
@Override
protected void doOpen() throws Throwable {
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
ThreadPoolConfig config = builder.getWorkerThreadPoolConfig();
config.setPoolName(CLIENT_THREAD_POOL_NAME)
.setQueueLimit(-1)
.setCorePoolSize(0)
.setMaxPoolSize(Integer.MAX_VALUE)
.setKeepAliveTime(60L, TimeUnit.SECONDS);
builder.setTcpNoDelay(true).setKeepAlive(true)
.setConnectionTimeout(getTimeout())
.setIOStrategy(SameThreadIOStrategy.getInstance());
transport = builder.build();
transport.setProcessor(filterChainBuilder.build());
transport.start();
}
@Override
protected void doConnect() throws Throwable {
connection = transport.connect(getConnectAddress())
.get(getUrl().getPositiveIntParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), TimeUnit.MILLISECONDS);
}
@Override
protected void doDisConnect() throws Throwable {
try {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
} catch (Throwable t) {
logger.warn(t.getMessage());
}
}
@Override
protected void doClose() throws Throwable {
try {
transport.stop();
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
}
}
@Override
protected Channel getChannel() {
Connection<?> c = connection;
if (c == null || ! c.isOpen())
return null;
return GrizzlyChannel.getOrAddChannel(c, getUrl(), this);
}
}

View File

@ -0,0 +1,189 @@
/*
* 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.remoting.transport.grizzly;
import java.io.IOException;
import org.glassfish.grizzly.Buffer;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.filterchain.BaseFilter;
import org.glassfish.grizzly.filterchain.FilterChainContext;
import org.glassfish.grizzly.filterchain.NextAction;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.io.Bytes;
import com.alibaba.dubbo.common.io.UnsafeByteArrayInputStream;
import com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.Codec;
import com.alibaba.dubbo.remoting.exchange.Response;
/**
* GrizzlyCodecAdapter
*
* @author william.liangf
*/
public class GrizzlyCodecAdapter extends BaseFilter {
private static final String BUFFER_KEY = GrizzlyCodecAdapter.class.getName() + ".BUFFER";
private final Codec upstreamCodec;
private final Codec downstreamCodec;
private final URL url;
private final ChannelHandler handler;
private final int bufferSize;
public GrizzlyCodecAdapter(Codec codec, URL url, ChannelHandler handler){
this(codec, codec, url, handler);
}
/**
* server 端如果有消息发送需要分开codec默认的上行code是dubbo1兼容的
*/
public GrizzlyCodecAdapter(Codec upstreamCodec, Codec downstreamCodec, URL url, ChannelHandler handler){
this.upstreamCodec = upstreamCodec;
this.downstreamCodec = downstreamCodec;
this.url = url;
this.handler = handler;
int b = url.getPositiveIntParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
@Override
public NextAction handleWrite(FilterChainContext context) throws IOException {
Connection<?> connection = context.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
UnsafeByteArrayOutputStream output = new UnsafeByteArrayOutputStream(1024); // 不需要关闭
if(!(context.getMessage() instanceof Response)){
downstreamCodec.encode(channel, output, context.getMessage());
}else{
upstreamCodec.encode(channel, output, context.getMessage());
}
GrizzlyChannel.removeChannelIfDisconnectd(connection);
byte[] bytes = output.toByteArray();
Buffer buffer = connection.getTransport().getMemoryManager().allocate(bytes.length);
buffer.put(bytes);
buffer.flip();
buffer.allowBufferDispose(true);
context.setMessage(buffer);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return context.getInvokeAction();
}
@Override
public NextAction handleRead(FilterChainContext context) throws IOException {
Object message = context.getMessage();
Connection<?> connection = context.getConnection();
Channel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
if (message instanceof Buffer) { // 收到新的数据包
Buffer buffer = (Buffer) message; // 缓存
int readable = buffer.capacity(); // 本次可读取新数据的大小
if (readable == 0) {
return context.getStopAction();
}
byte[] bytes; // byte[]缓存区将Buffer转成byte[]再转成UnsafeByteArrayInputStream
int offset; // 指向已用数据的偏移量off之前的数据都是已用过的
int limit; // 有效长度limit之后的长度是空白或无效数据off到limit之间的数据是准备使用的有效数据
Object[] remainder = (Object[]) channel.getAttribute(BUFFER_KEY); // 上次序列化剩下的数据
channel.removeAttribute(BUFFER_KEY);
if (remainder == null) { // 如果没有创建新的bytes缓存
bytes = new byte[bufferSize];
offset = 0;
limit = 0;
} else { // 如果有使用剩下的bytes缓存
bytes = (byte[]) remainder[0];
offset = (Integer) remainder[1];
limit = (Integer) remainder[2];
}
return receive(context, channel, buffer, readable, bytes, offset, limit);
} else if (message instanceof Object[]) { // 同一Buffer多轮Filter一个Buffer里有多个请求
Object[] remainder = (Object[]) message;
Buffer buffer = (Buffer) remainder[0];
int readable = (Integer) remainder[1];
byte[] bytes = (byte[]) remainder[2];
int offset = (Integer) remainder[3];
int limit = (Integer) remainder[4];
return receive(context, channel, buffer, readable, bytes, offset, limit);
} else { // 其它事件直接往下传
return context.getInvokeAction();
}
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
}
/*
* 接收
*
* @param context 上下文
* @param channel 通道
* @param buffer 缓存
* @param readable 缓存可读
* @param bytes 输入缓存
* @param offset 指向已读数据的偏移量off之前的数据都是已用过的
* @param limit 有效长度limit之后的长度是空白或无效数据off到limit之间的数据是准备使用的数据
* @return 后续动作
* @throws IOException
*/
private NextAction receive(FilterChainContext context, Channel channel, Buffer buffer, int readable, byte[] bytes, int offset, int limit) throws IOException {
for(;;) {
int read = Math.min(readable, bytes.length - limit); // 取bytes缓存空闲区和可读取新数据的最小值此次最多读写数据的大小
buffer.get(bytes, limit, read); // 从可读取新数据中读取数据尽量填满bytes缓存空闲区
limit += read; // 有效数据变长
readable -= read; // 可读数据变少
UnsafeByteArrayInputStream input = new UnsafeByteArrayInputStream(bytes, offset, limit - offset); // 将bytes缓存转成InputStream不需要关闭
Object msg = upstreamCodec.decode(channel, input); // 调用Codec接口解码数据
if (msg == Codec.NEED_MORE_INPUT) { // 如果Codec觉得数据不够不足以解码成一个对象
if (readable == 0) { // 如果没有更多可读数据
channel.setAttribute(BUFFER_KEY, new Object[] { bytes, offset, limit }); // 放入通道属性中等待下一个Buffer的到来
return context.getStopAction();
} else { // 扩充或挪出空闲区并循环直到可读数据都加载到bytes缓存
if (offset == 0) { // 如果bytes缓存全部没有被使用如果这时数据还不够
bytes = Bytes.copyOf(bytes, bytes.length << 1); // 将bytes缓存扩大一倍
} else { // 如果bytes缓存有一段数据已被使用
int len = limit - offset; // 计算有效数据长度
System.arraycopy(bytes, offset, bytes, 0, len); // 将数据向前移到压缩到已使用的部分这样limit后面就会多出一些空闲可以放数据
offset = 0; // 移到后bytes缓存没有数据被使用
limit = len; // 移到后有效数据都在bytes缓存最前面
}
}
} else { // 如果解析出一个结果
int position = input.position(); // 记录InputStream用了多少
if (position == offset) { // 如果InputStream没有被读过就返回了数据直接报错否则InputStream永远读不完会死递归
throw new IOException("Decode without read data.");
}
offset = position; // 记录已读数据
context.setMessage(msg); // 将消息改为解码后的对象以便被后面的Filter使用
if (limit - offset > 0 || readable > 0) { // 如果有效数据没有被读完或者Buffer区还有未读数据
return context.getInvokeAction(new Object[] { buffer, readable, bytes, offset, limit }); // 正常执行完Filter并重新发起一轮Filter继续读
} else { // 否则所有数据读完
return context.getInvokeAction(); // 正常执行完Filter
}
}
}
}
}

View File

@ -0,0 +1,119 @@
/*
* 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.remoting.transport.grizzly;
import java.io.IOException;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.filterchain.BaseFilter;
import org.glassfish.grizzly.filterchain.FilterChainContext;
import org.glassfish.grizzly.filterchain.NextAction;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.RemotingException;
/**
* GrizzlyHandler
*
* @author william.liangf
*/
public class GrizzlyHandler extends BaseFilter {
private static final Logger logger = LoggerFactory.getLogger(GrizzlyHandler.class);
private final URL url;
private final ChannelHandler handler;
public GrizzlyHandler(URL url, ChannelHandler handler){
this.url = url;
this.handler = handler;
}
@Override
public NextAction handleConnect(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.connected(channel);
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return ctx.getInvokeAction();
}
@Override
public NextAction handleClose(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.disconnected(channel);
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return ctx.getInvokeAction();
}
@Override
public NextAction handleRead(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.received(channel, ctx.getMessage());
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return ctx.getInvokeAction();
}
@Override
public NextAction handleWrite(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.sent(channel, ctx.getMessage());
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return ctx.getInvokeAction();
}
@Override
public void exceptionOccurred(FilterChainContext ctx, Throwable error) {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.caught(channel, error);
} catch (RemotingException e) {
logger.error("RemotingException on channel " + channel, e);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
}
}

View File

@ -0,0 +1,118 @@
/*
* 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.remoting.transport.grizzly;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.filterchain.TransportFilter;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder;
import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.transport.support.AbstractServer;
import com.alibaba.dubbo.remoting.transport.support.handler.ChannelHandlers;
/**
* GrizzlyServer
*
* @author william.liangf
*/
public class GrizzlyServer extends AbstractServer {
private final Map<String, Channel> channels = new ConcurrentHashMap<String, Channel>(); // <ip:port, channel>
private TCPNIOTransport transport;
public GrizzlyServer(URL url, ChannelHandler handler) throws RemotingException {
super(url, ChannelHandlers.wrap(handler, url));
}
@Override
protected void doOpen() throws Throwable {
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getDownstreamCodec(), getUrl(), this));
filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
ThreadPoolConfig config = builder.getWorkerThreadPoolConfig();
config.setPoolName(SERVER_THREAD_POOL_NAME).setQueueLimit(-1);
String threadpool = getUrl().getParameter(Constants.THREADPOOL_KEY, Constants.DEFAULT_THREADPOOL);
if (Constants.DEFAULT_THREADPOOL.equals(threadpool)) {
int threads = getUrl().getPositiveIntParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
config.setCorePoolSize(threads).setMaxPoolSize(threads)
.setKeepAliveTime(0L, TimeUnit.SECONDS);
} else if ("cached".equals(threadpool)) {
int threads = getUrl().getPositiveIntParameter(Constants.THREADS_KEY, Integer.MAX_VALUE);
config.setCorePoolSize(0).setMaxPoolSize(threads)
.setKeepAliveTime(60L, TimeUnit.SECONDS);
} else {
throw new IllegalArgumentException("Unsupported threadpool type " + threadpool);
}
builder.setKeepAlive(true).setReuseAddress(false)
.setIOStrategy(SameThreadIOStrategy.getInstance());
transport = builder.build();
transport.setProcessor(filterChainBuilder.build());
transport.bind(getBindAddress());
transport.start();
}
@Override
protected void doClose() throws Throwable {
try {
transport.stop();
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
}
}
public boolean isBound() {
return ! transport.isStopped();
}
public Collection<Channel> getChannels() {
return channels.values();
}
public Channel getChannel(InetSocketAddress remoteAddress) {
return channels.get(NetUtils.toAddressString(remoteAddress));
}
@Override
public void connected(Channel ch) throws RemotingException {
channels.put(NetUtils.toAddressString(ch.getRemoteAddress()), ch);
super.connected(ch);
}
@Override
public void disconnected(Channel ch) throws RemotingException {
channels.remove(NetUtils.toAddressString(ch.getRemoteAddress()));
super.disconnected(ch);
}
}

View File

@ -0,0 +1,44 @@
/*
* 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.remoting.transport.grizzly;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.Client;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.Server;
import com.alibaba.dubbo.remoting.Transporter;
/**
* GrizzlyTransporter
*
* @author william.liangf
*/
@Extension(GrizzlyTransporter.NAME)
public class GrizzlyTransporter implements Transporter {
public static final String NAME = "grizzly";
public Server bind(URL url, ChannelHandler listener) throws RemotingException {
return new GrizzlyServer(url, listener);
}
public Client connect(URL url, ChannelHandler listener) throws RemotingException {
return new GrizzlyClient(url, listener);
}
}

View File

@ -0,0 +1 @@
com.alibaba.dubbo.remoting.transport.grizzly.GrizzlyTransporter

View File

@ -31,5 +31,9 @@
<artifactId>dubbo-remoting</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,172 @@
/*
* 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.remoting.transport.mina;
import java.net.InetSocketAddress;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.WriteFuture;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.transport.support.AbstractChannel;
/**
* MinaChannel
*
* @author qian.lei
* @author william.liangf
*/
final class MinaChannel extends AbstractChannel {
private static final Logger logger = LoggerFactory.getLogger(MinaChannel.class);
private static final String CHANNEL_KEY = MinaChannel.class.getName() + ".CHANNEL";
private final IoSession session;
private MinaChannel(IoSession session, URL url, ChannelHandler handler){
super(url, handler);
if (session == null) {
throw new IllegalArgumentException("mina session == null");
}
this.session = session;
}
static MinaChannel getOrAddChannel(IoSession session, URL url, ChannelHandler handler) {
if (session == null) {
return null;
}
MinaChannel ret = (MinaChannel) session.getAttribute(CHANNEL_KEY);
if (ret == null) {
ret = new MinaChannel(session, url, handler);
if (session.isConnected()) {
MinaChannel old = (MinaChannel) session.setAttribute(CHANNEL_KEY, ret);
if (old != null) {
session.setAttribute(CHANNEL_KEY, old);
ret = old;
}
}
}
return ret;
}
static void removeChannelIfDisconnectd(IoSession session) {
if (session != null && ! session.isConnected()) {
session.removeAttribute(CHANNEL_KEY);
}
}
public InetSocketAddress getLocalAddress() {
return (InetSocketAddress) session.getLocalAddress();
}
public InetSocketAddress getRemoteAddress() {
return (InetSocketAddress) session.getRemoteAddress();
}
public boolean isConnected() {
return session.isConnected();
}
public void send(Object message, boolean sent) throws RemotingException {
super.send(message, sent);
boolean success = true;
int timeout = 0;
try {
WriteFuture future = session.write(message);
if (sent) {
timeout = getUrl().getPositiveIntParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
success = future.join(timeout);
}
} catch (Throwable e) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
}
if(!success) {
throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress()
+ "in timeout(" + timeout + "ms) limit");
}
}
public void close() {
try {
super.close();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
try {
removeChannelIfDisconnectd(session);
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
try {
if (logger.isInfoEnabled()) {
logger.info("CLose mina channel " + session);
}
session.close();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
}
}
public boolean hasAttribute(String key) {
return session.containsAttribute(key);
}
public Object getAttribute(String key) {
return session.getAttribute(key);
}
public void setAttribute(String key, Object value) {
session.setAttribute(key, value);
}
public void removeAttribute(String key) {
session.removeAttribute(key);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((session == null) ? 0 : session.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
MinaChannel other = (MinaChannel) obj;
if (session == null) {
if (other.session != null) return false;
} else if (!session.equals(other.session)) return false;
return true;
}
@Override
public String toString() {
return "MinaChannel [session=" + session + "]";
}
}

View File

@ -0,0 +1,177 @@
/*
* 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.remoting.transport.mina;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.IoFuture;
import org.apache.mina.common.IoFutureListener;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.ThreadModel;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.SocketConnector;
import org.apache.mina.transport.socket.nio.SocketConnectorConfig;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.Version;
import com.alibaba.dubbo.common.utils.NamedThreadFactory;
import com.alibaba.dubbo.common.utils.NetUtils;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.transport.support.AbstractClient;
import com.alibaba.dubbo.remoting.transport.support.handler.ChannelHandlers;
/**
* Mina client.
*
* @author qian.lei
* @author william.liangf
*/
public class MinaClient extends AbstractClient {
private static final Map<String, SocketConnector> connectors = new ConcurrentHashMap<String, SocketConnector>();
private String connectorKey;
private SocketConnector connector;
private volatile IoSession session; // volatile, please copy reference to use
public MinaClient(final URL url, final ChannelHandler handler) throws RemotingException {
super(url, wrapChannelHandler(url, handler));
}
protected static ChannelHandler wrapChannelHandler(URL url, ChannelHandler handler){
url = url.addParameter(Constants.THREAD_NAME_KEY, CLIENT_THREAD_POOL_NAME)
.addParameter(Constants.THREADPOOL_KEY, Constants.DEFAULT_CLIENT_THREADPOOL);
return ChannelHandlers.wrap(handler, url);
}
@Override
protected void doOpen() throws Throwable {
connectorKey = getUrl().toFullString();
SocketConnector c = connectors.get(connectorKey);
if (c != null) {
connector = c;
} else {
// set thread pool.
connector = new SocketConnector(Constants.DEFAULT_IO_THREADS,
Executors.newCachedThreadPool(new NamedThreadFactory("MinaClientWorker", true)));
// config
SocketConnectorConfig cfg = (SocketConnectorConfig) connector.getDefaultConfig();
cfg.setThreadModel(ThreadModel.MANUAL);
cfg.getSessionConfig().setTcpNoDelay(true);
cfg.getSessionConfig().setKeepAlive(true);
int timeout = getTimeout();
cfg.setConnectTimeout(timeout < 1000 ? 1 : timeout / 1000);
// set codec.
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this)));
connectors.put(connectorKey, connector);
}
}
@Override
protected void doConnect() throws Throwable {
ConnectFuture future = connector.connect(getConnectAddress(), new MinaHandler(getUrl(), this));
long start = System.currentTimeMillis();
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
final CountDownLatch finish = new CountDownLatch(1); // resolve future.awaitUninterruptibly() dead lock
future.addListener(new IoFutureListener() {
public void operationComplete(IoFuture future) {
try {
if (future.isReady()) {
IoSession newSession = future.getSession();
try {
// 关闭旧的连接
IoSession oldSession = MinaClient.this.session; // copy reference
if (oldSession != null) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close old mina channel " + oldSession + " on create new mina channel " + newSession);
}
oldSession.close();
} finally {
MinaChannel.removeChannelIfDisconnectd(oldSession);
}
}
} finally {
if (MinaClient.this.isClosed()) {
try {
if (logger.isInfoEnabled()) {
logger.info("Close new mina channel " + newSession + ", because the client closed.");
}
newSession.close();
} finally {
MinaClient.this.session = null;
MinaChannel.removeChannelIfDisconnectd(newSession);
}
} else {
MinaClient.this.session = newSession;
}
}
}
} catch (Exception e) {
exception.set(e);
} finally {
finish.countDown();
}
}
});
try {
finish.await(getTimeout(), TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RemotingException(this, "Failed to connect to server " + getRemoteAddress() + " client-side timeout "
+ getTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start)
+ "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version "
+ Version.getVersion() + ", cause: " + e.getMessage(), e);
}
Throwable e = exception.get();
if (e != null) {
throw e;
}
}
@Override
protected void doDisConnect() throws Throwable {
try {
MinaChannel.removeChannelIfDisconnectd(session);
} catch (Throwable t) {
logger.warn(t.getMessage());
}
}
@Override
protected void doClose() throws Throwable {
//release mina resouces.
}
@Override
protected Channel getChannel() {
IoSession s = session;
if (s == null || ! s.isConnected())
return null;
return MinaChannel.getOrAddChannel(s, getUrl(), this);
}
}

View File

@ -0,0 +1,193 @@
/*
* 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.remoting.transport.mina;
import java.io.IOException;
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.io.Bytes;
import com.alibaba.dubbo.common.io.UnsafeByteArrayInputStream;
import com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.Codec;
import com.alibaba.dubbo.remoting.exchange.Response;
/**
* MinaCodecAdapter.
*
* @author qian.lei
*/
final class MinaCodecAdapter implements ProtocolCodecFactory {
private static final String BUFFER_KEY = MinaCodecAdapter.class.getName() + ".BUFFER";
private final ProtocolEncoder encoder = new InternalEncoder();
private final ProtocolDecoder decoder = new InternalDecoder();
private final Codec upstreamCodec;
private final Codec downstreamCodec;
private final URL url;
private final ChannelHandler handler;
private final int bufferSize;
public MinaCodecAdapter(Codec codec, URL url, ChannelHandler handler){
this(codec,codec,url,handler);
}
/**
* server 端如果有消息发送需要分开codec默认的上行code是dubbo1兼容的
*/
public MinaCodecAdapter(Codec upstreamCodec, Codec downstreamCodec, URL url, ChannelHandler handler){
this.upstreamCodec = upstreamCodec;
this.downstreamCodec = downstreamCodec;
this.url = url;
this.handler = handler;
int b = url.getPositiveIntParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
public ProtocolEncoder getEncoder() {
return encoder;
}
public ProtocolDecoder getDecoder() {
return decoder;
}
private class InternalEncoder implements ProtocolEncoder {
public void dispose(IoSession session) throws Exception {
}
public void encode(IoSession session, Object msg, ProtocolEncoderOutput out) throws Exception {
UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream(1024); // 不需要关闭
MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
try {
if(!(msg instanceof Response)){
downstreamCodec.encode(channel, os, msg);
}else{
upstreamCodec.encode(channel, os, msg);
}
} finally {
MinaChannel.removeChannelIfDisconnectd(session);
}
out.write(ByteBuffer.wrap(os.toByteArray()));
out.flush();
}
}
private class InternalDecoder implements ProtocolDecoder {
public void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
int readable = in.limit();
if (readable <= 0) return;
int off, limit;
byte[] buf;
// load buffer from context.
Object[] tmp = (Object[]) session.getAttribute(BUFFER_KEY);
if (tmp == null) {
buf = new byte[bufferSize];
off = limit = 0;
} else {
buf = (byte[]) tmp[0];
off = (Integer) tmp[1];
limit = (Integer) tmp[2];
}
Channel channel = MinaChannel.getOrAddChannel(session, url, handler);
boolean remaining = true;
Object msg;
UnsafeByteArrayInputStream bis;
try {
do {
// read data into buffer.
int read = Math.min(readable, buf.length - limit);
in.get(buf, limit, read);
limit += read;
readable -= read;
bis = new UnsafeByteArrayInputStream(buf, off, limit - off); // 不需要关闭
// decode object.
do {
try {
msg = upstreamCodec.decode(channel, bis);
} catch (IOException e) {
remaining = false;
throw e;
}
if (msg == Codec.NEED_MORE_INPUT) {
if (off == 0) {
if (readable > 0) {
buf = Bytes.copyOf(buf, buf.length << 1);
}
} else {
int len = limit - off;
System.arraycopy(buf, off, buf, 0, len);
off = 0;
limit = len;
}
break;
} else {
int pos = bis.position();
if (pos == off) {
remaining = false;
throw new IOException("Decode without read data.");
}
if (msg != null) {
out.write(msg);
}
off = pos;
}
} while (bis.available() > 0);
} while (readable > 0);
} finally {
if (remaining) {
int len = limit - off;
if (len < buf.length / 2) {
System.arraycopy(buf, off, buf, 0, len);
off = 0;
limit = len;
}
session.setAttribute(BUFFER_KEY, new Object[] { buf, off, limit });
} else {
session.removeAttribute(BUFFER_KEY);
}
MinaChannel.removeChannelIfDisconnectd(session);
}
}
public void dispose(IoSession session) throws Exception {
}
public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception {
}
}
}

View File

@ -0,0 +1,96 @@
/*
* 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.remoting.transport.mina;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.remoting.ChannelHandler;
/**
* MinaHandler
*
* @author william.liangf
*/
public class MinaHandler extends IoHandlerAdapter {
private final URL url;
private final ChannelHandler handler;
public MinaHandler(URL url, ChannelHandler handler) {
if (url == null) {
throw new IllegalArgumentException("url == null");
}
if (handler == null) {
throw new IllegalArgumentException("handler == null");
}
this.url = url;
this.handler = handler;
}
@Override
public void sessionOpened(IoSession session) throws Exception {
MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
try {
handler.connected(channel);
} finally {
MinaChannel.removeChannelIfDisconnectd(session);
}
}
@Override
public void sessionClosed(IoSession session) throws Exception {
MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
try {
handler.disconnected(channel);
} finally {
MinaChannel.removeChannelIfDisconnectd(session);
}
}
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
try {
handler.received(channel, message);
} finally {
MinaChannel.removeChannelIfDisconnectd(session);
}
}
@Override
public void messageSent(IoSession session, Object message) throws Exception {
MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
try {
handler.sent(channel, message);
} finally {
MinaChannel.removeChannelIfDisconnectd(session);
}
}
@Override
public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
try {
handler.caught(channel, cause);
} finally {
MinaChannel.removeChannelIfDisconnectd(session);
}
}
}

View File

@ -0,0 +1,105 @@
/*
* 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.remoting.transport.mina;
import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.ThreadModel;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.SocketAcceptor;
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
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.transport.support.AbstractServer;
import com.alibaba.dubbo.remoting.transport.support.handler.ChannelHandlers;
/**
* MinaServer
*
* @author qian.lei
* @author william.liangf
* @author ding.lid
*/
public class MinaServer extends AbstractServer {
private SocketAcceptor acceptor;
public MinaServer(URL url, ChannelHandler handler) throws RemotingException{
super(url, ChannelHandlers.wrap(handler, url.addParameter(Constants.THREAD_NAME_KEY, SERVER_THREAD_POOL_NAME)));
}
@Override
protected void doOpen() throws Throwable {
// set thread pool.
acceptor = new SocketAcceptor(getUrl().getPositiveIntParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS),
Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker",
true)));
// config
SocketAcceptorConfig cfg = (SocketAcceptorConfig) acceptor.getDefaultConfig();
cfg.setThreadModel(ThreadModel.MANUAL);
// set codec.
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getDownstreamCodec(), getUrl(), this)));
acceptor.bind(getBindAddress(), new MinaHandler(getUrl(), this));
}
@Override
protected void doClose() throws Throwable {
try {
if (acceptor != null) {
acceptor.unbind(getBindAddress());
}
} catch (Throwable e) {
logger.warn(e.getMessage(), e);
}
}
public Collection<Channel> getChannels() {
Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
Collection<Channel> channels = new HashSet<Channel>();
for (IoSession session : sessions) {
if (session.isConnected()) {
channels.add(MinaChannel.getOrAddChannel(session, getUrl(), this));
}
}
return channels;
}
public Channel getChannel(InetSocketAddress remoteAddress) {
Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
for (IoSession session : sessions) {
if (session.getRemoteAddress().equals(remoteAddress)) {
return MinaChannel.getOrAddChannel(session, getUrl(), this);
}
}
return null;
}
public boolean isBound() {
return acceptor.isManaged(getBindAddress());
}
}

View File

@ -0,0 +1,42 @@
/*
* 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.remoting.transport.mina;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.remoting.ChannelHandler;
import com.alibaba.dubbo.remoting.Client;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.Server;
import com.alibaba.dubbo.remoting.Transporter;
/**
* @author ding.lid
*/
@Extension(MinaTransporter.NAME)
public class MinaTransporter implements Transporter {
public static final String NAME = "mina";
public Server bind(URL url, ChannelHandler handler) throws RemotingException {
return new MinaServer(url, handler);
}
public Client connect(URL url, ChannelHandler handler) throws RemotingException {
return new MinaClient(url, handler);
}
}

View File

@ -0,0 +1 @@
com.alibaba.dubbo.remoting.transport.support.grizzly.GrizzlyTransporter

View File

@ -0,0 +1,39 @@
<!--
- 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.0.8-SNAPSHOT</version>
</parent>
<artifactId>dubbo-remoting-netty</artifactId>
<packaging>jar</packaging>
<name>Dubbo Netty Remoting Module</name>
<description>The netty remoting module of dubbo project</description>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-remoting</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
</dependency>
</dependencies>
</project>

35
dubbo-rpc-default/pom.xml Normal file
View File

@ -0,0 +1,35 @@
<!--
- 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.0.8-SNAPSHOT</version>
</parent>
<artifactId>dubbo-rpc-default</artifactId>
<packaging>jar</packaging>
<name>Dubbo Default RPC Module</name>
<description>The default rpc module of dubbo project</description>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-rpc</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

35
dubbo-rpc-injvm/pom.xml Normal file
View File

@ -0,0 +1,35 @@
<!--
- 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.0.8-SNAPSHOT</version>
</parent>
<artifactId>dubbo-rpc-injvm</artifactId>
<packaging>jar</packaging>
<name>Dubbo InJVM RPC Module</name>
<description>The injvm rpc module of dubbo project</description>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-rpc</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

35
dubbo-rpc-xfire/pom.xml Normal file
View File

@ -0,0 +1,35 @@
<!--
- 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-parent</artifactId>
<version>2.0.8-SNAPSHOT</version>
</parent>
<artifactId>dubbo-rpc-xfire</artifactId>
<packaging>jar</packaging>
<name>Dubbo Xfire RPC Module</name>
<description>The xfire rpc module of dubbo project</description>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo-rpc</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -20,7 +20,7 @@ package com.alibaba.dubbo.rpc;
*
* @see com.alibaba.dubbo.rpc.Protocol#export(Invoker)
* @see com.alibaba.dubbo.rpc.ExporterListener
* @see com.alibaba.dubbo.rpc.support.AbstractExporter
* @see com.alibaba.dubbo.rpc.protocol.AbstractExporter
* @author william.liangf
*/
public interface Exporter<T> {

View File

@ -22,7 +22,7 @@ import com.alibaba.dubbo.common.URL;
*
* @see com.alibaba.dubbo.rpc.Protocol#refer(Class, URL)
* @see com.alibaba.dubbo.rpc.InvokerListener
* @see com.alibaba.dubbo.rpc.support.AbstractInvoker
* @see com.alibaba.dubbo.rpc.protocol.AbstractInvoker
* @author william.liangf
*/
public interface Invoker<T> {

View File

@ -13,14 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.proxy;
package com.alibaba.dubbo.rpc;
import com.alibaba.dubbo.common.Adaptive;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcException;
/**
* ProxyFactory. (SPI, Singleton, ThreadSafe)

View File

@ -27,7 +27,7 @@ import com.alibaba.dubbo.common.utils.NetUtils;
* Thread local context. (API, ThreadLocal, ThreadSafe)
*
* @see com.alibaba.dubbo.rpc.filter.ContextFilter
* @see com.alibaba.dubbo.rpc.support.AbstractExporter#invoke(Invocation, InetSocketAddress)
* @see com.alibaba.dubbo.rpc.protocol.AbstractExporter#invoke(Invocation, InetSocketAddress)
* @author qian.lei
* @author william.liangf
*/

View File

@ -33,7 +33,7 @@ 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.support.FutureAdapter;
import com.alibaba.dubbo.rpc.protocol.FutureAdapter;
/**
* EventFilter

View File

@ -28,7 +28,7 @@ import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcResult;
import com.alibaba.dubbo.rpc.service.GenericService;
import com.alibaba.dubbo.service.GenericService;
/**
* ExceptionInvokerFilter

View File

@ -28,7 +28,7 @@ import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.RpcResult;
import com.alibaba.dubbo.rpc.service.GenericException;
import com.alibaba.dubbo.service.GenericException;
/**
* GenericInvokerFilter.

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.support;
package com.alibaba.dubbo.rpc.protocol;
import java.net.InetSocketAddress;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.support;
package com.alibaba.dubbo.rpc.protocol;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.support;
package com.alibaba.dubbo.rpc.protocol;
import java.util.ArrayList;
import java.util.Map;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.support;
package com.alibaba.dubbo.rpc.protocol;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.support;
package com.alibaba.dubbo.rpc.protocol;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.support;
package com.alibaba.dubbo.rpc.protocol;
import java.util.ArrayList;
import java.util.List;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.support;
package com.alibaba.dubbo.rpc.protocol;
import java.util.ArrayList;
import java.util.Collections;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo;
package com.alibaba.dubbo.rpc.protocol.dubbo;
import java.io.IOException;
import java.util.HashMap;
@ -32,9 +32,9 @@ import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
/**
* callback 服务帮助类.

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo;
package com.alibaba.dubbo.rpc.protocol.dubbo;
import java.net.InetSocketAddress;
@ -31,7 +31,7 @@ import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.support.AbstractInvoker;
import com.alibaba.dubbo.rpc.protocol.AbstractInvoker;
/**
* 基于已有channel的invoker.

View File

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo;
package com.alibaba.dubbo.rpc.protocol.dubbo;
import static com.alibaba.dubbo.rpc.dubbo.CallbackServiceCodec.decodeInvocationArgument;
import static com.alibaba.dubbo.rpc.dubbo.CallbackServiceCodec.encodeInvocationArgument;
import static com.alibaba.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.decodeInvocationArgument;
import static com.alibaba.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.encodeInvocationArgument;
import java.io.IOException;
import java.util.HashMap;

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo;
package com.alibaba.dubbo.rpc.protocol.dubbo;
import java.util.Map;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.support.AbstractExporter;
import com.alibaba.dubbo.rpc.protocol.AbstractExporter;
/**
* DubboExporter

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo;
package com.alibaba.dubbo.rpc.protocol.dubbo;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
@ -28,8 +28,8 @@ import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.support.AbstractInvoker;
import com.alibaba.dubbo.rpc.support.FutureAdapter;
import com.alibaba.dubbo.rpc.protocol.AbstractInvoker;
import com.alibaba.dubbo.rpc.protocol.FutureAdapter;
/**
* DubboInvoker

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo;
package com.alibaba.dubbo.rpc.protocol.dubbo;
import java.net.InetSocketAddress;
import java.util.ArrayList;
@ -47,7 +47,7 @@ import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.RpcConstants;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.support.AbstractProtocol;
import com.alibaba.dubbo.rpc.protocol.AbstractProtocol;
/**
* dubbo protocol support.

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo;
package com.alibaba.dubbo.rpc.protocol.dubbo;
import java.net.InetSocketAddress;
import java.util.concurrent.locks.Lock;
@ -29,6 +29,7 @@ import com.alibaba.dubbo.remoting.exchange.ExchangeClient;
import com.alibaba.dubbo.remoting.exchange.ExchangeHandler;
import com.alibaba.dubbo.remoting.exchange.Exchangers;
import com.alibaba.dubbo.remoting.exchange.ResponseFuture;
import com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeClient;
import com.alibaba.dubbo.rpc.RpcConstants;
/**
@ -42,7 +43,7 @@ final class LazyConnectExchangeClient implements ExchangeClient {
private final URL url;
private final ExchangeHandler requestHandler;
private volatile ExchangeClient client;
private volatile HeaderExchangeClient client;
private final Lock connectLock = new ReentrantLock();
//lazy connect 如果没有初始化时的连接状态
private final boolean initialState ;
@ -64,7 +65,8 @@ final class LazyConnectExchangeClient implements ExchangeClient {
try {
if (client != null)
return;
this.client = Exchangers.connect(url, requestHandler);
this.client = new HeaderExchangeClient(Exchangers.connect(url, requestHandler));
// if (client == )
} finally {
connectLock.unlock();
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.status;
package com.alibaba.dubbo.rpc.protocol.dubbo.status;
import java.util.Collection;
@ -21,7 +21,7 @@ import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.status.Status;
import com.alibaba.dubbo.common.status.StatusChecker;
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
import com.alibaba.dubbo.rpc.dubbo.DubboProtocol;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
/**
* ServerStatusChecker

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.status;
package com.alibaba.dubbo.rpc.protocol.dubbo.status;
import java.util.Collection;
import java.util.concurrent.Executor;
@ -27,7 +27,7 @@ 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.support.handler.WrappedChannelHandler;
import com.alibaba.dubbo.rpc.dubbo.DubboProtocol;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
/**
* ThreadPoolStatusChecker

View File

@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.telnet;
package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.remoting.Channel;
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.dubbo.DubboProtocol;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
/**
* ChangeServiceTelnetHandler

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.telnet;
package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
import java.lang.reflect.Method;
import java.util.ArrayList;
@ -30,7 +30,7 @@ import com.alibaba.dubbo.remoting.telnet.support.TelnetUtils;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcStatus;
import com.alibaba.dubbo.rpc.dubbo.DubboProtocol;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
/**
* CountTelnetHandler

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.telnet;
package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.remoting.Channel;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.telnet;
package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
import java.lang.reflect.Method;
import java.util.List;
@ -29,7 +29,7 @@ import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.dubbo.DubboProtocol;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
/**
* InvokeTelnetHandler

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.telnet;
package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
import java.lang.reflect.Method;
@ -24,7 +24,7 @@ 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.dubbo.DubboProtocol;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
/**
* ListTelnetHandler

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.telnet;
package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
import java.io.File;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.telnet;
package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
import java.util.Collection;
@ -24,7 +24,7 @@ import com.alibaba.dubbo.remoting.exchange.ExchangeChannel;
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
import com.alibaba.dubbo.remoting.telnet.TelnetHandler;
import com.alibaba.dubbo.remoting.telnet.support.Help;
import com.alibaba.dubbo.rpc.dubbo.DubboProtocol;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
/**
* ServerTelnetHandler

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.dubbo.telnet;
package com.alibaba.dubbo.rpc.protocol.dubbo.telnet;
import java.lang.reflect.Method;
@ -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.dubbo.DubboProtocol;
import com.alibaba.dubbo.rpc.filter.TraceFilter;
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol;
/**
* TraceTelnetHandler

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.injvm;
package com.alibaba.dubbo.rpc.protocol.injvm;
import java.util.Map;
import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.support.AbstractExporter;
import com.alibaba.dubbo.rpc.protocol.AbstractExporter;
/**
* InjvmExporter

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.injvm;
package com.alibaba.dubbo.rpc.protocol.injvm;
import java.util.Map;
@ -23,7 +23,7 @@ import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.support.AbstractInvoker;
import com.alibaba.dubbo.rpc.protocol.AbstractInvoker;
/**
* InjvmInvoker

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.injvm;
package com.alibaba.dubbo.rpc.protocol.injvm;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;
@ -21,7 +21,7 @@ import com.alibaba.dubbo.rpc.Exporter;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.support.AbstractProtocol;
import com.alibaba.dubbo.rpc.protocol.AbstractProtocol;
/**
* InjvmProtocol

View File

@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.proxy.wrapper;
package com.alibaba.dubbo.rpc.proxy;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.proxy.ProxyFactory;
import com.alibaba.dubbo.rpc.service.EchoService;
import com.alibaba.dubbo.service.EchoService;
/**
* EchoProxyFactoryWrapper

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.proxy.support;
package com.alibaba.dubbo.rpc.proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.proxy.support;
package com.alibaba.dubbo.rpc.proxy;
import java.lang.reflect.InvocationTargetException;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.proxy.wrapper;
package com.alibaba.dubbo.rpc.proxy;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invocation;

Some files were not shown because too many files have changed in this diff Show More