View Javadoc
1   /*
2    * Copyright 2013 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.socket.oio;
17  
18  import io.netty.buffer.ByteBufAllocator;
19  import io.netty.channel.ChannelException;
20  import io.netty.channel.ChannelOption;
21  import io.netty.channel.MessageSizeEstimator;
22  import io.netty.channel.PreferHeapByteBufAllocator;
23  import io.netty.channel.RecvByteBufAllocator;
24  import io.netty.channel.WriteBufferWaterMark;
25  import io.netty.channel.socket.DefaultServerSocketChannelConfig;
26  import io.netty.channel.socket.ServerSocketChannel;
27  
28  import java.io.IOException;
29  import java.net.ServerSocket;
30  import java.util.Map;
31  
32  import static io.netty.channel.ChannelOption.*;
33  
34  /**
35   * Default {@link OioServerSocketChannelConfig} implementation
36   *
37   * @deprecated use NIO / EPOLL / KQUEUE transport.
38   */
39  @Deprecated
40  public class DefaultOioServerSocketChannelConfig extends DefaultServerSocketChannelConfig implements
41          OioServerSocketChannelConfig {
42  
43      @Deprecated
44      public DefaultOioServerSocketChannelConfig(ServerSocketChannel channel, ServerSocket javaSocket) {
45          super(channel, javaSocket);
46          setAllocator(new PreferHeapByteBufAllocator(getAllocator()));
47      }
48  
49      DefaultOioServerSocketChannelConfig(OioServerSocketChannel channel, ServerSocket javaSocket) {
50          super(channel, javaSocket);
51          setAllocator(new PreferHeapByteBufAllocator(getAllocator()));
52      }
53  
54      @Override
55      public Map<ChannelOption<?>, Object> getOptions() {
56          return getOptions(
57                  super.getOptions(), SO_TIMEOUT);
58      }
59  
60      @SuppressWarnings("unchecked")
61      @Override
62      public <T> T getOption(ChannelOption<T> option) {
63          if (option == SO_TIMEOUT) {
64              return (T) Integer.valueOf(getSoTimeout());
65          }
66          return super.getOption(option);
67      }
68  
69      @Override
70      public <T> boolean setOption(ChannelOption<T> option, T value) {
71          validate(option, value);
72  
73          if (option == SO_TIMEOUT) {
74              setSoTimeout((Integer) value);
75          } else {
76              return super.setOption(option, value);
77          }
78          return true;
79      }
80  
81      @Override
82      public OioServerSocketChannelConfig setSoTimeout(int timeout) {
83          try {
84              javaSocket.setSoTimeout(timeout);
85          } catch (IOException e) {
86              throw new ChannelException(e);
87          }
88          return this;
89      }
90  
91      @Override
92      public int getSoTimeout() {
93          try {
94              return javaSocket.getSoTimeout();
95          } catch (IOException e) {
96              throw new ChannelException(e);
97          }
98      }
99  
100     @Override
101     public OioServerSocketChannelConfig setBacklog(int backlog) {
102         super.setBacklog(backlog);
103         return this;
104     }
105 
106     @Override
107     public OioServerSocketChannelConfig setReuseAddress(boolean reuseAddress) {
108         super.setReuseAddress(reuseAddress);
109         return this;
110     }
111 
112     @Override
113     public OioServerSocketChannelConfig setReceiveBufferSize(int receiveBufferSize) {
114         super.setReceiveBufferSize(receiveBufferSize);
115         return this;
116     }
117 
118     @Override
119     public OioServerSocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth) {
120         super.setPerformancePreferences(connectionTime, latency, bandwidth);
121         return this;
122     }
123 
124     @Override
125     public OioServerSocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
126         super.setConnectTimeoutMillis(connectTimeoutMillis);
127         return this;
128     }
129 
130     @Override
131     @Deprecated
132     public OioServerSocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
133         super.setMaxMessagesPerRead(maxMessagesPerRead);
134         return this;
135     }
136 
137     @Override
138     public OioServerSocketChannelConfig setWriteSpinCount(int writeSpinCount) {
139         super.setWriteSpinCount(writeSpinCount);
140         return this;
141     }
142 
143     @Override
144     public OioServerSocketChannelConfig setAllocator(ByteBufAllocator allocator) {
145         super.setAllocator(allocator);
146         return this;
147     }
148 
149     @Override
150     public OioServerSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
151         super.setRecvByteBufAllocator(allocator);
152         return this;
153     }
154 
155     @Override
156     public OioServerSocketChannelConfig setAutoRead(boolean autoRead) {
157         super.setAutoRead(autoRead);
158         return this;
159     }
160 
161     @Override
162     protected void autoReadCleared() {
163         if (channel instanceof OioServerSocketChannel) {
164             ((OioServerSocketChannel) channel).clearReadPending0();
165         }
166     }
167 
168     @Override
169     public OioServerSocketChannelConfig setAutoClose(boolean autoClose) {
170         super.setAutoClose(autoClose);
171         return this;
172     }
173 
174     @Override
175     public OioServerSocketChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
176         super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
177         return this;
178     }
179 
180     @Override
181     public OioServerSocketChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
182         super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
183         return this;
184     }
185 
186     @Override
187     public OioServerSocketChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark) {
188         super.setWriteBufferWaterMark(writeBufferWaterMark);
189         return this;
190     }
191 
192     @Override
193     public OioServerSocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
194         super.setMessageSizeEstimator(estimator);
195         return this;
196     }
197 }