Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
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
DEMO
spring-boot
Commits
798882bd
Commit
798882bd
authored
Jan 29, 2018
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gh-11584'
parents
6582afea
3a12f98b
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
940 additions
and
171 deletions
+940
-171
EndpointDiscoverer.java
.../boot/actuate/endpoint/annotation/EndpointDiscoverer.java
+10
-21
CacheMetricsRegistrar.java
...ork/boot/actuate/metrics/cache/CacheMetricsRegistrar.java
+10
-39
CacheManagerCustomizers.java
...ork/boot/autoconfigure/cache/CacheManagerCustomizers.java
+5
-30
TransactionManagerCustomizers.java
...oconfigure/transaction/TransactionManagerCustomizers.java
+10
-35
LambdaSafe.java
...c/main/java/org/springframework/boot/util/LambdaSafe.java
+402
-0
package-info.java
...main/java/org/springframework/boot/util/package-info.java
+20
-0
WebServerFactoryCustomizerBeanPostProcessor.java
...b/server/WebServerFactoryCustomizerBeanPostProcessor.java
+8
-46
LambdaSafeTests.java
...t/java/org/springframework/boot/util/LambdaSafeTests.java
+475
-0
No files found.
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/annotation/EndpointDiscoverer.java
View file @
798882bd
...
@@ -26,12 +26,10 @@ import java.util.Map;
...
@@ -26,12 +26,10 @@ import java.util.Map;
import
java.util.Objects
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.function.Function
;
import
java.util.function.Supplier
;
import
java.util.function.Supplier
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.BeanFactoryUtils
;
import
org.springframework.beans.factory.BeanFactoryUtils
;
import
org.springframework.boot.actuate.endpoint.EndpointFilter
;
import
org.springframework.boot.actuate.endpoint.EndpointFilter
;
...
@@ -41,6 +39,7 @@ import org.springframework.boot.actuate.endpoint.Operation;
...
@@ -41,6 +39,7 @@ import org.springframework.boot.actuate.endpoint.Operation;
import
org.springframework.boot.actuate.endpoint.invoke.OperationInvoker
;
import
org.springframework.boot.actuate.endpoint.invoke.OperationInvoker
;
import
org.springframework.boot.actuate.endpoint.invoke.OperationInvokerAdvisor
;
import
org.springframework.boot.actuate.endpoint.invoke.OperationInvokerAdvisor
;
import
org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper
;
import
org.springframework.boot.actuate.endpoint.invoke.ParameterValueMapper
;
import
org.springframework.boot.util.LambdaSafe
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.core.annotation.AnnotatedElementUtils
;
import
org.springframework.core.annotation.AnnotatedElementUtils
;
...
@@ -66,8 +65,6 @@ import org.springframework.util.StringUtils;
...
@@ -66,8 +65,6 @@ import org.springframework.util.StringUtils;
public
abstract
class
EndpointDiscoverer
<
E
extends
ExposableEndpoint
<
O
>,
O
extends
Operation
>
public
abstract
class
EndpointDiscoverer
<
E
extends
ExposableEndpoint
<
O
>,
O
extends
Operation
>
implements
EndpointsSupplier
<
E
>
{
implements
EndpointsSupplier
<
E
>
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
EndpointDiscoverer
.
class
);
private
final
ApplicationContext
applicationContext
;
private
final
ApplicationContext
applicationContext
;
private
final
Collection
<
EndpointFilter
<
E
>>
filters
;
private
final
Collection
<
EndpointFilter
<
E
>>
filters
;
...
@@ -313,23 +310,15 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten
...
@@ -313,23 +310,15 @@ public abstract class EndpointDiscoverer<E extends ExposableEndpoint<O>, O exten
return
isFilterMatch
(
filter
,
getFilterEndpoint
(
endpointBean
));
return
isFilterMatch
(
filter
,
getFilterEndpoint
(
endpointBean
));
}
}
@SuppressWarnings
(
"unchecked"
)
private
boolean
isFilterMatch
(
EndpointFilter
<
E
>
filter
,
E
endpoint
)
{
private
boolean
isFilterMatch
(
EndpointFilter
<
E
>
filter
,
E
endpoint
)
{
try
{
return
LambdaSafe
.
callback
(
EndpointFilter
.
class
,
filter
,
endpoint
)
return
filter
.
match
(
endpoint
);
.
withLogger
(
EndpointDiscoverer
.
class
).
invokeAnd
((
f
)
->
f
.
match
(
endpoint
))
}
.
get
();
catch
(
ClassCastException
ex
)
{
}
String
msg
=
ex
.
getMessage
();
if
(
msg
==
null
||
msg
.
startsWith
(
endpoint
.
getClass
().
getName
()))
{
public
<
A
,
B
>
void
doIt
(
Function
<
A
,
B
>
x
)
{
// Possibly a lambda-defined EndpointFilter which we could not resolve the
// generic EndpointInfo type for
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Non-matching Endpoint for EndpointFilter: "
+
filter
,
ex
);
}
return
false
;
}
throw
ex
;
}
}
}
private
E
getFilterEndpoint
(
EndpointBean
endpointBean
)
{
private
E
getFilterEndpoint
(
EndpointBean
endpointBean
)
{
...
...
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/cache/CacheMetricsRegistrar.java
View file @
798882bd
...
@@ -17,16 +17,15 @@
...
@@ -17,16 +17,15 @@
package
org
.
springframework
.
boot
.
actuate
.
metrics
.
cache
;
package
org
.
springframework
.
boot
.
actuate
.
metrics
.
cache
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Objects
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.MeterRegistry
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.Tag
;
import
io.micrometer.core.instrument.Tags
;
import
io.micrometer.core.instrument.Tags
;
import
io.micrometer.core.instrument.binder.MeterBinder
;
import
io.micrometer.core.instrument.binder.MeterBinder
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.boot.util.LambdaSafe
;
import
org.springframework.cache.Cache
;
import
org.springframework.cache.Cache
;
import
org.springframework.core.ResolvableType
;
/**
/**
* Register supported {@link Cache} to a {@link MeterRegistry}.
* Register supported {@link Cache} to a {@link MeterRegistry}.
...
@@ -36,8 +35,6 @@ import org.springframework.core.ResolvableType;
...
@@ -36,8 +35,6 @@ import org.springframework.core.ResolvableType;
*/
*/
public
class
CacheMetricsRegistrar
{
public
class
CacheMetricsRegistrar
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
CacheMetricsRegistrar
.
class
);
private
final
MeterRegistry
registry
;
private
final
MeterRegistry
registry
;
private
final
String
metricName
;
private
final
String
metricName
;
...
@@ -74,41 +71,15 @@ public class CacheMetricsRegistrar {
...
@@ -74,41 +71,15 @@ public class CacheMetricsRegistrar {
return
false
;
return
false
;
}
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
@SuppressWarnings
({
"unchecked"
})
private
MeterBinder
getMeterBinder
(
Cache
cache
,
Tags
tags
)
{
private
MeterBinder
getMeterBinder
(
Cache
cache
,
Tags
tags
)
{
tags
=
tags
.
and
(
getAdditionalTags
(
cache
));
Tags
cacheTags
=
tags
.
and
(
getAdditionalTags
(
cache
));
for
(
CacheMeterBinderProvider
<?>
binderProvider
:
this
.
binderProviders
)
{
return
LambdaSafe
Class
<?>
cacheType
=
ResolvableType
.
callbacks
(
CacheMeterBinderProvider
.
class
,
this
.
binderProviders
,
cache
)
.
forClass
(
CacheMeterBinderProvider
.
class
,
binderProvider
.
getClass
())
.
withLogger
(
CacheMetricsRegistrar
.
class
)
.
resolveGeneric
();
.
invokeAnd
((
binderProvider
)
->
binderProvider
.
getMeterBinder
(
cache
,
if
(
cacheType
.
isInstance
(
cache
))
{
this
.
metricName
,
cacheTags
))
try
{
.
filter
(
Objects:
:
nonNull
).
findFirst
().
orElse
(
null
);
MeterBinder
meterBinder
=
((
CacheMeterBinderProvider
)
binderProvider
)
.
getMeterBinder
(
cache
,
this
.
metricName
,
tags
);
if
(
meterBinder
!=
null
)
{
return
meterBinder
;
}
}
catch
(
ClassCastException
ex
)
{
String
msg
=
ex
.
getMessage
();
if
(
msg
==
null
||
msg
.
startsWith
(
cache
.
getClass
().
getName
()))
{
// Possibly a lambda-defined CacheMeterBinderProvider which we
// could not resolve the generic Cache type for
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Non-matching Cache type for CacheMeterBinderProvider: "
+
binderProvider
,
ex
);
}
}
else
{
throw
ex
;
}
}
}
}
return
null
;
}
}
/**
/**
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheManagerCustomizers.java
View file @
798882bd
...
@@ -20,11 +20,8 @@ import java.util.ArrayList;
...
@@ -20,11 +20,8 @@ import java.util.ArrayList;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.commons.logging.Log
;
import
org.springframework.boot.util.LambdaSafe
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.cache.CacheManager
;
import
org.springframework.core.ResolvableType
;
/**
/**
* Invokes the available {@link CacheManagerCustomizer} instances in the context for a
* Invokes the available {@link CacheManagerCustomizer} instances in the context for a
...
@@ -35,8 +32,6 @@ import org.springframework.core.ResolvableType;
...
@@ -35,8 +32,6 @@ import org.springframework.core.ResolvableType;
*/
*/
public
class
CacheManagerCustomizers
{
public
class
CacheManagerCustomizers
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
CacheManagerCustomizers
.
class
);
private
final
List
<
CacheManagerCustomizer
<?>>
customizers
;
private
final
List
<
CacheManagerCustomizer
<?>>
customizers
;
public
CacheManagerCustomizers
(
public
CacheManagerCustomizers
(
...
@@ -53,32 +48,12 @@ public class CacheManagerCustomizers {
...
@@ -53,32 +48,12 @@ public class CacheManagerCustomizers {
* @param cacheManager the cache manager to customize
* @param cacheManager the cache manager to customize
* @return the cache manager
* @return the cache manager
*/
*/
@SuppressWarnings
(
"unchecked"
)
public
<
T
extends
CacheManager
>
T
customize
(
T
cacheManager
)
{
public
<
T
extends
CacheManager
>
T
customize
(
T
cacheManager
)
{
for
(
CacheManagerCustomizer
<?>
customizer
:
this
.
customizers
)
{
LambdaSafe
.
callbacks
(
CacheManagerCustomizer
.
class
,
this
.
customizers
,
cacheManager
)
Class
<?>
generic
=
ResolvableType
.
withLogger
(
CacheManagerCustomizers
.
class
)
.
forClass
(
CacheManagerCustomizer
.
class
,
customizer
.
getClass
())
.
invoke
((
customizer
)
->
customizer
.
customize
(
cacheManager
));
.
resolveGeneric
();
if
(
generic
.
isInstance
(
cacheManager
))
{
customize
(
cacheManager
,
customizer
);
}
}
return
cacheManager
;
return
cacheManager
;
}
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
private
void
customize
(
CacheManager
cacheManager
,
CacheManagerCustomizer
customizer
)
{
try
{
customizer
.
customize
(
cacheManager
);
}
catch
(
ClassCastException
ex
)
{
// Possibly a lambda-defined customizer which we could not resolve the generic
// cache manager type for
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Non-matching cache manager type for customizer: "
+
customizer
,
ex
);
}
}
}
}
}
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionManagerCustomizers.java
View file @
798882bd
...
@@ -18,12 +18,10 @@ package org.springframework.boot.autoconfigure.transaction;
...
@@ -18,12 +18,10 @@ package org.springframework.boot.autoconfigure.transaction;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.commons.logging.Log
;
import
org.springframework.boot.util.LambdaSafe
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.core.ResolvableType
;
import
org.springframework.transaction.PlatformTransactionManager
;
import
org.springframework.transaction.PlatformTransactionManager
;
/**
/**
...
@@ -34,44 +32,21 @@ import org.springframework.transaction.PlatformTransactionManager;
...
@@ -34,44 +32,21 @@ import org.springframework.transaction.PlatformTransactionManager;
*/
*/
public
class
TransactionManagerCustomizers
{
public
class
TransactionManagerCustomizers
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
TransactionManagerCustomizers
.
class
);
private
final
List
<
PlatformTransactionManagerCustomizer
<?>>
customizers
;
private
final
List
<
PlatformTransactionManagerCustomizer
<?>>
customizers
;
public
TransactionManagerCustomizers
(
public
TransactionManagerCustomizers
(
Collection
<?
extends
PlatformTransactionManagerCustomizer
<?>>
customizers
)
{
Collection
<?
extends
PlatformTransactionManagerCustomizer
<?>>
customizers
)
{
this
.
customizers
=
(
customizers
==
null
?
null
:
new
ArrayList
<>(
customizers
));
this
.
customizers
=
(
customizers
==
null
?
Collections
.
emptyList
()
:
new
ArrayList
<>(
customizers
));
}
}
@SuppressWarnings
(
"unchecked"
)
public
void
customize
(
PlatformTransactionManager
transactionManager
)
{
public
void
customize
(
PlatformTransactionManager
transactionManager
)
{
if
(
this
.
customizers
!=
null
)
{
LambdaSafe
for
(
PlatformTransactionManagerCustomizer
<?>
customizer
:
this
.
customizers
)
{
.
callbacks
(
PlatformTransactionManagerCustomizer
.
class
,
this
.
customizers
,
Class
<?>
generic
=
ResolvableType
transactionManager
)
.
forClass
(
PlatformTransactionManagerCustomizer
.
class
,
.
withLogger
(
TransactionManagerCustomizers
.
class
)
customizer
.
getClass
())
.
invoke
((
customizer
)
->
customizer
.
customize
(
transactionManager
));
.
resolveGeneric
();
if
(
generic
.
isInstance
(
transactionManager
))
{
customize
(
transactionManager
,
customizer
);
}
}
}
}
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
private
void
customize
(
PlatformTransactionManager
transactionManager
,
PlatformTransactionManagerCustomizer
customizer
)
{
try
{
customizer
.
customize
(
transactionManager
);
}
catch
(
ClassCastException
ex
)
{
// Possibly a lambda-defined customizer which we could not resolve the generic
// transaction manager type for
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Non-matching transaction manager type for customizer: "
+
customizer
,
ex
);
}
}
}
}
}
}
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/util/LambdaSafe.java
0 → 100644
View file @
798882bd
This diff is collapsed.
Click to expand it.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/util/package-info.java
0 → 100644
View file @
798882bd
/*
* Copyright 2012-2018 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.
*/
/**
* Contains miscellaneous utility classes.
*/
package
org
.
springframework
.
boot
.
util
;
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/WebServerFactoryCustomizerBeanPostProcessor.java
View file @
798882bd
...
@@ -21,15 +21,12 @@ import java.util.Collection;
...
@@ -21,15 +21,12 @@ import java.util.Collection;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.ListableBeanFactory
;
import
org.springframework.beans.factory.ListableBeanFactory
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.beans.factory.config.BeanPostProcessor
;
import
org.springframework.
core.ResolvableTyp
e
;
import
org.springframework.
boot.util.LambdaSaf
e
;
import
org.springframework.core.annotation.AnnotationAwareOrderComparator
;
import
org.springframework.core.annotation.AnnotationAwareOrderComparator
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
...
@@ -45,9 +42,6 @@ import org.springframework.util.Assert;
...
@@ -45,9 +42,6 @@ import org.springframework.util.Assert;
public
class
WebServerFactoryCustomizerBeanPostProcessor
public
class
WebServerFactoryCustomizerBeanPostProcessor
implements
BeanPostProcessor
,
BeanFactoryAware
{
implements
BeanPostProcessor
,
BeanFactoryAware
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
WebServerFactoryCustomizerBeanPostProcessor
.
class
);
private
ListableBeanFactory
beanFactory
;
private
ListableBeanFactory
beanFactory
;
private
List
<
WebServerFactoryCustomizer
<?>>
customizers
;
private
List
<
WebServerFactoryCustomizer
<?>>
customizers
;
...
@@ -75,45 +69,13 @@ public class WebServerFactoryCustomizerBeanPostProcessor
...
@@ -75,45 +69,13 @@ public class WebServerFactoryCustomizerBeanPostProcessor
return
bean
;
return
bean
;
}
}
private
void
postProcessBeforeInitialization
(
WebServerFactory
bean
)
{
@SuppressWarnings
(
"unchecked"
)
for
(
WebServerFactoryCustomizer
<?>
customizer
:
getCustomizers
())
{
private
void
postProcessBeforeInitialization
(
WebServerFactory
webServerFactory
)
{
Class
<?>
type
=
ResolvableType
LambdaSafe
.
forClass
(
WebServerFactoryCustomizer
.
class
,
customizer
.
getClass
())
.
callbacks
(
WebServerFactoryCustomizer
.
class
,
getCustomizers
(),
.
getGeneric
().
resolve
(
WebServerFactory
.
class
);
webServerFactory
)
if
(
type
.
isInstance
(
bean
))
{
.
withLogger
(
WebServerFactoryCustomizerBeanPostProcessor
.
class
)
invokeCustomizer
(
customizer
,
bean
);
.
invoke
((
customizer
)
->
customizer
.
customize
(
webServerFactory
));
}
}
}
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
private
void
invokeCustomizer
(
WebServerFactoryCustomizer
customizer
,
WebServerFactory
webServerFactory
)
{
try
{
customizer
.
customize
(
webServerFactory
);
}
catch
(
ClassCastException
ex
)
{
String
msg
=
ex
.
getMessage
();
if
(
msg
==
null
||
msg
.
startsWith
(
webServerFactory
.
getClass
().
getName
()))
{
// Possibly a lambda-defined WebServerFactoryCustomizer which we could not
// resolve the
// generic WebServerFactory type for
logLambdaDebug
(
customizer
,
ex
);
}
else
{
throw
ex
;
}
}
}
private
void
logLambdaDebug
(
WebServerFactoryCustomizer
<?>
customizer
,
ClassCastException
ex
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Non-matching WebServerFactory type for WebServerFactoryCustomizer: "
+
customizer
,
ex
);
}
}
}
private
Collection
<
WebServerFactoryCustomizer
<?>>
getCustomizers
()
{
private
Collection
<
WebServerFactoryCustomizer
<?>>
getCustomizers
()
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java
0 → 100644
View file @
798882bd
This diff is collapsed.
Click to expand it.
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