提交 18086908 编写于 作者: Y youyong

modify the cat reload thread

上级 32a0923f
......@@ -6,6 +6,7 @@ import java.io.InputStream;
import java.util.Map;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import com.dianping.cat.Cat;
import com.dianping.cat.configuration.client.entity.ClientConfig;
......@@ -46,6 +47,30 @@ public class ClientConfigReloader implements Task {
}
}
public ClientConfig getClientConfig() throws IOException, SAXException {
ClientConfig clientConfig = null;
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(CAT_CLIENT_XML);
if (in == null) {
in = Cat.class.getResourceAsStream(CAT_CLIENT_XML);
}
if (in != null) {
String xml = Files.forIO().readFrom(in, "utf-8");
clientConfig = new DefaultDomParser().parse(xml);
}
String content = Files.forIO().readFrom(m_file, "utf-8");
ClientConfig globalConfig = m_parser.parse(content);
if (globalConfig != null && clientConfig != null) {
globalConfig.accept(new ClientConfigMerger(clientConfig));
}
return clientConfig;
}
@Override
public void run() {
while (isActive()) {
......@@ -54,7 +79,7 @@ public class ClientConfigReloader implements Task {
long now = m_file.lastModified();
if (now > m_lastModifyTime) {
ClientConfig newConfig = mergerClientConfig();
ClientConfig newConfig = getClientConfig();
Map<String, Domain> domains = newConfig.getDomains();
Domain firstDomain = domains.isEmpty() ? null : domains.values().iterator().next();
......@@ -63,21 +88,25 @@ public class ClientConfigReloader implements Task {
boolean oldEnabled = m_config.isEnabled();
if (oldEnabled != catEnable) {
if(oldEnabled){
Cat.getProducer().logEvent("System", "Reload", Message.SUCCESS, String.format("Change from %s to %s", oldEnabled, catEnable));
if (oldEnabled) {
Cat.getProducer().logEvent("System", "Reload:" + catEnable, Message.SUCCESS,
String.format("Change from %s to %s", oldEnabled, catEnable));
}
synchronized (m_config) {
m_config.setEnabled(catEnable);
}
if(catEnable){
Cat.getProducer().logEvent("System", "Reload", Message.SUCCESS, String.format("Change from %s to %s", oldEnabled, catEnable));
if (catEnable) {
Cat.getProducer().logEvent("System", "Reload:" + catEnable, Message.SUCCESS,
String.format("Change from %s to %s", oldEnabled, catEnable));
}
}
}
} catch (IOException e) {
Cat.getProducer().logEvent("System", "ReloadIOException", "IOException", null);
} catch (SAXException e) {
} catch (SAXParseException e) {
Cat.getProducer().logEvent("System", "ReloadSAXException", "SAXException", null);
} catch (RuntimeException e) {
Cat.getProducer().logEvent("System", "ReloadException", "RuntimeException", null);
} catch (Exception e) {
Cat.logError(e);
}
......@@ -92,28 +121,4 @@ public class ClientConfigReloader implements Task {
public void shutdown() {
m_active = false;
}
public ClientConfig mergerClientConfig() throws IOException, SAXException {
ClientConfig clientConfig = null;
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(CAT_CLIENT_XML);
if (in == null) {
in = Cat.class.getResourceAsStream(CAT_CLIENT_XML);
}
if (in != null) {
String xml = Files.forIO().readFrom(in, "utf-8");
clientConfig = new DefaultDomParser().parse(xml);
}
String content = Files.forIO().readFrom(m_file, "utf-8");
ClientConfig globalConfig = m_parser.parse(content);
if (globalConfig != null && clientConfig != null) {
globalConfig.accept(new ClientConfigMerger(clientConfig));
}
return clientConfig;
}
}
\ No newline at end of file
......@@ -85,8 +85,6 @@ public class StatusUpdateTask implements Task, Initializable {
}
t.setStatus(Message.SUCCESS);
t.complete();
}else{
System.out.println("Cat is disable!");
}
long elapsed = MilliSecondTimer.currentTimeMillis() - start;
......
......@@ -220,11 +220,6 @@
<role-hint>cat-core</role-hint>
<implementation>com.dianping.cat.CatCoreModule</implementation>
</component>
<component>
<role>com.site.initialization.Module</role>
<role-hint>cat-client</role-hint>
<implementation>com.dianping.cat.CatClientModule</implementation>
</component>
<component>
<role>com.dianping.cat.message.spi.codec.BufferWriter</role>
<role-hint>escape</role-hint>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册