當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelFutureListener類代碼示例

本文整理匯總了Java中org.jboss.netty.channel.ChannelFutureListener的典型用法代碼示例。如果您正苦於以下問題:Java ChannelFutureListener類的具體用法?Java ChannelFutureListener怎麽用?Java ChannelFutureListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ChannelFutureListener類屬於org.jboss.netty.channel包,在下文中一共展示了ChannelFutureListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: send

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
/**
 * Sends this response to all the passed channels as a {@link TextWebSocketFrame}
 * @param listener A channel future listener to attach to each channel future. Ignored if null.
 * @param channels The channels to send this response to
 * @return An array of the futures for the write of this response to each channel written to
 */
public ChannelFuture[] send(ChannelFutureListener listener, Channel...channels) {
	if(channels!=null && channels.length>0) {
		Set<ChannelFuture> futures = new HashSet<ChannelFuture>(channels.length);
		if(opCode==null) {
			opCode = "ok";
		}
		TextWebSocketFrame frame = new TextWebSocketFrame(this.toChannelBuffer());
		for(Channel channel: channels) {
			if(channel!=null && channel.isWritable()) {
				ChannelFuture cf = Channels.future(channel);
				if(listener!=null) cf.addListener(listener);
				channel.getPipeline().sendDownstream(new DownstreamMessageEvent(channel, cf, frame, channel.getRemoteAddress()));
				futures.add(cf);
			}
		}
		return futures.toArray(new ChannelFuture[futures.size()]);
	}		
	return EMPTY_CHANNEL_FUTURE_ARR;
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:26,代碼來源:Netty3JSONResponse.java

示例2: decode

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    HttpRequest request = (HttpRequest) msg;
    QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());

    DeviceSession deviceSession = getDeviceSession(
            channel, remoteAddress, decoder.getParameters().get("UserName").get(0));
    if (deviceSession == null) {
        return null;
    }

    Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0));
    if (!parser.matches()) {
        return null;
    }

    Position position = new Position();
    position.setProtocol(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());

    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));

    position.setValid(true);
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setAltitude(parser.nextDouble(0));
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));

    if (channel != null) {
        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        channel.write(response).addListener(ChannelFutureListener.CLOSE);
    }

    return position;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:39,代碼來源:PathAwayProtocolDecoder.java

示例3: handle

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);

  Credentials creds = new Credentials();
  creds.addToken(new Text(serviceUrl), token);
  DataOutputBuffer out = new DataOutputBuffer();
  creds.write(out);
  int fileLength = out.getData().length;
  ChannelBuffer cbuffer = ChannelBuffers.buffer(fileLength);
  cbuffer.writeBytes(out.getData());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(fileLength));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestDelegationTokenRemoteFetcher.java

示例4: messageReceived

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
		throws Exception {
	super.messageReceived(ctx, e);

	System.out.println("-------- Server  Channel messageRecieved "
			+ System.currentTimeMillis());

	if (induceError.get()) {
		System.out
				.println("Inducing Error in Server messageReceived method");
		throw new IOException("Induced error ");
	}

	MessageEventBag bag = new MessageEventBag();
	bag.setBytes(e);
	bagList.add(bag);

	ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
	buffer.writeInt(200);

	ChannelFuture future = e.getChannel().write(buffer);

	future.addListener(ChannelFutureListener.CLOSE);

}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:27,代碼來源:ServerUtil.java

示例5: exceptionCaught

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
		throws Exception {
	System.out.println("Server Exception Caught");
	e.getCause().printStackTrace();

	/**
	 * Very important to respond here.
	 * The agent will always be listening for some kind of feedback.
	 */
	ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
	buffer.writeInt(500);

	ChannelFuture future = e.getChannel().write(buffer);

	future.addListener(ChannelFutureListener.CLOSE);

}
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:19,代碼來源:ServerUtil.java

示例6: messageReceived

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
@Override
public void messageReceived(ChannelHandlerContext context, MessageEvent messageEvent) throws Exception {
	context.getChannel().getPipeline().remove(this);
	Response response = (Response) context.getChannel().getAttachment();

	if (response == null) {
		logger.debug("response is null");
		HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
		httpResponse.headers().set(HttpHeaders.Names.CONTENT_LENGTH, "0");
		httpResponse.setContent(ChannelBuffers.EMPTY_BUFFER);
		httpResponse.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE);
		context.getChannel().write(httpResponse).addListener(ChannelFutureListener.CLOSE);

		return;
	}

	handleHttpResponse(context, response);
}
 
開發者ID:iceize,項目名稱:netty-http-3.x,代碼行數:19,代碼來源:HttpNullableResponseHandler.java

示例7: writeBodyAsync

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
/**
 * Writes the given body to Netty channel. Will <b>not</b >wait until the body has been written.
 *
 * @param log             logger to use
 * @param channel         the Netty channel
 * @param remoteAddress   the remote address when using UDP
 * @param body            the body to write (send)
 * @param exchange        the exchange
 * @param listener        listener with work to be executed when the operation is complete
 */
public static void writeBodyAsync(Logger log, Channel channel, SocketAddress remoteAddress, Object body,
                                  Exchange exchange, ChannelFutureListener listener) {
    ChannelFuture future;
    if (remoteAddress != null) {
        if (log.isDebugEnabled()) {
            log.debug("Channel: {} remote address: {} writing body: {}", new Object[]{channel, remoteAddress, body});
        }
        future = channel.write(body, remoteAddress);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Channel: {} writing body: {}", new Object[]{channel, body});
        }
        future = channel.write(body);
    }

    if (listener != null) {
        future.addListener(listener);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:30,代碼來源:NettyHelper.java

示例8: closeChannel

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
/**
 * Avoid channel double close
 * 
 * @param channel
 */
void closeChannel(final Channel channel) {
	synchronized (this) {
		if (closingChannel.contains(channel)) {
			LOG.info(channel.toString() + " is already closed");
			return ;
		}
		
		closingChannel.add(channel);
	}
	
	LOG.debug(channel.toString() + " begin to closed");
	ChannelFuture closeFuture = channel.close();
	closeFuture.addListener(new ChannelFutureListener() {
		@Override
		public void operationComplete(ChannelFuture future)
				throws Exception {

			synchronized (this) {
				closingChannel.remove(channel);
			}
			LOG.debug(channel.toString() + " finish closed");
		}
	});
}
 
開發者ID:zhangjunfang,項目名稱:jstorm-0.9.6.3-,代碼行數:30,代碼來源:NettyClient.java

示例9: channelConnected

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
@Override
public void channelConnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) {
    //prevent javax.net.ssl.SSLException: Received close_notify during handshake
    final SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);

    if (sslHandler == null) {
        return;
    }

    final ChannelFuture handshakeFuture = sslHandler.handshake();
    handshakeFuture.addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(final ChannelFuture future) throws Exception {
            if (logger.isTraceEnabled()) {
                logger.trace("Node to Node encryption cipher is {}/{}", sslHandler.getEngine().getSession().getProtocol(), sslHandler
                        .getEngine().getSession().getCipherSuite());
            }
            ctx.sendUpstream(e);
        }
    });
}
 
開發者ID:petalmd,項目名稱:armor,代碼行數:23,代碼來源:ArmorMessageChannelHandler.java

示例10: closeChannel

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
/**
 * Avoid channel double close
 * 
 * @param channel
 */
void closeChannel(final Channel channel) {
	synchronized (this) {
		if (closingChannel.contains(channel)) {
			LOG.info(channel.toString() + " is already closed");
			return ;
		}
		
		closingChannel.add(channel);
	}
	
	LOG.debug(channel.toString() + " begin to closed");
	ChannelFuture closeFuture = channel.close();
	closeFuture.addListener(new ChannelFutureListener() {
		public void operationComplete(ChannelFuture future)
				throws Exception {

			synchronized (this) {
				closingChannel.remove(channel);
			}
			LOG.debug(channel.toString() + " finish closed");
		}
	});
}
 
開發者ID:songtk,項目名稱:learn_jstorm,代碼行數:29,代碼來源:NettyClient.java

示例11: decode

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
	
    if (buffer.readableBytes() < 2) {
        return null;
    }

    final int magic1 = buffer.getUnsignedByte(buffer.readerIndex());
    final int magic2 = buffer.getUnsignedByte(buffer.readerIndex() + 1);
    boolean isFlashPolicyRequest = (magic1 == '<' && magic2 == 'p');

    if (isFlashPolicyRequest) {
    	l.info("flash policy requested");
        buffer.skipBytes(buffer.readableBytes()); // Discard everything
        channel.write(policyResponse).addListener(ChannelFutureListener.CLOSE);
        return null;
    }

    // Remove ourselves, important since the byte length check at top can hinder frame decoding
    // down the pipeline
    ctx.getPipeline().remove(this);
    return buffer.readBytes(buffer.readableBytes());
}
 
開發者ID:mirasworks,項目名稱:works,代碼行數:23,代碼來源:FlashPolicyHandler.java

示例12: shutdown

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
public void shutdown() {
    L4j.getL4j().info(SHUTDOWN);
    try {
        this.isShuttingDown = true;
        Channel channel = this.pipeline.getCurrentPipeline().getChannel();
        this.channelFuture.getChannel().write(ChannelBuffers.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
        L4j.getL4j().info(CLOSE_CHANNEL);
        channelFactory.releaseExternalResources();
        L4j.getL4j().info(RELEASE_FACTORY);
        clientBootstrap.releaseExternalResources();
        L4j.getL4j().info(RELEASE_CLIENT);

    } catch (Exception e) {
        L4j.getL4j().error(new StringBuilder(ERROR_CHANNEL).append(e.toString()).toString(), e);
    }

}
 
開發者ID:Buck2k,項目名稱:cellhealth-ng,代碼行數:18,代碼來源:GraphiteSender.java

示例13: closeChannel

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
/**
 * Avoid channel double close
 *
 * @param channel
 */
void closeChannel(final Channel channel) {
    synchronized (channelClosing) {
        if (closingChannel.contains(channel)) {
            LOG.info(channel.toString() + " is already closed");
            return;
        }

        closingChannel.add(channel);
    }

    LOG.debug(channel.toString() + " begin to closed");
    ChannelFuture closeFuture = channel.close();
    closeFuture.addListener(new ChannelFutureListener() {
        public void operationComplete(ChannelFuture future) throws Exception {

            synchronized (channelClosing) {
                closingChannel.remove(channel);
            }
            LOG.debug(channel.toString() + " finish closed");
        }
    });
}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:28,代碼來源:NettyClient.java

示例14: sendClosedPacket

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
private void sendClosedPacket(Channel channel) {
    if (!channel.isConnected()) {
        logger.debug("channel already closed. skip sendClosedPacket() {}", channel);
        return;
    }
    
    logger.debug("write ClientClosePacket");
    ClientClosePacket clientClosePacket = new ClientClosePacket();
    ChannelFuture write = channel.write(clientClosePacket);
    write.addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (!future.isSuccess()) {
                logger.warn("ClientClosePacket write failed. channel:{}", future.getCause(), future.getCause());
            } else {
                logger.debug("ClientClosePacket write success. channel:{}", future.getChannel());
            }
        }
    });
    write.awaitUninterruptibly(3000, TimeUnit.MILLISECONDS);
}
 
開發者ID:masonmei,項目名稱:apm-agent,代碼行數:22,代碼來源:PinpointSocketHandler.java

示例15: SocketChannel

import org.jboss.netty.channel.ChannelFutureListener; //導入依賴的package包/類
public SocketChannel(final Channel channel, long timeoutMillis, Timer timer) {
    if (channel == null) {
        throw new NullPointerException("channel");
    }
    if (timer == null) {
        throw new NullPointerException("channel");
    }
    this.channel = channel;
    this.timeoutMillis = timeoutMillis;
    this.timer = timer;
    this.requestManager = new RequestManager(this.timer);
    this.responseWriteFail = new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (!future.isSuccess()) {
                logger.warn("responseWriteFail. {}", channel);
            }
        }
    };
}
 
開發者ID:masonmei,項目名稱:apm-agent,代碼行數:21,代碼來源:SocketChannel.java


注:本文中的org.jboss.netty.channel.ChannelFutureListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。