1.概述
Dubbo 的 HTTP 服务器,在 dubbo-remoting-http 模块中实现,使用在 http://、 rest://、hessian://、webservice://协议上。
dubbo-remoting-http 模块,类图如下:
2.API
2.1 HttpServer
实现 Resetable 接口,HTTP 服务器接口。方法如下:
/**
* HTTP 服务器接口
*/
public interface HttpServer extends Resetable {
/**
* get http handler.
*
* @return http handler.
*/
HttpHandler getHttpHandler();
/**
* get url.
*
* @return url
*/
URL getUrl();
/**
* get local address.
*
* @return local address.
*/
InetSocketAddress getLocalAddress();
/**
* close the channel.
*/
void close();
/**
* Graceful close the channel.
*/
void close(int timeout);
/**
* is bound.
*
* @return bound
*/
boolean isBound();
/**
* is closed.
*
* @return closed
*/
boolean isClosed();
}
2.2 AbstractHttpServer
实现 HttpServer 接口,HTTP 服务器抽象类。代码如下:
/**
* AbstractHttpServer
*
* HTTP 服务器抽象类
*/
public abstract class AbstractHttpServer implements HttpServer {
/**
* URL 对象
*/
private final URL url;
/**
* 处理器
*/
private final HttpHandler handler;
/**
* 是否关闭
*/
private volatile boolean closed;
public AbstractHttpServer(URL url, HttpHandler handler) {
if (url == null) {
throw new IllegalArgumentException("url == null");
}
if (handler =