You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2023/01/02 04:39:56 UTC
[incubator-eventmesh] branch master updated: fix issue2766
This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new e306e319a fix issue2766
new 89f883846 Merge pull request #2767 from jonyangx/issue2766
e306e319a is described below
commit e306e319aa1273c28a5416dda2dfcf8db1739ef4
Author: jonyangx <jo...@gmail.com>
AuthorDate: Sat Dec 31 21:06:22 2022 +0800
fix issue2766
---
.../eventmesh/runtime/boot/EventMeshServer.java | 43 +++++++++++++++-------
.../eventmesh/runtime/boot/EventMeshStartup.java | 21 ++++++-----
.../eventmesh/runtime/client/common/Server.java | 7 +---
3 files changed, 42 insertions(+), 29 deletions(-)
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java
index 2f48b8e17..3d45985e5 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java
@@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory;
public class EventMeshServer {
- public Logger logger = LoggerFactory.getLogger(this.getClass());
+ public static final Logger LOGGER = LoggerFactory.getLogger(EventMeshServer.class);
private final Acl acl;
@@ -52,7 +52,9 @@ public class EventMeshServer {
private static final List<EventMeshBootstrap> BOOTSTRAP_LIST = new CopyOnWriteArrayList<>();
- public EventMeshServer(ConfigurationWrapper configurationWrapper) {
+ private static final String SERVER_STATE_MSG = "server state:{}";
+
+ public EventMeshServer(final ConfigurationWrapper configurationWrapper) throws Exception {
CommonConfiguration configuration = new CommonConfiguration(configurationWrapper);
configuration.init();
this.configuration = configuration;
@@ -65,20 +67,22 @@ public class EventMeshServer {
for (String provideServerProtocol : provideServerProtocols) {
if (ConfigurationContextUtil.HTTP.equals(provideServerProtocol)) {
BOOTSTRAP_LIST.add(new EventMeshHttpBootstrap(this,
- configurationWrapper, registry));
+ configurationWrapper, registry));
}
if (ConfigurationContextUtil.TCP.equals(provideServerProtocol)) {
BOOTSTRAP_LIST.add(new EventMeshTcpBootstrap(this,
- configurationWrapper, registry));
+ configurationWrapper, registry));
}
if (ConfigurationContextUtil.GRPC.equals(provideServerProtocol)) {
BOOTSTRAP_LIST.add(new EventMeshGrpcBootstrap(configurationWrapper,
- registry));
+ registry));
}
}
+
+ init();
}
- public void init() throws Exception {
+ private void init() throws Exception {
if (Objects.nonNull(configuration)) {
connectorResource.init(configuration.getEventMeshConnectorPluginType());
if (configuration.isEventMeshServerSecurityEnable()) {
@@ -98,11 +102,16 @@ public class EventMeshServer {
}
String eventStore = System
- .getProperty(EventMeshConstants.EVENT_STORE_PROPERTIES, System.getenv(EventMeshConstants.EVENT_STORE_ENV));
- logger.info("eventStore : {}", eventStore);
+ .getProperty(EventMeshConstants.EVENT_STORE_PROPERTIES, System.getenv(EventMeshConstants.EVENT_STORE_ENV));
+
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("eventStore : {}", eventStore);
+ }
serviceState = ServiceState.INITED;
- logger.info("server state:{}", serviceState);
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info(SERVER_STATE_MSG, serviceState);
+ }
}
public void start() throws Exception {
@@ -121,19 +130,22 @@ public class EventMeshServer {
}
serviceState = ServiceState.RUNNING;
- logger.info("server state:{}", serviceState);
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info(SERVER_STATE_MSG, serviceState);
+ }
+
}
public void shutdown() throws Exception {
serviceState = ServiceState.STOPING;
- logger.info("server state:{}", serviceState);
+ LOGGER.info(SERVER_STATE_MSG, serviceState);
for (EventMeshBootstrap eventMeshBootstrap : BOOTSTRAP_LIST) {
eventMeshBootstrap.shutdown();
}
if (configuration != null
- && configuration.isEventMeshServerRegistryEnable()) {
+ && configuration.isEventMeshServerRegistryEnable()) {
registry.shutdown();
}
@@ -149,7 +161,10 @@ public class EventMeshServer {
ConfigurationContextUtil.clear();
serviceState = ServiceState.STOPED;
- logger.info("server state:{}", serviceState);
+
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info(SERVER_STATE_MSG, serviceState);
+ }
}
public static Trace getTrace() {
@@ -164,7 +179,7 @@ public class EventMeshServer {
return registry;
}
- public void setRegistry(Registry registry) {
+ public void setRegistry(final Registry registry) {
this.registry = registry;
}
}
diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshStartup.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshStartup.java
index 34ec72201..33622a585 100644
--- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshStartup.java
+++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshStartup.java
@@ -25,30 +25,31 @@ import org.slf4j.LoggerFactory;
public class EventMeshStartup {
- public static final Logger logger = LoggerFactory.getLogger(EventMeshStartup.class);
+ public static final Logger LOGGER = LoggerFactory.getLogger(EventMeshStartup.class);
public static void main(String[] args) throws Exception {
try {
- ConfigurationWrapper configurationWrapper =
+ final EventMeshServer server = new EventMeshServer(
new ConfigurationWrapper(EventMeshConstants.EVENTMESH_CONF_HOME,
- EventMeshConstants.EVENTMESH_CONF_FILE, false);
- EventMeshServer server = new EventMeshServer(configurationWrapper);
- server.init();
+ EventMeshConstants.EVENTMESH_CONF_FILE, false));
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
- logger.info("eventMesh shutting down hook begin...");
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("eventMesh shutting down hook begin.");
+ }
long start = System.currentTimeMillis();
server.shutdown();
long end = System.currentTimeMillis();
- logger.info("eventMesh shutdown cost {}ms", end - start);
+ if (LOGGER.isInfoEnabled()) {
+ LOGGER.info("eventMesh shutdown cost {}ms", end - start);
+ }
} catch (Exception e) {
- logger.error("exception when shutdown...", e);
+ LOGGER.error("exception when shutdown.", e);
}
}));
} catch (Throwable e) {
- logger.error("EventMesh start fail.", e);
- e.printStackTrace();
+ LOGGER.error("EventMesh start fail.", e);
System.exit(-1);
}
diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/Server.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/Server.java
index 0232f3361..3b04d3e92 100644
--- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/Server.java
+++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/Server.java
@@ -33,11 +33,8 @@ public class Server {
}
public void startAccessServer() throws Exception {
- ConfigurationWrapper configurationWrapper =
- new ConfigurationWrapper(EventMeshConstants.EVENTMESH_CONF_HOME,
- EventMeshConstants.EVENTMESH_CONF_FILE, false);
- eventMeshServer = new EventMeshServer(configurationWrapper);
- eventMeshServer.init();
+ eventMeshServer = new EventMeshServer(new ConfigurationWrapper(EventMeshConstants.EVENTMESH_CONF_HOME,
+ EventMeshConstants.EVENTMESH_CONF_FILE, false));
eventMeshServer.start();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org