This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuring feature provider for bookkeeper client
* make the feature provider scope-able * passing the feature provider through client builder * provide cacheable and settable feature provider and by default disable all features in the default provider * deprecate #getFeature and #setFeature in configuration RB_ID=599328
- Loading branch information
Sijie Guo
committed
Mar 11, 2015
1 parent
5c198b6
commit c2a092a
Showing
14 changed files
with
201 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
bookkeeper-server/src/main/java/org/apache/bookkeeper/feature/CacheableFeatureProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.apache.bookkeeper.feature; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
/** | ||
* Cacheable Feature Provider | ||
*/ | ||
public abstract class CacheableFeatureProvider<T extends Feature> implements FeatureProvider { | ||
|
||
protected final String scope; | ||
protected final ConcurrentMap<String, FeatureProvider> scopes = | ||
new ConcurrentHashMap<String, FeatureProvider>(); | ||
protected final ConcurrentMap<String, T> features = | ||
new ConcurrentHashMap<String, T>(); | ||
|
||
protected CacheableFeatureProvider(String scope) { | ||
this.scope = scope; | ||
} | ||
|
||
protected String makeName(String name) { | ||
if (StringUtils.isBlank(scope)) { | ||
return name; | ||
} else { | ||
return scope + "." + name; | ||
} | ||
} | ||
|
||
@Override | ||
public T getFeature(String name) { | ||
T feature = features.get(name); | ||
if (null == feature) { | ||
T newFeature = makeFeature(makeName(name)); | ||
T oldFeature = features.putIfAbsent(name, newFeature); | ||
if (null == oldFeature) { | ||
feature = newFeature; | ||
} else { | ||
feature = oldFeature; | ||
} | ||
} | ||
return feature; | ||
} | ||
|
||
protected abstract T makeFeature(String featureName); | ||
|
||
@Override | ||
public FeatureProvider scope(String name) { | ||
FeatureProvider provider = scopes.get(name); | ||
if (null == provider) { | ||
FeatureProvider newProvider = makeProvider(makeName(name)); | ||
FeatureProvider oldProvider = scopes.putIfAbsent(name, newProvider); | ||
if (null == oldProvider) { | ||
provider = newProvider; | ||
} else { | ||
provider = oldProvider; | ||
} | ||
} | ||
return provider; | ||
} | ||
|
||
protected abstract FeatureProvider makeProvider(String fullScopeName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
bookkeeper-server/src/main/java/org/apache/bookkeeper/feature/FixedValueFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
bookkeeper-server/src/main/java/org/apache/bookkeeper/feature/SettableFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.