View Javadoc

1   /*
2    * Copyright 2017 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.bootstrap;
17  
18  import io.netty.channel.AbstractChannel;
19  import io.netty.channel.ChannelConfig;
20  import io.netty.channel.ChannelMetadata;
21  import io.netty.channel.ChannelOutboundBuffer;
22  import io.netty.channel.ChannelPromise;
23  import io.netty.channel.DefaultChannelConfig;
24  import io.netty.channel.EventLoop;
25  
26  import java.net.SocketAddress;
27  
28  final class FailedChannel extends AbstractChannel {
29      private static final ChannelMetadata METADATA = new ChannelMetadata(false);
30      private final ChannelConfig config = new DefaultChannelConfig(this);
31  
32      FailedChannel() {
33          super(null);
34      }
35  
36      @Override
37      protected AbstractUnsafe newUnsafe() {
38          return new FailedChannelUnsafe();
39      }
40  
41      @Override
42      protected boolean isCompatible(EventLoop loop) {
43          return false;
44      }
45  
46      @Override
47      protected SocketAddress localAddress0() {
48          return null;
49      }
50  
51      @Override
52      protected SocketAddress remoteAddress0() {
53          return null;
54      }
55  
56      @Override
57      protected void doBind(SocketAddress localAddress) {
58          throw new UnsupportedOperationException();
59      }
60  
61      @Override
62      protected void doDisconnect() {
63          throw new UnsupportedOperationException();
64      }
65  
66      @Override
67      protected void doClose() {
68          throw new UnsupportedOperationException();
69      }
70  
71      @Override
72      protected void doBeginRead() {
73          throw new UnsupportedOperationException();
74      }
75  
76      @Override
77      protected void doWrite(ChannelOutboundBuffer in) {
78          throw new UnsupportedOperationException();
79      }
80  
81      @Override
82      public ChannelConfig config() {
83          return config;
84      }
85  
86      @Override
87      public boolean isOpen() {
88          return false;
89      }
90  
91      @Override
92      public boolean isActive() {
93          return false;
94      }
95  
96      @Override
97      public ChannelMetadata metadata() {
98          return METADATA;
99      }
100 
101     private final class FailedChannelUnsafe extends AbstractUnsafe {
102         @Override
103         public void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
104             promise.setFailure(new UnsupportedOperationException());
105         }
106     }
107 }