netty5/transport/src/main/java/io/netty/channel/AbstractServerChannel.java

97 lines
2.6 KiB
Java
Raw Normal View History

/*
* Copyright 2011 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
2009-08-28 09:15:49 +02:00
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
2009-08-28 09:15:49 +02:00
* License for the specific language governing permissions and limitations
* under the License.
*/
2011-12-09 04:38:59 +01:00
package io.netty.channel;
import java.net.SocketAddress;
import java.util.AbstractQueue;
import java.util.Collections;
import java.util.Iterator;
/**
2008-09-02 09:13:20 +02:00
* A skeletal server-side {@link Channel} implementation. A server-side
2008-11-14 08:45:53 +01:00
* {@link Channel} does not allow the following operations:
2008-09-02 09:13:20 +02:00
* <ul>
* <li>{@link #connect(SocketAddress, ChannelFuture)}</li>
* <li>{@link #disconnect(ChannelFuture)}</li>
* <li>{@link #flush(ChannelFuture)}</li>
2008-09-02 09:13:20 +02:00
* <li>and the shortcut methods which calls the methods mentioned above
* </ul>
*/
2008-12-03 03:38:32 +01:00
public abstract class AbstractServerChannel extends AbstractChannel implements ServerChannel {
private final ChannelBufferHolder<Object> out = ChannelBufferHolders.messageBuffer(new NoopQueue());
2008-09-02 09:13:20 +02:00
/**
* Creates a new instance.
*/
protected AbstractServerChannel() {
super(null);
}
@Override
public ChannelBufferHolder<Object> out() {
return out;
}
@Override
public SocketAddress remoteAddress() {
return null;
}
@Override
protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelFuture future) {
future.setFailure(new UnsupportedOperationException());
}
@Override
protected void doDisconnect(ChannelFuture future) {
future.setFailure(new UnsupportedOperationException());
}
@Override
protected int doFlush(ChannelFuture future) {
future.setFailure(new UnsupportedOperationException());
return 0;
}
private static class NoopQueue extends AbstractQueue<Object> {
@Override
public boolean offer(Object e) {
return false;
}
@Override
public Object poll() {
return null;
}
@Override
public Object peek() {
return null;
}
@Override
public Iterator<Object> iterator() {
return Collections.emptyList().iterator();
}
@Override
public int size() {
return 0;
}
}
}