* Renamed LocalServerChannel to DefaultLocalServerChannel

* Added LocalServerChannel interface
* Covariant return types for Local*ChannelFactory
This commit is contained in:
Trustin Lee 2009-02-21 19:15:30 +00:00
parent 0e443c3a02
commit 3d7214ba61
6 changed files with 89 additions and 53 deletions

View File

@ -0,0 +1,74 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. 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.channel.local;
import static org.jboss.netty.channel.Channels.*;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.netty.channel.AbstractServerChannel;
import org.jboss.netty.channel.ChannelConfig;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelSink;
import org.jboss.netty.channel.DefaultServerChannelConfig;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
final class DefaultLocalServerChannel extends AbstractServerChannel
implements LocalServerChannel {
final ChannelConfig channelConfig;
final AtomicBoolean bound = new AtomicBoolean();
volatile LocalAddress localAddress;
DefaultLocalServerChannel(ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) {
super(factory, pipeline, sink);
channelConfig = new DefaultServerChannelConfig();
fireChannelOpen(this);
}
public ChannelConfig getConfig() {
return channelConfig;
}
public boolean isBound() {
return isOpen() && bound.get();
}
public LocalAddress getLocalAddress() {
return isBound()? localAddress : null;
}
public LocalAddress getRemoteAddress() {
return null;
}
@Override
protected boolean setClosed() {
return super.setClosed();
}
}

View File

@ -21,7 +21,6 @@
*/
package org.jboss.netty.channel.local;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelSink;
@ -40,7 +39,7 @@ public class LocalClientChannelFactory implements ChannelFactory {
sink = new LocalClientChannelSink();
}
public Channel newChannel(ChannelPipeline pipeline) {
public LocalChannel newChannel(ChannelPipeline pipeline) {
return new DefaultLocalChannel(null, this, pipeline, sink, null);
}

View File

@ -115,12 +115,12 @@ final class LocalClientChannelSink extends AbstractChannelSink {
private void connect(DefaultLocalChannel channel, ChannelFuture future, LocalAddress remoteAddress) {
Channel remoteChannel = LocalChannelRegistry.getChannel(remoteAddress);
if (!(remoteChannel instanceof LocalServerChannel)) {
if (!(remoteChannel instanceof DefaultLocalServerChannel)) {
future.setFailure(new ConnectException("connection refused"));
return;
}
LocalServerChannel serverChannel = (LocalServerChannel) remoteChannel;
DefaultLocalServerChannel serverChannel = (DefaultLocalServerChannel) remoteChannel;
ChannelPipeline pipeline;
try {
pipeline = serverChannel.getConfig().getPipelineFactory().getPipeline();

View File

@ -21,16 +21,8 @@
*/
package org.jboss.netty.channel.local;
import static org.jboss.netty.channel.Channels.*;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.netty.channel.AbstractServerChannel;
import org.jboss.netty.channel.ChannelConfig;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelSink;
import org.jboss.netty.channel.DefaultServerChannelConfig;
import org.jboss.netty.channel.ServerChannel;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
@ -38,36 +30,8 @@ import org.jboss.netty.channel.DefaultServerChannelConfig;
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
final class LocalServerChannel extends AbstractServerChannel {
final ChannelConfig channelConfig;
final AtomicBoolean bound = new AtomicBoolean();
volatile LocalAddress localAddress;
LocalServerChannel(ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink) {
super(factory, pipeline, sink);
channelConfig = new DefaultServerChannelConfig();
fireChannelOpen(this);
}
public ChannelConfig getConfig() {
return channelConfig;
}
public boolean isBound() {
return isOpen() && bound.get();
}
public LocalAddress getLocalAddress() {
return isBound()? localAddress : null;
}
public LocalAddress getRemoteAddress() {
return null;
}
@Override
protected boolean setClosed() {
return super.setClosed();
}
public interface LocalServerChannel extends ServerChannel {
ChannelConfig getConfig();
LocalAddress getLocalAddress();
LocalAddress getRemoteAddress();
}

View File

@ -21,7 +21,6 @@
*/
package org.jboss.netty.channel.local;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelSink;
@ -40,8 +39,8 @@ public class LocalServerChannelFactory implements ChannelFactory {
super();
}
public Channel newChannel(ChannelPipeline pipeline) {
return new LocalServerChannel(this, pipeline, sink);
public LocalServerChannel newChannel(ChannelPipeline pipeline) {
return new DefaultLocalServerChannel(this, pipeline, sink);
}
public void releaseExternalResources() {

View File

@ -47,7 +47,7 @@ final class LocalServerChannelSink extends AbstractChannelSink {
public void eventSunk(ChannelPipeline pipeline, ChannelEvent e) throws Exception {
Channel channel = e.getChannel();
if (channel instanceof LocalServerChannel) {
if (channel instanceof DefaultLocalServerChannel) {
handleServerChannel(e);
}
else if (channel instanceof DefaultLocalChannel) {
@ -61,8 +61,8 @@ final class LocalServerChannelSink extends AbstractChannelSink {
}
ChannelStateEvent event = (ChannelStateEvent) e;
LocalServerChannel channel =
(LocalServerChannel) event.getChannel();
DefaultLocalServerChannel channel =
(DefaultLocalServerChannel) event.getChannel();
ChannelFuture future = event.getFuture();
ChannelState state = event.getState();
Object value = event.getValue();
@ -114,7 +114,7 @@ final class LocalServerChannelSink extends AbstractChannelSink {
}
}
private void bind(LocalServerChannel channel, ChannelFuture future, LocalAddress localAddress) {
private void bind(DefaultLocalServerChannel channel, ChannelFuture future, LocalAddress localAddress) {
try {
if (!LocalChannelRegistry.register(localAddress, channel)) {
throw new ChannelException("address already in use: " + localAddress);
@ -133,7 +133,7 @@ final class LocalServerChannelSink extends AbstractChannelSink {
}
}
private void close(LocalServerChannel channel, ChannelFuture future) {
private void close(DefaultLocalServerChannel channel, ChannelFuture future) {
future.setSuccess();
if (channel.setClosed()) {
LocalAddress localAddress = channel.localAddress;