本文整理汇总了Java中io.netty.channel.ChannelHandlerContext.fireUserEventTriggered方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelHandlerContext.fireUserEventTriggered方法的具体用法?Java ChannelHandlerContext.fireUserEventTriggered怎么用?Java ChannelHandlerContext.fireUserEventTriggered使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.ChannelHandlerContext
的用法示例。
在下文中一共展示了ChannelHandlerContext.fireUserEventTriggered方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
/**
*IdleStateEvent事件,在指定时间没有进行读写,会进行回调
*/
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state().equals(IdleState.ALL_IDLE)) {
final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
RemotingUtil.closeChannel(ctx.channel()); //关闭channel
if (NettyRemotingServer.this.channelEventListener != null) {
NettyRemotingServer.this
.putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress, ctx.channel()));
}
}
}
ctx.fireUserEventTriggered(evt);
}
示例2: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state().equals(IdleState.ALL_IDLE)) {
final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
closeChannel(ctx.channel());
if (NettyRemotingClient.this.channelEventListener != null) {
NettyRemotingClient.this
.putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
}
}
}
ctx.fireUserEventTriggered(evt);
}
示例3: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state().equals(IdleState.ALL_IDLE)) {
final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
closeChannel(ctx.channel());
if (NettyRemotingClient.this.channelEventListener != null) {
NettyRemotingClient.this
.putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress, ctx.channel()));
}
}
}
ctx.fireUserEventTriggered(evt);
}
示例4: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent evnet = (IdleStateEvent) evt;
// 判断Channel是否读空闲, 读空闲时移除Channel
if (evnet.state().equals(IdleState.READER_IDLE)) {
final String remoteAddress = NettyUtil.parseChannelRemoteAddr(ctx.channel());
logger.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
UserInfoManager.removeChannel(ctx.channel());
UserInfoManager.broadCastInfo(ChatCode.SYS_USER_COUNT,UserInfoManager.getAuthUserCount());
}
}
ctx.fireUserEventTriggered(evt);
}
示例5: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent evnet = (IdleStateEvent) evt;
if (evnet.state().equals(IdleState.ALL_IDLE)) {
final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
RemotingUtil.closeChannel(ctx.channel());
if (NettyRemotingServer.this.channelEventListener != null) {
NettyRemotingServer.this
.putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
}
}
}
ctx.fireUserEventTriggered(evt);
}
示例6: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.WRITER_IDLE) {
ctx.writeAndFlush("heartbeat").addListener((ChannelFutureListener) future -> {
if (! future.isSuccess()) {
future.channel().close();
}
});
} else {
ctx.fireUserEventTriggered(evt);
}
}
示例7: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent evnet = (IdleStateEvent) evt;
if (evnet.state().equals(IdleState.ALL_IDLE)) {
final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
closeChannel(ctx.channel());
}
}
ctx.fireUserEventTriggered(evt);
}
示例8: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent evnet = (IdleStateEvent) evt;
if (evnet.state().equals(IdleState.ALL_IDLE)) {
final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
}
}
ctx.fireUserEventTriggered(evt);
}
示例9: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state().equals(IdleState.ALL_IDLE)) {
final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
closeChannel(ctx.channel());
}
}
ctx.fireUserEventTriggered(evt);
}
示例10: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent evnet = (IdleStateEvent) evt;
if (evnet.state().equals(IdleState.ALL_IDLE)) {
log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", ctx.channel().remoteAddress());
RemotingUtil.closeChannel(ctx.channel());
}
}
ctx.fireUserEventTriggered(evt);
}
示例11: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
/** Triggered based on events from an {@link io.netty.handler.timeout.IdleStateHandler}. */
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
IdleStateEvent e = (IdleStateEvent) evt;
// See class comment for timeout semantics. In addition to ensuring we only timeout while
// there are outstanding requests, we also do a secondary consistency check to ensure
// there's no race between the idle timeout and incrementing the numOutstandingRequests
// (see SPARK-7003).
//
// To avoid a race between TransportClientFactory.createClient() and this code which could
// result in an inactive client being returned, this needs to run in a synchronized block.
synchronized (this) {
boolean isActuallyOverdue =
System.nanoTime() - responseHandler.getTimeOfLastRequestNs() > requestTimeoutNs;
if (e.state() == IdleState.ALL_IDLE && isActuallyOverdue) {
if (responseHandler.numOutstandingRequests() > 0) {
String address = getRemoteAddress(ctx.channel());
logger.error("Connection to {} has been quiet for {} ms while there are outstanding " +
"requests. Assuming connection is dead; please adjust spark.network.timeout if " +
"this is wrong.", address, requestTimeoutNs / 1000 / 1000);
client.timeOut();
ctx.close();
} else if (closeIdleConnections) {
// While CloseIdleConnections is enable, we also close idle connection
client.timeOut();
ctx.close();
}
}
}
}
ctx.fireUserEventTriggered(evt);
}
示例12: handleBye
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
private void handleBye(ByteBuf in, ChannelHandlerContext handlerContext) {
String message = lineParser.parse(in);
UntaggedResponse response = new UntaggedResponse.Builder()
.setType(UntaggedResponseType.BYE)
.setMessage(message)
.build();
untaggedResponses.add(response);
handlerContext.fireUserEventTriggered(new ByeEvent(response));
}
示例13: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
{
if (evt instanceof NetworkHandshakeEstablished)
{
ctx.writeAndFlush(new ForgeMessage.FluidIdMapMessage());
return;
}
// pass it forward
ctx.fireUserEventTriggered(evt);
}
示例14: userEventTriggered
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof HandshakeDoneEvent) {
HandshakeDoneEvent handshake = (HandshakeDoneEvent)evt;
if (trace) {
log.trace("Processing handshake event [to={}, event={}]", id, evt);
}
// Try to update state and decide on whether the user callback should be notified.
boolean notify = withLock(() -> {
if (handshake.epoch() == client.epoch && state == CONNECTING) {
if (debug) {
log.debug("Updated connection state [old={}, new={}, to={}]", state, CONNECTED, id);
}
state = CONNECTED;
return true;
} else {
return false;
}
});
// Notify callback and future.
if (notify) {
callback.onConnect(client);
epochConnFuture.complete(client);
} else {
if (trace) {
log.trace("Skipped processing of handshake event [to={}, event={}]", id, evt);
}
}
}
// Check that channel wasn't closed by the callback.
if (ctx.channel().isOpen()) {
ctx.fireUserEventTriggered(evt);
}
}
示例15: decode
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception {
if (msg instanceof ContinuationResponse) {
out.add(msg);
} else if (msg instanceof TaggedResponse) {
TaggedResponse taggedResponse = ((TaggedResponse) msg);
fireEvents(ctx, taggedResponse);
switch (clientState.getCurrentCommand().getCommandType()) {
case SEARCH:
taggedResponse = new SearchResponse.Builder().fromResponse(taggedResponse);
break;
case LIST:
taggedResponse = new Builder().fromResponse(taggedResponse);
break;
case SELECT:
case EXAMINE:
taggedResponse = new OpenResponse.Builder().fromResponse(taggedResponse);
ctx.fireUserEventTriggered(new OpenEvent(((OpenResponse) taggedResponse)));
break;
case FETCH:
if (CommandUtils.isStreamingFetch(clientState.getCurrentCommand())) {
taggedResponse = new StreamingFetchResponse.Builder().fromResponse(taggedResponse);
} else {
taggedResponse = new FetchResponse.Builder().fromResponse(taggedResponse);
}
break;
case CAPABILITY:
taggedResponse = new CapabilityResponse.Builder().fromResponse(taggedResponse);
break;
case NOOP:
taggedResponse = new NoopResponse.Builder().fromResponse(taggedResponse);
break;
default:
break;
}
out.add(taggedResponse);
}
}