Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
aeaa7da8
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,发现更多精彩内容 >>
提交
aeaa7da8
编写于
2月 07, 2012
作者:
F
Frankie Wu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable unit test without CAT
上级
3742102c
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
72 addition
and
38 deletion
+72
-38
cat-core/src/main/java/com/dianping/cat/Cat.java
cat-core/src/main/java/com/dianping/cat/Cat.java
+6
-2
cat-core/src/main/java/com/dianping/cat/message/internal/DefaultMessageManager.java
.../dianping/cat/message/internal/DefaultMessageManager.java
+34
-12
cat-home/src/test/java/com/dianping/cat/SimpleServer.java
cat-home/src/test/java/com/dianping/cat/SimpleServer.java
+32
-24
未找到文件。
cat-core/src/main/java/com/dianping/cat/Cat.java
浏览文件 @
aeaa7da8
...
...
@@ -38,6 +38,7 @@ public class Cat {
if
(!
s_instance
.
m_initialized
)
{
try
{
s_instance
.
setContainer
(
new
DefaultPlexusContainer
());
s_instance
.
m_initialized
=
true
;
}
catch
(
PlexusContainerException
e
)
{
throw
new
RuntimeException
(
"Error when creating Plexus container, "
+
"please make sure the environment was setup correctly!"
,
e
);
...
...
@@ -87,6 +88,7 @@ public class Cat {
if
(
container
!=
null
)
{
if
(!
s_instance
.
m_initialized
)
{
s_instance
.
setContainer
(
container
);
s_instance
.
m_initialized
=
true
;
}
else
{
throw
new
RuntimeException
(
"Cat has already been initialized before!"
);
}
...
...
@@ -102,6 +104,10 @@ public class Cat {
}
}
public
static
boolean
isInitialized
()
{
return
s_instance
.
m_initialized
;
}
// this should be called when a thread ends to clean some thread local data
public
static
void
reset
()
{
getInstance
().
m_manager
.
reset
();
...
...
@@ -114,8 +120,6 @@ public class Cat {
}
void
setContainer
(
PlexusContainer
container
)
{
m_initialized
=
true
;
try
{
m_manager
=
(
MessageManager
)
container
.
lookup
(
MessageManager
.
class
);
}
catch
(
ComponentLookupException
e
)
{
...
...
cat-core/src/main/java/com/dianping/cat/message/internal/DefaultMessageManager.java
浏览文件 @
aeaa7da8
...
...
@@ -5,6 +5,10 @@ import java.net.UnknownHostException;
import
java.util.Stack
;
import
java.util.UUID
;
import
org.codehaus.plexus.logging.LogEnabled
;
import
org.codehaus.plexus.logging.Logger
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.configuration.model.entity.Config
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
...
...
@@ -15,7 +19,7 @@ import com.dianping.cat.message.spi.MessageTree;
import
com.dianping.cat.message.spi.internal.DefaultMessageTree
;
import
com.site.lookup.ContainerHolder
;
public
class
DefaultMessageManager
extends
ContainerHolder
implements
MessageManager
{
public
class
DefaultMessageManager
extends
ContainerHolder
implements
MessageManager
,
LogEnabled
{
private
TransportManager
m_manager
;
// we don't use static modifier since MessageManager is a singleton in
...
...
@@ -37,15 +41,28 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
private
String
m_ipAddress
;
private
Logger
m_logger
;
private
boolean
m_firstMessage
=
true
;
@Override
public
void
add
(
Message
message
)
{
if
(
Cat
.
isInitialized
())
{
getContext
().
add
(
this
,
message
);
}
}
@Override
public
void
enableLogging
(
Logger
logger
)
{
m_logger
=
logger
;
}
@Override
public
void
end
(
Transaction
transaction
)
{
if
(
Cat
.
isInitialized
())
{
getContext
().
end
(
this
,
transaction
);
}
}
void
flush
(
MessageTree
tree
)
{
if
(
m_manager
!=
null
)
{
...
...
@@ -62,11 +79,6 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
return
m_clientConfig
;
}
@Override
public
Config
getServerConfig
()
{
return
m_serverConfig
;
}
Context
getContext
()
{
Context
ctx
=
m_context
.
get
();
...
...
@@ -78,6 +90,11 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
}
}
@Override
public
Config
getServerConfig
()
{
return
m_serverConfig
;
}
@Override
public
void
initializeClient
(
Config
clientConfig
)
{
if
(
clientConfig
!=
null
)
{
...
...
@@ -123,7 +140,12 @@ public class DefaultMessageManager extends ContainerHolder implements MessageMan
@Override
public
void
start
(
Transaction
transaction
)
{
if
(
Cat
.
isInitialized
())
{
getContext
().
start
(
transaction
);
}
else
if
(
m_firstMessage
){
m_firstMessage
=
false
;
m_logger
.
warn
(
"CAT client is not enabled because it's not initialized yet"
);
}
}
static
class
Context
{
...
...
cat-home/src/test/java/com/dianping/cat/SimpleServer.java
浏览文件 @
aeaa7da8
...
...
@@ -36,11 +36,6 @@ public class SimpleServer extends SimpleServerSupport {
JettyTestSupport
.
startServer
(
new
SimpleServer
());
}
@Override
protected
File
getWarRoot
()
{
return
new
File
(
"src/main/webapp"
);
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SimpleServer
server
=
new
SimpleServer
();
...
...
@@ -70,19 +65,16 @@ public class SimpleServer extends SimpleServerSupport {
}
@Override
protected
void
postConfigure
(
Context
ctx
)
{
ServletHolder
holder
=
new
ServletHolder
(
s_mvc
);
ctx
.
addServlet
(
new
ServletHolder
(
s_cat
),
"/s/*"
);
ctx
.
addServlet
(
holder
,
"/"
);
ctx
.
addServlet
(
holder
,
"/r/*"
);
ctx
.
addFilter
(
GzipFilter
.
class
,
"/r/*"
,
Handler
.
ALL
);
super
.
postConfigure
(
ctx
);
protected
String
getContextPath
()
{
return
"/cat"
;
}
@Override
protected
String
getContextPath
()
{
return
"/cat"
;
protected
File
getScratchDir
()
{
File
work
=
new
File
(
System
.
getProperty
(
"java.io.tmpdir"
,
"."
),
"Cat"
);
work
.
mkdirs
();
return
work
;
}
@Override
...
...
@@ -90,6 +82,22 @@ public class SimpleServer extends SimpleServerSupport {
return
2281
;
}
@Override
protected
File
getWarRoot
()
{
return
new
File
(
"src/main/webapp"
);
}
@Override
protected
void
postConfigure
(
Context
ctx
)
{
ServletHolder
holder
=
new
ServletHolder
(
s_mvc
);
ctx
.
addServlet
(
new
ServletHolder
(
s_cat
),
"/s/*"
);
ctx
.
addServlet
(
holder
,
"/"
);
ctx
.
addServlet
(
holder
,
"/r/*"
);
ctx
.
addFilter
(
GzipFilter
.
class
,
"/r/*"
,
Handler
.
ALL
);
super
.
postConfigure
(
ctx
);
}
@Test
public
void
startServer
()
throws
Exception
{
// open the page in the default browser
...
...
@@ -118,15 +126,6 @@ public class SimpleServer extends SimpleServerSupport {
}
}
@Override
public
PlexusContainer
getContainer
()
{
return
super
.
getContainer
();
}
public
void
setServerPort
(
int
serverPort
)
{
m_serverPort
=
serverPort
;
}
public
void
display
(
String
requestUri
)
throws
Exception
{
StringBuilder
sb
=
new
StringBuilder
(
256
);
BrowserManager
manager
=
lookup
(
BrowserManager
.
class
);
...
...
@@ -140,6 +139,11 @@ public class SimpleServer extends SimpleServerSupport {
}
}
@Override
public
PlexusContainer
getContainer
()
{
return
super
.
getContainer
();
}
@Override
public
<
T
>
T
lookup
(
Class
<
T
>
role
)
throws
Exception
{
return
super
.
lookup
(
role
);
...
...
@@ -149,5 +153,9 @@ public class SimpleServer extends SimpleServerSupport {
public
<
T
>
T
lookup
(
Class
<
T
>
role
,
Object
roleHint
)
throws
Exception
{
return
super
.
lookup
(
role
,
roleHint
);
}
public
void
setServerPort
(
int
serverPort
)
{
m_serverPort
=
serverPort
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录