Fixed issue: NETTY-160 Make ChannelLocal non-abstract

This commit is contained in:
Trustin Lee 2009-05-28 23:41:26 +00:00
parent af3cd875f0
commit 382099fae2

View File

@ -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,38 +57,36 @@ 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.");
}
T oldValue = setIfAbsent(channel, value);
if (oldValue != null) {
value = oldValue;
if (value != null) {
T oldValue = setIfAbsent(channel, value);
if (oldValue != null) {
value = oldValue;
}
}
}
return value;
}
public T set(Channel channel, T value) {
if (channel == null) {
throw new NullPointerException("channel");
}
if (value == null) {
throw new NullPointerException("value");
return remove(channel);
} else {
if (channel == null) {
throw new NullPointerException("channel");
}
return map.put(channel, value);
}
return map.put(channel, value);
}
public T setIfAbsent(Channel channel, T value) {
if (channel == null) {
throw new NullPointerException("channel");
}
if (value == null) {
throw new NullPointerException("value");
return get(channel);
} else {
if (channel == null) {
throw new NullPointerException("channel");
}
return map.putIfAbsent(channel, value);
}
return map.putIfAbsent(channel, value);
}
public T remove(Channel channel) {