Fixed issue: NETTY-160 Make ChannelLocal non-abstract
This commit is contained in:
parent
af3cd875f0
commit
382099fae2
@ -34,6 +34,7 @@ import org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap;
|
||||
* @apiviz.stereotype utility
|
||||
*/
|
||||
public abstract class ChannelLocal<T> {
|
||||
|
||||
private final ConcurrentMap<Channel, T> map =
|
||||
new ConcurrentIdentityWeakKeyHashMap<Channel, T>();
|
||||
|
||||
@ -44,7 +45,9 @@ public abstract class ChannelLocal<T> {
|
||||
super();
|
||||
}
|
||||
|
||||
protected abstract T initialValue(Channel channel);
|
||||
protected T initialValue(@SuppressWarnings("unused") Channel channel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public T get(Channel channel) {
|
||||
if (channel == null) {
|
||||
@ -54,39 +57,37 @@ public abstract class ChannelLocal<T> {
|
||||
T value = map.get(channel);
|
||||
if (value == null) {
|
||||
value = initialValue(channel);
|
||||
if (value == null) {
|
||||
throw new IllegalStateException(
|
||||
ChannelLocal.class.getSimpleName() +
|
||||
".initialValue() must return non-null.");
|
||||
}
|
||||
|
||||
if (value != null) {
|
||||
T oldValue = setIfAbsent(channel, value);
|
||||
if (oldValue != null) {
|
||||
value = oldValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public T set(Channel channel, T value) {
|
||||
if (value == null) {
|
||||
return remove(channel);
|
||||
} else {
|
||||
if (channel == null) {
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
if (value == null) {
|
||||
throw new NullPointerException("value");
|
||||
}
|
||||
return map.put(channel, value);
|
||||
}
|
||||
}
|
||||
|
||||
public T setIfAbsent(Channel channel, T value) {
|
||||
if (value == null) {
|
||||
return get(channel);
|
||||
} else {
|
||||
if (channel == null) {
|
||||
throw new NullPointerException("channel");
|
||||
}
|
||||
if (value == null) {
|
||||
throw new NullPointerException("value");
|
||||
}
|
||||
return map.putIfAbsent(channel, value);
|
||||
}
|
||||
}
|
||||
|
||||
public T remove(Channel channel) {
|
||||
if (channel == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user