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    *   https://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.netty5.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)}</li>
25   * <li>{@link #disconnect()}</li>
26   * <li>{@link #write(Object)}</li>
27   * <li>{@link #flush()}</li>
28   * <li>{@link #shutdown(ChannelShutdownDirection)}</li>
29   * <li>and the shortcut methods which calls the methods mentioned above
30   * </ul>
31   */
32  public abstract class AbstractServerChannel<P extends Channel, L extends SocketAddress, R extends SocketAddress>
33          extends AbstractChannel<P, L, R> implements ServerChannel {
34      private static final ChannelMetadata METADATA = new ChannelMetadata(false, 16);
35  
36      private final EventLoopGroup childEventLoopGroup;
37  
38      /**
39       * Creates a new instance.
40       */
41      protected AbstractServerChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup,
42                                      Class<? extends Channel> childChannelType) {
43          this(eventLoop, childEventLoopGroup, METADATA, childChannelType);
44      }
45  
46      protected AbstractServerChannel(EventLoop eventLoop, EventLoopGroup childEventLoopGroup, ChannelMetadata metadata,
47                                      Class<? extends Channel> childChannelType) {
48          super(null, eventLoop, metadata, new ServerChannelRecvBufferAllocator());
49          this.childEventLoopGroup = validateEventLoopGroup(childEventLoopGroup, "childEventLoopGroup", childChannelType);
50      }
51  
52      @Override
53      public final EventLoopGroup childEventLoopGroup() {
54          return childEventLoopGroup;
55      }
56  
57      @Override
58      protected final R remoteAddress0() {
59          return null;
60      }
61  
62      @Override
63      protected final void doDisconnect() {
64          throw new UnsupportedOperationException();
65      }
66  
67      @Override
68      protected final void doShutdown(ChannelShutdownDirection direction) {
69          throw new UnsupportedOperationException();
70      }
71  
72      @Override
73      public final boolean isShutdown(ChannelShutdownDirection direction) {
74          return !isActive();
75      }
76  
77      @Override
78      protected final void doWrite(ChannelOutboundBuffer in) {
79          throw new UnsupportedOperationException();
80      }
81  
82      @Override
83      protected final Object filterOutboundMessage(Object msg) {
84          throw new UnsupportedOperationException();
85      }
86  
87      @Override
88      protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) {
89          throw new UnsupportedOperationException();
90      }
91  
92      @Override
93      protected boolean doFinishConnect(R requestedRemoteAddress) {
94          throw new UnsupportedOperationException();
95      }
96  }