Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
12be05d2
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,发现更多精彩内容 >>
提交
12be05d2
编写于
9月 22, 2013
作者:
A
ainilife
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor the abtest code.
上级
e8cc87bd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
36 addition
and
74 deletion
+36
-74
cat-client/src/main/java/com/dianping/cat/abtest/repository/FieldInjecter.java
...ava/com/dianping/cat/abtest/repository/FieldInjecter.java
+1
-2
cat-client/src/main/java/com/dianping/cat/abtest/repository/HttpABTestEntityRepository.java
...ing/cat/abtest/repository/HttpABTestEntityRepository.java
+11
-7
cat-client/src/main/java/com/dianping/cat/abtest/spi/ABTestEntity.java
...c/main/java/com/dianping/cat/abtest/spi/ABTestEntity.java
+18
-61
cat-client/src/main/java/com/dianping/cat/abtest/spi/ABTestGroupStrategy.java
...java/com/dianping/cat/abtest/spi/ABTestGroupStrategy.java
+2
-1
cat-client/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestContext.java
...ianping/cat/abtest/spi/internal/DefaultABTestContext.java
+3
-2
script/Cat.sql
script/Cat.sql
+1
-1
未找到文件。
cat-client/src/main/java/com/dianping/cat/abtest/repository/FieldInject
Util
.java
→
cat-client/src/main/java/com/dianping/cat/abtest/repository/FieldInject
er
.java
浏览文件 @
12be05d2
...
...
@@ -4,8 +4,7 @@ import com.dianping.cat.abtest.model.entity.Field;
import
com.dianping.cat.abtest.model.entity.GroupstrategyDescriptor
;
import
com.dianping.cat.abtest.spi.ABTestGroupStrategy
;
public
class
FieldInjectUtil
{
public
class
FieldInjecter
{
public
void
inject
(
ABTestGroupStrategy
targetGroupStrategy
,
GroupstrategyDescriptor
descriptor
)
throws
Exception
{
for
(
Field
field
:
descriptor
.
getFields
())
{
java
.
lang
.
reflect
.
Field
modifiersField
=
targetGroupStrategy
.
getClass
().
getDeclaredField
(
...
...
cat-client/src/main/java/com/dianping/cat/abtest/repository/HttpABTestEntityRepository.java
浏览文件 @
12be05d2
package
com.dianping.cat.abtest.repository
;
import
java.io.InputStream
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
...
...
@@ -29,6 +30,7 @@ import com.dianping.cat.abtest.spi.ABTestEntity;
import
com.dianping.cat.abtest.spi.ABTestGroupStrategy
;
import
com.dianping.cat.configuration.ClientConfigManager
;
import
com.dianping.cat.configuration.client.entity.Server
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
public
class
HttpABTestEntityRepository
extends
ContainerHolder
implements
ABTestEntityRepository
,
Initializable
,
Task
{
...
...
@@ -39,15 +41,15 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
@Inject
private
int
m_refreshTimeInSeconds
=
60
;
// seconds
private
Map
<
String
,
ABTestEntity
>
m_entities
=
new
Concurrent
HashMap
<
String
,
ABTestEntity
>();
private
Map
<
String
,
ABTestEntity
>
m_entities
=
new
HashMap
<
String
,
ABTestEntity
>();
private
Set
<
String
>
m_activeRuns
=
Collections
.
newSetFromMap
(
new
ConcurrentHashMap
<
String
,
Boolean
>()
);
private
Set
<
String
>
m_activeRuns
=
new
HashSet
<
String
>(
);
private
Map
<
Integer
,
ABTestGroupStrategy
>
m_strategies
=
new
ConcurrentHashMap
<
Integer
,
ABTestGroupStrategy
>();
private
Map
<
Integer
,
Invocable
>
m_invokeMap
=
new
ConcurrentHashMap
<
Integer
,
Invocable
>();
private
FieldInject
Util
m_fieldInjector
=
new
FieldInjectUtil
();
private
FieldInject
er
m_fieldInjector
=
new
FieldInjecter
();
private
ScriptEngineManager
m_mgr
;
...
...
@@ -105,6 +107,8 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
m_abtestModel
=
abtest
.
toString
();
break
;
}
t
.
setStatus
(
Message
.
SUCCESS
);
}
catch
(
Throwable
e
)
{
t
.
setStatus
(
e
);
Cat
.
logError
(
e
);
...
...
@@ -140,9 +144,9 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
class
ABTestVisitor
extends
BaseVisitor
{
private
String
m_domain
;
private
Map
<
String
,
ABTestEntity
>
m_entities
;
private
Map
<
String
,
ABTestEntity
>
m_entities
=
new
HashMap
<
String
,
ABTestEntity
>()
;
private
Set
<
String
>
m_activeRuns
;
private
Set
<
String
>
m_activeRuns
=
new
HashSet
<
String
>()
;
public
ABTestVisitor
(
String
domain
)
{
m_domain
=
domain
;
...
...
@@ -217,7 +221,7 @@ public class HttpABTestEntityRepository extends ContainerHolder implements ABTes
}
}
public
String
getAbtestModel
()
{
public
synchronized
String
getAbtestModel
()
{
return
m_abtestModel
;
}
...
...
cat-client/src/main/java/com/dianping/cat/abtest/spi/ABTestEntity.java
浏览文件 @
12be05d2
...
...
@@ -19,15 +19,15 @@ public class ABTestEntity {
private
Run
m_run
;
private
String
m_groupStrategyName
;
private
ABTestGroupStrategy
m_groupStrategy
;
private
Invocable
m_invocable
;
private
MessageManager
m_messageManager
;
private
ABTestCodec
m_cookieCodec
;
private
String
m_groupStrategyName
;
private
ABTestCodec
m_cookieCodec
;
public
ABTestEntity
()
{
m_run
=
new
Run
();
...
...
@@ -40,38 +40,6 @@ public class ABTestEntity {
m_run
=
run
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
ABTestEntity
other
=
(
ABTestEntity
)
obj
;
if
(
m_groupStrategy
==
null
)
{
if
(
other
.
m_groupStrategy
!=
null
)
return
false
;
}
else
if
(!
m_groupStrategy
.
equals
(
other
.
m_groupStrategy
))
return
false
;
if
(
m_groupStrategyName
==
null
)
{
if
(
other
.
m_groupStrategyName
!=
null
)
return
false
;
}
else
if
(!
m_groupStrategyName
.
equals
(
other
.
m_groupStrategyName
))
return
false
;
if
(
m_name
==
null
)
{
if
(
other
.
m_name
!=
null
)
return
false
;
}
else
if
(!
m_name
.
equals
(
other
.
m_name
))
return
false
;
if
(
m_run
==
null
)
{
if
(
other
.
m_run
!=
null
)
return
false
;
}
else
if
(!
m_run
.
equals
(
other
.
m_run
))
return
false
;
return
true
;
}
public
List
<
Condition
>
getConditions
()
{
return
m_run
.
getConditions
()
!=
null
?
m_run
.
getConditions
()
:
null
;
}
...
...
@@ -85,8 +53,8 @@ public class ABTestEntity {
}
public
ABTestCodec
getCookieCodec
()
{
return
m_cookieCodec
;
}
return
m_cookieCodec
;
}
public
Date
getEndDate
()
{
return
m_run
.
getEndDate
();
...
...
@@ -105,12 +73,12 @@ public class ABTestEntity {
}
public
Invocable
getInvocable
()
{
return
m_invocable
;
}
return
m_invocable
;
}
public
MessageManager
getMessageManager
()
{
return
m_messageManager
;
}
return
m_messageManager
;
}
public
String
getName
()
{
return
m_name
;
...
...
@@ -124,17 +92,6 @@ public class ABTestEntity {
return
m_run
.
getStartDate
();
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
m_groupStrategy
==
null
)
?
0
:
m_groupStrategy
.
hashCode
());
result
=
prime
*
result
+
((
m_groupStrategyName
==
null
)
?
0
:
m_groupStrategyName
.
hashCode
());
result
=
prime
*
result
+
((
m_name
==
null
)
?
0
:
m_name
.
hashCode
());
result
=
prime
*
result
+
((
m_run
==
null
)
?
0
:
m_run
.
hashCode
());
return
result
;
}
public
boolean
isDisabled
()
{
return
m_run
.
isDisabled
();
}
...
...
@@ -162,8 +119,8 @@ public class ABTestEntity {
}
public
void
setCookieCodec
(
ABTestCodec
cookieCodec
)
{
m_cookieCodec
=
cookieCodec
;
}
m_cookieCodec
=
cookieCodec
;
}
public
void
setDisabled
(
boolean
disabled
)
{
m_run
.
setDisabled
(
disabled
);
...
...
@@ -174,12 +131,12 @@ public class ABTestEntity {
}
public
void
setInvocable
(
Invocable
invocable
)
{
m_invocable
=
invocable
;
}
m_invocable
=
invocable
;
}
public
void
setMessageManager
(
MessageManager
messageManager
)
{
m_messageManager
=
messageManager
;
}
m_messageManager
=
messageManager
;
}
public
void
setName
(
String
name
)
{
m_name
=
name
;
...
...
cat-client/src/main/java/com/dianping/cat/abtest/spi/ABTestGroupStrategy.java
浏览文件 @
12be05d2
package
com.dianping.cat.abtest.spi
;
public
interface
ABTestGroupStrategy
{
public
void
apply
(
ABTestContext
ctx
);
public
void
init
();
public
void
apply
(
ABTestContext
ctx
);
}
\ No newline at end of file
cat-client/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestContext.java
浏览文件 @
12be05d2
...
...
@@ -104,15 +104,16 @@ public class DefaultABTestContext implements ABTestContext {
if
(
inv
!=
null
&&
m_entity
.
isEligible
(
new
Date
()))
{
boolean
isAccept
=
false
;
Transaction
t
=
Cat
.
newTransaction
(
"GroupStrategy"
,
m_entity
.
getGroupStrategyName
());
Transaction
t
=
Cat
.
newTransaction
(
"
ABTest-
GroupStrategy"
,
m_entity
.
getGroupStrategyName
());
try
{
isAccept
=
(
Boolean
)
inv
.
invokeFunction
(
"isEligible"
,
request
);
if
(
isAccept
)
{
m_groupStrategy
.
apply
(
this
);
t
.
setStatus
(
Message
.
SUCCESS
);
}
t
.
setStatus
(
Message
.
SUCCESS
);
}
catch
(
Throwable
e
)
{
t
.
setStatus
(
e
);
Cat
.
logError
(
e
);
...
...
script/Cat.sql
浏览文件 @
12be05d2
...
...
@@ -296,7 +296,7 @@ CREATE TABLE `abtest` (
`description`
varchar
(
512
)
DEFAULT
NULL
COMMENT
'描述'
,
PRIMARY
KEY
(
`id`
),
UNIQUE
KEY
`idx_name`
(
`name`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8
;
CREATE
TABLE
`abtest_report`
(
`id`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录