Java Code Examples for com.alibaba.dubbo.remoting.Channel#isConnected()

The following examples show how to use com.alibaba.dubbo.remoting.Channel#isConnected() . 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 File: NettyServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Collection<Channel> getChannels() {
    Collection<Channel> chs = new HashSet<Channel>();
    for (Channel channel : this.channels.values()) {
        if (channel.isConnected()) {
            chs.add(channel);
        } else {
            channels.remove(NetUtils.toAddressString(channel.getRemoteAddress()));
        }
    }
    return chs;
}
 
Example 2
Source File: HeaderExchangeServer.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
private void sendChannelReadOnlyEvent(){
    Request request = new Request();
    request.setEvent(Request.READONLY_EVENT);
    request.setTwoWay(false);
    request.setVersion(Version.getVersion());
    
    Collection<Channel> channels = getChannels();
    for (Channel channel : channels) {
        try {
            if (channel.isConnected())channel.send(request, getUrl().getParameter(Constants.CHANNEL_READONLYEVENT_SENT_KEY, true));
        } catch (RemotingException e) {
            logger.warn("send connot write messge error.", e);
        }
    }
}
 
Example 3
Source File: HeaderExchangeServer.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
private void sendChannelReadOnlyEvent(){
    Request request = new Request();
    request.setEvent(Request.READONLY_EVENT);
    request.setTwoWay(false);
    request.setVersion(Version.getVersion());
    
    Collection<Channel> channels = getChannels();
    for (Channel channel : channels) {
        try {
            if (channel.isConnected())channel.send(request, getUrl().getParameter(Constants.CHANNEL_READONLYEVENT_SENT_KEY, true));
        } catch (RemotingException e) {
            logger.warn("send connot write messge error.", e);
        }
    }
}
 
Example 4
Source File: NettyServer.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public Collection<Channel> getChannels() {
    Collection<Channel> chs = new HashSet<Channel>();
    for (Channel channel : this.channels.values()) {
        if (channel.isConnected()) {
            chs.add(channel);
        } else {
            channels.remove(NetUtils.toAddressString(channel.getRemoteAddress()));
        }
    }
    return chs;
}
 
Example 5
Source File: NettyServer.java    From dubbo-remoting-netty4 with Apache License 2.0 5 votes vote down vote up
public Collection<Channel> getChannels() {
    Collection<Channel> chs = new HashSet<Channel>();
    for (Channel channel : this.channels.values()) {
        if (channel.isConnected()) {
            chs.add(channel);
        } else {
            channels.remove(NetUtils.toAddressString(channel.getRemoteAddress()));
        }
    }
    return chs;
}
 
Example 6
Source File: AbstractServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void send(Object message, boolean sent) throws RemotingException {
    Collection<Channel> channels = getChannels();
    for (Channel channel : channels) {
        if (channel.isConnected()) {
            channel.send(message, sent);
        }
    }
}
 
Example 7
Source File: HeaderExchangeServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void sendChannelReadOnlyEvent(){
    Request request = new Request();
    request.setEvent(Request.READONLY_EVENT);
    request.setTwoWay(false);
    request.setVersion(Version.getVersion());
    
    Collection<Channel> channels = getChannels();
    for (Channel channel : channels) {
        try {
            if (channel.isConnected())channel.send(request, getUrl().getParameter(Constants.CHANNEL_READONLYEVENT_SENT_KEY, true));
        } catch (RemotingException e) {
            logger.warn("send connot write messge error.", e);
        }
    }
}
 
Example 8
Source File: Netty4Server.java    From dubbo-plus with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Channel> getChannels() {
    Collection<Channel> chs = new HashSet<Channel>();
    for (Channel channel : this.channels.values()) {
        if (channel.isConnected()) {
            chs.add(channel);
        } else {
            channels.remove(NetUtils.toAddressString(channel.getRemoteAddress()));
        }
    }
    return chs;
}
 
Example 9
Source File: HeaderExchangeChannel.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
static HeaderExchangeChannel getOrAddChannel(Channel ch) {
    if (ch == null) {
        return null;
    }
    HeaderExchangeChannel ret = (HeaderExchangeChannel) ch.getAttribute(CHANNEL_KEY);
    if (ret == null) {
        ret = new HeaderExchangeChannel(ch);
        if (ch.isConnected()) {
            ch.setAttribute(CHANNEL_KEY, ret);
        }
    }
    return ret;
}
 
Example 10
Source File: AbstractClient.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public void send(Object message, boolean sent) throws RemotingException {
    if (send_reconnect && !isConnected()) {
        connect();
    }
    Channel channel = getChannel();
    //TODO getChannel返回的状态是否包含null需要改进
    if (channel == null || !channel.isConnected()) {
        throw new RemotingException(this, "message can not send, because channel is closed . url:" + getUrl());
    }
    channel.send(message, sent);
}
 
Example 11
Source File: AbstractServer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void send(Object message, boolean sent) throws RemotingException {
    Collection<Channel> channels = getChannels();
    for (Channel channel : channels) {
        if (channel.isConnected()) {
            channel.send(message, sent);
        }
    }
}
 
Example 12
Source File: HeaderExchangeChannel.java    From dubbox with Apache License 2.0 5 votes vote down vote up
static HeaderExchangeChannel getOrAddChannel(Channel ch) {
    if (ch == null) {
        return null;
    }
    HeaderExchangeChannel ret = (HeaderExchangeChannel) ch.getAttribute(CHANNEL_KEY);
    if (ret == null) {
        ret = new HeaderExchangeChannel(ch);
        if (ch.isConnected()) {
            ch.setAttribute(CHANNEL_KEY, ret);
        }
    }
    return ret;
}
 
Example 13
Source File: AbstractServer.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public void send(Object message, boolean sent) throws RemotingException {
    Collection<Channel> channels = getChannels();
    for (Channel channel : channels) {
        if (channel.isConnected()) {
            channel.send(message, sent);
        }
    }
}
 
Example 14
Source File: HeaderExchangeServer.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private boolean isRunning() {
    Collection<Channel> channels = getChannels();
    for (Channel channel : channels) {

        /**
         *  If there are any client connections,
         *  our server should be running.
         */

        if (channel.isConnected()) {
            return true;
        }
    }
    return false;
}
 
Example 15
Source File: AbstractClient.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void send(Object message, boolean sent) throws RemotingException {
    if (send_reconnect && !isConnected()){
        connect();
    }
    Channel channel = getChannel();
    //TODO getChannel返回的状态是否包含null需要改进
    if (channel == null || ! channel.isConnected()) {
      throw new RemotingException(this, "message can not send, because channel is closed . url:" + getUrl());
    }
    channel.send(message, sent);
}
 
Example 16
Source File: AbstractClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public boolean isConnected() {
    Channel channel = getChannel();
    if (channel == null)
        return false;
    return channel.isConnected();
}
 
Example 17
Source File: HeaderExchangeChannel.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
static void removeChannelIfDisconnected(Channel ch) {
    if (ch != null && !ch.isConnected()) {
        ch.removeAttribute(CHANNEL_KEY);
    }
}
 
Example 18
Source File: HeaderExchangeChannel.java    From dubbox with Apache License 2.0 4 votes vote down vote up
static void removeChannelIfDisconnected(Channel ch) {
    if (ch != null && ! ch.isConnected()) {
        ch.removeAttribute(CHANNEL_KEY);
    }
}
 
Example 19
Source File: AbstractClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public boolean isConnected() {
    Channel channel = getChannel();
    if (channel == null)
        return false;
    return channel.isConnected();
}
 
Example 20
Source File: HeaderExchangeChannel.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
static void removeChannelIfDisconnected(Channel ch) {
    if (ch != null && ! ch.isConnected()) {
        ch.removeAttribute(CHANNEL_KEY);
    }
}