1 /*
2 * Copyright 2012 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package io.netty.channel;
17
18 import java.net.SocketAddress;
19
20 /**
21 * A skeletal server-side {@link Channel} implementation. A server-side
22 * {@link Channel} does not allow the following operations:
23 * <ul>
24 * <li>{@link #connect(SocketAddress, ChannelPromise)}</li>
25 * <li>{@link #disconnect(ChannelPromise)}</li>
26 * <li>{@link #write(Object, ChannelPromise)}</li>
27 * <li>{@link #flush()}</li>
28 * <li>and the shortcut methods which calls the methods mentioned above
29 * </ul>
30 */
31 public abstract class AbstractServerChannel extends AbstractChannel implements ServerChannel {
32
33 private static final ChannelMetadata METADATA = new ChannelMetadata(false);
34
35 /**
36 * Creates a new instance.
37 */
38 protected AbstractServerChannel() {
39 super(null);
40 }
41
42 @Override
43 public ChannelMetadata metadata() {
44 return METADATA;
45 }
46
47 @Override
48 public SocketAddress remoteAddress() {
49 return null;
50 }
51
52 @Override
53 protected SocketAddress remoteAddress0() {
54 return null;
55 }
56
57 @Override
58 protected void doDisconnect() throws Exception {
59 throw new UnsupportedOperationException();
60 }
61
62 @Override
63 protected AbstractUnsafe newUnsafe() {
64 return new DefaultServerUnsafe();
65 }
66
67 @Override
68 protected void doWrite(ChannelOutboundBuffer in) throws Exception {
69 throw new UnsupportedOperationException();
70 }
71
72 @Override
73 protected final Object filterOutboundMessage(Object msg) {
74 throw new UnsupportedOperationException();
75 }
76
77 private final class DefaultServerUnsafe extends AbstractUnsafe {
78 @Override
79 public void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
80 safeSetFailure(promise, new UnsupportedOperationException());
81 }
82 }
83 }