View Javadoc
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      private static final ChannelMetadata METADATA = new ChannelMetadata(false, 16);
33  
34      /**
35       * Creates a new instance.
36       */
37      protected AbstractServerChannel() {
38          super(null);
39      }
40  
41      @Override
42      public ChannelMetadata metadata() {
43          return METADATA;
44      }
45  
46      @Override
47      public SocketAddress remoteAddress() {
48          return null;
49      }
50  
51      @Override
52      protected SocketAddress remoteAddress0() {
53          return null;
54      }
55  
56      @Override
57      protected void doDisconnect() throws Exception {
58          throw new UnsupportedOperationException();
59      }
60  
61      @Override
62      protected AbstractUnsafe newUnsafe() {
63          return new DefaultServerUnsafe();
64      }
65  
66      @Override
67      protected void doWrite(ChannelOutboundBuffer in) throws Exception {
68          throw new UnsupportedOperationException();
69      }
70  
71      @Override
72      protected final Object filterOutboundMessage(Object msg) {
73          throw new UnsupportedOperationException();
74      }
75  
76      private final class DefaultServerUnsafe extends AbstractUnsafe {
77          @Override
78          public void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
79              safeSetFailure(promise, new UnsupportedOperationException());
80          }
81      }
82  }