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);
}
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);
}
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);
}
Aggregations