Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦中观雨
cat
提交
f6f7908e
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,发现更多精彩内容 >>
提交
f6f7908e
编写于
8月 05, 2014
作者:
L
leon.li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add project and hostname refresh method
上级
d5b1c9c4
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
127 addition
and
28 deletion
+127
-28
cat-core/src/main/java/com/dianping/cat/service/HostinfoService.java
...c/main/java/com/dianping/cat/service/HostinfoService.java
+58
-13
cat-core/src/main/java/com/dianping/cat/service/ProjectService.java
...rc/main/java/com/dianping/cat/service/ProjectService.java
+59
-14
cat-home/src/main/resources/META-INF/plexus/components.xml
cat-home/src/main/resources/META-INF/plexus/components.xml
+10
-1
未找到文件。
cat-core/src/main/java/com/dianping/cat/service/HostinfoService.java
浏览文件 @
f6f7908e
...
...
@@ -6,10 +6,13 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.TimeUnit
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
org.unidal.dal.jdbc.DalException
;
import
org.unidal.helper.Threads
;
import
org.unidal.helper.Threads.Task
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
...
...
@@ -31,26 +34,26 @@ public class HostinfoService implements Initializable {
public
boolean
deleteHostinfo
(
Hostinfo
host
)
{
int
id
=
host
.
getId
();
Iterator
<
Entry
<
String
,
Hostinfo
>>
iterator
=
m_hostinfos
.
entrySet
().
iterator
();
String
ip
=
null
;
while
(
iterator
.
hasNext
())
{
Entry
<
String
,
Hostinfo
>
entry
=
iterator
.
next
();
Hostinfo
hostinfo
=
entry
.
getValue
();
if
(
hostinfo
.
getId
()
==
id
)
{
iterator
.
remove
();
ip
=
hostinfo
.
getIp
();
break
;
}
}
try
{
hostinfo
.
setKeyId
(
hostinfo
.
getId
()
);
m_hostinfoDao
.
deleteByPK
(
hostinfo
);
m_hostinfos
.
remove
(
ip
);
m_hostinfoDao
.
deleteByPK
(
host
);
return
true
;
}
catch
(
Exception
e
)
{
Cat
.
logError
(
"delete hostinfo error "
+
hostinfo
.
toString
(),
e
);
Cat
.
logError
(
"delete hostinfo error "
+
host
.
toString
(),
e
);
return
false
;
}
}
}
return
true
;
}
public
List
<
Hostinfo
>
findAll
()
throws
DalException
{
return
new
ArrayList
<
Hostinfo
>(
m_hostinfos
.
values
());
...
...
@@ -76,11 +79,18 @@ public class HostinfoService implements Initializable {
@Override
public
void
initialize
()
throws
InitializationException
{
Threads
.
forGroup
(
"Cat"
).
start
(
new
HostinfoReloadTask
());
}
public
void
refresh
()
{
try
{
List
<
Hostinfo
>
hostinfos
=
m_hostinfoDao
.
findAllIp
(
HostinfoEntity
.
READSET_FULL
);
synchronized
(
this
)
{
for
(
Hostinfo
hostinfo
:
hostinfos
)
{
m_hostinfos
.
put
(
hostinfo
.
getIp
(),
hostinfo
);
}
}
}
catch
(
DalException
e
)
{
Cat
.
logError
(
"initialize HostService error"
,
e
);
}
...
...
@@ -108,4 +118,39 @@ public class HostinfoService implements Initializable {
return
false
;
}
}
public
class
HostinfoReloadTask
implements
Task
{
@Override
public
void
run
()
{
boolean
active
=
true
;
while
(
active
)
{
try
{
refresh
();
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
"reload hostinfo error"
,
ex
);
}
try
{
TimeUnit
.
MINUTES
.
sleep
(
1
);
}
catch
(
InterruptedException
ex
)
{
Cat
.
logError
(
"reload hostinfo stop"
,
ex
);
active
=
false
;
}
}
}
@Override
public
String
getName
()
{
return
"hostinfo-reload"
;
}
@Override
public
void
shutdown
()
{
}
}
}
cat-core/src/main/java/com/dianping/cat/service/ProjectService.java
浏览文件 @
f6f7908e
...
...
@@ -6,10 +6,13 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.TimeUnit
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable
;
import
org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException
;
import
org.unidal.dal.jdbc.DalException
;
import
org.unidal.helper.Threads
;
import
org.unidal.helper.Threads.Task
;
import
org.unidal.lookup.annotation.Inject
;
import
com.dianping.cat.Cat
;
...
...
@@ -31,26 +34,27 @@ public class ProjectService implements Initializable {
public
boolean
deleteProject
(
Project
project
)
{
int
id
=
project
.
getId
();
Iterator
<
Entry
<
String
,
Project
>>
iterator
=
m_projects
.
entrySet
().
iterator
();
String
domainName
=
null
;
while
(
iterator
.
hasNext
())
{
Entry
<
String
,
Project
>
entry
=
iterator
.
next
();
Project
pro
=
entry
.
getValue
();
if
(
pro
.
getId
()
==
id
)
{
iterator
.
remove
();
domainName
=
pro
.
getDomain
();
break
;
}
}
try
{
pro
.
setKeyId
(
pro
.
getId
()
);
m_projectDao
.
deleteByPK
(
pro
);
m_projects
.
remove
(
domainName
);
m_projectDao
.
deleteByPK
(
project
);
return
true
;
}
catch
(
Exception
e
)
{
Cat
.
logError
(
"delete project error "
+
pro
.
toString
()
,
e
);
Cat
.
logError
(
"delete project error "
,
e
);
return
false
;
}
}
}
return
true
;
}
public
List
<
Project
>
findAll
()
throws
DalException
{
return
new
ArrayList
<
Project
>(
m_projects
.
values
());
...
...
@@ -66,21 +70,28 @@ public class ProjectService implements Initializable {
while
(
iterator
.
hasNext
())
{
Entry
<
String
,
Project
>
entry
=
iterator
.
next
();
Project
pro
=
entry
.
getValue
();
if
(
pro
.
getId
()
==
id
)
{
return
pro
;
}
}
return
new
Project
();
}
@Override
public
void
initialize
()
throws
InitializationException
{
Threads
.
forGroup
(
"Cat"
).
start
(
new
ProjectReloadTask
());
}
public
void
refresh
()
{
try
{
List
<
Project
>
projects
=
m_projectDao
.
findAll
(
ProjectEntity
.
READSET_FULL
);
synchronized
(
this
)
{
for
(
Project
project
:
projects
)
{
m_projects
.
put
(
project
.
getDomain
(),
project
);
}
}
}
catch
(
DalException
e
)
{
Cat
.
logError
(
"initialize ProjectService error"
,
e
);
}
...
...
@@ -108,4 +119,38 @@ public class ProjectService implements Initializable {
return
false
;
}
}
public
class
ProjectReloadTask
implements
Task
{
@Override
public
void
run
()
{
boolean
active
=
true
;
while
(
active
)
{
try
{
refresh
();
}
catch
(
Exception
ex
)
{
Cat
.
logError
(
"reload project error"
,
ex
);
}
try
{
TimeUnit
.
MINUTES
.
sleep
(
1
);
}
catch
(
InterruptedException
ex
)
{
Cat
.
logError
(
"reload project stop"
,
ex
);
active
=
false
;
}
}
}
@Override
public
String
getName
()
{
return
"project-reload"
;
}
@Override
public
void
shutdown
()
{
}
}
}
cat-home/src/main/resources/META-INF/plexus/components.xml
浏览文件 @
f6f7908e
...
...
@@ -3258,7 +3258,7 @@
<implementation>
com.dianping.cat.DomainManager
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.
core.dal.HostinfoDao
</role>
<role>
com.dianping.cat.
service.HostinfoService
</role>
</requirement>
<requirement>
<role>
com.dianping.cat.service.ProjectService
</role>
...
...
@@ -3268,6 +3268,15 @@
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.service.HostinfoService
</role>
<implementation>
com.dianping.cat.service.HostinfoService
</implementation>
<requirements>
<requirement>
<role>
com.dianping.cat.core.dal.HostinfoDao
</role>
</requirement>
</requirements>
</component>
<component>
<role>
com.dianping.cat.core.dal.HostinfoDao
</role>
<implementation>
com.dianping.cat.core.dal.HostinfoDao
</implementation>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录