Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
c8be52b0
Commit
c8be52b0
authored
Aug 12, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
publish eureka instance events
parent
11d9ddbf
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
161 additions
and
30 deletions
+161
-30
EurekaServerAutoConfiguration.java
...latform/netflix/eureka/EurekaServerAutoConfiguration.java
+50
-0
LeaseManagerLite.java
...work/platform/netflix/eureka/advice/LeaseManagerLite.java
+0
-28
EurekaInstanceCanceledEvent.java
...orm/netflix/eureka/event/EurekaInstanceCanceledEvent.java
+21
-0
EurekaInstanceRegisteredEvent.java
...m/netflix/eureka/event/EurekaInstanceRegisteredEvent.java
+23
-0
EurekaInstanceRenewedEvent.java
...form/netflix/eureka/event/EurekaInstanceRenewedEvent.java
+21
-0
EurekaRegistryAvailableEvent.java
...rm/netflix/eureka/event/EurekaRegistryAvailableEvent.java
+1
-1
EurekaServerStartedEvent.java
...atform/netflix/eureka/event/EurekaServerStartedEvent.java
+1
-1
LeaseManagerMessageBroker.java
...tform/netflix/eureka/event/LeaseManagerMessageBroker.java
+44
-0
No files found.
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerAutoConfiguration.java
View file @
c8be52b0
...
...
@@ -18,14 +18,24 @@ package org.springframework.platform.netflix.eureka;
import
javax.servlet.ServletContext
;
import
javax.servlet.ServletContextEvent
;
import
com.netflix.eureka.PeerAwareInstanceRegistry
;
import
com.netflix.eureka.lease.LeaseManager
;
import
org.springframework.aop.framework.ProxyFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.SmartLifecycle
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
import
org.springframework.platform.netflix.eureka.advice.PiggybackMethodInterceptor
;
import
org.springframework.platform.netflix.eureka.event.EurekaRegistryAvailableEvent
;
import
org.springframework.platform.netflix.eureka.event.EurekaServerStartedEvent
;
import
org.springframework.platform.netflix.eureka.event.LeaseManagerMessageBroker
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.web.context.ServletContextAware
;
import
com.netflix.blitz4j.LoggingConfiguration
;
...
...
@@ -33,6 +43,9 @@ import com.netflix.eureka.EurekaBootStrap;
import
com.netflix.eureka.EurekaServerConfig
;
import
com.netflix.eureka.EurekaServerConfigurationManager
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Modifier
;
/**
* @author Dave Syer
*
...
...
@@ -113,4 +126,41 @@ public class EurekaServerAutoConfiguration implements ServletContextAware,
return
order
;
}
@Configuration
@ConditionalOnClass
(
PeerAwareInstanceRegistry
.
class
)
protected
static
class
Initializer
implements
ApplicationListener
<
EurekaRegistryAvailableEvent
>
{
@Autowired
private
ApplicationContext
applicationContext
;
@Bean
public
LeaseManagerMessageBroker
leaseManagerMessageBroker
()
{
return
new
LeaseManagerMessageBroker
();
}
@Override
public
void
onApplicationEvent
(
EurekaRegistryAvailableEvent
event
)
{
//wrap the instance registry...
ProxyFactory
factory
=
new
ProxyFactory
(
PeerAwareInstanceRegistry
.
getInstance
());
//...with the LeaseManagerMessageBroker
factory
.
addAdvice
(
new
PiggybackMethodInterceptor
(
leaseManagerMessageBroker
(),
LeaseManager
.
class
));
factory
.
setProxyTargetClass
(
true
);
//Now replace the PeerAwareInstanceRegistry with our wrapped version
Field
field
=
ReflectionUtils
.
findField
(
PeerAwareInstanceRegistry
.
class
,
"instance"
);
try
{
// Awful ugly hack to work around lack of DI in eureka
field
.
setAccessible
(
true
);
Field
modifiersField
=
Field
.
class
.
getDeclaredField
(
"modifiers"
);
modifiersField
.
setAccessible
(
true
);
modifiersField
.
setInt
(
field
,
field
.
getModifiers
()
&
~
Modifier
.
FINAL
);
ReflectionUtils
.
setField
(
field
,
null
,
factory
.
getProxy
());
}
catch
(
Exception
e
)
{
throw
new
IllegalStateException
(
"Cannot modify instance registry"
,
e
);
}
}
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/advice/LeaseManagerLite.java
deleted
100644 → 0
View file @
11d9ddbf
/*
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
platform
.
netflix
.
eureka
.
advice
;
import
com.netflix.appinfo.InstanceInfo
;
/**
* @author Dave Syer
*
*/
public
interface
LeaseManagerLite
{
void
register
(
final
InstanceInfo
info
,
final
boolean
isReplication
);
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceCanceledEvent.java
0 → 100644
View file @
c8be52b0
package
org
.
springframework
.
platform
.
netflix
.
eureka
.
event
;
import
lombok.Data
;
import
org.springframework.context.ApplicationEvent
;
/**
* @author Spencer Gibb
*/
@Data
public
class
EurekaInstanceCanceledEvent
extends
ApplicationEvent
{
private
String
appName
;
private
String
serverId
;
boolean
replication
;
public
EurekaInstanceCanceledEvent
(
Object
source
,
String
appName
,
String
serverId
,
boolean
replication
)
{
super
(
source
);
this
.
appName
=
appName
;
this
.
serverId
=
serverId
;
this
.
replication
=
replication
;
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRegisteredEvent.java
0 → 100644
View file @
c8be52b0
package
org
.
springframework
.
platform
.
netflix
.
eureka
.
event
;
import
lombok.Data
;
import
org.springframework.context.ApplicationEvent
;
/**
* @author Spencer Gibb
*/
@Data
public
class
EurekaInstanceRegisteredEvent
extends
ApplicationEvent
{
private
String
appName
;
private
String
vip
;
private
int
leaseDuration
;
boolean
replication
;
public
EurekaInstanceRegisteredEvent
(
Object
source
,
String
appName
,
String
vip
,
int
leaseDuration
,
boolean
replication
)
{
super
(
source
);
this
.
appName
=
appName
;
this
.
vip
=
vip
;
this
.
leaseDuration
=
leaseDuration
;
this
.
replication
=
replication
;
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRenewedEvent.java
0 → 100644
View file @
c8be52b0
package
org
.
springframework
.
platform
.
netflix
.
eureka
.
event
;
import
lombok.Data
;
import
org.springframework.context.ApplicationEvent
;
/**
* @author Spencer Gibb
*/
@Data
public
class
EurekaInstanceRenewedEvent
extends
ApplicationEvent
{
private
String
appName
;
private
String
serverId
;
boolean
replication
;
public
EurekaInstanceRenewedEvent
(
Object
source
,
String
appName
,
String
serverId
,
boolean
replication
)
{
super
(
source
);
this
.
appName
=
appName
;
this
.
serverId
=
serverId
;
this
.
replication
=
replication
;
}
}
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaRegistryAvailableEvent.java
→
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/
event/
EurekaRegistryAvailableEvent.java
View file @
c8be52b0
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
platform
.
netflix
.
eureka
;
package
org
.
springframework
.
platform
.
netflix
.
eureka
.
event
;
import
org.springframework.context.ApplicationEvent
;
...
...
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerStartedEvent.java
→
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/
event/
EurekaServerStartedEvent.java
View file @
c8be52b0
...
...
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
platform
.
netflix
.
eureka
;
package
org
.
springframework
.
platform
.
netflix
.
eureka
.
event
;
import
org.springframework.context.ApplicationEvent
;
...
...
spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/LeaseManagerMessageBroker.java
0 → 100644
View file @
c8be52b0
package
org
.
springframework
.
platform
.
netflix
.
eureka
.
event
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.eureka.lease.LeaseManager
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
/**
* @author Spencer Gibb
*/
public
class
LeaseManagerMessageBroker
implements
LeaseManager
<
InstanceInfo
>
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LeaseManagerMessageBroker
.
class
);
@Autowired
private
ApplicationContext
ctxt
;
@Override
public
void
register
(
InstanceInfo
info
,
int
leaseDuration
,
boolean
isReplication
)
{
logger
.
debug
(
"register {}, vip {}, leaseDuration {}, isReplication {}"
,
info
.
getAppName
(),
info
.
getVIPAddress
(),
leaseDuration
,
isReplication
);
//TODO: what to publish from info (whole object?)
ctxt
.
publishEvent
(
new
EurekaInstanceRegisteredEvent
(
this
,
info
.
getAppName
(),
info
.
getVIPAddress
(),
leaseDuration
,
isReplication
));
}
@Override
public
boolean
cancel
(
String
appName
,
String
serverId
,
boolean
isReplication
)
{
logger
.
debug
(
"cancel {}, serverId {}, isReplication {}"
,
appName
,
serverId
,
isReplication
);
ctxt
.
publishEvent
(
new
EurekaInstanceCanceledEvent
(
this
,
appName
,
serverId
,
isReplication
));
return
false
;
}
@Override
public
boolean
renew
(
String
appName
,
String
serverId
,
boolean
isReplication
)
{
logger
.
debug
(
"renew {}, serverId {}, isReplication {}"
,
appName
,
serverId
,
isReplication
);
ctxt
.
publishEvent
(
new
EurekaInstanceRenewedEvent
(
this
,
appName
,
serverId
,
isReplication
));
return
false
;
}
@Override
public
void
evict
()
{}
}
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