Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
matrix
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mall
arch
matrix
Commits
5b62b80b
Commit
5b62b80b
authored
Feb 01, 2021
by
房斌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1等待时间,10ms 优化
2配置 ,url 不需要。引用公共的
parent
2e5d8dce
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
216 additions
and
89 deletions
+216
-89
ConfigCenter.java
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/monitor/config/ConfigCenter.java
+5
-18
RegistryServerSync.java
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/monitor/dubbo/service/RegistryServerSync.java
+28
-7
GracefullyShoutDown.java
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/service/GracefullyShoutDown.java
+33
-33
DubboCustomerDownHock.java
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/service/impl/DubboCustomerDownHock.java
+138
-28
MatrixGracefulShutDownAutoConfiguration.java
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/spring/boot/autoconfigure/MatrixGracefulShutDownAutoConfiguration.java
+12
-3
No files found.
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/monitor/config/ConfigCenter.java
View file @
5b62b80b
...
@@ -36,31 +36,18 @@ public class ConfigCenter {
...
@@ -36,31 +36,18 @@ public class ConfigCenter {
public
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConfigCenter
.
class
);
public
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConfigCenter
.
class
);
@Value
(
"${
admin
.registry.address:}"
)
@Value
(
"${
dubbo
.registry.address:}"
)
public
String
registryAddress
;
public
String
registryAddress
;
@Value
(
"${dubbo.protocol.name}"
)
@Value
(
"${admin.registry.group:dubbo}"
)
public
String
registryGroup
;
public
String
registryGroup
;
@Value
(
"${admin.config-center.group:dubbo}"
)
@Value
(
"${dubbo.registry.username:}"
)
public
String
configCenterGroup
;
@Value
(
"${admin.config-center.username:}"
)
public
String
username
;
public
String
username
;
@Value
(
"${
admin.config-center
.password:}"
)
@Value
(
"${
dubbo.registry
.password:}"
)
public
String
password
;
public
String
password
;
@Value
(
"${
admin.
patch:}"
)
@Value
(
"${
dubbo.monitor
patch:}"
)
public
String
patch
;
public
String
patch
;
public
URL
configCenterUrl
;
public
URL
registryUrl
;
public
URL
registryUrl
;
public
String
getRegistryGroup
()
{
return
registryGroup
;
}
public
void
setRegistryGroup
(
String
registryGroup
)
{
this
.
registryGroup
=
registryGroup
;
}
public
URL
getRegistryUrl
()
{
public
URL
getRegistryUrl
()
{
return
registryUrl
;
return
registryUrl
;
}
}
...
...
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/monitor/dubbo/service/RegistryServerSync.java
View file @
5b62b80b
...
@@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
...
@@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.atomic.AtomicLong
;
import
java.util.concurrent.atomic.AtomicLong
;
public
class
RegistryServerSync
implements
InitializingBean
,
DisposableBean
,
NotifyListener
,
CommandLineRunner
{
public
class
RegistryServerSync
extends
Observable
implements
InitializingBean
,
DisposableBean
,
NotifyListener
,
CommandLineRunner
{
public
RegistryServerSync
(
Registry
registry
)
{
public
RegistryServerSync
(
Registry
registry
)
{
this
.
registry
=
registry
;
this
.
registry
=
registry
;
}
}
...
@@ -73,7 +73,7 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
...
@@ -73,7 +73,7 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
* ConcurrentMap<category, ConcurrentMap<servicename, Map<MD5, URL>>>
* ConcurrentMap<category, ConcurrentMap<servicename, Map<MD5, URL>>>
* registryCache
* registryCache
*/
*/
private
final
ConcurrentMap
<
String
,
ConcurrentMap
<
String
,
Map
<
String
,
URL
>>>
registryCache
=
new
ConcurrentHashMap
<>();
private
final
ConcurrentMap
<
String
,
ConcurrentMap
<
String
,
Map
<
String
,
URL
>>>
registryCache
=
new
ConcurrentHashMap
<>();
// @Autowired
// @Autowired
public
Registry
registry
;
public
Registry
registry
;
...
@@ -83,6 +83,16 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
...
@@ -83,6 +83,16 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
return
registryCache
;
return
registryCache
;
}
}
volatile
boolean
signal
=
false
;
public
boolean
isSignal
()
{
return
signal
;
}
public
void
setSignal
(
boolean
signal
)
{
this
.
signal
=
signal
;
}
@Override
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
public
void
afterPropertiesSet
()
throws
Exception
{
logger
.
info
(
"Init Dubbo Admin Sync Cache..."
);
logger
.
info
(
"Init Dubbo Admin Sync Cache..."
);
...
@@ -119,15 +129,17 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
...
@@ -119,15 +129,17 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
String
group
=
url
.
getParameter
(
Constants
.
GROUP_KEY
);
String
group
=
url
.
getParameter
(
Constants
.
GROUP_KEY
);
String
version
=
url
.
getParameter
(
Constants
.
VERSION_KEY
);
String
version
=
url
.
getParameter
(
Constants
.
VERSION_KEY
);
// NOTE: group and version in empty protocol is *
// NOTE: group and version in empty protocol is *
if
(!
Constants
.
ANY_VALUE
.
equals
(
group
)
&&
!
Constants
.
ANY_VALUE
.
equals
(
version
))
{
if
(!
Constants
.
ANY_VALUE
.
equals
(
group
)
&&
!
Constants
.
ANY_VALUE
.
equals
(
version
))
{
//移除带版本的key
services
.
remove
(
url
.
getServiceKey
());
// services.remove(url.getServiceKey());
removeAndNotice
(
services
,
url
.
getServiceKey
());
}
else
{
}
else
{
for
(
Map
.
Entry
<
String
,
Map
<
String
,
URL
>>
serviceEntry
:
services
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
Map
<
String
,
URL
>>
serviceEntry
:
services
.
entrySet
())
{
String
service
=
serviceEntry
.
getKey
();
String
service
=
serviceEntry
.
getKey
();
if
(
Tool
.
getInterface
(
service
).
equals
(
url
.
getServiceInterface
())
if
(
Tool
.
getInterface
(
service
).
equals
(
url
.
getServiceInterface
())
&&
(
Constants
.
ANY_VALUE
.
equals
(
group
)
||
StringUtils
.
isEquals
(
group
,
Tool
.
getGroup
(
service
)))
&&
(
Constants
.
ANY_VALUE
.
equals
(
group
)
||
StringUtils
.
isEquals
(
group
,
Tool
.
getGroup
(
service
)))
&&
(
Constants
.
ANY_VALUE
.
equals
(
version
)
||
StringUtils
.
isEquals
(
version
,
Tool
.
getVersion
(
service
))))
{
&&
(
Constants
.
ANY_VALUE
.
equals
(
version
)
||
StringUtils
.
isEquals
(
version
,
Tool
.
getVersion
(
service
))))
{
services
.
remove
(
service
);
//版本 和分组匹配就干掉?
services
.
remove
(
service
);
//如果版本和分组匹配就干掉
removeAndNotice
(
services
,
service
);
}
}
}
}
}
}
...
@@ -141,7 +153,7 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
...
@@ -141,7 +153,7 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
services
=
new
HashMap
<>();
services
=
new
HashMap
<>();
categories
.
put
(
category
,
services
);
categories
.
put
(
category
,
services
);
}
}
String
service
=
url
.
getServiceKey
();
String
service
=
url
.
getServiceKey
();
//带版本
Map
<
String
,
URL
>
ids
=
services
.
get
(
service
);
Map
<
String
,
URL
>
ids
=
services
.
get
(
service
);
if
(
ids
==
null
)
{
if
(
ids
==
null
)
{
ids
=
new
HashMap
<>();
ids
=
new
HashMap
<>();
...
@@ -171,7 +183,8 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
...
@@ -171,7 +183,8 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
Set
<
String
>
keys
=
new
HashSet
<
String
>(
services
.
keySet
());
Set
<
String
>
keys
=
new
HashSet
<
String
>(
services
.
keySet
());
for
(
String
key
:
keys
)
{
//接口
for
(
String
key
:
keys
)
{
//接口
if
(
Tool
.
getInterface
(
key
).
equals
(
interfaceName
)
&&
!
categoryEntry
.
getValue
().
entrySet
().
contains
(
key
))
{
if
(
Tool
.
getInterface
(
key
).
equals
(
interfaceName
)
&&
!
categoryEntry
.
getValue
().
entrySet
().
contains
(
key
))
{
services
.
remove
(
key
);
// services.remove(key);
removeAndNotice
(
services
,
key
);
}
}
}
}
}
}
...
@@ -219,5 +232,13 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
...
@@ -219,5 +232,13 @@ public class RegistryServerSync implements InitializingBean, DisposableBean, Not
}
}
}
}
public
void
removeAndNotice
(
ConcurrentMap
<
String
,
Map
<
String
,
URL
>>
services
,
String
serviceKey
){
services
.
remove
(
serviceKey
);
if
(
signal
)
{
this
.
setChanged
();
this
.
notifyObservers
(
serviceKey
);
}
}
}
}
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/service/GracefullyShoutDown.java
View file @
5b62b80b
...
@@ -7,6 +7,7 @@ import com.secoo.mall.common.util.date.DateUtil;
...
@@ -7,6 +7,7 @@ import com.secoo.mall.common.util.date.DateUtil;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetail
;
import
com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetail
;
import
com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetails
;
import
com.secoo.mall.common.core.bean.gracefulshowtdownBean.ExecutorDetails
;
import
com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync
;
import
com.secoo.mall.dubbo.service.impl.TomcatConnectShoutDownHock
;
import
com.secoo.mall.dubbo.service.impl.TomcatConnectShoutDownHock
;
import
org.apache.dubbo.common.utils.NetUtils
;
import
org.apache.dubbo.common.utils.NetUtils
;
import
org.apache.dubbo.config.DubboShutdownHook
;
import
org.apache.dubbo.config.DubboShutdownHook
;
...
@@ -34,6 +35,8 @@ public class GracefullyShoutDown implements CommandLineRunner, ApplicationListen
...
@@ -34,6 +35,8 @@ public class GracefullyShoutDown implements CommandLineRunner, ApplicationListen
private
ApplicationContext
context
;
private
ApplicationContext
context
;
// private ProviderService providerService ;
// private ProviderService providerService ;
RegistryServerSync
registryServerSync
;
UpDatas
dubboUpdata
;
UpDatas
dubboUpdata
;
// public GracefullyShoutDown(TomcatConnectShoutDownHock tomcatConnectShoutDownHock,ProviderService providerService,UpDatas dubboUpdata){
// public GracefullyShoutDown(TomcatConnectShoutDownHock tomcatConnectShoutDownHock,ProviderService providerService,UpDatas dubboUpdata){
...
@@ -62,28 +65,29 @@ public class GracefullyShoutDown implements CommandLineRunner, ApplicationListen
...
@@ -62,28 +65,29 @@ public class GracefullyShoutDown implements CommandLineRunner, ApplicationListen
}
}
//test-------------------------------------> begin
//test-------------------------------------> begin
//
ExecutorDetails result = new ExecutorDetails();
ExecutorDetails
result
=
new
ExecutorDetails
();
//
result.setCode(0);
result
.
setCode
(
0
);
//
List<ExecutorDetail> details = new ArrayList<ExecutorDetail>();
List
<
ExecutorDetail
>
details
=
new
ArrayList
<
ExecutorDetail
>();
//
result.setT(details);
result
.
setT
(
details
);
//
String ip = NetUtils.getIpByHost(NetUtils.getLocalAddress().getHostName());
String
ip
=
NetUtils
.
getIpByHost
(
NetUtils
.
getLocalAddress
().
getHostName
());
//
String name = ApplicationModel.getApplication();
String
name
=
ApplicationModel
.
getApplication
();
//
result.setIp(ip);
result
.
setIp
(
ip
);
//
result.setName(name);
result
.
setName
(
name
);
//
//
Map<String, StopService> map = this.context.getBeansOfType(StopService.class);
Map
<
String
,
StopService
>
map
=
this
.
context
.
getBeansOfType
(
StopService
.
class
);
//
if (map != null && map.size() > 0) {
if
(
map
!=
null
&&
map
.
size
()
>
0
)
{
//
Set<StopService> ts = new TreeSet<StopService>();
Set
<
StopService
>
ts
=
new
TreeSet
<
StopService
>();
//
for (StopService service : map.values()) {
for
(
StopService
service
:
map
.
values
())
{
//
if (!(service instanceof TomcatConnectShoutDownHock)) {
if
(!(
service
instanceof
TomcatConnectShoutDownHock
))
{
//
ts.add(service);
ts
.
add
(
service
);
//
}
}
//
}
}
//
//按定义顺序执行
//按定义顺序执行
//
Iterator<StopService> it = ts.iterator();
Iterator
<
StopService
>
it
=
ts
.
iterator
();
//
while (it.hasNext()) {
while
(
it
.
hasNext
())
{
//
StopService service = (StopService) it.next();
StopService
service
=
(
StopService
)
it
.
next
();
// ExecutorDetail one = (ExecutorDetail) service.stop();
// ExecutorDetail one = (ExecutorDetail) service.stop();
// if (one != null) {
// if (one != null) {
// details.add(one);
// details.add(one);
...
@@ -91,21 +95,17 @@ public class GracefullyShoutDown implements CommandLineRunner, ApplicationListen
...
@@ -91,21 +95,17 @@ public class GracefullyShoutDown implements CommandLineRunner, ApplicationListen
// result.setCode(-1);
// result.setCode(-1);
// }
// }
// }
// }
//
// }
// } catch (Exception e) {
// LoggerUtil.error("matrix.GracefullyShoutDown.error", e);
// }
// try {
// dubboUpdata.upData(result);
// } catch (Exception e) {
// LoggerUtil.error("matrix.GracefullyShoutDown update .error data:" + JSON.toJSONString(result), e);
// }
// }
}
try
{
dubboUpdata
.
upData
(
result
);
}
catch
(
Exception
e
)
{
LoggerUtil
.
error
(
"matrix.GracefullyShoutDown update .error data:"
+
JSON
.
toJSONString
(
result
),
e
);
}
//test------------------------------------->
//test------------------------------------->
}
}
}
...
...
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/service/impl/DubboCustomerDownHock.java
View file @
5b62b80b
...
@@ -6,6 +6,7 @@ import com.secoo.mall.common.util.date.DateUtil;
...
@@ -6,6 +6,7 @@ import com.secoo.mall.common.util.date.DateUtil;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.util.log.LoggerUtil
;
import
com.secoo.mall.common.util.string.StringUtil
;
import
com.secoo.mall.common.util.string.StringUtil
;
import
com.secoo.mall.dubbo.monitor.dubbo.service.ProviderService
;
import
com.secoo.mall.dubbo.monitor.dubbo.service.ProviderService
;
import
com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync
;
import
com.secoo.mall.dubbo.monitor.utils.Stack
;
import
com.secoo.mall.dubbo.monitor.utils.Stack
;
import
com.secoo.mall.dubbo.service.AbstractStop
;
import
com.secoo.mall.dubbo.service.AbstractStop
;
import
org.apache.dubbo.common.URL
;
import
org.apache.dubbo.common.URL
;
...
@@ -24,28 +25,43 @@ import org.slf4j.LoggerFactory;
...
@@ -24,28 +25,43 @@ import org.slf4j.LoggerFactory;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.*
;
public
class
DubboCustomerDownHock
extends
AbstractStop
{
public
class
DubboCustomerDownHock
extends
AbstractStop
implements
Observer
{
//@Autowired
private
ProviderService
providerService
;
private
ProviderService
providerService
;
RegistryServerSync
registryServerSync
;
public
RegistryServerSync
getRegistryServerSync
()
{
return
registryServerSync
;
}
public
void
setRegistryServerSync
(
RegistryServerSync
registryServerSync
)
{
this
.
registryServerSync
=
registryServerSync
;
}
public
DubboCustomerDownHock
(
ProviderService
providerService
)
{
public
DubboCustomerDownHock
(
ProviderService
providerService
)
{
this
.
providerService
=
providerService
;
this
.
providerService
=
providerService
;
}
}
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
this
.
getClass
());
private
volatile
boolean
check
=
false
;
Map
<
String
,
Boolean
>
checkContent
=
new
HashMap
<
String
,
Boolean
>();
//string 是key boolean 代表是否查找了
String
ip
;
String
name
;
@Override
@Override
public
ExecutorDetail
stop
()
{
public
ExecutorDetail
stop
()
{
ExecutorDetail
detail
=
new
ExecutorDetail
();
ExecutorDetail
detail
=
new
ExecutorDetail
();
detail
.
setBeginTime
(
DateUtil
.
getDateTime
());
detail
.
setBeginTime
(
DateUtil
.
getDateTime
());
detail
.
setServiceName
(
"dubboDownHock10
25
"
);
detail
.
setServiceName
(
"dubboDownHock10
38
"
);
List
<
String
>
str
=
new
ArrayList
<
String
>();
List
<
String
>
str
=
new
ArrayList
<
String
>();
detail
.
setDetail
(
str
);
detail
.
setDetail
(
str
);
detail
.
setCode
(
0
);
detail
.
setCode
(
0
);
String
ip
=
NetUtils
.
getIpByHost
(
NetUtils
.
getLocalAddress
().
getHostName
());
ip
=
NetUtils
.
getIpByHost
(
NetUtils
.
getLocalAddress
().
getHostName
());
String
name
=
ApplicationModel
.
getApplication
();
name
=
ApplicationModel
.
getApplication
();
try
{
try
{
Collection
<
Registry
>
registries
=
AbstractRegistryFactory
.
getRegistries
();
Collection
<
Registry
>
registries
=
AbstractRegistryFactory
.
getRegistries
();
...
@@ -69,11 +85,15 @@ public class DubboCustomerDownHock extends AbstractStop {
...
@@ -69,11 +85,15 @@ public class DubboCustomerDownHock extends AbstractStop {
str
.
add
(
"provider url executer unregister before:"
+
value
.
getServiceInterface
()
+
" time:"
+
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss:SSS"
).
format
(
new
Date
())
+
StringUtil
.
line
());
str
.
add
(
"provider url executer unregister before:"
+
value
.
getServiceInterface
()
+
" time:"
+
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss:SSS"
).
format
(
new
Date
())
+
StringUtil
.
line
());
// throw new IllegalStateException("failed to tet");
// throw new IllegalStateException("failed to tet");
zookperRegster
.
unregister
((
URL
)
value
);
zookperRegster
.
unregister
((
URL
)
value
);
registryServerSync
.
setSignal
(
true
);
LoggerUtil
.
info
(
"provider url unregister success :"
+
value
.
getServiceInterface
()
+
" time:"
+
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss:SSS"
).
format
(
new
Date
())
+
StringUtil
.
line
());
LoggerUtil
.
info
(
"provider url unregister success :"
+
value
.
getServiceInterface
()
+
" time:"
+
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss:SSS"
).
format
(
new
Date
())
+
StringUtil
.
line
());
str
.
add
(
"delete provider url success:"
+
value
.
getServiceInterface
()
+
" time:"
+
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss:SSS"
).
format
(
new
Date
())
+
StringUtil
.
line
());
str
.
add
(
"delete provider url success:"
+
value
.
getServiceInterface
()
+
" time:"
+
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss:SSS"
).
format
(
new
Date
())
+
StringUtil
.
line
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LoggerUtil
.
error
(
"matirx-monitor deleteService error:"
,
e
);
LoggerUtil
.
error
(
"matirx-monitor deleteService error:"
,
e
);
str
.
add
(
"matirx-monitor delete Service error service:"
+
value
.
getServiceInterface
()
+
StringUtil
.
line
()
+
Stack
.
errInfo
(
e
)+
StringUtil
.
line
());
str
.
add
(
"matirx-monitor delete Service error service:"
+
value
.
getServiceInterface
()
+
StringUtil
.
line
()
+
Stack
.
errInfo
(
e
)+
StringUtil
.
line
());
}
finally
{
registryServerSync
.
setSignal
(
true
);
}
}
}
}
}
else
{
}
else
{
...
@@ -88,31 +108,17 @@ public class DubboCustomerDownHock extends AbstractStop {
...
@@ -88,31 +108,17 @@ public class DubboCustomerDownHock extends AbstractStop {
}
}
//step3 check检查
//step3 check检查
if
(
checks
!=
null
&&
checks
.
size
()>
0
)
{
if
(
checks
!=
null
&&
checks
.
size
()>
0
)
{
//TODO 监听hashmap的数据变化
CuratorZookeeperClient
client
=
(
CuratorZookeeperClient
)
getFieldValueByFieldName
(
"zkClient"
,
zookperRegster
);
CuratorZookeeperClient
client
=
(
CuratorZookeeperClient
)
getFieldValueByFieldName
(
"zkClient"
,
zookperRegster
);
int
sessionExpireMs
=
client
.
getUrl
().
getParameter
(
"zk.session.expire"
,
10000
);
int
sessionExpireMs
=
client
.
getUrl
().
getParameter
(
"zk.session.expire"
,
6000
);
Thread
.
sleep
(
sessionExpireMs
);
//zookper 目前最大超时时间
long
startTime
=
System
.
currentTimeMillis
();
//获取开始时间
detail
=
checkNoticed
(
detail
,
str
,
checks
,
sessionExpireMs
);
//通过通知进行检查
for
(
URL
url
:
checks
)
{
long
endTime
=
System
.
currentTimeMillis
();
//获取结束时间
if
(
StringUtil
.
isNotEmpty
(
url
.
getAddress
())
&&
StringUtil
.
isNotEmpty
(
name
))
{
System
.
out
.
println
(
"程序运行时间------------>: "
+(
endTime
-
startTime
)+
"ms"
);
List
<
String
>
check
=
null
;
try
{
// throw new IllegalStateException("failed to tet");
check
=
providerService
.
findServicesByAddressAndName
(
url
.
getAddress
(),
name
);
}
catch
(
Exception
e
)
{
detail
.
setCode
(-
1
);
str
.
add
(
" error :matirx-monitor checko Dubbo service "
+
StringUtil
.
line
()+
Stack
.
errInfo
(
e
)
+
StringUtil
.
line
());
}
if
(
check
!=
null
&&
check
.
size
()
>
0
)
{
str
.
add
(
"warn:matrix-monitor check service failure "
+
url
.
getServiceKey
()
+
" reason zk notice failed "
+
StringUtil
.
line
());
detail
.
setCode
(-
1
);
}
else
{
if
(
check
!=
null
&&
check
.
size
()==
0
)
{
str
.
add
(
"matrix-monitor dubbo check service ok "
+
url
.
getServiceKey
()
+
StringUtil
.
line
());
}
}
if
(
checks
.
size
()
>
0
)
{
// 处理 没有接到通知的场景
logger
.
info
(
"NNNNNNNNNNNNNNNNNNNNNNNNOOOOOOOOOOOO!"
+
JSON
.
toJSONString
(
checks
));
for
(
URL
check
:
checks
)
{
checkService
(
check
,
checks
,
detail
,
str
);
}
}
}
}
}
else
{
}
else
{
...
@@ -173,4 +179,108 @@ public class DubboCustomerDownHock extends AbstractStop {
...
@@ -173,4 +179,108 @@ public class DubboCustomerDownHock extends AbstractStop {
}
}
@Override
public
void
update
(
Observable
o
,
Object
arg
)
{
logger
.
info
(
"result:"
+
arg
);
synchronized
(
checkContent
)
{
check
=
true
;
checkContent
.
put
((
String
)
arg
,
false
);
}
}
public
ExecutorDetail
checkNoticed
(
ExecutorDetail
detail
,
List
<
String
>
str
,
List
<
URL
>
checks
,
int
time
)
{
ExecutorService
es
=
Executors
.
newSingleThreadExecutor
();
Future
<
ExecutorDetail
>
future
=
es
.
submit
(
new
CheckDubbo
(
detail
,
str
,
checks
,
time
));
try
{
return
future
.
get
(
time
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
"matrix dubboshutdown check error"
,
e
);
}
catch
(
ExecutionException
e
)
{
logger
.
error
(
"matrix dubboshutdown check error"
,
e
);
}
catch
(
TimeoutException
e
)
{
logger
.
error
(
"matrix dubboshutdown check error"
,
e
);
}
finally
{
if
(
future
.
isDone
())
{
//TODO 结束线程,如何结束?
}
es
.
shutdownNow
();
}
return
detail
;
}
//检查服务逻辑
public
List
<
String
>
checkService
(
URL
url
,
List
<
URL
>
urls
,
ExecutorDetail
detail
,
List
<
String
>
content
)
{
List
<
String
>
result
=
null
;
try
{
// throw new IllegalStateException("failed to tet");
result
=
providerService
.
findServicesByAddressAndName
(
url
.
getAddress
(),
name
);
}
catch
(
Exception
e
)
{
urls
.
remove
(
url
);
detail
.
setCode
(-
1
);
content
.
add
(
" error :matirx-monitor checko Dubbo service "
+
StringUtil
.
line
()
+
Stack
.
errInfo
(
e
)
+
StringUtil
.
line
());
}
if
(
result
!=
null
&&
result
.
size
()
>
0
)
{
content
.
add
(
"warn:matrix-monitor check service failure "
+
url
.
getServiceKey
()
+
" reason zk notice failed "
+
StringUtil
.
line
());
detail
.
setCode
(-
1
);
}
else
{
if
(
result
!=
null
&&
result
.
size
()
==
0
)
{
content
.
add
(
"matrix-monitor dubbo check service ok "
+
url
.
getServiceKey
()
+
StringUtil
.
line
());
}
}
logger
.
info
(
"checkServicecheckServicecheckServicecheckServicecheckServicecheckServicecheckServicecheckService!!!!!"
);
return
result
;
}
private
class
CheckDubbo
implements
Callable
<
ExecutorDetail
>
{
ExecutorDetail
detail
;
List
<
String
>
str
;
List
<
URL
>
checks
;
int
time
;
public
CheckDubbo
(
ExecutorDetail
detail
,
List
<
String
>
str
,
List
<
URL
>
checks
,
int
time
)
{
this
.
detail
=
detail
;
this
.
str
=
str
;
this
.
checks
=
checks
;
this
.
time
=
time
;
}
/**
* Computes a result, or throws an exception if unable to do so.
*
* @return computed result
* @throws Exception if unable to compute a result
*/
@Override
public
ExecutorDetail
call
()
throws
Exception
{
long
beginTime
=
System
.
currentTimeMillis
();
//集合转换方便查找
Map
<
String
,
URL
>
allService
=
new
HashMap
<
String
,
URL
>();
for
(
URL
url
:
checks
)
{
allService
.
put
(
url
.
getServiceKey
(),
url
);
}
while
(
checks
.
size
()
>
0
&&(
System
.
currentTimeMillis
()-
beginTime
<
time
))
{
if
(
check
)
{
//根据通知去判断结果
for
(
Map
.
Entry
<
String
,
Boolean
>
entry
:
checkContent
.
entrySet
())
{
//循环遍历信号
String
notice
=
entry
.
getKey
();
URL
url
=
allService
.
get
(
notice
);
if
(
url
!=
null
&&
!
entry
.
getValue
())
{
//没检查,进行检查
entry
.
setValue
(
true
);
//查找完后不再查找
if
(
StringUtil
.
isNotEmpty
(
url
.
getAddress
())
&&
StringUtil
.
isNotEmpty
(
name
))
{
List
<
String
>
check
=
null
;
check
=
checkService
(
url
,
checks
,
detail
,
str
);
//检查服务去
checks
.
remove
(
url
);
//检查完后移除
logger
.
info
(
"remove------------------- url!!!!!"
+
url
.
getServiceInterface
());
}
}
}
}
Thread
.
sleep
(
500
);
//休息500毫秒
}
logger
.
info
(
"checks size!!!!!"
+
checks
.
size
());
return
detail
;
}
}
}
}
matrix-gracefulshutdown/src/main/java/com/secoo/mall/dubbo/spring/boot/autoconfigure/MatrixGracefulShutDownAutoConfiguration.java
View file @
5b62b80b
package
com
.
secoo
.
mall
.
dubbo
.
spring
.
boot
.
autoconfigure
;
package
com
.
secoo
.
mall
.
dubbo
.
spring
.
boot
.
autoconfigure
;
import
com.secoo.mall.common.core.service.UpDatas
;
import
com.secoo.mall.common.core.service.UpDatas
;
import
com.secoo.mall.common.util.string.StringUtil
;
import
com.secoo.mall.dubbo.monitor.config.ConfigCenter
;
import
com.secoo.mall.dubbo.monitor.config.ConfigCenter
;
import
com.secoo.mall.dubbo.monitor.dubbo.service.ProviderService
;
import
com.secoo.mall.dubbo.monitor.dubbo.service.ProviderService
;
import
com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync
;
import
com.secoo.mall.dubbo.monitor.dubbo.service.RegistryServerSync
;
...
@@ -39,21 +40,29 @@ public class MatrixGracefulShutDownAutoConfiguration {
...
@@ -39,21 +40,29 @@ public class MatrixGracefulShutDownAutoConfiguration {
DubboUpdata
transport
=
new
DubboUpdata
();
DubboUpdata
transport
=
new
DubboUpdata
();
URL
url
=
configCenter
.
formUrl
(
configCenter
.
registryAddress
,
configCenter
.
registryGroup
,
configCenter
.
username
,
configCenter
.
password
);
URL
url
=
configCenter
.
formUrl
(
configCenter
.
registryAddress
,
configCenter
.
registryGroup
,
configCenter
.
username
,
configCenter
.
password
);
transport
.
setUrl
(
url
);
transport
.
setUrl
(
url
);
if
(
StringUtil
.
isEmpty
(
configCenter
.
patch
)){
configCenter
.
patch
=
"/monitorZ"
;
}
transport
.
setPath
(
configCenter
.
patch
);
transport
.
setPath
(
configCenter
.
patch
);
return
transport
;
return
transport
;
}
}
@Bean
@Bean
@ConditionalOnClass
({
ProviderService
.
class
,
RegistryServerSync
.
class
})
@ConditionalOnExpression
(
"!T(org.springframework.util.StringUtils).isEmpty('${dubbo.registry.address:}')"
)
@ConditionalOnExpression
(
"!T(org.springframework.util.StringUtils).isEmpty('${dubbo.registry.address:}')"
)
DubboCustomerDownHock
createDubboConsumerDownHock
(
ProviderService
providerService
)
{
DubboCustomerDownHock
createDubboConsumerDownHock
(
ProviderService
providerService
,
RegistryServerSync
registryServerSync
)
{
return
new
DubboCustomerDownHock
(
providerService
);
DubboCustomerDownHock
hock
=
new
DubboCustomerDownHock
(
providerService
);
registryServerSync
.
addObserver
(
hock
);
hock
.
setRegistryServerSync
(
registryServerSync
);
return
hock
;
}
}
@Bean
@Bean
@ConditionalOnExpression
(
"!T(org.springframework.util.StringUtils).isEmpty('${dubbo.registry.address:}')"
)
@ConditionalOnExpression
(
"!T(org.springframework.util.StringUtils).isEmpty('${dubbo.registry.address:}')"
)
public
RegistryServerSync
createSynObject
(
Registry
registry
)
{
public
RegistryServerSync
createSynObject
(
Registry
registry
)
{
return
new
RegistryServerSync
(
registry
);
RegistryServerSync
r
=
new
RegistryServerSync
(
registry
);
return
r
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment