@Override public Object getAttribute(String key) { Channel channel = getChannel(); if (channel == null) { return null; } return channel.getAttribute(key); }
@Override public void setAttribute(String key, Object value) { Channel channel = getChannel(); if (channel == null) { return; } channel.setAttribute(key, value); }
@Override public boolean hasAttribute(String key) { Channel channel = getChannel(); if (channel == null) { return false; } return channel.hasAttribute(key); }
@Override public void removeAttribute(String key) { Channel channel = getChannel(); if (channel == null) { return; } channel.removeAttribute(key); }
@Override public boolean isConnected() { Channel channel = getChannel(); if (channel == null) { return false; } return channel.isConnected(); }
@Override public void setAttribute(String key, Object value) { Channel channel = getChannel(); if (channel == null) { return; } channel.setAttribute(key, value); }
@Override public boolean isConnected() { Channel channel = getChannel(); if (channel == null) { return false; } return channel.isConnected(); }
@Override public Object getAttribute(String key) { Channel channel = getChannel(); if (channel == null) { return null; } return channel.getAttribute(key); }
@Override public void removeAttribute(String key) { Channel channel = getChannel(); if (channel == null) { return; } channel.removeAttribute(key); }
@Override public boolean hasAttribute(String key) { Channel channel = getChannel(); if (channel == null) { return false; } return channel.hasAttribute(key); }
@Override public InetSocketAddress getLocalAddress() { Channel channel = getChannel(); if (channel == null) { return InetSocketAddress.createUnresolved(NetUtils.getLocalHost(), 0); } return channel.getLocalAddress(); }
@Override public InetSocketAddress getLocalAddress() { Channel channel = getChannel(); if (channel == null) { return InetSocketAddress.createUnresolved(NetUtils.getLocalHost(), 0); } return channel.getLocalAddress(); }
public void disconnect() { connectLock.lock(); try { try { Channel channel = getChannel(); if (channel != null) { channel.close(); } } catch (Throwable e) { logger.warn(e.getMessage(), e); } try { doDisConnect(); } catch (Throwable e) { logger.warn(e.getMessage(), e); } } finally { connectLock.unlock(); } }
public void disconnect() { connectLock.lock(); try { try { Channel channel = getChannel(); if (channel != null) { channel.close(); } } catch (Throwable e) { logger.warn(e.getMessage(), e); } try { doDisConnect(); } catch (Throwable e) { logger.warn(e.getMessage(), e); } } finally { connectLock.unlock(); } }
@Override public InetSocketAddress getRemoteAddress() { Channel channel = getChannel(); if (channel == null) { return getUrl().toInetSocketAddress(); } return channel.getRemoteAddress(); }
@Override public InetSocketAddress getRemoteAddress() { Channel channel = getChannel(); if (channel == null) { return getUrl().toInetSocketAddress(); } return channel.getRemoteAddress(); }
@Override public void send(Object message, boolean sent) throws RemotingException { if (needReconnect && !isConnected()) { connect(); } Channel channel = getChannel(); //TODO Can the value returned by getChannel() be null? need improvement. if (channel == null || !channel.isConnected()) { throw new RemotingException(this, "message can not send, because channel is closed . url:" + getUrl()); } channel.send(message, sent); }
protected void connect() throws RemotingException { connectLock.lock(); try { if (isConnected()) { return; } doConnect(); if (!isConnected()) { throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", cause: Connect wait timeout: " + getConnectTimeout() + "ms."); } else { if (logger.isInfoEnabled()) { logger.info("Successed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", channel is " + this.getChannel()); } } } catch (RemotingException e) { throw e; } catch (Throwable e) { throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", cause: " + e.getMessage(), e); } finally { connectLock.unlock(); } }
@Override public void send(Object message, boolean sent) throws RemotingException { if (needReconnect && !isConnected()) { connect(); } Channel channel = getChannel(); //TODO Can the value returned by getChannel() be null? need improvement. if (channel == null || !channel.isConnected()) { throw new RemotingException(this, "message can not send, because channel is closed . url:" + getUrl()); } channel.send(message, sent); }
protected void connect() throws RemotingException { connectLock.lock(); try { if (isConnected()) { return; } doConnect(); if (!isConnected()) { throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", cause: Connect wait timeout: " + getConnectTimeout() + "ms."); } else { if (logger.isInfoEnabled()) { logger.info("Successed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", channel is " + this.getChannel()); } } } catch (RemotingException e) { throw e; } catch (Throwable e) { throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", cause: " + e.getMessage(), e); } finally { connectLock.unlock(); } }