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
4c9cd5a5
Commit
4c9cd5a5
authored
Jul 09, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
封装事件总线
parent
a947a694
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
61 additions
and
16 deletions
+61
-16
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/ConfigEndpoint.java
+3
-3
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/VersionEndpoint.java
+4
-4
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigAdapter.java
+5
-4
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/configuration/PluginAutoConfiguration.java
+6
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginEventWapper.java
+37
-0
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginSubscriber.java
+3
-3
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/adapter/DiscoveryConfigAdapter.java
+1
-1
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/extension/MySubscriber.java
+2
-1
No files found.
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/ConfigEndpoint.java
View file @
4c9cd5a5
...
@@ -37,7 +37,7 @@ import com.nepxion.discovery.plugin.framework.cache.RuleCache;
...
@@ -37,7 +37,7 @@ 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
;
import
com.nepxion.discovery.plugin.framework.event.Plugin
Publish
er
;
import
com.nepxion.discovery.plugin.framework.event.Plugin
EventWapp
er
;
import
com.nepxion.discovery.plugin.framework.event.RuleChangedEvent
;
import
com.nepxion.discovery.plugin.framework.event.RuleChangedEvent
;
@RestController
@RestController
...
@@ -51,7 +51,7 @@ public class ConfigEndpoint implements MvcEndpoint {
...
@@ -51,7 +51,7 @@ public class ConfigEndpoint implements MvcEndpoint {
private
PluginContextAware
pluginContextAware
;
private
PluginContextAware
pluginContextAware
;
@Autowired
@Autowired
private
Plugin
Publisher
pluginPublish
er
;
private
Plugin
EventWapper
pluginEventWapp
er
;
@Autowired
@Autowired
private
RuleCache
ruleCache
;
private
RuleCache
ruleCache
;
...
@@ -68,7 +68,7 @@ public class ConfigEndpoint implements MvcEndpoint {
...
@@ -68,7 +68,7 @@ public class ConfigEndpoint implements MvcEndpoint {
try
{
try
{
InputStream
inputStream
=
IOUtils
.
toInputStream
(
config
,
PluginConstant
.
ENCODING_UTF_8
);
InputStream
inputStream
=
IOUtils
.
toInputStream
(
config
,
PluginConstant
.
ENCODING_UTF_8
);
plugin
Publisher
.
asyncPublish
(
new
RuleChangedEvent
(
inputStream
)
);
plugin
EventWapper
.
fireRuleChanged
(
new
RuleChangedEvent
(
inputStream
),
true
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
LOG
.
error
(
"Publish config failed"
,
e
);
LOG
.
error
(
"Publish config failed"
,
e
);
...
...
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/VersionEndpoint.java
View file @
4c9cd5a5
...
@@ -33,7 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -33,7 +33,7 @@ import org.springframework.web.bind.annotation.RestController;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.event.Plugin
Publish
er
;
import
com.nepxion.discovery.plugin.framework.event.Plugin
EventWapp
er
;
import
com.nepxion.discovery.plugin.framework.event.VersionChangedEvent
;
import
com.nepxion.discovery.plugin.framework.event.VersionChangedEvent
;
@RestController
@RestController
...
@@ -47,7 +47,7 @@ public class VersionEndpoint implements MvcEndpoint {
...
@@ -47,7 +47,7 @@ public class VersionEndpoint implements MvcEndpoint {
private
PluginAdapter
pluginAdapter
;
private
PluginAdapter
pluginAdapter
;
@Autowired
@Autowired
private
Plugin
Publisher
pluginPublish
er
;
private
Plugin
EventWapper
pluginEventWapp
er
;
@RequestMapping
(
path
=
"/version/send"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/version/send"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"设置服务的动态版本"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ApiOperation
(
value
=
"设置服务的动态版本"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
...
@@ -61,7 +61,7 @@ public class VersionEndpoint implements MvcEndpoint {
...
@@ -61,7 +61,7 @@ public class VersionEndpoint implements MvcEndpoint {
pluginAdapter
.
setDynamicVersion
(
version
);
pluginAdapter
.
setDynamicVersion
(
version
);
plugin
Publisher
.
asyncPublish
(
new
VersionChangedEvent
()
);
plugin
EventWapper
.
fireVersionChanged
(
new
VersionChangedEvent
(),
true
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
}
...
@@ -78,7 +78,7 @@ public class VersionEndpoint implements MvcEndpoint {
...
@@ -78,7 +78,7 @@ public class VersionEndpoint implements MvcEndpoint {
pluginAdapter
.
clearDynamicVersion
();
pluginAdapter
.
clearDynamicVersion
();
plugin
Publisher
.
asyncPublish
(
new
VersionChangedEvent
()
);
plugin
EventWapper
.
fireVersionChanged
(
new
VersionChangedEvent
(),
true
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
}
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigAdapter.java
View file @
4c9cd5a5
...
@@ -12,14 +12,14 @@ package com.nepxion.discovery.plugin.configcenter;
...
@@ -12,14 +12,14 @@ package com.nepxion.discovery.plugin.configcenter;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.nepxion.discovery.plugin.configcenter.loader.AbstractConfigLoader
;
import
com.nepxion.discovery.plugin.configcenter.loader.AbstractConfigLoader
;
import
com.nepxion.discovery.plugin.framework.event.Plugin
Publish
er
;
import
com.nepxion.discovery.plugin.framework.event.Plugin
EventWapp
er
;
import
com.nepxion.discovery.plugin.framework.event.RuleChangedEvent
;
import
com.nepxion.discovery.plugin.framework.event.RuleChangedEvent
;
public
abstract
class
ConfigAdapter
extends
AbstractConfigLoader
{
public
abstract
class
ConfigAdapter
extends
AbstractConfigLoader
{
@Autowired
@Autowired
private
Plugin
Publisher
pluginPublish
er
;
private
Plugin
EventWapper
pluginEventWapp
er
;
public
void
publish
(
RuleChangedEvent
ruleChangedEvent
)
{
public
void
fireRuleChanged
(
RuleChangedEvent
ruleChangedEvent
,
boolean
async
)
{
plugin
Publisher
.
asyncPublish
(
ruleChangedEvent
);
plugin
EventWapper
.
fireRuleChanged
(
ruleChangedEvent
,
async
);
}
}
}
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/configuration/PluginAutoConfiguration.java
View file @
4c9cd5a5
...
@@ -16,6 +16,7 @@ import com.nepxion.discovery.plugin.framework.cache.PluginCache;
...
@@ -16,6 +16,7 @@ import com.nepxion.discovery.plugin.framework.cache.PluginCache;
import
com.nepxion.discovery.plugin.framework.cache.RuleCache
;
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.event.PluginEventWapper
;
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
;
...
@@ -51,6 +52,11 @@ public class PluginAutoConfiguration {
...
@@ -51,6 +52,11 @@ public class PluginAutoConfiguration {
}
}
@Bean
@Bean
public
PluginEventWapper
pluginEventWapper
()
{
return
new
PluginEventWapper
();
}
@Bean
public
PluginCache
pluginCache
()
{
public
PluginCache
pluginCache
()
{
return
new
PluginCache
();
return
new
PluginCache
();
}
}
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginEventWapper.java
0 → 100644
View file @
4c9cd5a5
package
com
.
nepxion
.
discovery
.
plugin
.
framework
.
event
;
/**
* <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
org.springframework.beans.factory.annotation.Autowired
;
public
class
PluginEventWapper
{
@Autowired
private
PluginPublisher
pluginPublisher
;
@Autowired
private
PluginSubscriber
pluginSubscriber
;
public
void
fireRuleChanged
(
RuleChangedEvent
ruleChangedEvent
,
boolean
async
)
{
if
(
async
)
{
pluginPublisher
.
asyncPublish
(
ruleChangedEvent
);
}
else
{
pluginSubscriber
.
onRuleChanged
(
ruleChangedEvent
);
}
}
public
void
fireVersionChanged
(
VersionChangedEvent
versionChangedEvent
,
boolean
async
)
{
if
(
async
)
{
pluginPublisher
.
asyncPublish
(
versionChangedEvent
);
}
else
{
pluginSubscriber
.
onVersionChanged
(
versionChangedEvent
);
}
}
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginSubscriber.java
View file @
4c9cd5a5
...
@@ -36,7 +36,7 @@ public class PluginSubscriber {
...
@@ -36,7 +36,7 @@ public class PluginSubscriber {
private
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
;
private
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
;
@Subscribe
@Subscribe
public
void
subscribe
RuleChanged
(
RuleChangedEvent
ruleChangedEvent
)
{
public
void
on
RuleChanged
(
RuleChangedEvent
ruleChangedEvent
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
remoteConfigEnabled
=
pluginContextAware
.
isRemoteConfigEnabled
();
Boolean
remoteConfigEnabled
=
pluginContextAware
.
isRemoteConfigEnabled
();
...
@@ -57,11 +57,11 @@ public class PluginSubscriber {
...
@@ -57,11 +57,11 @@ public class PluginSubscriber {
InputStream
inputStream
=
ruleChangedEvent
.
getInputStream
();
InputStream
inputStream
=
ruleChangedEvent
.
getInputStream
();
pluninConfigParser
.
parse
(
inputStream
);
pluninConfigParser
.
parse
(
inputStream
);
subscribe
VersionChanged
(
null
);
on
VersionChanged
(
null
);
}
}
@Subscribe
@Subscribe
public
void
subscribe
VersionChanged
(
VersionChangedEvent
versionChangedEvent
)
{
public
void
on
VersionChanged
(
VersionChangedEvent
versionChangedEvent
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
if
(!
discoveryControlEnabled
)
{
if
(!
discoveryControlEnabled
)
{
LOG
.
info
(
"********** Discovery control is disabled, ignore to subscribe **********"
);
LOG
.
info
(
"********** Discovery control is disabled, ignore to subscribe **********"
);
...
...
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/adapter/DiscoveryConfigAdapter.java
View file @
4c9cd5a5
...
@@ -48,7 +48,7 @@ public class DiscoveryConfigAdapter extends ConfigAdapter {
...
@@ -48,7 +48,7 @@ public class DiscoveryConfigAdapter extends ConfigAdapter {
public void publish() {
public void publish() {
try {
try {
InputStream inputStream = FileUtils.openInputStream(new File("src/main/resources/rule.xml"));
InputStream inputStream = FileUtils.openInputStream(new File("src/main/resources/rule.xml"));
publish(new RuleChangedEvent(inputStream)
);
fireRuleChanged(new RuleChangedEvent(inputStream), true
);
} catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
}
}
...
...
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/extension/MySubscriber.java
View file @
4c9cd5a5
...
@@ -16,7 +16,7 @@ import com.nepxion.eventbus.annotation.EventBus;
...
@@ -16,7 +16,7 @@ import com.nepxion.eventbus.annotation.EventBus;
@EventBus
@EventBus
public
class
MySubscriber
{
public
class
MySubscriber
{
@Subscribe
@Subscribe
public
void
subscribe
RegisterFailure
(
RegisterFailureEvent
registerFailureEvent
)
{
public
void
on
RegisterFailure
(
RegisterFailureEvent
registerFailureEvent
)
{
System
.
out
.
println
(
"========== 注册失败:eventType="
+
registerFailureEvent
.
getEventType
()
+
", eventDescription="
+
registerFailureEvent
.
getEventDescription
()
+
", serviceId="
+
registerFailureEvent
.
getServiceId
()
+
", ipAddress="
+
registerFailureEvent
.
getIpAddress
()
+
", port="
+
registerFailureEvent
.
getPort
());
System
.
out
.
println
(
"========== 注册失败:eventType="
+
registerFailureEvent
.
getEventType
()
+
", eventDescription="
+
registerFailureEvent
.
getEventDescription
()
+
", serviceId="
+
registerFailureEvent
.
getServiceId
()
+
", ipAddress="
+
registerFailureEvent
.
getIpAddress
()
+
", port="
+
registerFailureEvent
.
getPort
());
}
}
}
}
\ No newline at end of file
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