Search in sources :

Example 6 with DefaultCoordinator

use of io.seata.server.coordinator.DefaultCoordinator 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 7 with DefaultCoordinator

use of io.seata.server.coordinator.DefaultCoordinator 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)

Example 8 with DefaultCoordinator

use of io.seata.server.coordinator.DefaultCoordinator in project seata by seata.

the class TmNettyClientTest method testReconnect.

/**
 * Client rely on server's starting first
 *
 * @throws Exception
 */
@Test
public void testReconnect() throws Exception {
    // start services server first
    workingThreads.submit(new Runnable() {

        @Override
        public void run() {
            NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(workingThreads);
            nettyRemotingServer.setHandler(new DefaultCoordinator(nettyRemotingServer));
            UUIDGenerator.init(1L);
            nettyRemotingServer.init();
        }
    });
    // then test client
    Thread.sleep(3000);
    String applicationId = "app 1";
    String transactionServiceGroup = "my_test_tx_group";
    TmNettyRemotingClient tmNettyRemotingClient = TmNettyRemotingClient.getInstance(applicationId, transactionServiceGroup);
    tmNettyRemotingClient.init();
    Method doConnectMethod = TmNettyRemotingClient.class.getDeclaredMethod("reconnect");
    doConnectMethod.setAccessible(true);
    doConnectMethod.invoke(tmNettyRemotingClient);
}
Also used : DefaultCoordinator(io.seata.server.coordinator.DefaultCoordinator) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultCoordinator (io.seata.server.coordinator.DefaultCoordinator)8 NettyRemotingServer (io.seata.core.rpc.netty.NettyRemotingServer)4 Test (org.junit.jupiter.api.Test)4 Method (java.lang.reflect.Method)3 Channel (io.netty.channel.Channel)2 Logger (org.slf4j.Logger)2 NamedThreadFactory (io.seata.common.thread.NamedThreadFactory)1 GlobalTransactionEvent (io.seata.core.event.GlobalTransactionEvent)1 GlobalStatus (io.seata.core.model.GlobalStatus)1 BranchRegisterRequest (io.seata.core.protocol.transaction.BranchRegisterRequest)1 BranchRegisterResponse (io.seata.core.protocol.transaction.BranchRegisterResponse)1 RemotingServer (io.seata.core.rpc.RemotingServer)1 ParameterParser (io.seata.server.ParameterParser)1 DefaultCoordinatorTest (io.seata.server.coordinator.DefaultCoordinatorTest)1 DefaultCore (io.seata.server.coordinator.DefaultCore)1 File (java.io.File)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1