Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
4ae45bfb
C
cat
项目概览
梦中观雨
/
cat
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4ae45bfb
编写于
3月 19, 2012
作者:
F
Frankie Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revise cat configurtion
上级
8851f607
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
214 addition
and
55 deletion
+214
-55
cat-core/pom.xml
cat-core/pom.xml
+1
-1
cat-core/src/main/java/com/dianping/cat/Cat.java
cat-core/src/main/java/com/dianping/cat/Cat.java
+9
-9
cat-core/src/main/java/com/dianping/cat/configuration/ClientConfigMerger.java
...va/com/dianping/cat/configuration/ClientConfigMerger.java
+3
-2
cat-core/src/main/java/com/dianping/cat/configuration/ClientConfigValidator.java
...com/dianping/cat/configuration/ClientConfigValidator.java
+14
-3
cat-core/src/main/java/com/dianping/cat/message/MessageProducer.java
...c/main/java/com/dianping/cat/message/MessageProducer.java
+21
-9
cat-core/src/main/java/com/dianping/cat/message/internal/DefaultMessageManager.java
.../dianping/cat/message/internal/DefaultMessageManager.java
+18
-11
cat-core/src/main/java/com/dianping/cat/message/internal/DefaultMessageProducer.java
...dianping/cat/message/internal/DefaultMessageProducer.java
+31
-10
cat-core/src/main/java/com/dianping/cat/message/internal/NullMessage.java
...n/java/com/dianping/cat/message/internal/NullMessage.java
+92
-0
cat-core/src/main/java/com/dianping/cat/message/io/DefaultTransportManager.java
.../com/dianping/cat/message/io/DefaultTransportManager.java
+3
-3
cat-core/src/main/java/com/dianping/cat/message/spi/MessageManager.java
...ain/java/com/dianping/cat/message/spi/MessageManager.java
+7
-0
cat-core/src/main/resources/META-INF/dal/model/config-codegen.xml
.../src/main/resources/META-INF/dal/model/config-codegen.xml
+1
-0
cat-core/src/main/resources/META-INF/dal/model/config-model.xml
...re/src/main/resources/META-INF/dal/model/config-model.xml
+1
-0
cat-core/src/test/resources/com/dianping/cat/message/configuration/config.xml
...sources/com/dianping/cat/message/configuration/config.xml
+1
-1
cat-home/src/main/java/com/dianping/cat/Server.java
cat-home/src/main/java/com/dianping/cat/Server.java
+4
-3
cat-home/src/main/webapp/WEB-INF/web.xml
cat-home/src/main/webapp/WEB-INF/web.xml
+4
-0
cat-home/src/test/java/com/dianping/cat/TestServer.java
cat-home/src/test/java/com/dianping/cat/TestServer.java
+4
-3
未找到文件。
cat-core/pom.xml
浏览文件 @
4ae45bfb
...
...
@@ -39,7 +39,7 @@
<plugin>
<groupId>
com.site.maven.plugins
</groupId>
<artifactId>
maven-codegen-plugin
</artifactId>
<version>
1.0.1
1
</version>
<version>
1.0.1
3
</version>
<executions>
<execution>
<id>
default-cli
</id>
...
...
cat-core/src/main/java/com/dianping/cat/Cat.java
浏览文件 @
4ae45bfb
...
...
@@ -65,7 +65,14 @@ public class Cat {
// this should be called during application initialization time
public
static
void
initialize
(
File
configFile
)
{
initialize
(
null
,
configFile
);
Config
config
=
loadClientConfig
(
configFile
);
if
(
config
!=
null
)
{
getInstance
().
m_manager
.
initializeClient
(
config
);
}
else
{
getInstance
().
m_manager
.
initializeClient
(
null
);
System
.
out
.
println
(
"[WARN] Cat client is disabled due to no config file found!"
);
}
}
public
static
void
initialize
(
PlexusContainer
container
,
File
configFile
)
{
...
...
@@ -78,14 +85,7 @@ public class Cat {
}
}
Config
config
=
loadClientConfig
(
configFile
);
if
(
config
!=
null
)
{
getInstance
().
m_manager
.
initializeClient
(
config
);
}
else
{
getInstance
().
m_manager
.
initializeClient
(
null
);
System
.
out
.
println
(
"[WARN] Cat client is disabled due to no config file found!"
);
}
initialize
(
configFile
);
}
static
Config
loadClientConfig
(
File
configFile
)
{
...
...
cat-core/src/main/java/com/dianping/cat/configuration/ClientConfigMerger.java
浏览文件 @
4ae45bfb
...
...
@@ -15,8 +15,9 @@ public class ClientConfigMerger extends DefaultMerger {
if
(
old
!=
null
)
{
getStack
().
push
(
old
);
// if servers is configured, then never merge it
if
(
old
.
getServers
().
isEmpty
())
{
// if servers is configured, then override it instead of merge
if
(!
config
.
getServers
().
isEmpty
())
{
old
.
getServers
().
clear
();
old
.
getServers
().
addAll
(
config
.
getServers
());
}
...
...
cat-core/src/main/java/com/dianping/cat/configuration/ClientConfigValidator.java
浏览文件 @
4ae45bfb
...
...
@@ -9,6 +9,8 @@ import com.dianping.cat.configuration.model.entity.Server;
import
com.dianping.cat.configuration.model.transform.DefaultValidator
;
public
class
ClientConfigValidator
extends
DefaultValidator
{
private
Config
m_config
;
private
String
getLocalAddress
()
{
try
{
return
InetAddress
.
getLocalHost
().
getHostAddress
();
...
...
@@ -24,10 +26,15 @@ public class ClientConfigValidator extends DefaultValidator {
if
(!
"client"
.
equals
(
config
.
getMode
()))
{
throw
new
RuntimeException
(
String
.
format
(
"Attribute(%s) of /config is required in config: %s"
,
"mode"
,
config
));
}
else
if
(
config
.
getServers
().
size
()
==
0
)
{
throw
new
RuntimeException
(
String
.
format
(
"Element(%s) of /config is required in config: %s"
,
"servers"
,
config
));
config
.
setEnabled
(
false
);
System
.
out
.
println
(
"[WARN] CAT client was disabled due to no CAT servers configured!"
);
}
else
if
(
config
.
getEnabled
()
!=
null
&&
!
config
.
isEnabled
())
{
System
.
out
.
println
(
"[WARN] CAT client was globally disabled!"
);
}
else
if
(
config
.
getEnabled
()
==
null
)
{
config
.
setEnabled
(
true
);
}
m_config
=
config
;
super
.
visitConfig
(
config
);
}
...
...
@@ -43,6 +50,11 @@ public class ClientConfigValidator extends DefaultValidator {
if
(
domain
.
getIp
()
==
null
)
{
domain
.
setIp
(
getLocalAddress
());
}
if
(!
domain
.
isEnabled
()
&&
m_config
.
isEnabled
())
{
m_config
.
setEnabled
(
false
);
System
.
out
.
println
(
"[WARN] CAT client was disabled in domain("
+
domain
.
getId
()
+
") explicitly!"
);
}
}
@Override
...
...
@@ -58,5 +70,4 @@ public class ClientConfigValidator extends DefaultValidator {
server
.
setEnabled
(
true
);
}
}
}
cat-core/src/main/java/com/dianping/cat/message/MessageProducer.java
浏览文件 @
4ae45bfb
...
...
@@ -117,8 +117,28 @@ package com.dianping.cat.message;
* @author Frankie Wu
*/
public
interface
MessageProducer
{
/**
* Create a new message id.
*
* @return new message id
*/
public
String
createMessageId
();
/**
* Check if the CAT client is enabled for current domain.
*
* @return true if CAT client is enabled, false means CAT client is disabled.
*/
public
boolean
isEnabled
();
/**
* Log an error.
*
* @param cause
* root cause exception
*/
public
void
logError
(
Throwable
cause
);
/**
* Log an event in one shot.
*
...
...
@@ -133,14 +153,6 @@ public interface MessageProducer {
*/
public
void
logEvent
(
String
type
,
String
name
,
String
status
,
String
nameValuePairs
);
/**
* Log an error.
*
* @param cause
* root cause exception
*/
public
void
logError
(
Throwable
cause
);
/**
* Log a heartbeat in one shot.
*
...
...
cat-core/src/main/java/com/dianping/cat/message/internal/DefaultMessageManager.java
浏览文件 @
4ae45bfb
...
...
@@ -39,12 +39,10 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
private
Config
m_serverConfig
;
private
String
m_domain
;
private
Domain
m_domain
;
private
String
m_hostName
;
private
String
m_ipAddress
;
private
Logger
m_logger
;
private
boolean
m_firstMessage
=
true
;
...
...
@@ -56,10 +54,6 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
}
}
String
nextMessageId
()
{
return
m_factory
.
getNextId
();
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
...
...
@@ -124,14 +118,18 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
}
Map
<
String
,
Domain
>
domains
=
clientConfig
.
getDomains
();
Domain
firstDomain
=
domains
.
isEmpty
()
?
null
:
domains
.
values
().
iterator
().
next
();
m_domain
=
domains
.
isEmpty
()
?
"unknown"
:
domains
.
keySet
().
iterator
().
next
()
;
m_domain
=
firstDomain
==
null
?
new
Domain
(
"unknown"
).
setEnabled
(
false
)
:
firstDomain
;
try
{
InetAddress
localHost
=
InetAddress
.
getLocalHost
();
m_hostName
=
localHost
.
getHostName
();
m_ipAddress
=
localHost
.
getHostAddress
();
if
(
m_domain
.
getIp
()
==
null
)
{
m_domain
.
setIp
(
localHost
.
getHostAddress
());
}
}
catch
(
UnknownHostException
e
)
{
m_logger
.
warn
(
"Unable to get local host!"
,
e
);
}
...
...
@@ -140,7 +138,7 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
m_factory
=
lookup
(
MessageIdFactory
.
class
);
// initialize domain and ip address
m_factory
.
initialize
(
m_domain
);
m_factory
.
initialize
(
m_domain
.
getId
()
);
// initialize milli-second resolution level timer
MilliSecondTimer
.
initialize
();
...
...
@@ -151,6 +149,15 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
m_serverConfig
=
serverConfig
;
}
@Override
public
boolean
isCatEnabled
()
{
return
m_domain
!=
null
&&
m_domain
.
isEnabled
();
}
String
nextMessageId
()
{
return
m_factory
.
getNextId
();
}
@Override
public
void
reset
()
{
// destroy current thread local data
...
...
@@ -159,7 +166,7 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
@Override
public
void
setup
()
{
Context
ctx
=
new
Context
(
m_domain
,
m_hostName
,
m_ipAddress
);
Context
ctx
=
new
Context
(
m_domain
.
getId
(),
m_hostName
,
m_domain
.
getIp
()
);
m_context
.
set
(
ctx
);
}
...
...
cat-core/src/main/java/com/dianping/cat/message/internal/DefaultMessageProducer.java
浏览文件 @
4ae45bfb
...
...
@@ -19,7 +19,16 @@ public class DefaultMessageProducer implements MessageProducer {
@Override
public
String
createMessageId
()
{
return
m_factory
.
getNextId
();
if
(
m_manager
.
isCatEnabled
())
{
return
m_factory
.
getNextId
();
}
else
{
return
"cat-is-disabled"
;
}
}
@Override
public
boolean
isEnabled
()
{
return
m_manager
.
isCatEnabled
();
}
@Override
...
...
@@ -60,25 +69,37 @@ public class DefaultMessageProducer implements MessageProducer {
@Override
public
Event
newEvent
(
String
type
,
String
name
)
{
DefaultEvent
event
=
new
DefaultEvent
(
type
,
name
);
if
(
m_manager
.
isCatEnabled
())
{
DefaultEvent
event
=
new
DefaultEvent
(
type
,
name
);
m_manager
.
add
(
event
);
return
event
;
m_manager
.
add
(
event
);
return
event
;
}
else
{
return
NullMessage
.
EVENT
;
}
}
@Override
public
Heartbeat
newHeartbeat
(
String
type
,
String
name
)
{
DefaultHeartbeat
heartbeat
=
new
DefaultHeartbeat
(
type
,
name
);
if
(
m_manager
.
isCatEnabled
())
{
DefaultHeartbeat
heartbeat
=
new
DefaultHeartbeat
(
type
,
name
);
m_manager
.
add
(
heartbeat
);
return
heartbeat
;
m_manager
.
add
(
heartbeat
);
return
heartbeat
;
}
else
{
return
NullMessage
.
HEARTBEAT
;
}
}
@Override
public
Transaction
newTransaction
(
String
type
,
String
name
)
{
DefaultTransaction
transaction
=
new
DefaultTransaction
(
type
,
name
,
m_manager
);
if
(
m_manager
.
isCatEnabled
())
{
DefaultTransaction
transaction
=
new
DefaultTransaction
(
type
,
name
,
m_manager
);
m_manager
.
start
(
transaction
);
return
transaction
;
m_manager
.
start
(
transaction
);
return
transaction
;
}
else
{
return
NullMessage
.
TRANSACTION
;
}
}
}
cat-core/src/main/java/com/dianping/cat/message/internal/NullMessage.java
0 → 100644
浏览文件 @
4ae45bfb
package
com.dianping.cat.message.internal
;
import
java.util.Collections
;
import
java.util.List
;
import
com.dianping.cat.message.Event
;
import
com.dianping.cat.message.Heartbeat
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
public
enum
NullMessage
implements
Transaction
,
Event
,
Heartbeat
{
TRANSACTION
,
EVENT
,
HEARTBEAT
;
@Override
public
void
addData
(
String
keyValuePairs
)
{
}
@Override
public
void
addData
(
String
key
,
Object
value
)
{
}
@Override
public
void
complete
()
{
}
@Override
public
Object
getData
()
{
return
null
;
}
@Override
public
String
getName
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
String
getStatus
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
long
getTimestamp
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
String
getType
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
boolean
isCompleted
()
{
return
true
;
}
@Override
public
boolean
isSuccess
()
{
return
true
;
}
@Override
public
void
setStatus
(
String
status
)
{
}
@Override
public
void
setStatus
(
Throwable
e
)
{
}
@Override
public
Transaction
addChild
(
Message
message
)
{
return
this
;
}
@Override
public
List
<
Message
>
getChildren
()
{
return
Collections
.
emptyList
();
}
@Override
public
boolean
hasChildren
()
{
return
false
;
}
@Override
public
long
getDuration
()
{
return
0
;
}
}
cat-core/src/main/java/com/dianping/cat/message/io/DefaultTransportManager.java
浏览文件 @
4ae45bfb
...
...
@@ -40,7 +40,9 @@ public class DefaultTransportManager extends ContainerHolder implements Transpor
List
<
Server
>
servers
=
config
.
getServers
();
int
size
=
servers
.
size
();
if
(
size
==
1
)
{
if
(
size
==
0
||
!
config
.
isEnabled
())
{
m_sender
=
lookup
(
MessageSender
.
class
,
"in-memory"
);
}
else
if
(
size
==
1
)
{
TcpSocketSender
sender
=
(
TcpSocketSender
)
lookup
(
MessageSender
.
class
,
"tcp-socket"
);
Server
server
=
servers
.
get
(
0
);
...
...
@@ -49,8 +51,6 @@ public class DefaultTransportManager extends ContainerHolder implements Transpor
sender
.
initialize
();
m_sender
=
sender
;
}
else
if
(
size
==
0
)
{
m_sender
=
lookup
(
MessageSender
.
class
,
"in-memory"
);
}
else
{
throw
new
UnsupportedOperationException
(
"Not implemented yet"
);
}
...
...
cat-core/src/main/java/com/dianping/cat/message/spi/MessageManager.java
浏览文件 @
4ae45bfb
...
...
@@ -61,6 +61,13 @@ public interface MessageManager {
*/
public
void
initializeServer
(
Config
config
);
/**
* Check if CAT logging is enabled or disabled.
*
* @return true if CAT is enabled
*/
public
boolean
isCatEnabled
();
/**
* Do cleanup for current thread environment in order to release resources in
* thread local objects.
...
...
cat-core/src/main/resources/META-INF/dal/model/config-codegen.xml
浏览文件 @
4ae45bfb
...
...
@@ -2,6 +2,7 @@
<model>
<entity
name=
"config"
root=
"true"
>
<attribute
name=
"mode"
value-type=
"String"
/>
<attribute
name=
"enabled"
value-type=
"boolean"
/>
<entity-ref
name=
"server"
type=
"list"
names=
"servers"
xml-indent=
"true"
/>
<entity-ref
name=
"domain"
type=
"list"
names=
"domains"
/>
<entity-ref
name=
"bind"
/>
...
...
cat-core/src/main/resources/META-INF/dal/model/config-model.xml
浏览文件 @
4ae45bfb
...
...
@@ -4,6 +4,7 @@
enable-xml-schema=
"true"
enable-merger=
"true"
>
<entity
name=
"config"
root=
"true"
dynamic-attributes=
"true"
>
<attribute
name=
"mode"
required=
"true"
/>
<attribute
name=
"enabled"
value-type=
"boolean"
/>
<element
name=
"base-log-dir"
value-type=
"String"
default-value=
"target/catlog"
/>
<entity-ref
name=
"domain"
type=
"map"
names=
"domains"
/>
<entity-ref
name=
"property"
type=
"map"
names=
"properties"
/>
...
...
cat-core/src/test/resources/com/dianping/cat/message/configuration/config.xml
浏览文件 @
4ae45bfb
<config
mode=
"client"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema"
xsi:noNamespaceSchemaLocation=
"config.xsd"
>
<config
mode=
"client"
enabled=
"true"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema"
xsi:noNamespaceSchemaLocation=
"config.xsd"
>
<servers>
<server
ip=
"192.168.8.21"
port=
"2280"
enabled=
"true"
/>
<server
ip=
"192.168.8.22"
port=
"2281"
enabled=
"false"
/>
...
...
cat-home/src/main/java/com/dianping/cat/Server.java
浏览文件 @
4ae45bfb
...
...
@@ -86,11 +86,12 @@ public class Server extends SimpleServerSupport {
@Override
protected
void
postConfigure
(
Context
ctx
)
{
ServletHolder
holder
=
new
ServletHolder
(
s_mvc
);
ServletHolder
mvc
=
new
ServletHolder
(
s_mvc
);
mvc
.
setInitParameter
(
"cat-client-xml"
,
"/data/appdatas/cat/client.xml"
);
ctx
.
addServlet
(
new
ServletHolder
(
s_cat
),
"/s/*"
);
ctx
.
addServlet
(
holder
,
"/"
);
ctx
.
addServlet
(
holder
,
"/r/*"
);
ctx
.
addServlet
(
mvc
,
"/"
);
ctx
.
addServlet
(
mvc
,
"/r/*"
);
ctx
.
addFilter
(
GzipFilter
.
class
,
"/r/*"
,
Handler
.
ALL
);
super
.
postConfigure
(
ctx
);
}
...
...
cat-home/src/main/webapp/WEB-INF/web.xml
浏览文件 @
4ae45bfb
...
...
@@ -6,6 +6,10 @@
<servlet-name>
mvc-servlet
</servlet-name>
<servlet-class>
com.site.web.MVC
</servlet-class>
<load-on-startup>
2
</load-on-startup>
<init-param>
<param-name>
cat-client-xml
</param-name>
<param-value>
/data/appdatas/cat/client.xml
</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>
cat-servlet
</servlet-name>
...
...
cat-home/src/test/java/com/dianping/cat/TestServer.java
浏览文件 @
4ae45bfb
...
...
@@ -89,11 +89,12 @@ public class TestServer extends SimpleServerSupport {
@Override
protected
void
postConfigure
(
Context
ctx
)
{
ServletHolder
holder
=
new
ServletHolder
(
s_mvc
);
ServletHolder
mvc
=
new
ServletHolder
(
s_mvc
);
mvc
.
setInitParameter
(
"cat-client-xml"
,
"/data/appdatas/cat/client.xml"
);
ctx
.
addServlet
(
new
ServletHolder
(
s_cat
),
"/s/*"
);
ctx
.
addServlet
(
holder
,
"/"
);
ctx
.
addServlet
(
holder
,
"/r/*"
);
ctx
.
addServlet
(
mvc
,
"/"
);
ctx
.
addServlet
(
mvc
,
"/r/*"
);
ctx
.
addFilter
(
GzipFilter
.
class
,
"/r/*"
,
Handler
.
ALL
);
super
.
postConfigure
(
ctx
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录