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