Skip to content

Commit 90000a5

Browse files
committed
[change] notify helper use new api
[fix bug] fix springcloud read tarsserver config error
1 parent f334c4b commit 90000a5

File tree

8 files changed

+39
-114
lines changed

8 files changed

+39
-114
lines changed

core/src/main/java/com/qq/tars/client/support/ServantCacheManager.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import com.qq.tars.common.util.Loader;
2121
import com.qq.tars.common.util.StringUtils;
2222
import com.qq.tars.support.log.LoggerFactory;
23-
import org.slf4j.Logger;
24-
2523
import java.io.BufferedInputStream;
2624
import java.io.BufferedOutputStream;
2725
import java.io.File;
@@ -38,6 +36,7 @@
3836
import java.util.Properties;
3937
import java.util.concurrent.atomic.AtomicBoolean;
4038
import java.util.concurrent.locks.ReentrantLock;
39+
import org.slf4j.Logger;
4140

4241
public final class ServantCacheManager {
4342
private static final Logger LOGGER = LoggerFactory.getClientLogger();
@@ -91,7 +90,12 @@ private File getCacheFile(String dataPath) throws Exception {
9190
}
9291
File f = new File(path, Constants.SERVER_NODE_CACHE_FILENAME);
9392
if (!f.exists()) {
94-
f.createNewFile();
93+
try {
94+
f.createNewFile();
95+
}catch(IOException e){
96+
LOGGER.error("Create TarsClient cachefile error,please check path is correct, path is :{}{}", path , Constants.SERVER_NODE_CACHE_FILENAME );
97+
throw new IOException(e);
98+
}
9599
}
96100
return f;
97101
}

core/src/main/java/com/qq/tars/server/apps/BaseAppContext.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.qq.tars.support.trace.TraceCallbackFilter;
3737
import com.qq.tars.support.trace.TraceClientFilter;
3838
import com.qq.tars.support.trace.TraceServerFilter;
39-
4039
import java.util.HashMap;
4140
import java.util.HashSet;
4241
import java.util.LinkedList;
@@ -67,6 +66,7 @@ public abstract class BaseAppContext implements AppContext {
6766
@Override
6867
public void init() {
6968
try {
69+
7070
loadServants();
7171
//inject om admin servant
7272
injectAdminServant();
@@ -79,7 +79,6 @@ public void init() {
7979
System.out.println("[SERVER] failed to start the application.");
8080
}
8181
}
82-
8382
protected abstract void loadServants() throws Exception;
8483

8584
@Override

core/src/main/java/com/qq/tars/server/config/ServerConfig.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import com.qq.tars.common.support.Endpoint;
2121
import com.qq.tars.common.util.Config;
2222
import com.qq.tars.support.om.OmConstants;
23-
2423
import java.io.File;
24+
import java.io.IOException;
2525
import java.util.LinkedHashMap;
2626
import java.util.List;
2727

@@ -55,6 +55,14 @@ public class ServerConfig {
5555
private LinkedHashMap<String, ServantAdapterConfig> servantAdapterConfMap;
5656
private CommunicatorConfig communicatorConfig;
5757

58+
59+
public void loadSystemConfig(){
60+
try {
61+
this.load(Config.parseFile(System.getProperty("config")));
62+
} catch (IOException e) {
63+
throw new RuntimeException(e);
64+
}
65+
}
5866
public ServerConfig load(Config conf) {
5967
application = conf.get("/tars/application/server<app>", "UNKNOWN");
6068
serverName = conf.get("/tars/application/server<server>", null);

core/src/main/java/com/qq/tars/support/notify/NotifyHelper.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ private void notify(NOTIFYLEVEL level, String message) {
4848
if (communicator == null) {
4949
return;
5050
}
51-
52-
NotifyPrx notifyPrx = communicator.stringToProxy(NotifyPrx.class, ConfigurationManager.getInstance().getServerConfig().getNotify());
53-
notifyPrx.async_notifyServer(null, app + "." + server, level.value(), message);
51+
report( message, level,false);
5452
} catch (Exception e) {
5553
omLogger.error("RemoteNotify|notify error", e);
5654
}
@@ -69,23 +67,24 @@ public void notifyError(String info) {
6967
}
7068

7169
public void syncReport(String result) {
72-
report(result, true);
70+
report(result,NOTIFYLEVEL.NOTIFYNORMAL, true);
7371
}
7472

7573
public void asyncReport(String result) {
76-
report(result, false);
74+
report(result, NOTIFYLEVEL.NOTIFYNORMAL,false);
7775
}
7876

79-
private void report(String result, boolean sync) {
77+
private void report(String result,final NOTIFYLEVEL notifylevel, final Boolean sync) {
8078
try {
8179
if (communicator == null) {
8280
return;
8381
}
84-
NotifyPrx notifyPrx = communicator.stringToProxy(NotifyPrx.class, ConfigurationManager.getInstance().getServerConfig().getNotify());
82+
final NotifyPrx notifyPrx = communicator.stringToProxy(NotifyPrx.class, ConfigurationManager.getInstance().getServerConfig().getNotify());
8583
final ReportInfo reportInfo = new ReportInfo();
8684
reportInfo.setSThreadId(String.valueOf(Thread.currentThread().getId()));
8785
reportInfo.setSServer(app + "." + server );
8886
reportInfo.setSMessage( result);
87+
reportInfo.setELevel(notifylevel.value());
8988
if(sync){
9089
notifyPrx.reportNotifyInfo(reportInfo);
9190
}else{

core/src/main/java/com/qq/tars/support/notify/prx/NotifyPrx.java

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -28,90 +28,6 @@
2828

2929
@Servant
3030
public interface NotifyPrx {
31-
/**
32-
* The information reported by the framework is stored in the database
33-
* @param sServerName, server name
34-
* @param sThreadId, server current thread id
35-
* @param sMessage, message
36-
**/
37-
public void reportServer(String sServerName, String sThreadId, String sMessage);
38-
/**
39-
* The information reported by the framework is stored in the database
40-
* @param sServerName, server name
41-
* @param sThreadId, server current thread id
42-
* @param sMessage, message
43-
**/
44-
public void reportServer(String sServerName, String sThreadId, String sMessage, @TarsContext java.util.Map<String, String> ctx);
45-
/**
46-
* The information reported by the framework is stored in the database
47-
* @param sServerName, server name
48-
* @param sThreadId, server current thread id
49-
* @param sMessage, message
50-
**/
51-
public void async_reportServer(@TarsCallback NotifyPrxCallback callback, String sServerName, String sThreadId, String sMessage);
52-
/**
53-
* The information reported by the framework is stored in the database
54-
* @param sServerName, server name
55-
* @param sThreadId, server current thread id
56-
* @param sMessage, message
57-
**/
58-
public void async_reportServer(@TarsCallback NotifyPrxCallback callback, String sServerName, String sThreadId, String sMessage, @TarsContext java.util.Map<String, String> ctx);
59-
/**
60-
* Business reported information, used for alarm
61-
* @param sServerName, server name
62-
* @param level, notify level
63-
* @param sMessage, message
64-
**/
65-
public void notifyServer(String sServerName, int level, String sMessage);
66-
/**
67-
* Business reported information, used for alarm
68-
* @param sServerName, server name
69-
* @param level, notify level
70-
* @param sMessage, message
71-
**/
72-
public void notifyServer(String sServerName, int level, String sMessage, @TarsContext java.util.Map<String, String> ctx);
73-
/**
74-
* Business reported information, used for alarm
75-
* @param sServerName, server name
76-
* @param level, notify level
77-
* @param sMessage, message
78-
**/
79-
public void async_notifyServer(@TarsCallback NotifyPrxCallback callback, String sServerName, int level, String sMessage);
80-
/**
81-
* Business reported information, used for alarm
82-
* @param sServerName, server name
83-
* @param level, notify level
84-
* @param sMessage, message
85-
**/
86-
public void async_notifyServer(@TarsCallback NotifyPrxCallback callback, String sServerName, int level, String sMessage, @TarsContext java.util.Map<String, String> ctx);
87-
/**
88-
* Get report information
89-
* @param sServerName, server name
90-
* @param out , notify info detail
91-
* @return int 0=success, others=failed
92-
**/
93-
public int getNotifyInfo(NotifyKey stKey, @TarsHolder Holder<NotifyInfo> stInfo);
94-
/**
95-
* Get report information
96-
* @param sServerName, server name
97-
* @param out , notify info detail
98-
* @return int 0=success, others=failed
99-
**/
100-
public int getNotifyInfo(NotifyKey stKey, @TarsHolder Holder<NotifyInfo> stInfo, @TarsContext java.util.Map<String, String> ctx);
101-
/**
102-
* Get report information
103-
* @param sServerName, server name
104-
* @param out , notify info detail
105-
* @return int 0=success, others=failed
106-
**/
107-
public void async_getNotifyInfo(@TarsCallback NotifyPrxCallback callback, NotifyKey stKey);
108-
/**
109-
* Get report information
110-
* @param sServerName, server name
111-
* @param out , notify info detail
112-
* @return int 0=success, others=failed
113-
**/
114-
public void async_getNotifyInfo(@TarsCallback NotifyPrxCallback callback, NotifyKey stKey, @TarsContext java.util.Map<String, String> ctx);
11531

11632
public void reportNotifyInfo(ReportInfo info);
11733

core/src/main/java/com/qq/tars/support/om/OmServiceMngr.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static OmServiceMngr getInstance() {
4545
return Instance;
4646
}
4747

48-
public void initAndStartOmService() {
48+
public synchronized void initAndStartOmService() {
4949
Communicator communicator = CommunicatorFactory.getInstance().getCommunicator();
5050
String app = ConfigurationManager.getInstance().getServerConfig().getApplication();
5151
String serverName = ConfigurationManager.getInstance().getServerConfig().getServerName();

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<groupId>com.tencent.tars</groupId>
1212
<artifactId>tars-parent</artifactId>
13-
<version>${revision}</version>
13+
<version>${revision}</version>
1414
<packaging>pom</packaging>
1515
<name>Tars</name>
1616
<description>Super POM For Projects</description>

spring/tars-spring-cloud-starter/src/main/java/com/qq/tars/server/apps/TarsStartLifecycle.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
package com.qq.tars.server.apps;
1818

19-
import com.qq.tars.common.support.Endpoint;
2019
import com.qq.tars.common.util.StringUtils;
2120
import com.qq.tars.protocol.annotation.Servant;
2221
import com.qq.tars.protocol.util.TarsHelper;
22+
import com.qq.tars.server.config.ConfigurationException;
2323
import com.qq.tars.server.config.ConfigurationManager;
2424
import com.qq.tars.server.config.ServantAdapterConfig;
2525
import com.qq.tars.server.config.ServerConfig;
@@ -28,7 +28,11 @@
2828
import com.qq.tars.spring.annotation.TarsServant;
2929
import com.qq.tars.spring.config.TarsClientProperties;
3030
import com.qq.tars.spring.config.TarsServerProperties;
31+
import com.qq.tars.support.om.OmServiceMngr;
3132
import com.qq.tars.support.trace.TarsTraceZipkinConfiguration;
33+
import java.io.IOException;
34+
import java.util.LinkedHashMap;
35+
import java.util.Map;
3236
import org.apache.commons.logging.Log;
3337
import org.apache.commons.logging.LogFactory;
3438
import org.springframework.beans.BeansException;
@@ -38,10 +42,6 @@
3842
import org.springframework.context.SmartLifecycle;
3943
import org.springframework.core.annotation.AnnotatedElementUtils;
4044

41-
import java.io.IOException;
42-
import java.util.LinkedHashMap;
43-
import java.util.Map;
44-
4545
public class TarsStartLifecycle extends BaseAppContext implements SmartLifecycle, ApplicationContextAware {
4646

4747
private static final Log log = LogFactory.getLog(TarsStartLifecycle.class);
@@ -82,12 +82,12 @@ public void start() {
8282

8383
initConfig();
8484
loadAppServants();
85-
initServants();
8685
injectAdminServant();
86+
initServants();
8787
appContextStarted();
8888
startServantAdapter();
8989
setAppContext();
90-
90+
OmServiceMngr.getInstance().initAndStartOmService();
9191
this.isRunning = true;
9292
} catch (IOException e) {
9393
e.printStackTrace();
@@ -119,14 +119,13 @@ private void initConfig() {
119119
serverProperties.setServantAdapterConfMap(new LinkedHashMap<String, ServantAdapterConfig>());
120120
ConfigurationManager.getInstance().setServerConfig(this.serverProperties);
121121
ConfigurationManager.getInstance().setCommunicatorConfig(this.clientProperties);
122+
try {
123+
ConfigurationManager.getInstance().init();
124+
} catch (ConfigurationException e) {
125+
log.error("spring cloud init server config error!" ,e);
126+
throw new RuntimeException(e);
127+
}
122128

123-
servantAdapterConfig = new ServantAdapterConfig();
124-
servantAdapterConfig.setEndpoint(new Endpoint(serverProperties.isUdp() ? "udp" : "tcp", StringUtils.isEmpty(serverProperties.getLocalIP()) ? "0.0.0.0" : serverProperties.getLocalIP(), serverProperties.getPort(), 0, 0, 0, null));
125-
servantAdapterConfig.setHandleGroup("default");
126-
servantAdapterConfig.setMaxConns(serverProperties.getMaxConns());
127-
servantAdapterConfig.setThreads(serverProperties.getThreads());
128-
servantAdapterConfig.setQueueCap(serverProperties.getQueueCap());
129-
servantAdapterConfig.setQueueTimeout(serverProperties.getQueueTimeout());
130129

131130
TarsTraceZipkinConfiguration.getInstance().init();
132131
}
@@ -178,7 +177,7 @@ private ServantHomeSkeleton loadServant(Object bean) throws Exception {
178177

179178
skeleton = new ServantHomeSkeleton(homeName, homeClassImpl, homeApiClazz, null, null, maxLoadLimit);
180179
skeleton.setAppContext(this);
181-
180+
servantAdapterConfig = ConfigurationManager.getInstance().getServerConfig().getServantAdapterConfMap().get(homeName);
182181
ConfigurationManager.getInstance().getServerConfig().getServantAdapterConfMap().put(homeName, servantAdapterConfig);
183182

184183
return skeleton;

0 commit comments

Comments
 (0)