Search in sources :

Example 21 with GenericFutureListener

use of io.netty.util.concurrent.GenericFutureListener in project SMSGate by Lihuanghe.

the class SMPPSessionLoginManager method failedLogin.

@Override
protected void failedLogin(ChannelHandlerContext ctx, Object msg, long status) {
    if (msg instanceof BaseBind) {
        logger.error("Connected error status :{},msg : {}", status, msg);
        BaseBind message = (BaseBind) msg;
        // 认证失败
        PduResponse resp = message.createResponse();
        resp.setCommandStatus((int) SmppConstants.STATUS_BINDFAIL);
        ChannelFuture promise = ctx.writeAndFlush(resp);
        final ChannelHandlerContext finalctx = ctx;
        promise.addListener(new GenericFutureListener() {

            public void operationComplete(Future future) throws Exception {
                finalctx.close();
            }
        });
    } else {
        logger.error("connect msg type error : {}", msg);
        ctx.close();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) PduResponse(com.zx.sms.codec.smpp.msg.PduResponse) BaseBind(com.zx.sms.codec.smpp.msg.BaseBind) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) TlvConvertException(com.zx.sms.codec.smpp.TlvConvertException)

Example 22 with GenericFutureListener

use of io.netty.util.concurrent.GenericFutureListener in project SMSGate by Lihuanghe.

the class SgipUnbindRequestMessageHandler method channelRead0.

@Override
protected void channelRead0(final ChannelHandlerContext ctx, SgipUnbindRequestMessage msg) throws Exception {
    SgipUnbindResponseMessage resp = new SgipUnbindResponseMessage(msg.getHeader());
    ChannelFuture future = ctx.channel().writeAndFlush(resp);
    final ChannelHandlerContext finalctx = ctx;
    future.addListeners(new GenericFutureListener() {

        @Override
        public void operationComplete(Future future) throws Exception {
            ctx.executor().schedule(new Runnable() {

                @Override
                public void run() {
                    finalctx.channel().close();
                }
            }, 500, TimeUnit.MILLISECONDS);
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) ChannelFuture(io.netty.channel.ChannelFuture) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) SgipUnbindResponseMessage(com.zx.sms.codec.sgip12.msg.SgipUnbindResponseMessage)

Example 23 with GenericFutureListener

use of io.netty.util.concurrent.GenericFutureListener in project SMSGate by Lihuanghe.

the class UnbindMessageHandler method channelRead0.

@Override
protected void channelRead0(final ChannelHandlerContext ctx, Unbind msg) throws Exception {
    UnbindResp resp = msg.createResponse();
    ChannelFuture future = ctx.channel().writeAndFlush(resp);
    final ChannelHandlerContext finalctx = ctx;
    future.addListeners(new GenericFutureListener() {

        @Override
        public void operationComplete(Future future) throws Exception {
            ctx.executor().schedule(new Runnable() {

                @Override
                public void run() {
                    finalctx.channel().close();
                }
            }, 500, TimeUnit.MILLISECONDS);
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) ChannelFuture(io.netty.channel.ChannelFuture) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) UnbindResp(com.zx.sms.codec.smpp.msg.UnbindResp)

Example 24 with GenericFutureListener

use of io.netty.util.concurrent.GenericFutureListener in project WindSpigot by Wind-Development.

the class PlayerConnection method disconnect.

// No called of force closed
public void disconnect(String s) {
    // CraftBukkit start - fire PlayerKickEvent
    String leaveMessage = EnumChatFormat.YELLOW + this.player.getName() + " left the game.";
    PlayerKickEvent event = new PlayerKickEvent(this.server.getPlayer(this.player), s, leaveMessage);
    if (this.server.getServer().isRunning()) {
        this.server.getPluginManager().callEvent(event);
    }
    if (event.isCancelled()) {
        // Do not kick the player
        return;
    }
    // Send the possibly modified leave message
    s = event.getReason();
    // CraftBukkit end
    final ChatComponentText chatcomponenttext = new ChatComponentText(s);
    this.networkManager.a(new PacketPlayOutKickDisconnect(chatcomponenttext), new GenericFutureListener() {

        @Override
        public void operationComplete(Future future) throws Exception {
            // CraftBukkit - fix decompile error
            PlayerConnection.this.networkManager.close(chatcomponenttext);
        }
    }, new GenericFutureListener[0]);
    // CraftBukkit - fire quit instantly
    this.a(chatcomponenttext);
    this.networkManager.k();
    // CraftBukkit - Don't wait
    this.minecraftServer.postToMainThread(new Runnable() {

        @Override
        public void run() {
            PlayerConnection.this.networkManager.l();
        }
    });
}
Also used : Future(io.netty.util.concurrent.Future) PlayerKickEvent(org.bukkit.event.player.PlayerKickEvent) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 25 with GenericFutureListener

use of io.netty.util.concurrent.GenericFutureListener in project PaperDev by Kamillaova.

the class ServerConnection method c.

public void c() {
    List list = this.h;
    synchronized (this.h) {
        // Spigot Start
        // Paper
        addPending();
        // This prevents players from 'gaming' the server, and strategically relogging to increase their position in the tick order
        if (org.spigotmc.SpigotConfig.playerShuffle > 0 && MinecraftServer.currentTick % org.spigotmc.SpigotConfig.playerShuffle == 0) {
            Collections.shuffle(this.h);
        }
        // Spigot End
        Iterator iterator = this.h.iterator();
        while (iterator.hasNext()) {
            final NetworkManager networkmanager = (NetworkManager) iterator.next();
            if (!networkmanager.h()) {
                if (networkmanager.isConnected()) {
                    try {
                        networkmanager.a();
                    } catch (Exception exception) {
                        if (networkmanager.isLocal()) {
                            CrashReport crashreport = CrashReport.a(exception, "Ticking memory connection");
                            CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Ticking connection");
                            crashreportsystemdetails.a("Connection", new CrashReportCallable() {

                                public String a() throws Exception {
                                    return networkmanager.toString();
                                }

                                public Object call() throws Exception {
                                    return this.a();
                                }
                            });
                            throw new ReportedException(crashreport);
                        }
                        ServerConnection.e.warn("Failed to handle packet for {}", networkmanager.getSocketAddress(), exception);
                        final ChatComponentText chatcomponenttext = new ChatComponentText("Internal server error");
                        networkmanager.sendPacket(new PacketPlayOutKickDisconnect(chatcomponenttext), new GenericFutureListener() {

                            public void operationComplete(Future future) throws Exception {
                                networkmanager.close(chatcomponenttext);
                            }
                        }, new GenericFutureListener[0]);
                        networkmanager.stopReading();
                    }
                } else {
                    // Fix a race condition where a NetworkManager could be unregistered just before connection.
                    if (networkmanager.preparing)
                        continue;
                    // Spigot End
                    iterator.remove();
                    networkmanager.handleDisconnection();
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) List(java.util.List) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) IOException(java.io.IOException) ChannelException(io.netty.channel.ChannelException)

Aggregations

GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)73 ChannelFuture (io.netty.channel.ChannelFuture)40 Future (io.netty.util.concurrent.Future)39 Channel (io.netty.channel.Channel)27 InetSocketAddress (java.net.InetSocketAddress)22 Logger (org.slf4j.Logger)19 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)18 Bootstrap (io.netty.bootstrap.Bootstrap)17 IOException (java.io.IOException)17 ChannelPipeline (io.netty.channel.ChannelPipeline)15 List (java.util.List)14 ArrayList (java.util.ArrayList)13 SocketAddress (java.net.SocketAddress)12 URI (java.net.URI)12 Map (java.util.Map)12 ChannelHandler (io.netty.channel.ChannelHandler)11 EventLoopGroup (io.netty.channel.EventLoopGroup)11 ChannelOption (io.netty.channel.ChannelOption)10 SocketChannel (io.netty.channel.socket.SocketChannel)10 Future (io.vertx.core.Future)10