Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
2916681f
Commit
2916681f
authored
Jul 06, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重入读写分离锁改成高性能缓存Caffeine组件来代替
parent
8f72c9c2
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
123 additions
and
63 deletions
+123
-63
README.md
+1
-1
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/ConfigEndpoint.java
+8
-2
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigParser.java
+5
-10
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/cache/RuleCache.java
+56
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/configuration/PluginAutoConfiguration.java
+3
-10
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/configuration/PluginLoadBalanceConfiguration.java
+5
-4
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/constant/PluginConstant.java
+1
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/discovery/DiscoveryListenerExecutor.java
+0
-10
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/discovery/IpAddressFilterDiscoveryListener.java
+8
-1
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/discovery/VersionFilterDiscoveryListener.java
+7
-1
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/loadbalance/IpAddressFilterLoadBalanceListener.java
+8
-1
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/loadbalance/LoadBalanceListenerExecutor.java
+0
-10
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/loadbalance/VersionFilterLoadBalanceListener.java
+7
-1
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/CountFilterRegisterListener.java
+7
-1
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/IpAddressFilterRegisterListener.java
+7
-1
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/RegisterListenerExecutor.java
+0
-10
No files found.
README.md
View file @
2916681f
...
@@ -262,7 +262,7 @@ http://IP:[management.port]/config/send
...
@@ -262,7 +262,7 @@ http://IP:[management.port]/config/send
```
java
```
java
Java:
Java:
@RequestMapping
(
path
=
"view"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"view"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
String
>
view
()
public
ResponseEntity
<
?
>
view
()
Url:
Url:
http:
//IP:[management.port]/config/view
http:
//IP:[management.port]/config/view
...
...
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/ConfigEndpoint.java
View file @
2916681f
...
@@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.entity.RuleEntity
;
import
com.nepxion.discovery.plugin.framework.entity.RuleEntity
;
...
@@ -46,7 +47,7 @@ public class ConfigEndpoint implements MvcEndpoint {
...
@@ -46,7 +47,7 @@ public class ConfigEndpoint implements MvcEndpoint {
private
PluginPublisher
pluginPublisher
;
private
PluginPublisher
pluginPublisher
;
@Autowired
@Autowired
private
Rule
Entity
ruleEntity
;
private
Rule
Cache
ruleCache
;
// 推送规则配置信息
// 推送规则配置信息
@RequestMapping
(
path
=
"send"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"send"
,
method
=
RequestMethod
.
POST
)
...
@@ -76,7 +77,12 @@ public class ConfigEndpoint implements MvcEndpoint {
...
@@ -76,7 +77,12 @@ public class ConfigEndpoint implements MvcEndpoint {
@RequestMapping
(
path
=
"view"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"view"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
@ResponseBody
@ManagedOperation
@ManagedOperation
public
ResponseEntity
<
String
>
view
()
{
public
ResponseEntity
<?>
view
()
{
RuleEntity
ruleEntity
=
ruleCache
.
get
(
PluginConstant
.
RULE
);
if
(
ruleEntity
==
null
)
{
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"No config to view"
),
HttpStatus
.
OK
);
}
String
content
=
ruleEntity
.
getContent
();
String
content
=
ruleEntity
.
getContent
();
return
ResponseEntity
.
ok
().
body
(
content
);
return
ResponseEntity
.
ok
().
body
(
content
);
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigParser.java
View file @
2916681f
...
@@ -15,7 +15,6 @@ import java.util.Arrays;
...
@@ -15,7 +15,6 @@ import java.util.Arrays;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -27,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -27,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
com.nepxion.discovery.plugin.configcenter.constant.ConfigConstant
;
import
com.nepxion.discovery.plugin.configcenter.constant.ConfigConstant
;
import
com.nepxion.discovery.plugin.configcenter.xml.Dom4JParser
;
import
com.nepxion.discovery.plugin.configcenter.xml.Dom4JParser
;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
import
com.nepxion.discovery.plugin.framework.config.PluginConfigParser
;
import
com.nepxion.discovery.plugin.framework.config.PluginConfigParser
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.entity.CountEntity
;
import
com.nepxion.discovery.plugin.framework.entity.CountEntity
;
...
@@ -44,10 +44,7 @@ public class ConfigParser extends Dom4JParser implements PluginConfigParser {
...
@@ -44,10 +44,7 @@ public class ConfigParser extends Dom4JParser implements PluginConfigParser {
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ConfigParser
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ConfigParser
.
class
);
@Autowired
@Autowired
private
RuleEntity
ruleEntity
;
private
RuleCache
ruleCache
;
@Autowired
private
ReentrantReadWriteLock
reentrantReadWriteLock
;
@Override
@Override
public
void
parse
(
InputStream
inputStream
)
{
public
void
parse
(
InputStream
inputStream
)
{
...
@@ -99,15 +96,13 @@ public class ConfigParser extends Dom4JParser implements PluginConfigParser {
...
@@ -99,15 +96,13 @@ public class ConfigParser extends Dom4JParser implements PluginConfigParser {
}
}
String
text
=
getText
();
String
text
=
getText
();
try
{
reentrantReadWriteLock
.
writeLock
().
lock
();
RuleEntity
ruleEntity
=
new
RuleEntity
();
ruleEntity
.
setRegisterEntity
(
registerEntity
);
ruleEntity
.
setRegisterEntity
(
registerEntity
);
ruleEntity
.
setDiscoveryEntity
(
discoveryEntity
);
ruleEntity
.
setDiscoveryEntity
(
discoveryEntity
);
ruleEntity
.
setContent
(
text
);
ruleEntity
.
setContent
(
text
);
}
finally
{
reentrantReadWriteLock
.
writeLock
().
unlock
();
ruleCache
.
put
(
PluginConstant
.
RULE
,
ruleEntity
);
}
LOG
.
info
(
"Rule entity=\n{}"
,
ruleEntity
);
LOG
.
info
(
"Rule entity=\n{}"
,
ruleEntity
);
}
}
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/cache/RuleCache.java
0 → 100644
View file @
2916681f
package
com
.
nepxion
.
discovery
.
plugin
.
framework
.
cache
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
java.util.concurrent.TimeUnit
;
import
com.github.benmanes.caffeine.cache.CacheLoader
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
com.github.benmanes.caffeine.cache.LoadingCache
;
import
com.nepxion.discovery.plugin.framework.entity.RuleEntity
;
public
class
RuleCache
{
private
LoadingCache
<
String
,
RuleEntity
>
loadingCache
;
public
RuleCache
()
{
loadingCache
=
Caffeine
.
newBuilder
()
.
expireAfterWrite
(
365
*
100
,
TimeUnit
.
DAYS
)
.
initialCapacity
(
1
)
.
maximumSize
(
1
)
.
recordStats
()
.
build
(
new
CacheLoader
<
String
,
RuleEntity
>()
{
@Override
public
RuleEntity
load
(
String
key
)
throws
Exception
{
return
null
;
}
});
}
public
boolean
put
(
String
key
,
RuleEntity
ruleEntity
)
{
loadingCache
.
put
(
key
,
ruleEntity
);
return
Boolean
.
TRUE
;
}
public
RuleEntity
get
(
String
key
)
{
try
{
return
loadingCache
.
get
(
key
);
}
catch
(
Exception
e
)
{
return
null
;
}
}
public
boolean
clear
(
String
key
)
{
loadingCache
.
invalidate
(
key
);
return
Boolean
.
TRUE
;
}
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/configuration/PluginAutoConfiguration.java
View file @
2916681f
...
@@ -9,15 +9,13 @@ package com.nepxion.discovery.plugin.framework.configuration;
...
@@ -9,15 +9,13 @@ package com.nepxion.discovery.plugin.framework.configuration;
* @version 1.0
* @version 1.0
*/
*/
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
com.nepxion.discovery.plugin.framework.cache.PluginCache
;
import
com.nepxion.discovery.plugin.framework.cache.PluginCache
;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
import
com.nepxion.discovery.plugin.framework.context.PluginContainerInitializedHandler
;
import
com.nepxion.discovery.plugin.framework.context.PluginContainerInitializedHandler
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.entity.RuleEntity
;
import
com.nepxion.discovery.plugin.framework.event.PluginPublisher
;
import
com.nepxion.discovery.plugin.framework.event.PluginPublisher
;
import
com.nepxion.discovery.plugin.framework.event.PluginSubscriber
;
import
com.nepxion.discovery.plugin.framework.event.PluginSubscriber
;
import
com.nepxion.discovery.plugin.framework.listener.discovery.DiscoveryListenerExecutor
;
import
com.nepxion.discovery.plugin.framework.listener.discovery.DiscoveryListenerExecutor
;
...
@@ -58,13 +56,8 @@ public class PluginAutoConfiguration {
...
@@ -58,13 +56,8 @@ public class PluginAutoConfiguration {
}
}
@Bean
@Bean
public
RuleEntity
ruleEntity
()
{
public
RuleCache
ruleCache
()
{
return
new
RuleEntity
();
return
new
RuleCache
();
}
@Bean
public
ReentrantReadWriteLock
reentrantReadWriteLock
()
{
return
new
ReentrantReadWriteLock
();
}
}
@Bean
@Bean
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/configuration/PluginLoadBalanceConfiguration.java
View file @
2916681f
...
@@ -53,8 +53,8 @@ public class PluginLoadBalanceConfiguration {
...
@@ -53,8 +53,8 @@ public class PluginLoadBalanceConfiguration {
return
loadBalancer
;
return
loadBalancer
;
}
}
@Bean
//
@Bean
public
ServerListUpdater
ribbonServerListUpdater
(
IClientConfig
config
)
{
//
public ServerListUpdater ribbonServerListUpdater(IClientConfig config) {
return
new
PollingServerListUpdaterDecorator
(
config
);
//
return new PollingServerListUpdaterDecorator(config);
}
//
}
}
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/constant/PluginConstant.java
View file @
2916681f
...
@@ -22,6 +22,7 @@ public class PluginConstant {
...
@@ -22,6 +22,7 @@ public class PluginConstant {
public
static
final
String
HOST
=
"host"
;
public
static
final
String
HOST
=
"host"
;
public
static
final
String
PORT
=
"port"
;
public
static
final
String
PORT
=
"port"
;
public
static
final
String
INSTANCES
=
"instances"
;
public
static
final
String
INSTANCES
=
"instances"
;
public
static
final
String
RULE
=
"rule"
;
public
static
final
String
REACH_MAX_LIMITED_COUNT
=
"reach max limited count"
;
public
static
final
String
REACH_MAX_LIMITED_COUNT
=
"reach max limited count"
;
public
static
final
String
ENCODING_UTF_8
=
"UTF-8"
;
public
static
final
String
ENCODING_UTF_8
=
"UTF-8"
;
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/discovery/DiscoveryListenerExecutor.java
View file @
2916681f
...
@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.framework.listener.discovery;
...
@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.framework.listener.discovery;
*/
*/
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.ServiceInstance
;
...
@@ -26,13 +25,7 @@ public class DiscoveryListenerExecutor {
...
@@ -26,13 +25,7 @@ public class DiscoveryListenerExecutor {
@Autowired
@Autowired
private
List
<
DiscoveryListener
>
discoveryListenerList
;
private
List
<
DiscoveryListener
>
discoveryListenerList
;
@Autowired
private
ReentrantReadWriteLock
reentrantReadWriteLock
;
public
void
onGetInstances
(
String
serviceId
,
List
<
ServiceInstance
>
instances
)
{
public
void
onGetInstances
(
String
serviceId
,
List
<
ServiceInstance
>
instances
)
{
try
{
reentrantReadWriteLock
.
readLock
().
lock
();
ipAddressFilterDiscoveryListener
.
onGetInstances
(
serviceId
,
instances
);
ipAddressFilterDiscoveryListener
.
onGetInstances
(
serviceId
,
instances
);
versionFilterDiscoveryListener
.
onGetInstances
(
serviceId
,
instances
);
versionFilterDiscoveryListener
.
onGetInstances
(
serviceId
,
instances
);
...
@@ -41,9 +34,6 @@ public class DiscoveryListenerExecutor {
...
@@ -41,9 +34,6 @@ public class DiscoveryListenerExecutor {
discoveryListener
.
onGetInstances
(
serviceId
,
instances
);
discoveryListener
.
onGetInstances
(
serviceId
,
instances
);
}
}
}
}
}
finally
{
reentrantReadWriteLock
.
readLock
().
unlock
();
}
}
}
public
void
onGetServices
(
List
<
String
>
services
)
{
public
void
onGetServices
(
List
<
String
>
services
)
{
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/discovery/IpAddressFilterDiscoveryListener.java
View file @
2916681f
...
@@ -18,6 +18,8 @@ import org.apache.commons.collections4.CollectionUtils;
...
@@ -18,6 +18,8 @@ import org.apache.commons.collections4.CollectionUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.ServiceInstance
;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryEntity
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryEntity
;
import
com.nepxion.discovery.plugin.framework.entity.FilterEntity
;
import
com.nepxion.discovery.plugin.framework.entity.FilterEntity
;
import
com.nepxion.discovery.plugin.framework.entity.FilterType
;
import
com.nepxion.discovery.plugin.framework.entity.FilterType
;
...
@@ -25,7 +27,7 @@ import com.nepxion.discovery.plugin.framework.entity.RuleEntity;
...
@@ -25,7 +27,7 @@ import com.nepxion.discovery.plugin.framework.entity.RuleEntity;
public
class
IpAddressFilterDiscoveryListener
extends
AbstractDiscoveryListener
{
public
class
IpAddressFilterDiscoveryListener
extends
AbstractDiscoveryListener
{
@Autowired
@Autowired
private
Rule
Entity
ruleEntity
;
private
Rule
Cache
ruleCache
;
@Override
@Override
public
void
onGetInstances
(
String
serviceId
,
List
<
ServiceInstance
>
instances
)
{
public
void
onGetInstances
(
String
serviceId
,
List
<
ServiceInstance
>
instances
)
{
...
@@ -33,6 +35,11 @@ public class IpAddressFilterDiscoveryListener extends AbstractDiscoveryListener
...
@@ -33,6 +35,11 @@ public class IpAddressFilterDiscoveryListener extends AbstractDiscoveryListener
}
}
private
void
applyIpAddressFilter
(
String
providerServiceId
,
List
<
ServiceInstance
>
instances
)
{
private
void
applyIpAddressFilter
(
String
providerServiceId
,
List
<
ServiceInstance
>
instances
)
{
RuleEntity
ruleEntity
=
ruleCache
.
get
(
PluginConstant
.
RULE
);
if
(
ruleEntity
==
null
)
{
return
;
}
DiscoveryEntity
discoveryEntity
=
ruleEntity
.
getDiscoveryEntity
();
DiscoveryEntity
discoveryEntity
=
ruleEntity
.
getDiscoveryEntity
();
if
(
discoveryEntity
==
null
)
{
if
(
discoveryEntity
==
null
)
{
return
;
return
;
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/discovery/VersionFilterDiscoveryListener.java
View file @
2916681f
...
@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.ServiceInstance
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryEntity
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryEntity
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryServiceEntity
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryServiceEntity
;
...
@@ -29,7 +30,7 @@ import com.nepxion.discovery.plugin.framework.entity.VersionEntity;
...
@@ -29,7 +30,7 @@ import com.nepxion.discovery.plugin.framework.entity.VersionEntity;
public
class
VersionFilterDiscoveryListener
extends
AbstractDiscoveryListener
{
public
class
VersionFilterDiscoveryListener
extends
AbstractDiscoveryListener
{
@Autowired
@Autowired
private
Rule
Entity
ruleEntity
;
private
Rule
Cache
ruleCache
;
@Autowired
@Autowired
private
PluginAdapter
pluginAdapter
;
private
PluginAdapter
pluginAdapter
;
...
@@ -48,6 +49,11 @@ public class VersionFilterDiscoveryListener extends AbstractDiscoveryListener {
...
@@ -48,6 +49,11 @@ public class VersionFilterDiscoveryListener extends AbstractDiscoveryListener {
return
;
return
;
}
}
RuleEntity
ruleEntity
=
ruleCache
.
get
(
PluginConstant
.
RULE
);
if
(
ruleEntity
==
null
)
{
return
;
}
DiscoveryEntity
discoveryEntity
=
ruleEntity
.
getDiscoveryEntity
();
DiscoveryEntity
discoveryEntity
=
ruleEntity
.
getDiscoveryEntity
();
if
(
discoveryEntity
==
null
)
{
if
(
discoveryEntity
==
null
)
{
return
;
return
;
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/loadbalance/IpAddressFilterLoadBalanceListener.java
View file @
2916681f
...
@@ -17,6 +17,8 @@ import java.util.Map;
...
@@ -17,6 +17,8 @@ import java.util.Map;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryEntity
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryEntity
;
import
com.nepxion.discovery.plugin.framework.entity.FilterEntity
;
import
com.nepxion.discovery.plugin.framework.entity.FilterEntity
;
import
com.nepxion.discovery.plugin.framework.entity.FilterType
;
import
com.nepxion.discovery.plugin.framework.entity.FilterType
;
...
@@ -25,7 +27,7 @@ import com.netflix.loadbalancer.Server;
...
@@ -25,7 +27,7 @@ import com.netflix.loadbalancer.Server;
public
class
IpAddressFilterLoadBalanceListener
extends
AbstractLoadBalanceListener
{
public
class
IpAddressFilterLoadBalanceListener
extends
AbstractLoadBalanceListener
{
@Autowired
@Autowired
private
Rule
Entity
ruleEntity
;
private
Rule
Cache
ruleCache
;
@Override
@Override
public
void
onGetServers
(
String
serviceId
,
List
<?
extends
Server
>
servers
)
{
public
void
onGetServers
(
String
serviceId
,
List
<?
extends
Server
>
servers
)
{
...
@@ -33,6 +35,11 @@ public class IpAddressFilterLoadBalanceListener extends AbstractLoadBalanceListe
...
@@ -33,6 +35,11 @@ public class IpAddressFilterLoadBalanceListener extends AbstractLoadBalanceListe
}
}
private
void
applyIpAddressFilter
(
String
providerServiceId
,
List
<?
extends
Server
>
servers
)
{
private
void
applyIpAddressFilter
(
String
providerServiceId
,
List
<?
extends
Server
>
servers
)
{
RuleEntity
ruleEntity
=
ruleCache
.
get
(
PluginConstant
.
RULE
);
if
(
ruleEntity
==
null
)
{
return
;
}
DiscoveryEntity
discoveryEntity
=
ruleEntity
.
getDiscoveryEntity
();
DiscoveryEntity
discoveryEntity
=
ruleEntity
.
getDiscoveryEntity
();
if
(
discoveryEntity
==
null
)
{
if
(
discoveryEntity
==
null
)
{
return
;
return
;
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/loadbalance/LoadBalanceListenerExecutor.java
View file @
2916681f
...
@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.framework.listener.loadbalance;
...
@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.framework.listener.loadbalance;
*/
*/
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -25,20 +24,11 @@ public class LoadBalanceListenerExecutor {
...
@@ -25,20 +24,11 @@ public class LoadBalanceListenerExecutor {
@Autowired
@Autowired
private
VersionFilterLoadBalanceListener
versionFilterLoadBalanceListener
;
private
VersionFilterLoadBalanceListener
versionFilterLoadBalanceListener
;
@Autowired
private
ReentrantReadWriteLock
reentrantReadWriteLock
;
private
ZoneAwareLoadBalancer
<?>
loadBalancer
;
private
ZoneAwareLoadBalancer
<?>
loadBalancer
;
public
void
onGetServers
(
String
serviceId
,
List
<?
extends
Server
>
servers
)
{
public
void
onGetServers
(
String
serviceId
,
List
<?
extends
Server
>
servers
)
{
try
{
reentrantReadWriteLock
.
readLock
().
lock
();
ipAddressFilterLoadBalanceListener
.
onGetServers
(
serviceId
,
servers
);
ipAddressFilterLoadBalanceListener
.
onGetServers
(
serviceId
,
servers
);
versionFilterLoadBalanceListener
.
onGetServers
(
serviceId
,
servers
);
versionFilterLoadBalanceListener
.
onGetServers
(
serviceId
,
servers
);
}
finally
{
reentrantReadWriteLock
.
readLock
().
unlock
();
}
}
}
public
ZoneAwareLoadBalancer
<?>
getLoadBalancer
()
{
public
ZoneAwareLoadBalancer
<?>
getLoadBalancer
()
{
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/loadbalance/VersionFilterLoadBalanceListener.java
View file @
2916681f
...
@@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils;
...
@@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryEntity
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryEntity
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryServiceEntity
;
import
com.nepxion.discovery.plugin.framework.entity.DiscoveryServiceEntity
;
...
@@ -29,7 +30,7 @@ import com.netflix.loadbalancer.Server;
...
@@ -29,7 +30,7 @@ import com.netflix.loadbalancer.Server;
public
class
VersionFilterLoadBalanceListener
extends
AbstractLoadBalanceListener
{
public
class
VersionFilterLoadBalanceListener
extends
AbstractLoadBalanceListener
{
@Autowired
@Autowired
private
Rule
Entity
ruleEntity
;
private
Rule
Cache
ruleCache
;
@Autowired
@Autowired
private
PluginAdapter
pluginAdapter
;
private
PluginAdapter
pluginAdapter
;
...
@@ -48,6 +49,11 @@ public class VersionFilterLoadBalanceListener extends AbstractLoadBalanceListene
...
@@ -48,6 +49,11 @@ public class VersionFilterLoadBalanceListener extends AbstractLoadBalanceListene
return
;
return
;
}
}
RuleEntity
ruleEntity
=
ruleCache
.
get
(
PluginConstant
.
RULE
);
if
(
ruleEntity
==
null
)
{
return
;
}
DiscoveryEntity
discoveryEntity
=
ruleEntity
.
getDiscoveryEntity
();
DiscoveryEntity
discoveryEntity
=
ruleEntity
.
getDiscoveryEntity
();
if
(
discoveryEntity
==
null
)
{
if
(
discoveryEntity
==
null
)
{
return
;
return
;
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/CountFilterRegisterListener.java
View file @
2916681f
...
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.cloud.client.serviceregistry.Registration
;
import
org.springframework.cloud.client.serviceregistry.Registration
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.decorator.DiscoveryClientDecorator
;
import
com.nepxion.discovery.plugin.framework.decorator.DiscoveryClientDecorator
;
import
com.nepxion.discovery.plugin.framework.entity.CountEntity
;
import
com.nepxion.discovery.plugin.framework.entity.CountEntity
;
...
@@ -26,7 +27,7 @@ import com.nepxion.discovery.plugin.framework.exception.PluginException;
...
@@ -26,7 +27,7 @@ import com.nepxion.discovery.plugin.framework.exception.PluginException;
public
class
CountFilterRegisterListener
extends
AbstractRegisterListener
{
public
class
CountFilterRegisterListener
extends
AbstractRegisterListener
{
@Autowired
@Autowired
private
Rule
Entity
ruleEntity
;
private
Rule
Cache
ruleCache
;
@Autowired
@Autowired
private
PluginAdapter
pluginAdapter
;
private
PluginAdapter
pluginAdapter
;
...
@@ -47,6 +48,11 @@ public class CountFilterRegisterListener extends AbstractRegisterListener {
...
@@ -47,6 +48,11 @@ public class CountFilterRegisterListener extends AbstractRegisterListener {
}
}
private
void
applyCountFilter
(
String
serviceId
,
String
ipAddress
,
int
port
)
{
private
void
applyCountFilter
(
String
serviceId
,
String
ipAddress
,
int
port
)
{
RuleEntity
ruleEntity
=
ruleCache
.
get
(
PluginConstant
.
RULE
);
if
(
ruleEntity
==
null
)
{
return
;
}
RegisterEntity
registerEntity
=
ruleEntity
.
getRegisterEntity
();
RegisterEntity
registerEntity
=
ruleEntity
.
getRegisterEntity
();
if
(
registerEntity
==
null
)
{
if
(
registerEntity
==
null
)
{
return
;
return
;
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/IpAddressFilterRegisterListener.java
View file @
2916681f
...
@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.cloud.client.serviceregistry.Registration
;
import
org.springframework.cloud.client.serviceregistry.Registration
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.entity.FilterEntity
;
import
com.nepxion.discovery.plugin.framework.entity.FilterEntity
;
import
com.nepxion.discovery.plugin.framework.entity.FilterType
;
import
com.nepxion.discovery.plugin.framework.entity.FilterType
;
...
@@ -29,7 +30,7 @@ import com.nepxion.discovery.plugin.framework.exception.PluginException;
...
@@ -29,7 +30,7 @@ import com.nepxion.discovery.plugin.framework.exception.PluginException;
public
class
IpAddressFilterRegisterListener
extends
AbstractRegisterListener
{
public
class
IpAddressFilterRegisterListener
extends
AbstractRegisterListener
{
@Autowired
@Autowired
private
Rule
Entity
ruleEntity
;
private
Rule
Cache
ruleCache
;
@Autowired
@Autowired
private
PluginAdapter
pluginAdapter
;
private
PluginAdapter
pluginAdapter
;
...
@@ -47,6 +48,11 @@ public class IpAddressFilterRegisterListener extends AbstractRegisterListener {
...
@@ -47,6 +48,11 @@ public class IpAddressFilterRegisterListener extends AbstractRegisterListener {
}
}
private
void
applyIpAddressFilter
(
String
serviceId
,
String
ipAddress
,
int
port
)
{
private
void
applyIpAddressFilter
(
String
serviceId
,
String
ipAddress
,
int
port
)
{
RuleEntity
ruleEntity
=
ruleCache
.
get
(
PluginConstant
.
RULE
);
if
(
ruleEntity
==
null
)
{
return
;
}
RegisterEntity
registerEntity
=
ruleEntity
.
getRegisterEntity
();
RegisterEntity
registerEntity
=
ruleEntity
.
getRegisterEntity
();
if
(
registerEntity
==
null
)
{
if
(
registerEntity
==
null
)
{
return
;
return
;
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/RegisterListenerExecutor.java
View file @
2916681f
...
@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.framework.listener.register;
...
@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.framework.listener.register;
*/
*/
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.locks.ReentrantReadWriteLock
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.client.serviceregistry.Registration
;
import
org.springframework.cloud.client.serviceregistry.Registration
;
...
@@ -26,13 +25,7 @@ public class RegisterListenerExecutor {
...
@@ -26,13 +25,7 @@ public class RegisterListenerExecutor {
@Autowired
@Autowired
private
List
<
RegisterListener
>
registerListenerList
;
private
List
<
RegisterListener
>
registerListenerList
;
@Autowired
private
ReentrantReadWriteLock
reentrantReadWriteLock
;
public
void
onRegister
(
Registration
registration
)
{
public
void
onRegister
(
Registration
registration
)
{
try
{
reentrantReadWriteLock
.
readLock
().
lock
();
for
(
RegisterListener
registerListener
:
registerListenerList
)
{
for
(
RegisterListener
registerListener
:
registerListenerList
)
{
if
(
registerListener
!=
countFilterRegisterListener
&&
registerListener
!=
ipAddressFilterRegisterListener
)
{
if
(
registerListener
!=
countFilterRegisterListener
&&
registerListener
!=
ipAddressFilterRegisterListener
)
{
registerListener
.
onRegister
(
registration
);
registerListener
.
onRegister
(
registration
);
...
@@ -41,9 +34,6 @@ public class RegisterListenerExecutor {
...
@@ -41,9 +34,6 @@ public class RegisterListenerExecutor {
countFilterRegisterListener
.
onRegister
(
registration
);
countFilterRegisterListener
.
onRegister
(
registration
);
ipAddressFilterRegisterListener
.
onRegister
(
registration
);
ipAddressFilterRegisterListener
.
onRegister
(
registration
);
}
finally
{
reentrantReadWriteLock
.
readLock
().
unlock
();
}
}
}
public
void
onDeregister
(
Registration
registration
)
{
public
void
onDeregister
(
Registration
registration
)
{
...
...
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