Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
540bb42d
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,发现更多精彩内容 >>
提交
540bb42d
编写于
5月 24, 2013
作者:
W
wukezhu
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #61 from ainilife/master
Abtest Communication Channel initial
上级
76ac0de2
8ca4851f
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
269 addition
and
20 deletion
+269
-20
cat-core/pom.xml
cat-core/pom.xml
+1
-1
cat-core/src/main/java/com/dianping/cat/abtest/ABTestManager.java
.../src/main/java/com/dianping/cat/abtest/ABTestManager.java
+1
-1
cat-core/src/main/java/com/dianping/cat/abtest/internal/DefaultABTest.java
.../java/com/dianping/cat/abtest/internal/DefaultABTest.java
+1
-1
cat-core/src/main/java/com/dianping/cat/abtest/repository/ABTestEntityRepository.java
...ianping/cat/abtest/repository/ABTestEntityRepository.java
+10
-0
cat-core/src/main/java/com/dianping/cat/abtest/repository/DefaultABTestEntityRepository.java
.../cat/abtest/repository/DefaultABTestEntityRepository.java
+70
-0
cat-core/src/main/java/com/dianping/cat/abtest/repository/ProtocolMessage.java
...a/com/dianping/cat/abtest/repository/ProtocolMessage.java
+39
-0
cat-core/src/main/java/com/dianping/cat/abtest/repository/ProtocolMessageCodec.java
.../dianping/cat/abtest/repository/ProtocolMessageCodec.java
+81
-0
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/ABTestContextManager.java
...ianping/cat/abtest/spi/internal/ABTestContextManager.java
+2
-1
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/ABTestEntityManager.java
...dianping/cat/abtest/spi/internal/ABTestEntityManager.java
+2
-1
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestContextManager.java
.../cat/abtest/spi/internal/DefaultABTestContextManager.java
+0
-2
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestEntityManager.java
...g/cat/abtest/spi/internal/DefaultABTestEntityManager.java
+0
-1
cat-core/src/main/java/com/dianping/cat/build/ABTestComponentConfigurator.java
...a/com/dianping/cat/build/ABTestComponentConfigurator.java
+9
-2
cat-core/src/main/java/com/dianping/cat/configuration/ClientConfigManager.java
...a/com/dianping/cat/configuration/ClientConfigManager.java
+10
-5
cat-core/src/main/resources/META-INF/plexus/components.xml
cat-core/src/main/resources/META-INF/plexus/components.xml
+19
-3
cat-core/src/test/java/com/dianping/cat/abtest/demo/annotation/CookieGroupStrategy.java
...nping/cat/abtest/demo/annotation/CookieGroupStrategy.java
+23
-0
cat-core/src/test/java/com/dianping/cat/abtest/demo/roundrobin/ABTestServerConfigurator.java
.../cat/abtest/demo/roundrobin/ABTestServerConfigurator.java
+1
-1
cat-core/src/test/java/com/dianping/cat/abtest/spi/internal/DefaultABTestEntityManagerTest.java
...t/abtest/spi/internal/DefaultABTestEntityManagerTest.java
+0
-1
未找到文件。
cat-core/pom.xml
浏览文件 @
540bb42d
...
...
@@ -13,7 +13,7 @@
<dependency>
<groupId>
org.unidal.framework
</groupId>
<artifactId>
foundation-service
</artifactId>
<version>
2.0.
2
</version>
<version>
2.0.
3-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.jboss.netty
</groupId>
...
...
cat-core/src/main/java/com/dianping/cat/abtest/ABTestManager.java
浏览文件 @
540bb42d
...
...
@@ -5,7 +5,7 @@ import javax.servlet.http.HttpServletRequest;
import
org.unidal.lookup.ContainerLoader
;
import
com.dianping.cat.abtest.internal.DefaultABTest
;
import
com.dianping.cat.abtest.spi.ABTestContextManager
;
import
com.dianping.cat.abtest.spi.
internal.
ABTestContextManager
;
public
final
class
ABTestManager
{
private
static
ABTestContextManager
s_contextManager
;
...
...
cat-core/src/main/java/com/dianping/cat/abtest/internal/DefaultABTest.java
浏览文件 @
540bb42d
...
...
@@ -3,7 +3,7 @@ package com.dianping.cat.abtest.internal;
import
com.dianping.cat.abtest.ABTest
;
import
com.dianping.cat.abtest.ABTestId
;
import
com.dianping.cat.abtest.spi.ABTestContext
;
import
com.dianping.cat.abtest.spi.ABTestContextManager
;
import
com.dianping.cat.abtest.spi.
internal.
ABTestContextManager
;
public
class
DefaultABTest
implements
ABTest
{
private
ABTestContextManager
m_contextManager
;
...
...
cat-core/src/main/java/com/dianping/cat/abtest/repository/ABTestEntityRepository.java
0 → 100644
浏览文件 @
540bb42d
package
com.dianping.cat.abtest.repository
;
import
java.util.Date
;
import
java.util.List
;
import
com.dianping.cat.abtest.spi.ABTestEntity
;
public
interface
ABTestEntityRepository
{
public
List
<
ABTestEntity
>
getEntities
(
Date
from
,
Date
to
);
}
cat-core/src/main/java/com/dianping/cat/abtest/repository/DefaultABTestEntityRepository.java
0 → 100644
浏览文件 @
540bb42d
package
com.dianping.cat.abtest.repository
;
import
java.net.InetSocketAddress
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
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.abtest.spi.ABTestEntity
;
import
com.dianping.cat.configuration.ClientConfigManager
;
public
class
DefaultABTestEntityRepository
implements
ABTestEntityRepository
,
Initializable
{
@Inject
private
ClientConfigManager
m_configManager
;
@Inject
private
InetSocketAddress
m_address
=
new
InetSocketAddress
(
"228.0.0.3"
,
2283
);
private
UdpSocket
m_socket
;
private
String
m_domain
;
private
List
<
ABTestEntity
>
m_entities
=
new
ArrayList
<
ABTestEntity
>();
@Override
public
List
<
ABTestEntity
>
getEntities
(
Date
from
,
Date
to
)
{
return
null
;
}
@Override
public
void
initialize
()
throws
InitializationException
{
m_domain
=
m_configManager
.
getFirstDomain
().
getId
();
m_socket
=
new
UdpSocket
();
m_socket
.
setName
(
"ABTest"
);
m_socket
.
setCodec
(
new
ProtocolMessageCodec
());
m_socket
.
onMessage
(
new
ProtocolHandler
());
m_socket
.
listenOn
(
m_address
);
}
public
void
setAddress
(
String
address
)
{
List
<
String
>
parts
=
Splitters
.
by
(
':'
).
trim
().
split
(
address
);
int
len
=
parts
.
size
();
int
index
=
0
;
String
host
=
len
>
index
?
parts
.
get
(
index
++)
:
"228.0.0.3"
;
String
port
=
len
>
index
?
parts
.
get
(
index
++)
:
"2283"
;
m_address
=
new
InetSocketAddress
(
host
,
Integer
.
parseInt
(
port
));
}
class
ProtocolHandler
implements
MessageInboundHandler
<
ProtocolMessage
>
{
@Override
public
void
handle
(
ProtocolMessage
message
)
{
String
name
=
message
.
getName
();
if
(
"hi"
.
equals
(
name
))
{
}
else
if
(
"heartbeat"
.
equals
(
name
))
{
List
<
ABTestEntity
>
entities
=
new
ArrayList
<
ABTestEntity
>();
m_entities
=
entities
;
}
}
}
}
cat-core/src/main/java/com/dianping/cat/abtest/repository/ProtocolMessage.java
0 → 100644
浏览文件 @
540bb42d
package
com.dianping.cat.abtest.repository
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.unidal.socket.Message
;
public
class
ProtocolMessage
implements
Message
{
private
String
m_name
;
private
String
m_content
;
private
Map
<
String
,
String
>
m_headers
=
new
HashMap
<
String
,
String
>();
public
String
getContent
()
{
return
m_content
;
}
public
Map
<
String
,
String
>
getHeaders
()
{
return
m_headers
;
}
public
String
getName
()
{
return
m_name
;
}
public
void
setContent
(
String
content
)
{
m_content
=
content
;
}
public
void
setName
(
String
name
)
{
m_name
=
name
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"ProtocolMessage[name=%s, content=%s, headers=%s]"
,
m_name
,
m_content
,
m_headers
);
}
}
\ No newline at end of file
cat-core/src/main/java/com/dianping/cat/abtest/repository/ProtocolMessageCodec.java
0 → 100644
浏览文件 @
540bb42d
package
com.dianping.cat.abtest.repository
;
import
java.io.UnsupportedEncodingException
;
import
java.util.Map
;
import
org.jboss.netty.buffer.ChannelBuffer
;
import
org.jboss.netty.buffer.ChannelBuffers
;
import
org.unidal.socket.MessageCodec
;
public
class
ProtocolMessageCodec
implements
MessageCodec
<
ProtocolMessage
>
{
@Override
public
ProtocolMessage
decode
(
ChannelBuffer
buf
)
{
ProtocolMessage
message
=
new
ProtocolMessage
();
buf
.
readInt
();
// get rid of the place-holder
message
.
setName
(
readString
(
buf
));
message
.
setContent
(
readString
(
buf
));
while
(
buf
.
readable
())
{
String
key
=
readString
(
buf
);
String
value
=
readString
(
buf
);
message
.
getHeaders
().
put
(
key
,
value
);
}
return
message
;
}
@Override
public
ChannelBuffer
encode
(
ProtocolMessage
message
)
{
ChannelBuffer
buf
=
ChannelBuffers
.
dynamicBuffer
(
4096
);
buf
.
writeInt
(
0
);
// place-holder
writeString
(
buf
,
message
.
getName
());
writeString
(
buf
,
message
.
getContent
());
for
(
Map
.
Entry
<
String
,
String
>
e
:
message
.
getHeaders
().
entrySet
())
{
writeString
(
buf
,
e
.
getKey
());
writeString
(
buf
,
e
.
getValue
());
}
return
buf
;
}
private
String
readString
(
ChannelBuffer
buf
)
{
int
length
=
buf
.
readShort
();
if
(
length
==
-
1
)
{
return
null
;
}
else
{
byte
[]
bytes
=
new
byte
[
length
];
buf
.
readBytes
(
bytes
);
try
{
return
new
String
(
bytes
,
"utf-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
return
new
String
(
bytes
);
}
}
}
private
void
writeString
(
ChannelBuffer
buf
,
String
str
)
{
byte
[]
bytes
=
null
;
if
(
str
!=
null
)
{
try
{
bytes
=
str
.
getBytes
(
"utf-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
bytes
=
str
.
getBytes
();
}
}
if
(
bytes
==
null
)
{
buf
.
writeShort
(-
1
);
}
else
{
buf
.
writeShort
(
bytes
.
length
);
buf
.
writeBytes
(
bytes
);
}
}
}
\ No newline at end of file
cat-core/src/main/java/com/dianping/cat/abtest/spi/ABTestContextManager.java
→
cat-core/src/main/java/com/dianping/cat/abtest/spi/
internal/
ABTestContextManager.java
浏览文件 @
540bb42d
package
com.dianping.cat.abtest.spi
;
package
com.dianping.cat.abtest.spi
.internal
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
com.dianping.cat.abtest.ABTestId
;
import
com.dianping.cat.abtest.spi.ABTestContext
;
public
interface
ABTestContextManager
{
public
ABTestContext
getContext
(
ABTestId
testId
);
...
...
cat-core/src/main/java/com/dianping/cat/abtest/spi/ABTestEntityManager.java
→
cat-core/src/main/java/com/dianping/cat/abtest/spi/
internal/
ABTestEntityManager.java
浏览文件 @
540bb42d
package
com.dianping.cat.abtest.spi
;
package
com.dianping.cat.abtest.spi
.internal
;
import
java.util.List
;
import
com.dianping.cat.abtest.ABTestId
;
import
com.dianping.cat.abtest.spi.ABTestEntity
;
public
interface
ABTestEntityManager
{
public
ABTestEntity
getEntity
(
ABTestId
id
);
...
...
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestContextManager.java
浏览文件 @
540bb42d
...
...
@@ -13,9 +13,7 @@ import org.unidal.lookup.annotation.Inject;
import
com.dianping.cat.abtest.ABTestId
;
import
com.dianping.cat.abtest.spi.ABTestContext
;
import
com.dianping.cat.abtest.spi.ABTestContextManager
;
import
com.dianping.cat.abtest.spi.ABTestEntity
;
import
com.dianping.cat.abtest.spi.ABTestEntityManager
;
import
com.dianping.cat.abtest.spi.ABTestGroupStrategy
;
public
class
DefaultABTestContextManager
extends
ContainerHolder
implements
ABTestContextManager
{
...
...
cat-core/src/main/java/com/dianping/cat/abtest/spi/internal/DefaultABTestEntityManager.java
浏览文件 @
540bb42d
...
...
@@ -18,7 +18,6 @@ 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.abtest.spi.ABTestEntityManager
;
import
com.dianping.cat.abtest.spi.ABTestGroupStrategy
;
public
class
DefaultABTestEntityManager
extends
ContainerHolder
implements
ABTestEntityManager
,
Initializable
{
...
...
cat-core/src/main/java/com/dianping/cat/build/ABTestComponentConfigurator.java
浏览文件 @
540bb42d
...
...
@@ -6,10 +6,13 @@ import java.util.List;
import
org.unidal.lookup.configuration.AbstractResourceConfigurator
;
import
org.unidal.lookup.configuration.Component
;
import
com.dianping.cat.abtest.spi.ABTestContextManager
;
import
com.dianping.cat.abtest.spi.ABTestEntityManager
;
import
com.dianping.cat.abtest.repository.ABTestEntityRepository
;
import
com.dianping.cat.abtest.repository.DefaultABTestEntityRepository
;
import
com.dianping.cat.abtest.spi.internal.ABTestContextManager
;
import
com.dianping.cat.abtest.spi.internal.ABTestEntityManager
;
import
com.dianping.cat.abtest.spi.internal.DefaultABTestContextManager
;
import
com.dianping.cat.abtest.spi.internal.DefaultABTestEntityManager
;
import
com.dianping.cat.configuration.ClientConfigManager
;
class
ABTestComponentConfigurator
extends
AbstractResourceConfigurator
{
@Override
...
...
@@ -21,6 +24,10 @@ class ABTestComponentConfigurator extends AbstractResourceConfigurator {
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"
)));
return
all
;
}
}
cat-core/src/main/java/com/dianping/cat/configuration/ClientConfigManager.java
浏览文件 @
540bb42d
...
...
@@ -41,13 +41,18 @@ public class ClientConfigManager implements LogEnabled {
}
public
Domain
getFirstDomain
()
{
if
(
m_config
==
null
)
{
return
new
Domain
(
"UNKNOWN"
).
setEnabled
(
false
);
}
else
{
Domain
domain
=
null
;
if
(
m_config
!=
null
)
{
Map
<
String
,
Domain
>
domains
=
m_config
.
getDomains
();
Domain
firstDomain
=
domains
.
isEmpty
()
?
null
:
domains
.
values
().
iterator
().
next
();
return
firstDomain
;
domain
=
domains
.
isEmpty
()
?
null
:
domains
.
values
().
iterator
().
next
();
}
if
(
domain
!=
null
)
{
return
domain
;
}
else
{
return
new
Domain
(
"UNKNOWN"
).
setEnabled
(
false
);
}
}
...
...
cat-core/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
540bb42d
...
...
@@ -303,17 +303,33 @@
</requirements>
</component>
<component>
<role>
com.dianping.cat.abtest.spi.ABTestContextManager
</role>
<role>
com.dianping.cat.abtest.spi.
internal.
ABTestContextManager
</role>
<implementation>
com.dianping.cat.abtest.spi.internal.DefaultABTestContextManager
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.abtest.spi.ABTestEntityManager
</role>
<role>
com.dianping.cat.abtest.spi.
internal.
ABTestEntityManager
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.abtest.spi.ABTestEntityManager
</role>
<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>
<configuration>
<address>
228.0.0.3:2283
</address>
</configuration>
<requirements>
<requirement>
<role>
com.dianping.cat.configuration.ClientConfigManager
</role>
</requirement>
<requirement>
<role>
org.unidal.socket.udp.UdpSocket
</role>
<role-hint>
abtest
</role-hint>
</requirement>
</requirements>
</component>
</components>
</plexus>
cat-core/src/test/java/com/dianping/cat/abtest/demo/annotation/CookieGroupStrategy.java
0 → 100644
浏览文件 @
540bb42d
package
com.dianping.cat.abtest.demo.annotation
;
import
com.dianping.cat.abtest.annotation.Cookie
;
import
com.dianping.cat.abtest.spi.ABTestContext
;
import
com.dianping.cat.abtest.spi.ABTestGroupStrategy
;
public
class
CookieGroupStrategy
implements
ABTestGroupStrategy
{
@Cookie
(
"cityId"
)
private
String
cityId
;
@Override
public
void
apply
(
ABTestContext
ctx
)
{
if
(
cityId
.
equals
(
"default"
)){
}
else
{
ctx
.
setGroupName
(
"A"
);
}
}
}
cat-core/src/test/java/com/dianping/cat/abtest/demo/roundrobin/ABTestServerConfigurator.java
浏览文件 @
540bb42d
...
...
@@ -6,8 +6,8 @@ import java.util.List;
import
org.unidal.lookup.configuration.AbstractResourceConfigurator
;
import
org.unidal.lookup.configuration.Component
;
import
com.dianping.cat.abtest.spi.ABTestEntityManager
;
import
com.dianping.cat.abtest.spi.ABTestGroupStrategy
;
import
com.dianping.cat.abtest.spi.internal.ABTestEntityManager
;
import
com.dianping.cat.abtest.spi.internal.DefaultABTestEntityManager
;
public
class
ABTestServerConfigurator
extends
AbstractResourceConfigurator
{
...
...
cat-core/src/test/java/com/dianping/cat/abtest/spi/internal/DefaultABTestEntityManagerTest.java
浏览文件 @
540bb42d
...
...
@@ -9,7 +9,6 @@ import org.junit.Test;
import
org.unidal.lookup.ComponentTestCase
;
import
com.dianping.cat.abtest.spi.ABTestEntity
;
import
com.dianping.cat.abtest.spi.ABTestEntityManager
;
public
class
DefaultABTestEntityManagerTest
extends
ComponentTestCase
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录