Skip to content

Commit

Permalink
Update Spring Boot to 2.0.0 version #1323
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita committed Mar 5, 2018
1 parent 3869ba1 commit 5e77ffc
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 45 deletions.
17 changes: 16 additions & 1 deletion redisson/pom.xml
Expand Up @@ -268,10 +268,25 @@
<scope>provided</scope> <scope>provided</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>

<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId> <artifactId>spring-boot-actuator</artifactId>
<version>[1.4,2.0.0)</version> <version>[2.0.0,)</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>[2.0.0,)</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>[1.0.1,)</version>
<scope>provided</scope> <scope>provided</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
Expand Down
Expand Up @@ -43,8 +43,10 @@ public class RedissonCache implements Cache {


private final AtomicLong hits = new AtomicLong(); private final AtomicLong hits = new AtomicLong();


private final AtomicLong puts = new AtomicLong();

private final AtomicLong misses = new AtomicLong(); private final AtomicLong misses = new AtomicLong();

public RedissonCache(RMapCache<Object, Object> mapCache, CacheConfig config, boolean allowNullValues) { public RedissonCache(RMapCache<Object, Object> mapCache, CacheConfig config, boolean allowNullValues) {
this(mapCache, allowNullValues); this(mapCache, allowNullValues);
this.mapCache = mapCache; this.mapCache = mapCache;
Expand Down Expand Up @@ -106,6 +108,7 @@ public void put(Object key, Object value) {
} else { } else {
map.fastPut(key, value); map.fastPut(key, value);
} }
addCachePut();
} }


public ValueWrapper putIfAbsent(Object key, Object value) { public ValueWrapper putIfAbsent(Object key, Object value) {
Expand All @@ -119,6 +122,9 @@ public ValueWrapper putIfAbsent(Object key, Object value) {
} else { } else {
prevValue = map.putIfAbsent(key, value); prevValue = map.putIfAbsent(key, value);
} }
if (prevValue == null) {
addCachePut();
}
} }


return toValueWrapper(prevValue); return toValueWrapper(prevValue);
Expand Down Expand Up @@ -205,6 +211,14 @@ long getCacheHits(){
long getCacheMisses(){ long getCacheMisses(){
return misses.get(); return misses.get();
} }

long getCachePuts() {
return puts.get();
}

private void addCachePut() {
puts.incrementAndGet();
}


private void addCacheHit(){ private void addCacheHit(){
hits.incrementAndGet(); hits.incrementAndGet();
Expand Down
@@ -0,0 +1,36 @@
/**
* Copyright 2018 Nikita Koksharov
*
* 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.redisson.spring.cache;

import org.springframework.boot.actuate.metrics.cache.CacheMeterBinderProvider;

import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.MeterBinder;

/**
*
*
* @author Nikita Koksharov
*
*/
public class RedissonCacheMeterBinderProvider implements CacheMeterBinderProvider<RedissonCache> {

@Override
public MeterBinder getMeterBinder(RedissonCache cache, Iterable<Tag> tags) {
return new RedissonCacheMetrics(cache, tags);
}

}
@@ -0,0 +1,78 @@
/**
* Copyright 2018 Nikita Koksharov
*
* 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.redisson.spring.cache;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.cache.CacheMeterBinder;

/**
*
* @author Nikita Koksharov
*
*/
public class RedissonCacheMetrics extends CacheMeterBinder {

private final RedissonCache cache;

public RedissonCacheMetrics(RedissonCache cache, Iterable<Tag> tags) {
super(cache, cache.getName(), tags);
this.cache = cache;
}

/**
* Record metrics on a Redisson cache.
*
* @param registry - registry to bind metrics to
* @param cache - cache to instrument
* @param tags - tags to apply to all recorded metrics
* @return cache
*/
public static RedissonCache monitor(MeterRegistry registry, RedissonCache cache, Iterable<Tag> tags) {
new RedissonCacheMetrics(cache, tags).bindTo(registry);
return cache;
}

@Override
protected Long size() {
return (long) cache.getNativeCache().size();
}

@Override
protected long hitCount() {
return cache.getCacheHits();
}

@Override
protected long missCount() {
return cache.getCacheMisses();
}

@Override
protected Long evictionCount() {
return null;
}

@Override
protected long putCount() {
return cache.getCachePuts();
}

@Override
protected void bindImplementationSpecificMetrics(MeterRegistry registry) {
}

}
Expand Up @@ -15,7 +15,6 @@
*/ */
package org.redisson.spring.cache; package org.redisson.spring.cache;


import org.springframework.boot.actuate.cache.CacheStatisticsProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
Expand All @@ -25,20 +24,25 @@
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 io.micrometer.core.instrument.binder.MeterBinder;

/** /**
* *
* @author Craig Andrews * @author Craig Andrews
* @author Nikita Koksharov
* *
* {@link EnableAutoConfiguration Auto-configuration} for {@link RedissonCacheStatisticsProvider} * {@link EnableAutoConfiguration Auto-configuration} for {@link RedissonCacheMeterBinderProvider}
* *
*/ */
@Configuration @Configuration
@AutoConfigureAfter(CacheAutoConfiguration.class) @AutoConfigureAfter(CacheAutoConfiguration.class)
@ConditionalOnBean(CacheManager.class) @ConditionalOnBean(CacheManager.class)
@ConditionalOnClass(CacheStatisticsProvider.class) @ConditionalOnClass(MeterBinder.class)
public class RedissonCacheStatisticsAutoConfiguration { public class RedissonCacheStatisticsAutoConfiguration {

@Bean @Bean
public RedissonCacheStatisticsProvider redissonCacheStatisticsProvider(){ public RedissonCacheMeterBinderProvider redissonCacheMeterBinderProvider(){
return new RedissonCacheStatisticsProvider(); return new RedissonCacheMeterBinderProvider();
} }

} }

This file was deleted.

0 comments on commit 5e77ffc

Please sign in to comment.