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