Search in sources :

Example 1 with NettyRemotingServer

use of io.seata.core.rpc.netty.NettyRemotingServer in project seata by seata.

the class AbstractServerTest method startSeataServer.

protected static void startSeataServer() throws InterruptedException {
    (new Thread(new Runnable() {

        @Override
        public void run() {
            File file = new File("sessionStore/root.data");
            if (file.exists()) {
                file.delete();
            }
            ParameterParser parameterParser = new ParameterParser(new String[] {});
            // initialize the metrics
            MetricsManager.get().init();
            System.setProperty(ConfigurationKeys.STORE_MODE, parameterParser.getStoreMode());
            nettyServer = new NettyRemotingServer(workingThreads);
            // server port
            nettyServer.setListenPort(parameterParser.getPort());
            UUIDGenerator.init(parameterParser.getServerNode());
            // log store mode : file态db
            SessionHolder.init(parameterParser.getStoreMode());
            DefaultCoordinator coordinator = new DefaultCoordinator(nettyServer);
            coordinator.init();
            nettyServer.setHandler(coordinator);
            // register ShutdownHook
            ShutdownHook.getInstance().addDisposable(coordinator);
            // 127.0.0.1 and 0.0.0.0 are not valid here.
            if (NetUtil.isValidIp(parameterParser.getHost(), false)) {
                XID.setIpAddress(parameterParser.getHost());
            } else {
                XID.setIpAddress(NetUtil.getLocalIp());
            }
            XID.setPort(nettyServer.getListenPort());
            nettyServer.init();
        }
    })).start();
    Thread.sleep(5000);
}
Also used : NettyRemotingServer(io.seata.core.rpc.netty.NettyRemotingServer) ParameterParser(io.seata.server.ParameterParser) DefaultCoordinator(io.seata.server.coordinator.DefaultCoordinator) File(java.io.File)

Example 2 with NettyRemotingServer

use of io.seata.core.rpc.netty.NettyRemotingServer in project XHuiCloud by sindaZeng.

the class Server method main.

/**
 * The entry point of application.
 *
 * @param args the input arguments
 * @throws IOException the io exception
 */
public static void main(String[] args) throws IOException {
    // get port first, use to logback.xml
    int port = PortHelper.getPort(args);
    System.setProperty(ConfigurationKeys.SERVER_PORT, Integer.toString(port));
    // create logger
    final Logger logger = LoggerFactory.getLogger(Server.class);
    if (ContainerHelper.isRunningInContainer()) {
        logger.info("The server is running in container.");
    }
    // initialize the parameter parser
    // Note that the parameter parser should always be the first line to execute.
    // Because, here we need to parse the parameters needed for startup.
    ParameterParser parameterParser = new ParameterParser(args);
    // initialize the metrics
    MetricsManager.get().init();
    System.setProperty(ConfigurationKeys.STORE_MODE, parameterParser.getStoreMode());
    NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(WORKING_THREADS);
    // server port
    nettyRemotingServer.setListenPort(parameterParser.getPort());
    UUIDGenerator.init(parameterParser.getServerNode());
    // log store mode : file, db, redis
    SessionHolder.init(parameterParser.getStoreMode());
    DefaultCoordinator coordinator = new DefaultCoordinator(nettyRemotingServer);
    coordinator.init();
    nettyRemotingServer.setHandler(coordinator);
    // register ShutdownHook
    ShutdownHook.getInstance().addDisposable(coordinator);
    ShutdownHook.getInstance().addDisposable(nettyRemotingServer);
    // 127.0.0.1 and 0.0.0.0 are not valid here.
    if (NetUtil.isValidIp(parameterParser.getHost(), false)) {
        XID.setIpAddress(parameterParser.getHost());
    } else {
        XID.setIpAddress(NetUtil.getLocalIp());
    }
    XID.setPort(nettyRemotingServer.getListenPort());
    try {
        nettyRemotingServer.init();
    } catch (Throwable e) {
        logger.error("nettyServer init error:{}", e.getMessage(), e);
        System.exit(-1);
    }
    System.exit(0);
}
Also used : NettyRemotingServer(io.seata.core.rpc.netty.NettyRemotingServer) DefaultCoordinator(io.seata.server.coordinator.DefaultCoordinator) Logger(org.slf4j.Logger)

Example 3 with NettyRemotingServer

use of io.seata.core.rpc.netty.NettyRemotingServer in project seata by seata.

the class ServerTest method main.

/**
 * The entry point of application.
 *
 * @param args the input arguments
 */
public static void main(String[] args) {
    NettyRemotingServer nettyServer = new NettyRemotingServer(workingThreads);
    nettyServer.setHandler(new DefaultCoordinator(nettyServer));
    UUIDGenerator.init(1L);
    XID.setIpAddress(NetUtil.getLocalIp());
    XID.setPort(nettyServer.getListenPort());
    nettyServer.init();
    System.exit(0);
}
Also used : NettyRemotingServer(io.seata.core.rpc.netty.NettyRemotingServer) DefaultCoordinator(io.seata.server.coordinator.DefaultCoordinator)

Example 4 with NettyRemotingServer

use of io.seata.core.rpc.netty.NettyRemotingServer in project seata by seata.

the class Server method main.

/**
 * The entry point of application.
 *
 * @param args the input arguments
 * @throws IOException the io exception
 */
public static void main(String[] args) throws IOException {
    // get port first, use to logback.xml
    int port = PortHelper.getPort(args);
    System.setProperty(ConfigurationKeys.SERVER_PORT, Integer.toString(port));
    // create logger
    final Logger logger = LoggerFactory.getLogger(Server.class);
    if (ContainerHelper.isRunningInContainer()) {
        logger.info("The server is running in container.");
    }
    // initialize the parameter parser
    // Note that the parameter parser should always be the first line to execute.
    // Because, here we need to parse the parameters needed for startup.
    ParameterParser parameterParser = new ParameterParser(args);
    // initialize the metrics
    MetricsManager.get().init();
    System.setProperty(ConfigurationKeys.STORE_MODE, parameterParser.getStoreMode());
    ThreadPoolExecutor workingThreads = new ThreadPoolExecutor(NettyServerConfig.getMinServerPoolSize(), NettyServerConfig.getMaxServerPoolSize(), NettyServerConfig.getKeepAliveTime(), TimeUnit.SECONDS, new LinkedBlockingQueue<>(NettyServerConfig.getMaxTaskQueueSize()), new NamedThreadFactory("ServerHandlerThread", NettyServerConfig.getMaxServerPoolSize()), new ThreadPoolExecutor.CallerRunsPolicy());
    NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(workingThreads);
    // server port
    nettyRemotingServer.setListenPort(parameterParser.getPort());
    UUIDGenerator.init(parameterParser.getServerNode());
    // log store mode : file, db, redis
    SessionHolder.init(parameterParser.getStoreMode());
    DefaultCoordinator coordinator = new DefaultCoordinator(nettyRemotingServer);
    coordinator.init();
    nettyRemotingServer.setHandler(coordinator);
    // register ShutdownHook
    ShutdownHook.getInstance().addDisposable(coordinator);
    ShutdownHook.getInstance().addDisposable(nettyRemotingServer);
    // 127.0.0.1 and 0.0.0.0 are not valid here.
    if (NetUtil.isValidIp(parameterParser.getHost(), false)) {
        XID.setIpAddress(parameterParser.getHost());
    } else {
        XID.setIpAddress(NetUtil.getLocalIp());
    }
    XID.setPort(nettyRemotingServer.getListenPort());
    try {
        nettyRemotingServer.init();
    } catch (Throwable e) {
        logger.error("nettyServer init error:{}", e.getMessage(), e);
        System.exit(-1);
    }
    System.exit(0);
}
Also used : NettyRemotingServer(io.seata.core.rpc.netty.NettyRemotingServer) NamedThreadFactory(io.seata.common.thread.NamedThreadFactory) DefaultCoordinator(io.seata.server.coordinator.DefaultCoordinator) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Logger(org.slf4j.Logger)

Aggregations

NettyRemotingServer (io.seata.core.rpc.netty.NettyRemotingServer)4 DefaultCoordinator (io.seata.server.coordinator.DefaultCoordinator)4 Logger (org.slf4j.Logger)2 NamedThreadFactory (io.seata.common.thread.NamedThreadFactory)1 ParameterParser (io.seata.server.ParameterParser)1 File (java.io.File)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1