1 /*
2 * JBoss, Home of Professional Open Source
3 *
4 * Copyright 2008 Red Hat, Inc. and/or its affiliates.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.xnio.channels;
20
21 import java.io.IOException;
22 import org.xnio.Option;
23
24 /**
25 * A channel that has parameters that may be configured while the channel is open.
26 *
27 * @apiviz.exclude
28 */
29 public interface Configurable {
30
31 /**
32 * Determine whether an option is supported on this channel.
33 *
34 * @param option the option
35 * @return {@code true} if it is supported
36 */
37 boolean supportsOption(Option<?> option);
38
39 /**
40 * Get the value of a channel option.
41 *
42 * @param <T> the type of the option value
43 * @param option the option to get
44 * @return the value of the option, or {@code null} if it is not set
45 * @throws IOException if an I/O error occurred when reading the option
46 */
47 <T> T getOption(Option<T> option) throws IOException;
48
49 /**
50 * Set an option for this channel. Unsupported options are ignored.
51 *
52 * @param <T> the type of the option value
53 * @param option the option to set
54 * @param value the value of the option to set
55 * @return the previous option value, if any
56 * @throws IllegalArgumentException if the value is not acceptable for this option
57 * @throws IOException if an I/O error occurred when modifying the option
58 */
59 <T> T setOption(Option<T> option, T value) throws IllegalArgumentException, IOException;
60
61 /**
62 * An empty configurable instance.
63 */
64 Configurable EMPTY = new Configurable() {
65 public boolean supportsOption(final Option<?> option) {
66 return false;
67 }
68
69 public <T> T getOption(final Option<T> option) throws IOException {
70 return null;
71 }
72
73 public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
74 return null;
75 }
76 };
77 }
78