Added ThreadLocalBoolean and replaced unnecessary anonymous classes

This commit is contained in:
Trustin Lee 2009-02-21 19:12:03 +00:00
parent cd6fce50bc
commit 0e443c3a02
3 changed files with 50 additions and 12 deletions

View File

@ -37,6 +37,7 @@ import org.jboss.netty.channel.ChannelSink;
import org.jboss.netty.channel.DefaultChannelConfig;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.util.LinkedTransferQueue;
import org.jboss.netty.util.ThreadLocalBoolean;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
@ -45,14 +46,9 @@ import org.jboss.netty.util.LinkedTransferQueue;
* @version $Rev$, $Date$
*/
final class DefaultLocalChannel extends AbstractChannel implements LocalChannel {
private final ThreadLocal<Boolean> delivering = new ThreadLocal<Boolean>() {
@Override
protected Boolean initialValue() {
return false;
}
};
private final ChannelConfig config;
private final ThreadLocalBoolean delivering = new ThreadLocalBoolean();
final AtomicBoolean bound = new AtomicBoolean();
final Queue<MessageEvent> writeBuffer = new LinkedTransferQueue<MessageEvent>();

View File

@ -40,6 +40,7 @@ import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelSink;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.util.LinkedTransferQueue;
import org.jboss.netty.util.ThreadLocalBoolean;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
@ -164,12 +165,7 @@ class NioSocketChannel extends AbstractChannel
private final class WriteBuffer extends LinkedTransferQueue<MessageEvent> {
private final ThreadLocal<Boolean> notifying = new ThreadLocal<Boolean>() {
@Override
protected Boolean initialValue() {
return Boolean.FALSE;
}
};
private final ThreadLocalBoolean notifying = new ThreadLocalBoolean();
WriteBuffer() {
super();

View File

@ -0,0 +1,46 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.util;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
public class ThreadLocalBoolean extends ThreadLocal<Boolean> {
private final boolean defaultValue;
public ThreadLocalBoolean() {
this(false);
}
public ThreadLocalBoolean(boolean defaultValue) {
this.defaultValue = defaultValue;
}
@Override
protected Boolean initialValue() {
return defaultValue? Boolean.TRUE : Boolean.FALSE;
}
}