Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HYSTRIX-1625] HystrixCollapserKey, HystrixCommandGroupKey, HystrixCo… #1626

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,12 +1,12 @@
/**
* Copyright 2012 Netflix, Inc.
*
*
* 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.
Expand All @@ -15,29 +15,27 @@
*/
package com.netflix.hystrix;

import java.util.concurrent.ConcurrentHashMap;
import com.netflix.hystrix.util.InternMap;

/**
* A key to represent a {@link HystrixCollapser} for monitoring, circuit-breakers, metrics publishing, caching and other such uses.
* <p>
* This interface is intended to work natively with Enums so that implementing code can be an enum that implements this interface.
*/
public interface HystrixCollapserKey {

/**
* The word 'name' is used instead of 'key' so that Enums can implement this interface and it work natively.
*
* @return String
*/
public String name();

public static class Factory {

public interface HystrixCollapserKey extends HystrixKey {
class Factory {
private Factory() {
}

// used to intern instances so we don't keep re-creating them millions of times for the same key
private static ConcurrentHashMap<String, HystrixCollapserKey> intern = new ConcurrentHashMap<String, HystrixCollapserKey>();
private static final InternMap<String, HystrixCollapserKey> intern
= new InternMap<String, HystrixCollapserKey>(
new InternMap.ValueConstructor<String, HystrixCollapserKey>() {
@Override
public HystrixCollapserKey create(String key) {
return new HystrixCollapserKeyDefault(key);
}
});

/**
* Retrieve (or create) an interned HystrixCollapserKey instance for a given name.
Expand All @@ -46,30 +44,17 @@ private Factory() {
* @return HystrixCollapserKey instance that is interned (cached) so a given name will always retrieve the same instance.
*/
public static HystrixCollapserKey asKey(String name) {
HystrixCollapserKey k = intern.get(name);
if (k == null) {
intern.putIfAbsent(name, new HystrixCollapserKeyDefault(name));
}
return intern.get(name);
return intern.interned(name);
}

private static class HystrixCollapserKeyDefault implements HystrixCollapserKey {

private String name;

private HystrixCollapserKeyDefault(String name) {
this.name = name;
private static class HystrixCollapserKeyDefault extends HystrixKey.HystrixKeyDefault implements HystrixCollapserKey {
public HystrixCollapserKeyDefault(String name) {
super(name);
}
}

@Override
public String name() {
return name;
}

@Override
public String toString() {
return name;
}
/* package-private */ static int getCollapserCount() {
return intern.size();
}
}
}
Expand Up @@ -5,7 +5,7 @@
* 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
* 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,
Expand All @@ -30,28 +30,27 @@ private Factory() {
}

// used to intern instances so we don't keep re-creating them millions of times for the same key
private static final InternMap<String, HystrixCommandGroupDefault> intern
= new InternMap<String, HystrixCommandGroupDefault>(
new InternMap.ValueConstructor<String, HystrixCommandGroupDefault>() {
private static final InternMap<String, HystrixCommandGroupKey> intern
= new InternMap<String, HystrixCommandGroupKey>(
new InternMap.ValueConstructor<String, HystrixCommandGroupKey>() {
@Override
public HystrixCommandGroupDefault create(String key) {
return new HystrixCommandGroupDefault(key);
public HystrixCommandGroupKey create(String key) {
return new HystrixCommandGroupKeyDefault(key);
}
});


/**
* Retrieve (or create) an interned HystrixCommandGroup instance for a given name.
*
* @param name command group name
* @return HystrixCommandGroup instance that is interned (cached) so a given name will always retrieve the same instance.
*/
public static HystrixCommandGroupKey asKey(String name) {
return intern.interned(name);
return intern.interned(name);
}

private static class HystrixCommandGroupDefault extends HystrixKey.HystrixKeyDefault implements HystrixCommandGroupKey {
public HystrixCommandGroupDefault(String name) {
private static class HystrixCommandGroupKeyDefault extends HystrixKey.HystrixKeyDefault implements HystrixCommandGroupKey {
public HystrixCommandGroupKeyDefault(String name) {
super(name);
}
}
Expand All @@ -60,4 +59,4 @@ public HystrixCommandGroupDefault(String name) {
return intern.size();
}
}
}
}
@@ -1,12 +1,12 @@
/**
* Copyright 2012 Netflix, Inc.
*
*
* 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.
Expand All @@ -28,19 +28,18 @@ private Factory() {
}

// used to intern instances so we don't keep re-creating them millions of times for the same key
private static final InternMap<String, HystrixCommandKeyDefault> intern
= new InternMap<String, HystrixCommandKeyDefault>(
new InternMap.ValueConstructor<String, HystrixCommandKeyDefault>() {
private static final InternMap<String, HystrixCommandKey> intern
= new InternMap<String, HystrixCommandKey>(
new InternMap.ValueConstructor<String, HystrixCommandKey>() {
@Override
public HystrixCommandKeyDefault create(String key) {
public HystrixCommandKey create(String key) {
return new HystrixCommandKeyDefault(key);
}
});


/**
* Retrieve (or create) an interned HystrixCommandKey instance for a given name.
*
*
* @param name command name
* @return HystrixCommandKey instance that is interned (cached) so a given name will always retrieve the same instance.
*/
Expand All @@ -58,5 +57,4 @@ public HystrixCommandKeyDefault(String name) {
return intern.size();
}
}

}
@@ -1,12 +1,12 @@
/**
* Copyright 2012 Netflix, Inc.
*
*
* 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.
Expand Down Expand Up @@ -39,12 +39,12 @@ public HystrixThreadPoolKey create(String key) {

/**
* Retrieve (or create) an interned HystrixThreadPoolKey instance for a given name.
*
*
* @param name thread pool name
* @return HystrixThreadPoolKey instance that is interned (cached) so a given name will always retrieve the same instance.
*/
public static HystrixThreadPoolKey asKey(String name) {
return intern.interned(name);
return intern.interned(name);
}

private static class HystrixThreadPoolKeyDefault extends HystrixKeyDefault implements HystrixThreadPoolKey {
Expand Down