本文整理了Java中org.xnio.Option
类的一些代码示例,展示了Option
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option
类的具体详情如下:
包路径:org.xnio.Option
类名称:Option
[英]A strongly-typed option to configure an aspect of a service or connection. Options are immutable and use identity comparisons and hash codes. Options should always be declared as public static final
members in order to support serialization.
[中]用于配置服务或连接的一个方面的强类型选项。选项是不可变的,并使用身份比较和哈希代码。为了支持序列化,选项应始终声明为public static final
成员。
代码示例来源:origin: jooby-project/jooby
@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);
}
};
}
代码示例来源:origin: wildfly/wildfly
private OptionMap getOptionMap(final Map<String, ?> environment, final String prefix, final ClassLoader classLoader) {
OptionMap.Builder builder = OptionMap.builder();
builder.set(Options.SASL_POLICY_NOANONYMOUS, false);
for (String name : environment.keySet()) {
if (name.startsWith(prefix)) {
final String optionName = name.substring(prefix.length());
final Option<?> option = Option.fromString(optionName, classLoader);
final Object valueObj = environment.get(name);
if (valueObj != null) builder.parse(option, valueObj.toString(), classLoader);
}
}
return builder.getMap();
}
代码示例来源:origin: wildfly/wildfly
/**
* Return the given object as the type of this option. If the cast could not be completed, an exception is thrown.
*
* @param o the object to cast
* @param defaultVal the value to return if {@code o} is {@code null}
*
* @return the cast object
*
* @throws ClassCastException if the object is not of a compatible type
*/
public final T cast(Object o, T defaultVal) throws ClassCastException {
return o == null ? defaultVal : cast(o);
}
代码示例来源:origin: org.apache.camel/camel-undertow
Option option = Option.fromString(key, cl);
value = option.parseValue(value.toString(), cl);
LOG.trace("Parsed option {}={}", option.getName(), value);
builder.set(option, value);
optionMap = builder.getMap();
} else {
builder.addAll(optionMap).set(Options.KEEP_ALIVE, keepAlive);
optionMap = builder.getMap();
代码示例来源:origin: wildfly/wildfly
private OptionMap createChannelOptionMap(final OperationContext context, final ModelNode channelCreationOptionsNode)
throws OperationFailedException {
final OptionMap optionMap;
if (channelCreationOptionsNode.isDefined()) {
final OptionMap.Builder optionMapBuilder = OptionMap.builder();
final ClassLoader loader = this.getClass().getClassLoader();
for (final Property optionProperty : channelCreationOptionsNode.asPropertyList()) {
final String name = optionProperty.getName();
final ModelNode propValueModel = optionProperty.getValue();
final String type = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_TYPE
.resolveModelAttribute(context, propValueModel).asString();
final String optionClassName = this.getClassNameForChannelOptionType(type);
final String fullyQualifiedOptionName = optionClassName + "." + name;
final Option option = Option.fromString(fullyQualifiedOptionName, loader);
final String value = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_VALUE
.resolveModelAttribute(context, propValueModel).asString();
optionMapBuilder.set(option, option.parseValue(value, loader));
}
optionMap = optionMapBuilder.getMap();
} else {
optionMap = OptionMap.EMPTY;
}
return optionMap;
}
代码示例来源:origin: io.skullabs.kikaha/kikaha-core
private static void populate(Option option) {
final String name = option.getName();
OPTIONS.put(name, option);
}
代码示例来源:origin: wildfly/wildfly
/**
* Set a key-value pair, parsing the value from the given string.
*
* @param key the key
* @param stringValue the string value
* @param <T> the option type
* @return this builder
*/
public <T> Builder parse(Option<T> key, String stringValue) {
set(key, key.parseValue(stringValue, key.getClass().getClassLoader()));
return this;
}
代码示例来源:origin: wildfly/wildfly-core
builder.addAll(connectorPropertiesOptionMap);
OptionMap resultingMap = builder.getMap();
try {
final ExternalConnectionProvider provider = endpoint.getConnectionProviderInterface(Protocol.HTTP_REMOTING.toString(), ExternalConnectionProvider.class);
Option<?> optionMechanismNames = Option.fromString("org.xnio.Options."+ Options.SASL_MECHANISMS.getName(), loader);
String[] mechanismNames = null;
if(connectorPropertiesOptionMap.contains(optionMechanismNames)) {
Option<?> optionPolicyNonanonymous = Option.fromString("org.xnio.Options."+ Options.SASL_POLICY_NOANONYMOUS.getName(), loader);
代码示例来源:origin: stackoverflow.com
t1.Text = o.getName().ToString();
if (t2 != null)
t2.Text = o.getData().ToString();
代码示例来源:origin: wildfly/wildfly
TypeOption(final Class<?> declClass, final String name, final Class<T> type) {
super(declClass, name);
if (type == null) {
throw msg.nullParameter("type");
}
this.type = type;
parser = Option.getClassParser(type);
}
代码示例来源:origin: wildfly/wildfly
@SuppressWarnings("unchecked")
static <T> Option.ValueParser<T> getParser(final Class<T> argType) {
if (argType.isEnum()) {
return getEnumParser(argType);
} else {
final Option.ValueParser<?> value = parsers.get(argType);
return (Option.ValueParser<T>) (value == null ? noParser : value);
}
}
}
代码示例来源:origin: wildfly/wildfly
private OptionMap getChannelCreationOptions(final OperationContext context) throws OperationFailedException {
// read the full model of the current resource
final ModelNode fullModel = Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS));
final ModelNode channelCreationOptions = fullModel.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
if (channelCreationOptions.isDefined() && channelCreationOptions.asInt() > 0) {
final ClassLoader loader = this.getClass().getClassLoader();
final OptionMap.Builder builder = OptionMap.builder();
for (final Property optionProperty : channelCreationOptions.asPropertyList()) {
final String name = optionProperty.getName();
final ModelNode propValueModel = optionProperty.getValue();
final String type = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_TYPE.resolveModelAttribute(context,propValueModel).asString();
final String optionClassName = this.getClassNameForChannelOptionType(type);
final String fullyQualifiedOptionName = optionClassName + "." + name;
final Option option = Option.fromString(fullyQualifiedOptionName, loader);
final String value = RemoteConnectorChannelCreationOptionResource.CHANNEL_CREATION_OPTION_VALUE.resolveModelAttribute(context, propValueModel).asString();
builder.set(option, option.parseValue(value, loader));
}
return builder.getMap();
}
return OptionMap.EMPTY;
}
代码示例来源:origin: stackoverflow.com
private void onFileClick(Option o) {
String path = o.getName();
Intent data = new Intent();
data.putExtra("path", path);
setResult(Activity.RESULT_OK, data);
finish();
}
代码示例来源:origin: wildfly/wildfly
/**
* Set a key-value pair, parsing the value from the given string.
*
* @param key the key
* @param stringValue the string value
* @param classLoader the class loader to use for parsing the value
* @param <T> the option type
* @return this builder
*/
public <T> Builder parse(Option<T> key, String stringValue, ClassLoader classLoader) {
set(key, key.parseValue(stringValue, classLoader));
return this;
}
代码示例来源:origin: stackoverflow.com
fileName.setText(o.getName());
if(o.getData().equalsIgnoreCase("folder")||o.getData().equalsIgnoreCase("parent directory")){
fileIcon.setImageRessource(<FolderIcon>)
} else {
代码示例来源:origin: wildfly/wildfly
TypeSequenceOption(final Class<?> declClass, final String name, final Class<T> elementDeclType) {
super(declClass, name);
if (elementDeclType == null) {
throw msg.nullParameter("elementDeclType");
}
this.elementDeclType = elementDeclType;
parser = Option.getClassParser(elementDeclType);
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
@SuppressWarnings("unchecked")
static <T> Option.ValueParser<T> getParser(final Class<T> argType) {
if (argType.isEnum()) {
return getEnumParser(argType);
} else {
final Option.ValueParser<?> value = parsers.get(argType);
return (Option.ValueParser<T>) (value == null ? noParser : value);
}
}
}
代码示例来源:origin: wildfly/wildfly
public <T> T getOption(final Option<T> option) {
if (option == RemotingOptions.MAX_INBOUND_MESSAGES) {
return option.cast(maxInboundMessages);
} else if (option == RemotingOptions.MAX_OUTBOUND_MESSAGES) {
return option.cast(maxOutboundMessages);
} else if (option == RemotingOptions.RECEIVE_WINDOW_SIZE) {
return option.cast(inboundWindow);
} else if (option == RemotingOptions.TRANSMIT_WINDOW_SIZE) {
return option.cast(outboundWindow);
} else if (option == RemotingOptions.MAX_INBOUND_MESSAGE_SIZE) {
return option.cast(maxInboundMessageSize);
} else if (option == RemotingOptions.MAX_OUTBOUND_MESSAGE_SIZE) {
return option.cast(maxOutboundMessageSize);
} else {
return null;
}
}
代码示例来源:origin: org.jboss.as/jboss-as-remoting
private static void addOptions(OperationContext context, ModelNode properties, OptionMap.Builder builder) throws OperationFailedException {
final ClassLoader loader = SecurityActions.getClassLoader(ConnectorResource.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));
}
}
代码示例来源:origin: SoftInstigate/restheart
@SuppressWarnings("unchecked")
public static void setConnectionOptions(
Builder builder,
Configuration configuration) {
Map<String, Object> options = configuration.getConnectionOptions();
UNDERTOW_OPTIONS.stream().forEach(option -> {
if (options.containsKey(option.getName())) {
Object value = options.get(option.getName());
if (value != null) {
builder.setServerOption(option, value);
LOGGER.trace("Connection option {}={}", option.getName(), value);
}
}
});
LONG_UNDERTOW_OPTIONS.stream().forEach(option -> {
if (options.containsKey(option.getName())) {
Object value = options.get(option.getName());
if (value != null) {
Long lvalue = 0l + (Integer) value;
builder.setServerOption(option, lvalue);
LOGGER.trace("Connection option {}={}", option.getName(), lvalue);
}
}
});
}
内容来源于网络,如有侵权,请联系作者删除!