本文整理汇总了Java中org.xnio.Option类的典型用法代码示例。如果您正苦于以下问题:Java Option类的具体用法?Java Option怎么用?Java Option使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Option类属于org.xnio包,在下文中一共展示了Option类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveOption
import org.xnio.Option; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public OptionMap.Builder resolveOption(final ExpressionResolver context, final ModelNode model, OptionMap.Builder builder) throws OperationFailedException {
ModelNode value = resolveModelAttribute(context, model);
if (value.isDefined()) {
if (getType() == ModelType.INT) {
builder.set((Option<Integer>) option, value.asInt());
} else if (getType() == ModelType.LONG) {
builder.set(option, value.asLong());
} else if (getType() == ModelType.BOOLEAN) {
builder.set(option, value.asBoolean());
} else if (optionType.isEnum()) {
builder.set(option, option.parseValue(value.asString(), option.getClass().getClassLoader()));
}else if (option.getClass().getSimpleName().equals("SequenceOption")) {
builder.setSequence(option, value.asString().split("\\s*,\\s*"));
} else if (getType() == ModelType.STRING) {
builder.set(option, value.asString());
} else {
throw new OperationFailedException("Don't know how to handle: " + option + " with value: " + value);
}
}
return builder;
}
示例2: setUp
import org.xnio.Option; //导入依赖的package包/类
@Before
@SuppressWarnings("unchecked")
public void setUp() {
sut = new Application();
builder = mock(Undertow.Builder.class);
when(builder.setServerOption(any(Option.class), any())).thenReturn(builder);
}
示例3: testCustomize
import org.xnio.Option; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testCustomize() {
sut.customize(builder);
verify(builder, times(2)).setServerOption(any(Option.class), any());
verify(builder, times(1)).addHttpListener(0, "0.0.0.0");
}
示例4: setOption
import org.xnio.Option; //导入依赖的package包/类
@Override
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
T ret = super.setOption(option, value);
if (option == Options.READ_TIMEOUT) {
readTimeout = (Integer) value;
if (handle != null) {
handle.remove();
if (readTimeout > 0) {
getReadThread().executeAfter(timeoutCommand, readTimeout, TimeUnit.MILLISECONDS);
}
}
}
return ret;
}
示例5: setOption
import org.xnio.Option; //导入依赖的package包/类
@Override
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
T ret = super.setOption(option, value);
if (option == Options.WRITE_TIMEOUT) {
writeTimeout = (Integer) value;
if (handle != null) {
handle.remove();
if(writeTimeout > 0) {
getWriteThread().executeAfter(timeoutCommand, writeTimeout, TimeUnit.MILLISECONDS);
}
}
}
return ret;
}
示例6: getOption
import org.xnio.Option; //导入依赖的package包/类
@Override
public <T> T getOption(final Option<T> option) throws IOException {
if (isFinished()) {
throw UndertowMessages.MESSAGES.channelIsClosed();
}
return delegate.getOption(option);
}
示例7: setOption
import org.xnio.Option; //导入依赖的package包/类
@Override
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
if (isFinished()) {
throw UndertowMessages.MESSAGES.channelIsClosed();
}
return delegate.setOption(option, value);
}
示例8: setOption
import org.xnio.Option; //导入依赖的package包/类
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
if (isFinished()) {
throw UndertowMessages.MESSAGES.channelIsClosed();
}
return delegate.setOption(option, value);
}
示例9: toOption
import org.xnio.Option; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Option<T> toOption(String name, Logger logger) {
Option<T> option = null;
try {
option = Option.class.cast(UndertowOptions.class.getField(name).get(null));
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
logger.error("Exception while accessing field: [{}]", name, ex);
}
return option;
}
示例10: createOptionAttribute
import org.xnio.Option; //导入依赖的package包/类
private static OptionAttributeDefinition createOptionAttribute(String name, Option<?> option, ModelNode defaultValue) {
OptionAttributeDefinition.Builder builder = OptionAttributeDefinition.builder(name, option)
.setAllowExpression(true)
.setAttributeGroup(ENDPOINT)
.setFlags(AttributeAccess.Flag.RESTART_ALL_SERVICES);
if (defaultValue != null) {
builder = builder.setDefaultValue(defaultValue);
}
return builder.build();
}
示例11: addOptions
import org.xnio.Option; //导入依赖的package包/类
private static void addOptions(OperationContext context, ModelNode properties, OptionMap.Builder builder) throws OperationFailedException {
final ClassLoader loader = WildFlySecurityManager.getClassLoaderPrivileged(ConnectorUtils.class);
for (Property property : properties.asPropertyList()) {
String name = property.getName();
if (!name.contains(".")) {
name = "org.xnio.Options." + name;
}
final Option option = Option.fromString(name, loader);
String value = PropertyResource.VALUE.resolveModelAttribute(context, property.getValue()).asString();
builder.set(option, option.parseValue(value, loader));
}
}
示例12: addOption
import org.xnio.Option; //导入依赖的package包/类
public Builder addOption(Option<?> option, String name, ModelNode defaultValue, boolean allowExpression, boolean allowNull) {
attributes.add(OptionAttributeDefinition.builder(name, option)
.setDefaultValue(defaultValue)
.setAllowExpression(allowExpression)
.setRequired(!allowNull)
.build()
);
return this;
}
示例13: getTypeName
import org.xnio.Option; //导入依赖的package包/类
/**
*
* @return - returns Option type as String
* Currently, only Options in UndertowOptions are supported
*/
private String getTypeName(String parameter) {
try {
Field field = UndertowOptions.class.getDeclaredField(parameter);
if (Option.class.getName().equals(field.getType().getTypeName())) {
Object value = field.get(null);
Field optionField = value.getClass().getDeclaredField("type");
optionField.setAccessible(true);
return optionField.get(value).toString();
}
} catch (Exception e) {
log.debug("getting Option type for parameter {} failed with {}", parameter, e);
}
return null;
}
示例14: addUndertowOption
import org.xnio.Option; //导入依赖的package包/类
private <T> void addUndertowOption(Undertow.Builder builder, Option<T> option, T value, String prefix) {
switch (prefix) {
case UNDERTOW_SERVER_PREFIX:
builder.setServerOption(option, value);
break;
case UNDERTOW_SOCKET_PREFIX:
builder.setSocketOption(option, value);
break;
case UNDERTOW_WORKER_PREFIX:
builder.setWorkerOption(option, value);
break;
default:
break;
}
}
示例15: setOption
import org.xnio.Option; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private static Consumer<Map.Entry<String, ConfigValue>> setOption(final Config config,
final String level,
final BiConsumer<Option, Object> setter) {
return entry -> {
String name = entry.getKey();
Object value = entry.getValue().unwrapped();
Option option = findOption(name, UndertowOptions.class, Options.class);
if (option != null) {
// parse option to adjust correct type
Object parsedValue = value.toString();
try {
parsedValue = option.parseValue(value.toString(), null);
} catch (NumberFormatException ex) {
// try bytes
try {
parsedValue = option.parseValue(config.getBytes(level + "." + name).toString(), null);
} catch (ConfigException.BadValue badvalue) {
// try duration
parsedValue = option.parseValue(
config.getDuration(level + "." + name, TimeUnit.MILLISECONDS) + "", null);
}
}
log.debug("{}.{}({})", level, option.getName(), parsedValue);
setter.accept(option, parsedValue);
} else {
log.error("Unknown option: 'undertow.{}.{} = {}'", level, name, value);
}
};
}