Java Code Examples for com.alibaba.dubbo.remoting.ChannelHandler

The following examples show how to use com.alibaba.dubbo.remoting.ChannelHandler. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dubbo3   Source File: AbstractServer.java    License: Apache License 2.0 6 votes vote down vote up
public AbstractServer(URL url, ChannelHandler handler) throws RemotingException {
    super(url, handler);
    localAddress = getUrl().toInetSocketAddress();
    String host = url.getParameter(Constants.ANYHOST_KEY, false)
                    || NetUtils.isInvalidLocalHost(getUrl().getHost())
                    ? NetUtils.ANYHOST : getUrl().getHost();
    bindAddress = new InetSocketAddress(host, getUrl().getRealPort());
    this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS);
    this.idleTimeout = url.getParameter(Constants.IDLE_TIMEOUT_KEY, Constants.DEFAULT_IDLE_TIMEOUT);
    try {
        doOpen();
        if (logger.isInfoEnabled()) {
            logger.info("Start " + getClass().getSimpleName() + " bind " + getBindAddress() + ", export " + getLocalAddress());
        }
    } catch (Throwable t) {
        throw new RemotingException(url.toInetSocketAddress(), null, "Failed to bind " + getClass().getSimpleName()
                                    + " on " + getLocalAddress() + ", cause: " + t.getMessage(), t);
    }
    if (handler instanceof WrappedChannelHandler ){
        executor = ((WrappedChannelHandler)handler).getExecutor();
    }
}
 
Example 2
Source Project: dubbox   Source File: WrappedChannelHandler.java    License: Apache License 2.0 5 votes vote down vote up
public WrappedChannelHandler(ChannelHandler handler, URL url) {
    this.handler = handler;
    this.url = url;
    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url);

    String componentKey = Constants.EXECUTOR_SERVICE_COMPONENT_KEY;
    if (Constants.CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(Constants.SIDE_KEY))) {
        componentKey = Constants.CONSUMER_SIDE;
    }
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    dataStore.put(componentKey, Integer.toString(url.getPort()), executor);
}
 
Example 3
Source Project: dubbo-plus   Source File: Netty4CodecAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public Netty4CodecAdapter(Codec2 codec, URL url, ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example 4
Source Project: dubbo3   Source File: ChannelEventRunnable.java    License: Apache License 2.0 5 votes vote down vote up
public ChannelEventRunnable(Channel channel, ChannelHandler handler, ChannelState state, Object message, Throwable exception) {
    this.channel = channel;
    this.handler = handler;
    this.state = state;
    this.message = message;
    this.exception = exception;
}
 
Example 5
Source Project: dubbox   Source File: ChannelEventRunnable.java    License: Apache License 2.0 5 votes vote down vote up
public ChannelEventRunnable(Channel channel, ChannelHandler handler, ChannelState state, Object message, Throwable exception) {
    this.channel = channel;
    this.handler = handler;
    this.state = state;
    this.message = message;
    this.exception = exception;
}
 
Example 6
Source Project: dubbox   Source File: MinaCodecAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public MinaCodecAdapter(Codec2 codec, URL url, ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example 7
Source Project: dubbox   Source File: MinaChannel.java    License: Apache License 2.0 5 votes vote down vote up
private MinaChannel(IoSession session, URL url, ChannelHandler handler){
    super(url, handler);
    if (session == null) {
        throw new IllegalArgumentException("mina session == null");
    }
    this.session = session;
}
 
Example 8
Source Project: dubbo-2.6.5   Source File: AbstractServer.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractServer(URL url, ChannelHandler handler) throws RemotingException {
        super(url, handler);
        localAddress = getUrl().toInetSocketAddress();

//        获取bind.ip参数值,默认从url中查询host属性
        String bindIp = getUrl().getParameter(Constants.BIND_IP_KEY, getUrl().getHost());
//        获取bind.port参数值,默认从url中查询port属性
        int bindPort = getUrl().getParameter(Constants.BIND_PORT_KEY, getUrl().getPort());
//        查询anyhost参数值,默认false
        if (url.getParameter(Constants.ANYHOST_KEY, false) || NetUtils.isInvalidLocalHost(bindIp)) {
            bindIp = NetUtils.ANYHOST;
        }
        bindAddress = new InetSocketAddress(bindIp, bindPort);
//        查询accepts参数,服务端可以接收处理的最大线程数,默认0不限制
        this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS);
//        idle.timeout 空闲超时时间,默认600s
        this.idleTimeout = url.getParameter(Constants.IDLE_TIMEOUT_KEY, Constants.DEFAULT_IDLE_TIMEOUT);
        try {
//            创建server
            doOpen();
            if (logger.isInfoEnabled()) {
                logger.info("Start " + getClass().getSimpleName() + " bind " + getBindAddress() + ", export " + getLocalAddress());
            }
        } catch (Throwable t) {
            throw new RemotingException(url.toInetSocketAddress(), null, "Failed to bind " + getClass().getSimpleName()
                    + " on " + getLocalAddress() + ", cause: " + t.getMessage(), t);
        }
        //fixme replace this with better method
        DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
        executor = (ExecutorService) dataStore.get(Constants.EXECUTOR_SERVICE_COMPONENT_KEY, Integer.toString(url.getPort()));
    }
 
Example 9
Source Project: dubbox   Source File: NettyHandler.java    License: Apache License 2.0 5 votes vote down vote up
public NettyHandler(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;
}
 
Example 10
Source Project: dubbox   Source File: AbstractPeer.java    License: Apache License 2.0 5 votes vote down vote up
public AbstractPeer(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;
}
 
Example 11
Source Project: dubbo-2.6.5   Source File: MinaChannel.java    License: Apache License 2.0 5 votes vote down vote up
private MinaChannel(IoSession session, URL url, ChannelHandler handler) {
    super(url, handler);
    if (session == null) {
        throw new IllegalArgumentException("mina session == null");
    }
    this.session = session;
}
 
Example 12
Source Project: dubbox   Source File: GrizzlyChannel.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 13
Source Project: dubbox   Source File: GrizzlyCodecAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public GrizzlyCodecAdapter(Codec2 codec, URL url, ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example 14
Source Project: dubbo3   Source File: WrappedChannelHandler.java    License: Apache License 2.0 5 votes vote down vote up
public WrappedChannelHandler(ChannelHandler handler, URL url) {
    this.handler = handler;
    this.url = url;
    executor = (ExecutorService) ExtensionLoader.getExtensionLoader(ThreadPool.class).getAdaptiveExtension().getExecutor(url);

    String componentKey = Constants.EXECUTOR_SERVICE_COMPONENT_KEY;
    if (Constants.CONSUMER_SIDE.equalsIgnoreCase(url.getParameter(Constants.SIDE_KEY))) {
        componentKey = Constants.CONSUMER_SIDE;
    }
    DataStore dataStore = ExtensionLoader.getExtensionLoader(DataStore.class).getDefaultExtension();
    dataStore.put(componentKey, Integer.toString(url.getPort()), executor);
}
 
Example 15
Source Project: dubbox   Source File: AbstractPeer.java    License: Apache License 2.0 5 votes vote down vote up
public ChannelHandler getChannelHandler() {
    if (handler instanceof ChannelHandlerDelegate) {
        return ((ChannelHandlerDelegate) handler).getHandler();
    } else {
        return handler;
    }
}
 
Example 16
Source Project: dubbox   Source File: ChannelEventRunnable.java    License: Apache License 2.0 5 votes vote down vote up
public ChannelEventRunnable(Channel channel, ChannelHandler handler, ChannelState state, Object message, Throwable exception) {
    this.channel = channel;
    this.handler = handler;
    this.state = state;
    this.message = message;
    this.exception = exception;
}
 
Example 17
Source Project: dubbox-hystrix   Source File: GrizzlyCodecAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public GrizzlyCodecAdapter(Codec2 codec, URL url, ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example 18
Source Project: dubbox   Source File: WrappedChannelHandler.java    License: Apache License 2.0 5 votes vote down vote up
public ChannelHandler getHandler() {
    if (handler instanceof ChannelHandlerDelegate) {
        return ((ChannelHandlerDelegate) handler).getHandler();
    } else {
        return handler;
    }
}
 
Example 19
Source Project: dubbo-2.6.5   Source File: ChannelHandlerDispatcher.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void disconnected(Channel channel) {
    for (ChannelHandler listener : channelHandlers) {
        try {
            listener.disconnected(channel);
        } catch (Throwable t) {
            logger.error(t.getMessage(), t);
        }
    }
}
 
Example 20
Source Project: dubbo3   Source File: NettyHandler.java    License: Apache License 2.0 5 votes vote down vote up
public NettyHandler(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;
}
 
Example 21
Source Project: dubbo-2.6.5   Source File: AbstractPeer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ChannelHandler getChannelHandler() {
    if (handler instanceof ChannelHandlerDelegate) {
        return ((ChannelHandlerDelegate) handler).getHandler();
    } else {
        return handler;
    }
}
 
Example 22
Source Project: dubbox   Source File: MinaHandler.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 23
Source Project: dubbox   Source File: MultiMessageHandler.java    License: Apache License 2.0 4 votes vote down vote up
public MultiMessageHandler(ChannelHandler handler) {
    super(handler);
}
 
Example 24
Source Project: dubbo3   Source File: ChannelHandlers.java    License: Apache License 2.0 4 votes vote down vote up
public static ChannelHandler wrap(ChannelHandler handler, URL url){
    return ChannelHandlers.getInstance().wrapInternal(handler, url);
}
 
Example 25
Source Project: dubbox   Source File: ChannelWrappedInvoker.java    License: Apache License 2.0 4 votes vote down vote up
public ChannelHandler getChannelHandler() {
    return channel.getChannelHandler();
}
 
Example 26
Source Project: dubbo3   Source File: ChannelHandlerDispatcher.java    License: Apache License 2.0 4 votes vote down vote up
public ChannelHandlerDispatcher addChannelHandler(ChannelHandler handler) {
    this.channelHandlers.add(handler);
    return this;
}
 
Example 27
Source Project: dubbo3   Source File: AbstractMockChannel.java    License: Apache License 2.0 4 votes vote down vote up
public AbstractMockChannel(ChannelHandler handler){
    this.handler = handler;
}
 
Example 28
Source Project: dubbox-hystrix   Source File: FakeChannelHandlers.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected ChannelHandler wrapInternal(ChannelHandler handler, URL url) {
    return ExtensionLoader.getExtensionLoader(Dispatcher.class)
        .getAdaptiveExtension().dispatch(handler, url);
}
 
Example 29
Source Project: dubbo-2.6.5   Source File: NettyTransporter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
    public Client connect(URL url, ChannelHandler listener) throws RemotingException {
//        创建netty client连接=》
        return new NettyClient(url, listener);
    }
 
Example 30
Source Project: dubbox   Source File: NettyClient.java    License: Apache License 2.0 4 votes vote down vote up
public NettyClient(final URL url, final ChannelHandler handler) throws RemotingException{
    super(url, wrapChannelHandler(url, handler));
}