View Javadoc
1   /*
2    * Copyright 2015 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.epoll;
17  
18  import io.netty.buffer.ByteBufAllocator;
19  import io.netty.channel.ChannelOption;
20  import io.netty.channel.MessageSizeEstimator;
21  import io.netty.channel.RecvByteBufAllocator;
22  import io.netty.channel.WriteBufferWaterMark;
23  import io.netty.channel.unix.DomainSocketChannelConfig;
24  import io.netty.channel.unix.DomainSocketReadMode;
25  
26  import java.util.Map;
27  
28  public final class EpollDomainSocketChannelConfig extends EpollChannelConfig
29          implements DomainSocketChannelConfig {
30      private volatile DomainSocketReadMode mode = DomainSocketReadMode.BYTES;
31  
32      EpollDomainSocketChannelConfig(AbstractEpollChannel channel) {
33          super(channel);
34      }
35  
36      @Override
37      public Map<ChannelOption<?>, Object> getOptions() {
38          return getOptions(super.getOptions(), EpollChannelOption.DOMAIN_SOCKET_READ_MODE);
39      }
40  
41      @SuppressWarnings("unchecked")
42      @Override
43      public <T> T getOption(ChannelOption<T> option) {
44          if (option == EpollChannelOption.DOMAIN_SOCKET_READ_MODE) {
45              return (T) getReadMode();
46          }
47          return super.getOption(option);
48      }
49  
50      @Override
51      public <T> boolean setOption(ChannelOption<T> option, T value) {
52          validate(option, value);
53  
54          if (option == EpollChannelOption.DOMAIN_SOCKET_READ_MODE) {
55              setReadMode((DomainSocketReadMode) value);
56          } else {
57              return super.setOption(option, value);
58          }
59  
60          return true;
61      }
62  
63      @Override
64      @Deprecated
65      public EpollDomainSocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
66          super.setMaxMessagesPerRead(maxMessagesPerRead);
67          return this;
68      }
69  
70      @Override
71      public EpollDomainSocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
72          super.setConnectTimeoutMillis(connectTimeoutMillis);
73          return this;
74      }
75  
76      @Override
77      public EpollDomainSocketChannelConfig setWriteSpinCount(int writeSpinCount) {
78          super.setWriteSpinCount(writeSpinCount);
79          return this;
80      }
81  
82      @Override
83      public EpollDomainSocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
84          super.setRecvByteBufAllocator(allocator);
85          return this;
86      }
87  
88      @Override
89      public EpollDomainSocketChannelConfig setAllocator(ByteBufAllocator allocator) {
90          super.setAllocator(allocator);
91          return this;
92      }
93  
94      @Override
95      public EpollDomainSocketChannelConfig setAutoClose(boolean autoClose) {
96          super.setAutoClose(autoClose);
97          return this;
98      }
99  
100     @Override
101     public EpollDomainSocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
102         super.setMessageSizeEstimator(estimator);
103         return this;
104     }
105 
106     @Override
107     @Deprecated
108     public EpollDomainSocketChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
109         super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
110         return this;
111     }
112 
113     @Override
114     @Deprecated
115     public EpollDomainSocketChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
116         super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
117         return this;
118     }
119 
120     @Override
121     public EpollDomainSocketChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark) {
122         super.setWriteBufferWaterMark(writeBufferWaterMark);
123         return this;
124     }
125 
126     @Override
127     public EpollDomainSocketChannelConfig setAutoRead(boolean autoRead) {
128         super.setAutoRead(autoRead);
129         return this;
130     }
131 
132     @Override
133     public EpollDomainSocketChannelConfig setEpollMode(EpollMode mode) {
134         super.setEpollMode(mode);
135         return this;
136     }
137 
138     @Override
139     public EpollDomainSocketChannelConfig setReadMode(DomainSocketReadMode mode) {
140         if (mode == null) {
141             throw new NullPointerException("mode");
142         }
143         this.mode = mode;
144         return this;
145     }
146 
147     @Override
148     public DomainSocketReadMode getReadMode() {
149         return mode;
150     }
151 }