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.Channel;
20  import io.netty.channel.ChannelOption;
21  import io.netty.channel.ChannelPipeline;
22  import io.netty.channel.MessageSizeEstimator;
23  import io.netty.channel.RecvByteBufAllocator;
24  import io.netty.channel.unix.DomainSocketChannelConfig;
25  import io.netty.channel.unix.DomainSocketReadMode;
26  
27  import java.util.Map;
28  
29  public final class EpollDomainSocketChannelConfig extends EpollChannelConfig
30          implements DomainSocketChannelConfig {
31      private volatile DomainSocketReadMode mode =
32              DomainSocketReadMode.BYTES;
33  
34      EpollDomainSocketChannelConfig(AbstractEpollChannel channel) {
35          super(channel);
36      }
37  
38      @Override
39      public Map<ChannelOption<?>, Object> getOptions() {
40          return getOptions(super.getOptions(), EpollChannelOption.DOMAIN_SOCKET_READ_MODE);
41      }
42  
43      @SuppressWarnings("unchecked")
44      @Override
45      public <T> T getOption(ChannelOption<T> option) {
46          if (option == EpollChannelOption.DOMAIN_SOCKET_READ_MODE) {
47              return (T) getReadMode();
48          }
49          return super.getOption(option);
50      }
51  
52      @Override
53      public <T> boolean setOption(ChannelOption<T> option, T value) {
54          validate(option, value);
55  
56          if (option == EpollChannelOption.DOMAIN_SOCKET_READ_MODE) {
57              setReadMode((DomainSocketReadMode) value);
58          } else {
59              return super.setOption(option, value);
60          }
61  
62          return true;
63      }
64      @Override
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 setMessageSizeEstimator(MessageSizeEstimator estimator) {
96          super.setMessageSizeEstimator(estimator);
97          return this;
98      }
99  
100     @Override
101     public EpollDomainSocketChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
102         super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
103         return this;
104     }
105 
106     @Override
107     public EpollDomainSocketChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
108         super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
109         return this;
110     }
111 
112     @Override
113     public EpollDomainSocketChannelConfig setAutoRead(boolean autoRead) {
114         super.setAutoRead(autoRead);
115         return this;
116     }
117 
118     @Override
119     public EpollDomainSocketChannelConfig setEpollMode(EpollMode mode) {
120         super.setEpollMode(mode);
121         return this;
122     }
123 
124     @Override
125     public EpollDomainSocketChannelConfig setReadMode(DomainSocketReadMode mode) {
126         if (mode == null) {
127             throw new NullPointerException("mode");
128         }
129         this.mode = mode;
130         return this;
131     }
132 
133     @Override
134     public DomainSocketReadMode getReadMode() {
135         return mode;
136     }
137 }