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
fa0a137c
Commit
fa0a137c
authored
Jun 17, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.3.x'
parents
2ff9e3cf
a2446080
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
8 deletions
+17
-8
SimpleInMemoryRepository.java
...k/boot/actuate/metrics/util/SimpleInMemoryRepository.java
+17
-8
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/util/SimpleInMemoryRepository.java
View file @
fa0a137c
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -18,29 +18,26 @@ package org.springframework.boot.actuate.metrics.util;
...
@@ -18,29 +18,26 @@ package org.springframework.boot.actuate.metrics.util;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.NavigableMap
;
import
java.util.NavigableMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.ConcurrentMap
;
import
java.util.concurrent.ConcurrentNavigableMap
;
import
java.util.concurrent.ConcurrentNavigableMap
;
import
java.util.concurrent.ConcurrentSkipListMap
;
import
java.util.concurrent.ConcurrentSkipListMap
;
import
org.springframework.util.ConcurrentReferenceHashMap
;
/**
/**
* Repository utility that stores stuff in memory with period-separated String keys.
* Repository utility that stores stuff in memory with period-separated String keys.
*
*
* @param <T> the type to store
* @param <T> the type to store
* @author Dave Syer
* @author Dave Syer
* @author Andy Wilkinson
*/
*/
public
class
SimpleInMemoryRepository
<
T
>
{
public
class
SimpleInMemoryRepository
<
T
>
{
private
ConcurrentNavigableMap
<
String
,
T
>
values
=
new
ConcurrentSkipListMap
<
String
,
T
>();
private
ConcurrentNavigableMap
<
String
,
T
>
values
=
new
ConcurrentSkipListMap
<
String
,
T
>();
private
final
ConcurrentMap
<
String
,
Object
>
locks
=
new
Concurrent
Reference
HashMap
<
String
,
Object
>();
private
final
ConcurrentMap
<
String
,
Object
>
locks
=
new
ConcurrentHashMap
<
String
,
Object
>();
public
T
update
(
String
name
,
Callback
<
T
>
callback
)
{
public
T
update
(
String
name
,
Callback
<
T
>
callback
)
{
Object
lock
=
this
.
locks
.
putIfAbsent
(
name
,
new
Object
());
Object
lock
=
getLock
(
name
);
if
(
lock
==
null
)
{
lock
=
this
.
locks
.
get
(
name
);
}
synchronized
(
lock
)
{
synchronized
(
lock
)
{
T
current
=
this
.
values
.
get
(
name
);
T
current
=
this
.
values
.
get
(
name
);
T
value
=
callback
.
modify
(
current
);
T
value
=
callback
.
modify
(
current
);
...
@@ -49,6 +46,18 @@ public class SimpleInMemoryRepository<T> {
...
@@ -49,6 +46,18 @@ public class SimpleInMemoryRepository<T> {
}
}
}
}
private
Object
getLock
(
String
name
)
{
Object
lock
=
this
.
locks
.
get
(
name
);
if
(
lock
==
null
)
{
Object
newLock
=
new
Object
();
lock
=
this
.
locks
.
putIfAbsent
(
name
,
newLock
);
if
(
lock
==
null
)
{
lock
=
newLock
;
}
}
return
lock
;
}
public
void
set
(
String
name
,
T
value
)
{
public
void
set
(
String
name
,
T
value
)
{
T
current
=
this
.
values
.
get
(
name
);
T
current
=
this
.
values
.
get
(
name
);
if
(
current
!=
null
)
{
if
(
current
!=
null
)
{
...
...
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