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
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
61 deletions
+78
-61
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
+0
-0
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
This diff is collapsed.
Click to expand it.
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