Ejemplo n.º 1
0
 public boolean channelWriteAble() {
   try {
     if (channel != null && channel.isWritable()) {
       return true;
     } else {
       return false;
     }
   } catch (Exception e) {
     return false;
   }
 }
 private void sendNumbers(ChannelStateEvent e) {
   Channel channel = e.getChannel();
   while (channel.isWritable()) {
     if (i <= count) {
       channel.write(Integer.valueOf(i));
       i++;
     } else {
       break;
     }
   }
 }
 @Override
 public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e) throws Exception {
   ChannelBuffer msg = (ChannelBuffer) e.getMessage();
   // System.out.println(">>> " + ChannelBuffers.hexDump(msg));
   synchronized (trafficLock) {
     outboundChannel.write(msg);
     // If outboundChannel is saturated, do not read until notified in
     // OutboundHandler.channelInterestChanged().
     if (!outboundChannel.isWritable()) {
       e.getChannel().setReadable(false);
     }
   }
 }
Ejemplo n.º 4
0
    @Override
    public void run() {
      Channel conn = sq.channel;
      if (conn == null || !conn.isOpen()) {
        PerChannelQueue.logger.error("connection missing, no outbound communication");
        return;
      }

      while (true) {
        if (!forever && sq.outbound.size() == 0) break;

        try {
          // block until a message is enqueued
          GeneratedMessage msg = sq.outbound.take();
          System.out.println("++ reply msg -> " + msg);
          if (conn.isWritable()) {
            boolean rtn = false;
            if (channel != null && channel.isOpen() && channel.isWritable()) {
              ChannelFuture cf = channel.write(msg);

              // blocks on write - use listener to be async
              cf.awaitUninterruptibly();
              rtn = cf.isSuccess();
              if (!rtn) sq.outbound.putFirst(msg);
            }

          } else sq.outbound.putFirst(msg);
        } catch (InterruptedException ie) {
          break;
        } catch (Exception e) {
          PerChannelQueue.logger.error("Unexpected communcation failure", e);
          break;
        }
      }

      if (!forever) {
        PerChannelQueue.logger.info("connection queue closing");
      }
    }
Ejemplo n.º 5
0
 /** Is the write queue full?, see {@link WriteStream#writeQueueFull} */
 public boolean writeQueueFull() {
   return !channel.isWritable();
 }
 public boolean isWritable() {
   return channel.isWritable();
 }
 /** Is the write queue full?, see {@link WriteStream#writeQueueFull} */
 public boolean writeQueueFull() {
   checkThread();
   return !channel.isWritable();
 }