Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
3f9d6fd9
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,发现更多精彩内容 >>
提交
3f9d6fd9
编写于
5月 28, 2013
作者:
A
ainilife
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Client Side communication channel
上级
5d2a819f
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
142 addition
and
111 deletion
+142
-111
cat-core/src/main/java/com/dianping/cat/abtest/repository/ABTestEntityRepository.java
...ianping/cat/abtest/repository/ABTestEntityRepository.java
+4
-3
cat-core/src/main/java/com/dianping/cat/abtest/repository/DefaultABTestEntityRepository.java
.../cat/abtest/repository/DefaultABTestEntityRepository.java
+54
-9
cat-core/src/main/java/com/dianping/cat/abtest/repository/ProtocolMessage.java
...a/com/dianping/cat/abtest/repository/ProtocolMessage.java
+4
-0
cat-core/src/main/java/com/dianping/cat/abtest/repository/ProtocolNames.java
...ava/com/dianping/cat/abtest/repository/ProtocolNames.java
+13
-0
cat-core/src/main/java/com/dianping/cat/abtest/spi/ABTestEntity.java
...c/main/java/com/dianping/cat/abtest/spi/ABTestEntity.java
+34
-34
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/ABTestEntityManager.java
...dianping/cat/abtest/spi/internal/ABTestEntityManager.java
+1
-0
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestContextManager.java
.../cat/abtest/spi/internal/DefaultABTestContextManager.java
+0
-1
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestEntityManager.java
...g/cat/abtest/spi/internal/DefaultABTestEntityManager.java
+20
-54
cat-core/src/main/java/com/dianping/cat/build/ABTestComponentConfigurator.java
...a/com/dianping/cat/build/ABTestComponentConfigurator.java
+3
-2
cat-core/src/main/resources/META-INF/plexus/components.xml
cat-core/src/main/resources/META-INF/plexus/components.xml
+9
-8
未找到文件。
cat-core/src/main/java/com/dianping/cat/abtest/repository/ABTestEntityRepository.java
浏览文件 @
3f9d6fd9
package
com.dianping.cat.abtest.repository
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
com.dianping.cat.abtest.spi.ABTestEntity
;
public
interface
ABTestEntityRepository
{
public
List
<
ABTestEntity
>
getEntities
(
Date
from
,
Date
to
);
public
Map
<
Integer
,
ABTestEntity
>
getAllEntities
();
}
cat-core/src/main/java/com/dianping/cat/abtest/repository/DefaultABTestEntityRepository.java
浏览文件 @
3f9d6fd9
package
com.dianping.cat.abtest.repository
;
import
java.net.InetSocketAddress
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
org.codehaus.plexus.util.StringUtils
;
import
org.unidal.helper.Splitters
;
import
org.unidal.lookup.annotation.Inject
;
import
org.unidal.socket.MessageInboundHandler
;
import
org.unidal.socket.udp.UdpSocket
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.abtest.model.entity.AbtestModel
;
import
com.dianping.cat.abtest.model.entity.Case
;
import
com.dianping.cat.abtest.model.entity.Run
;
import
com.dianping.cat.abtest.model.transform.BaseVisitor
;
import
com.dianping.cat.abtest.model.transform.DefaultSaxParser
;
import
com.dianping.cat.abtest.spi.ABTestEntity
;
import
com.dianping.cat.configuration.ClientConfigManager
;
...
...
@@ -26,11 +33,11 @@ public class DefaultABTestEntityRepository implements ABTestEntityRepository, In
private
String
m_domain
;
private
List
<
ABTestEntity
>
m_entities
=
new
ArrayList
<
ABTestEntity
>();
private
Map
<
Integer
,
ABTestEntity
>
m_entities
=
new
HashMap
<
Integer
,
ABTestEntity
>();
@Override
public
List
<
ABTestEntity
>
getEntities
(
Date
from
,
Date
to
)
{
return
null
;
public
Map
<
Integer
,
ABTestEntity
>
getAllEntities
(
)
{
return
m_entities
;
}
@Override
...
...
@@ -42,6 +49,11 @@ public class DefaultABTestEntityRepository implements ABTestEntityRepository, In
m_socket
.
setCodec
(
new
ProtocolMessageCodec
());
m_socket
.
onMessage
(
new
ProtocolHandler
());
m_socket
.
listenOn
(
m_address
);
ProtocolMessage
hi
=
new
ProtocolMessage
();
hi
.
setName
(
ProtocolNames
.
HI
);
hi
.
addHeader
(
ProtocolNames
.
HEARTBEAT
,
m_domain
);
m_socket
.
send
(
hi
);
}
public
void
setAddress
(
String
address
)
{
...
...
@@ -59,12 +71,45 @@ public class DefaultABTestEntityRepository implements ABTestEntityRepository, In
public
void
handle
(
ProtocolMessage
message
)
{
String
name
=
message
.
getName
();
if
(
"hi"
.
equals
(
name
))
{
}
else
if
(
"heartbeat"
.
equals
(
name
))
{
List
<
ABTestEntity
>
entities
=
new
ArrayList
<
ABTestEntity
>();
if
(
ProtocolNames
.
HEARTBEAT
.
equalsIgnoreCase
(
name
))
{
String
content
=
message
.
getContent
();
if
(
StringUtils
.
isNotBlank
(
content
))
{
try
{
AbtestModel
abtest
=
DefaultSaxParser
.
parse
(
content
);
ABTestVisitor
visitor
=
new
ABTestVisitor
();
abtest
.
accept
(
visitor
);
m_entities
=
visitor
.
getEntities
();
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
}
}
}
}
}
class
ABTestVisitor
extends
BaseVisitor
{
private
Map
<
Integer
,
ABTestEntity
>
m_entities
;
public
ABTestVisitor
()
{
m_entities
=
new
HashMap
<
Integer
,
ABTestEntity
>();
}
m_entities
=
entities
;
@Override
public
void
visitCase
(
Case
_case
)
{
for
(
Run
run
:
_case
.
getRuns
())
{
// filter abtest-entities by domain
if
(
run
.
getDomains
()
!=
null
&&
run
.
getDomains
().
contains
(
m_domain
))
{
ABTestEntity
abTestEntity
=
new
ABTestEntity
(
_case
,
run
);
m_entities
.
put
(
abTestEntity
.
getId
(),
abTestEntity
);
}
}
}
public
Map
<
Integer
,
ABTestEntity
>
getEntities
()
{
return
m_entities
;
}
}
}
cat-core/src/main/java/com/dianping/cat/abtest/repository/ProtocolMessage.java
浏览文件 @
3f9d6fd9
...
...
@@ -15,6 +15,10 @@ public class ProtocolMessage implements Message {
public
String
getContent
()
{
return
m_content
;
}
public
void
addHeader
(
String
header
,
String
value
){
m_headers
.
put
(
header
,
value
);
}
public
Map
<
String
,
String
>
getHeaders
()
{
return
m_headers
;
...
...
cat-core/src/main/java/com/dianping/cat/abtest/repository/ProtocolNames.java
0 → 100644
浏览文件 @
3f9d6fd9
package
com.dianping.cat.abtest.repository
;
public
class
ProtocolNames
{
// protocol method
public
static
final
String
HI
=
"hi"
;
public
static
final
String
HEARTBEAT
=
"heartbeat"
;
// protocol headers
public
static
final
String
DOMAIN
=
"domain"
;
}
cat-core/src/main/java/com/dianping/cat/abtest/spi/ABTestEntity.java
浏览文件 @
3f9d6fd9
...
...
@@ -6,39 +6,37 @@ import com.dianping.cat.abtest.model.entity.Case;
import
com.dianping.cat.abtest.model.entity.Run
;
public
class
ABTestEntity
{
private
Case
m_case
;
private
int
m_id
;
private
String
m_name
;
private
String
m_groupStrategyName
;
private
Run
m_run
;
private
ABTestGroupStrategy
m_groupStrategy
;
public
ABTestEntity
()
{
m_case
=
new
Case
();
m_run
=
new
Run
();
m_run
.
setDisabled
(
true
);
}
public
ABTestEntity
(
Case
_case
,
Run
run
)
{
m_case
=
_case
;
m_id
=
_case
.
getId
();
m_name
=
_case
.
getName
();
m_groupStrategyName
=
_case
.
getGroupStrategy
();
m_run
=
run
;
}
public
String
getGroupStrategyName
()
{
return
m_
case
.
getGroupStrategy
()
!=
null
?
m_case
.
getGroupStrategy
()
:
null
;
return
m_
groupStrategyName
!=
null
?
m_groupStrategyName
:
null
;
}
public
String
getGroupStrategyConfiguration
()
{
return
m_run
.
getGroupStrategyConfiguration
()
!=
null
?
m_run
.
getGroupStrategyConfiguration
()
:
null
;
}
public
int
getId
()
{
return
m_case
.
getId
();
}
public
String
getName
()
{
return
m_case
.
getName
();
}
public
Date
getEndDate
()
{
return
m_run
.
getEndDate
();
}
...
...
@@ -77,22 +75,6 @@ public class ABTestEntity {
m_run
.
setDisabled
(
disabled
);
}
public
void
setGroupStrategyName
(
String
groupStrategy
)
{
m_case
.
setGroupStrategy
(
groupStrategy
);
}
public
void
setGroupStrategyConfiguration
(
String
groupStrategyConfiguration
)
{
m_run
.
setGroupStrategyConfiguration
(
groupStrategyConfiguration
);
}
public
void
setId
(
int
id
)
{
m_case
.
setId
(
id
);
}
public
void
setName
(
String
name
)
{
m_case
.
setName
(
name
);
}
public
ABTestGroupStrategy
getGroupStrategy
()
{
return
m_groupStrategy
;
}
...
...
@@ -100,18 +82,31 @@ public class ABTestEntity {
public
void
setGroupStrategy
(
ABTestGroupStrategy
groupStrategy
)
{
m_groupStrategy
=
groupStrategy
;
}
public
void
setId
(
int
id
){
m_id
=
id
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"%s[id=%s, name=%s, groupStrategy=%s, configuation=%s]"
,
getClass
().
getSimpleName
(),
getId
(),
getName
(),
getGroupStrategyName
(),
getGroupStrategyConfiguration
());
public
int
getId
()
{
return
m_id
;
}
public
String
getName
()
{
return
m_name
;
}
public
Run
getRun
()
{
return
m_run
;
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
getId
();
result
=
prime
*
result
+
((
m_groupStrategy
==
null
)
?
0
:
m_groupStrategy
.
hashCode
());
result
=
prime
*
result
+
((
m_groupStrategyName
==
null
)
?
0
:
m_groupStrategyName
.
hashCode
());
result
=
prime
*
result
+
m_id
;
result
=
prime
*
result
+
((
m_run
==
null
)
?
0
:
m_run
.
hashCode
());
return
result
;
}
...
...
@@ -129,4 +124,9 @@ public class ABTestEntity {
return
true
;
}
@Override
public
String
toString
()
{
return
"ABTestEntity [m_id="
+
m_id
+
", m_groupStrategyName="
+
m_groupStrategyName
+
", m_run="
+
m_run
+
", m_groupStrategy="
+
m_groupStrategy
+
"]"
;
}
}
\ No newline at end of file
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/ABTestEntityManager.java
浏览文件 @
3f9d6fd9
...
...
@@ -6,6 +6,7 @@ import com.dianping.cat.abtest.ABTestId;
import
com.dianping.cat.abtest.spi.ABTestEntity
;
public
interface
ABTestEntityManager
{
public
ABTestEntity
getEntity
(
ABTestId
id
);
public
List
<
ABTestEntity
>
getEntityList
();
...
...
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestContextManager.java
浏览文件 @
3f9d6fd9
...
...
@@ -134,5 +134,4 @@ public class DefaultABTestContextManager extends ContainerHolder implements ABTe
m_req
=
req
;
}
}
}
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestEntityManager.java
浏览文件 @
3f9d6fd9
package
com.dianping.cat.abtest.spi.internal
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
org.unidal.lookup.ContainerHolder
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.abtest.ABTestId
;
import
com.dianping.cat.abtest.model.entity.AbtestModel
;
import
com.dianping.cat.abtest.model.entity.Case
;
import
com.dianping.cat.abtest.model.entity.Run
;
import
com.dianping.cat.abtest.model.transform.BaseVisitor
;
import
com.dianping.cat.abtest.model.transform.DefaultSaxParser
;
import
com.dianping.cat.abtest.repository.ABTestEntityRepository
;
import
com.dianping.cat.abtest.spi.ABTestEntity
;
import
com.dianping.cat.abtest.spi.ABTestGroupStrategy
;
public
class
DefaultABTestEntityManager
extends
ContainerHolder
implements
ABTestEntityManager
,
Initializable
{
private
Map
<
Integer
,
ABTestEntity
>
m_entities
=
new
HashMap
<
Integer
,
ABTestEntity
>();
private
List
<
ABTestEntity
>
m_entityList
=
new
ArrayList
<
ABTestEntity
>();
@Inject
private
ABTestEntityRepository
m_repository
;
@Override
public
ABTestEntity
getEntity
(
ABTestId
id
)
{
ABTestEntity
entity
=
m_
entities
.
get
(
id
.
getValue
());
ABTestEntity
entity
=
m_
repository
.
getAllEntities
()
.
get
(
id
.
getValue
());
if
(
entity
==
null
)
{
entity
=
new
ABTestEntity
();
entity
.
setId
(
id
.
getValue
());
entity
.
setDisabled
(
true
);
m_
entities
.
put
(
id
.
getValue
(),
entity
);
m_
repository
.
getAllEntities
()
.
put
(
id
.
getValue
(),
entity
);
}
return
entity
;
}
@Override
public
List
<
ABTestEntity
>
getEntityList
()
{
return
m_entityList
;
List
<
ABTestEntity
>
entitiesList
=
new
ArrayList
<
ABTestEntity
>();
for
(
ABTestEntity
entity
:
m_repository
.
getAllEntities
().
values
())
{
entitiesList
.
add
(
entity
);
}
return
entitiesList
;
}
@Override
public
void
initialize
()
throws
InitializationException
{
try
{
InputStream
in
=
getClass
().
getResourceAsStream
(
"abtest.xml"
);
AbtestModel
abtest
=
DefaultSaxParser
.
parse
(
in
);
ABTestVisitor
visitor
=
new
ABTestVisitor
(
m_entities
,
m_entityList
);
abtest
.
accept
(
visitor
);
for
(
ABTestEntity
entity
:
m_entityList
)
{
try
{
ABTestGroupStrategy
groupStrategy
=
lookup
(
ABTestGroupStrategy
.
class
,
entity
.
getGroupStrategyName
());
entity
.
setGroupStrategy
(
groupStrategy
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
entity
.
setDisabled
(
true
);
}
for
(
ABTestEntity
entity
:
m_repository
.
getAllEntities
().
values
())
{
try
{
ABTestGroupStrategy
groupStrategy
=
lookup
(
ABTestGroupStrategy
.
class
,
entity
.
getGroupStrategyName
());
entity
.
setGroupStrategy
(
groupStrategy
);
}
catch
(
Exception
e
)
{
Cat
.
logError
(
e
);
entity
.
setDisabled
(
true
);
}
}
catch
(
Exception
e
)
{
throw
new
InitializationException
(
"Error when loading resource(abtest.xml)!"
,
e
);
}
}
static
class
ABTestVisitor
extends
BaseVisitor
{
private
Map
<
Integer
,
ABTestEntity
>
m_entities
;
private
List
<
ABTestEntity
>
m_entityList
;
public
ABTestVisitor
(
Map
<
Integer
,
ABTestEntity
>
entities
,
List
<
ABTestEntity
>
entityList
)
{
m_entities
=
entities
;
m_entityList
=
entityList
;
}
@Override
public
void
visitCase
(
Case
_case
)
{
for
(
Run
run
:
_case
.
getRuns
())
{
ABTestEntity
abTestEntity
=
new
ABTestEntity
(
_case
,
run
);
m_entities
.
put
(
abTestEntity
.
getId
(),
abTestEntity
);
m_entityList
.
add
(
abTestEntity
);
}
}
}
}
\ No newline at end of file
cat-core/src/main/java/com/dianping/cat/build/ABTestComponentConfigurator.java
浏览文件 @
3f9d6fd9
...
...
@@ -22,12 +22,13 @@ class ABTestComponentConfigurator extends AbstractResourceConfigurator {
all
.
add
(
C
(
ABTestContextManager
.
class
,
DefaultABTestContextManager
.
class
)
//
.
req
(
ABTestEntityManager
.
class
));
all
.
add
(
C
(
ABTestEntityManager
.
class
,
DefaultABTestEntityManager
.
class
));
all
.
add
(
C
(
ABTestEntityRepository
.
class
,
DefaultABTestEntityRepository
.
class
)
//
.
req
(
ClientConfigManager
.
class
)
//
.
config
(
E
(
"address"
).
value
(
"228.0.0.3:2283"
)));
all
.
add
(
C
(
ABTestEntityManager
.
class
,
DefaultABTestEntityManager
.
class
)
//
.
req
(
ABTestEntityRepository
.
class
));
return
all
;
}
}
cat-core/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
3f9d6fd9
...
...
@@ -312,12 +312,8 @@
</requirements>
</component>
<component>
<role>
com.dianping.cat.abtest.spi.internal.ABTestEntityManager
</role>
<implementation>
com.dianping.cat.abtest.spi.internal.DefaultABTestEntityManager
</implementation>
</component>
<component>
<role>
com.dianping.cat.abtest.spi.internal.ABTestEntityRepository
</role>
<implementation>
com.dianping.cat.abtest.spi.internal.DefaultABTestEntityRepository
</implementation>
<role>
com.dianping.cat.abtest.repository.ABTestEntityRepository
</role>
<implementation>
com.dianping.cat.abtest.repository.DefaultABTestEntityRepository
</implementation>
<configuration>
<address>
228.0.0.3:2283
</address>
</configuration>
...
...
@@ -325,9 +321,14 @@
<requirement>
<role>
com.dianping.cat.configuration.ClientConfigManager
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.abtest.spi.internal.ABTestEntityManager
</role>
<implementation>
com.dianping.cat.abtest.spi.internal.DefaultABTestEntityManager
</implementation>
<requirements>
<requirement>
<role>
org.unidal.socket.udp.UdpSocket
</role>
<role-hint>
abtest
</role-hint>
<role>
com.dianping.cat.abtest.repository.ABTestEntityRepository
</role>
</requirement>
</requirements>
</component>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录