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