@Override public boolean isConnected() { return channel.isConnected(); }
@Override public boolean isConnected() { return channel.isConnected(); }
static void removeChannelIfDisconnected(org.jboss.netty.channel.Channel ch) { if (ch != null && !ch.isConnected()) { channelMap.remove(ch); } }
static void removeChannelIfDisconnected(org.jboss.netty.channel.Channel ch) { if (ch != null && !ch.isConnected()) { channelMap.remove(ch); } }
static NettyChannel getOrAddChannel(org.jboss.netty.channel.Channel ch, URL url, ChannelHandler handler) { if (ch == null) { return null; } NettyChannel ret = channelMap.get(ch); if (ret == null) { NettyChannel nc = new NettyChannel(ch, url, handler); if (ch.isConnected()) { ret = channelMap.putIfAbsent(ch, nc); } if (ret == null) { ret = nc; } } return ret; }
static NettyChannel getOrAddChannel(org.jboss.netty.channel.Channel ch, URL url, ChannelHandler handler) { if (ch == null) { return null; } NettyChannel ret = channelMap.get(ch); if (ret == null) { NettyChannel nc = new NettyChannel(ch, url, handler); if (ch.isConnected()) { ret = channelMap.putIfAbsent(ch, nc); } if (ret == null) { ret = nc; } } return ret; }
@Override protected org.apache.dubbo.remoting.Channel getChannel() { Channel c = channel; if (c == null || !c.isConnected()) { return null; } return NettyChannel.getOrAddChannel(c, getUrl(), this); }
@Override protected org.apache.dubbo.remoting.Channel getChannel() { Channel c = channel; if (c == null || !c.isConnected()) { return null; } return NettyChannel.getOrAddChannel(c, getUrl(), this); }
@Override public void execute(Channel chan, List<String> command) throws DatastoreException { m_counter.incrementAndGet(); if (chan.isConnected()) { Package thisPackage = getClass().getPackage(); String versionString = thisPackage.getImplementationTitle()+" "+thisPackage.getImplementationVersion(); chan.write(versionString+"\n"); } }
/** * This method will write an event to the channel and then add a close * listener which will close it after the write has completed. * * @param channel * @param event */ public void closeAfterFlushingPendingWrites(Channel channel, Event event) { if (channel.isConnected()) { channel.write(event).addListener(ChannelFutureListener.CLOSE); } else { System.err.println("Unable to write the Event :" + event + " to socket as channel is ot connected"); } }
private void protocolViolation(Channel channel, CorruptedFrameException ex) throws CorruptedFrameException { checkpoint(State.CORRUPT); if (channel.isConnected()) { channel.write(ChannelBuffers.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } throw ex; }
/** * Tests whether the given channel is ready for writing. * @return true if the channel is open and ready; false otherwise. */ private static boolean isChannelReady(Channel channel) { return (channel != null) && channel.isOpen() && channel.isBound() && channel.isConnected(); }
void setWritable(ChannelHandlerContext ctx, boolean writable) { Channel channel = ctx.getChannel(); if (channel.isConnected()) { channel.setUserDefinedWritability(index, writable); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { Channel ch = e.getChannel(); Throwable cause = e.getCause(); if (cause instanceof TooLongFrameException) { sendError(ctx, BAD_REQUEST); return; } else if (cause instanceof IOException) { if (cause instanceof ClosedChannelException) { LOG.debug("Ignoring closed channel error", cause); return; } String message = String.valueOf(cause.getMessage()); if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) { LOG.debug("Ignoring client socket close", cause); return; } } LOG.error("Shuffle error: ", cause); if (ch.isConnected()) { LOG.error("Shuffle error " + e); sendError(ctx, INTERNAL_SERVER_ERROR); } } }
/** * Writes an the {@link Events#DISCONNECT} to the client, flushes * all the pending writes and closes the channel. * */ @Override public void close() { LOG.debug("Going to close tcp connection in class: {}", this .getClass().getName()); Event event = Events.event(null, Events.DISCONNECT); if (channel.isConnected()) { channel.write(event).addListener(ChannelFutureListener.CLOSE); } else { channel.close(); LOG.trace("Unable to write the Event {} with type {} to socket", event, event.getType()); } }
@Override public void releaseExternalResources() { Channel channel = ctx.getChannel(); synchronized (this) { if (ctx != null && ctx.getChannel().isConnected()) { for (ToSend toSend : messagesQueue) { if (! channel.isConnected()) { // ignore break; } ctx.sendDownstream(toSend.toSend); } } messagesQueue.clear(); } if (writeTimeout != null) { writeTimeout.cancel(); } super.releaseExternalResources(); }
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception { if (!(e instanceof MessageEvent)) { ctx.sendDownstream(e); return; } boolean offered = queue.offer((MessageEvent) e); assert offered; final Channel channel = ctx.getChannel(); // call flush if the channel is writable or not connected. flush(..) will take care of the rest if (channel.isWritable() || !channel.isConnected()) { this.ctx = ctx; flush(ctx, false); } }
@Override public boolean isGood(ChannelFuture resource) { Channel channel = resource.awaitUninterruptibly().getChannel(); boolean isSuccess = resource.isSuccess(); boolean isConnected = channel.isConnected(); boolean isOpen = channel.isOpen(); if (log.isTraceEnabled()) { log.trace("isGood = isSucess[%s] && isConnected[%s] && isOpen[%s]", isSuccess, isConnected, isOpen); } return isSuccess && isConnected && isOpen; }
private void processRequest(final ChannelHandlerContext ctx, final Request request, long processStartTime) { Object result; try { result = messageHandler.handle(serverChannel, request); } catch (Exception e) { LoggerUtil.error("NettyChannelHandler processRequest fail!request:" + MotanFrameworkUtil.toString(request), e); result = MotanFrameworkUtil.buildErrorResponse(request.getRequestId(), new MotanServiceException("process request fail. errmsg:" + e.getMessage())); } MotanFrameworkUtil.logRequestEvent(request.getRequestId(), "after invoke biz method: " + MotanFrameworkUtil.getFullMethodString(request), System.currentTimeMillis()); DefaultResponse response = null; if (!(result instanceof DefaultResponse)) { response = new DefaultResponse(result); } else { response = (DefaultResponse) result; } response.setRequestId(request.getRequestId()); response.setProcessTime(System.currentTimeMillis() - processStartTime); if (ctx.getChannel().isConnected()) { ChannelFuture channelFuture = ctx.getChannel().write(response); if (channelFuture != null && request instanceof TraceableRequest) { channelFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { MotanFrameworkUtil.logRequestEvent(request.getRequestId(), "after send rpc response: " + MotanFrameworkUtil.getFullMethodString(request), System.currentTimeMillis()); ((TraceableRequest) request).onFinish(); } }); } } }
private void sendGoAwayFrame(ChannelHandlerContext ctx, ChannelStateEvent e) { // Avoid NotYetConnectedException if (!e.getChannel().isConnected()) { ctx.sendDownstream(e); return; } ChannelFuture future = sendGoAwayFrame(ctx, e.getChannel(), null, SpdySessionStatus.OK); if (spdySession.noActiveStreams()) { future.addListener(new ClosingChannelFutureListener(ctx, e)); } else { closeSessionFutureListener = new ClosingChannelFutureListener(ctx, e); } }