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.udt;
17  
18  import com.barchart.udt.nio.ChannelUDT;
19  import io.netty.buffer.ByteBufAllocator;
20  import io.netty.channel.ChannelOption;
21  import io.netty.channel.MessageSizeEstimator;
22  import io.netty.channel.RecvByteBufAllocator;
23  
24  import java.io.IOException;
25  import java.util.Map;
26  
27  import static io.netty.channel.ChannelOption.*;
28  
29  /**
30   * The default {@link UdtServerChannelConfig} implementation.
31   */
32  public class DefaultUdtServerChannelConfig extends DefaultUdtChannelConfig
33          implements UdtServerChannelConfig {
34  
35      private volatile int backlog = 64;
36  
37      public DefaultUdtServerChannelConfig(
38              final UdtChannel channel, final ChannelUDT channelUDT, final boolean apply) throws IOException {
39          super(channel, channelUDT, apply);
40          if (apply) {
41              apply(channelUDT);
42          }
43      }
44  
45      @Override
46      protected void apply(final ChannelUDT channelUDT) throws IOException {
47          // nothing to apply for now.
48      }
49  
50      @Override
51      public int getBacklog() {
52          return backlog;
53      }
54  
55      @SuppressWarnings("unchecked")
56      @Override
57      public <T> T getOption(final ChannelOption<T> option) {
58          if (option == SO_BACKLOG) {
59              return (T) Integer.valueOf(getBacklog());
60          }
61          return super.getOption(option);
62      }
63  
64      @Override
65      public Map<ChannelOption<?>, Object> getOptions() {
66          return getOptions(super.getOptions(), SO_BACKLOG);
67      }
68  
69      @Override
70      public UdtServerChannelConfig setBacklog(final int backlog) {
71          this.backlog = backlog;
72          return this;
73      }
74  
75      @Override
76      public <T> boolean setOption(final ChannelOption<T> option, final T value) {
77          validate(option, value);
78          if (option == SO_BACKLOG) {
79              setBacklog((Integer) value);
80          } else {
81              return super.setOption(option, value);
82          }
83          return true;
84      }
85  
86      @Override
87      public UdtServerChannelConfig setProtocolReceiveBufferSize(
88              final int protocolReceiveBufferSize) {
89          super.setProtocolReceiveBufferSize(protocolReceiveBufferSize);
90          return this;
91      }
92  
93      @Override
94      public UdtServerChannelConfig setProtocolSendBufferSize(
95              final int protocolSendBufferSize) {
96          super.setProtocolSendBufferSize(protocolSendBufferSize);
97          return this;
98      }
99  
100     @Override
101     public UdtServerChannelConfig setReceiveBufferSize(
102             final int receiveBufferSize) {
103         super.setReceiveBufferSize(receiveBufferSize);
104         return this;
105     }
106 
107     @Override
108     public UdtServerChannelConfig setReuseAddress(final boolean reuseAddress) {
109         super.setReuseAddress(reuseAddress);
110         return this;
111     }
112 
113     @Override
114     public UdtServerChannelConfig setSendBufferSize(final int sendBufferSize) {
115         super.setSendBufferSize(sendBufferSize);
116         return this;
117     }
118 
119     @Override
120     public UdtServerChannelConfig setSoLinger(final int soLinger) {
121         super.setSoLinger(soLinger);
122         return this;
123     }
124 
125     @Override
126     public UdtServerChannelConfig setSystemReceiveBufferSize(
127             final int systemSendBufferSize) {
128         super.setSystemReceiveBufferSize(systemSendBufferSize);
129         return this;
130     }
131 
132     @Override
133     public UdtServerChannelConfig setSystemSendBufferSize(
134             final int systemReceiveBufferSize) {
135         super.setSystemSendBufferSize(systemReceiveBufferSize);
136         return this;
137     }
138 
139     @Override
140     public UdtServerChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
141         super.setConnectTimeoutMillis(connectTimeoutMillis);
142         return this;
143     }
144 
145     @Override
146     public UdtServerChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
147         super.setMaxMessagesPerRead(maxMessagesPerRead);
148         return this;
149     }
150 
151     @Override
152     public UdtServerChannelConfig setWriteSpinCount(int writeSpinCount) {
153         super.setWriteSpinCount(writeSpinCount);
154         return this;
155     }
156 
157     @Override
158     public UdtServerChannelConfig setAllocator(ByteBufAllocator allocator) {
159         super.setAllocator(allocator);
160         return this;
161     }
162 
163     @Override
164     public UdtServerChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
165         super.setRecvByteBufAllocator(allocator);
166         return this;
167     }
168 
169     @Override
170     public UdtServerChannelConfig setAutoRead(boolean autoRead) {
171         super.setAutoRead(autoRead);
172         return this;
173     }
174 
175     @Override
176     public UdtServerChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
177         super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
178         return this;
179     }
180 
181     @Override
182     public UdtServerChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
183         super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
184         return this;
185     }
186 
187     @Override
188     public UdtServerChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
189         super.setMessageSizeEstimator(estimator);
190         return this;
191     }
192 }