Java tutorial
/* * Copyright (C) 2014 a5834099147(lxd) <a5834099147@126.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.lxd.client; import java.awt.EventQueue; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.lxd.client.link.ClientInitalizer; import com.lxd.client.secondary.MsgInPre; import com.lxd.client.view.control.UiSingleton; import com.lxd.secondary.MessageSend; import com.lxd.threadpool.impl.TaskThreadPool; import io.netty.bootstrap.Bootstrap; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; /** * CMD? * * @author: a5834099147 * @mailto: a5834099147@126.com * @date: 20141222 * @blog : http://a5834099147.github.io/ * @review */ public class AdamClient { private static final Logger log = LogManager.getLogger(); private static final int PORT = 8463; public static void main(String[] args) { ///< ?? EventQueue.invokeLater(new Runnable() { @Override public void run() { UiSingleton.getSingleton().BamInit(); } }); ///< ?? new AdamClient().initServer(); } public void initServer() { // /< new TaskThreadPool().start(); log.info("??"); // /< ?? new MsgInPre().start(); log.info("???"); // /< ??? new MessageSend().start(); log.info("????"); if (!netStart(PORT)) { return; } } private boolean netStart(int prot) { // /< EventLoopGroup workerGroup = new NioEventLoopGroup(); try { Bootstrap bootstrap = new Bootstrap(); // /< ?? bootstrap.group(workerGroup).channel(NioSocketChannel.class) // /< , ?? INFO .handler(new ClientInitalizer()); // /< ? try { bootstrap.connect("localhost", prot).sync().channel().closeFuture().sync(); } catch (InterruptedException e) { e.printStackTrace(); return false; } } finally { // /< try { workerGroup.shutdownGracefully().sync(); } catch (InterruptedException e) { e.printStackTrace(); return false; } } return true; } }