Java Code Examples for org.jboss.dmr.ModelType#INT

The following examples show how to use org.jboss.dmr.ModelType#INT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OptionAttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@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;
}
 
Example 2
Source File: ModelTypeValidatorUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testInt() {
    ModelTypeValidator testee = new ModelTypeValidator(ModelType.INT, false, false, false);
    validateNumbers(testee);
    invalidateIntRange(testee);

    testee = new ModelTypeValidator(ModelType.INT, false, false, true);
    assertOk(testee, new ModelNode().set(1));
    assertInvalid(testee, new ModelNode().set((double) 1));
    testee = new ModelTypeValidator(ModelType.INT, false, false, false);
    assertOk(testee, new ModelNode().set("99"));
    assertInvalid(testee, new ModelNode().set("999999999999"), true);
}
 
Example 3
Source File: TestUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static AttributeDefinition createMetric(String name, ModelType type, String groupName) {
    SimpleAttributeDefinitionBuilder attribute = SimpleAttributeDefinitionBuilder.create(name, type).setStorageRuntime();
    if(groupName != null && ! groupName.isEmpty()) {
        attribute.setAttributeGroup(groupName);
    }
    if (type == ModelType.INT) {
        attribute.setUndefinedMetricValue(new ModelNode(-1));
    }
    if (type == ModelType.STRING) {
        attribute.setRequired(false);
    }
    return attribute.build();
}
 
Example 4
Source File: ManagementModelNode.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean isNumeric() {
    ModelType type = getType();
    return (type == ModelType.BIG_DECIMAL) ||
           (type == ModelType.BIG_INTEGER) ||
           (type == ModelType.DOUBLE) ||
           (type == ModelType.INT) ||
           (type == ModelType.LONG);
}
 
Example 5
Source File: ModelTestModelDescriptionValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String validate(ModelType currentType, ModelNode currentNode, String descriptor) {
    if (currentNode.hasDefined(descriptor)) {
        if (currentType != ModelType.BIG_DECIMAL && currentType != ModelType.BIG_INTEGER &&
                currentType != ModelType.DOUBLE && currentType != ModelType.INT && currentType != ModelType.LONG) {
            return "Unnecessary '" + descriptor + "' for non-numeric type=" + currentType;
        }
        if (!descriptor.equals(UNIT)) {
            try {
                if (currentType == ModelType.BIG_DECIMAL) {
                    currentNode.get(descriptor).asBigDecimal();
                } else if (currentType == ModelType.BIG_INTEGER) {
                    currentNode.get(descriptor).asBigInteger();
                } else if (currentType == ModelType.DOUBLE) {
                    currentNode.get(descriptor).asDouble();
                } else if (currentType == ModelType.INT) {
                    currentNode.get(descriptor).asInt();
                } else if (currentType == ModelType.LONG) {
                    currentNode.get(descriptor).asLong();
                }
            } catch (Exception e) {
                return "'" + descriptor + "' is not a " + currentType;

            }
        }
    }
    return null;
}
 
Example 6
Source File: OptionAttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void setType() {
    try {
        final Field typeField;
        if (option.getClass().getSimpleName().equals("SequenceOption")) {
            typeField = option.getClass().getDeclaredField("elementType");
        } else {
            typeField = option.getClass().getDeclaredField("type");
        }

        typeField.setAccessible(true);
        optionType = (Class<?>) typeField.get(option);

        if (optionType.isAssignableFrom(Integer.class)) {
            type = ModelType.INT;
        } else if (optionType.isAssignableFrom(Long.class)) {
            type = ModelType.LONG;
        } else if (optionType.isAssignableFrom(BigInteger.class)) {
            type = ModelType.BIG_INTEGER;
        } else if (optionType.isAssignableFrom(Double.class)) {
            type = ModelType.DOUBLE;
        } else if (optionType.isAssignableFrom(BigDecimal.class)) {
            type = ModelType.BIG_DECIMAL;
        } else if (optionType.isEnum() || optionType.isAssignableFrom(String.class)) {
            type = ModelType.STRING;
        } else if (optionType.isAssignableFrom(Boolean.class)) {
            type = ModelType.BOOLEAN;
        } else {
            type = ModelType.UNDEFINED;
        }

    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example 7
Source File: ModelControllerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private IntAllowedValuesValidator(int ... allowedValues) {
    super(ModelType.INT);
    for (int allowedValue : allowedValues) {
        this.allowedValues.add(new ModelNode(allowedValue));
    }
}
 
Example 8
Source File: IntRangeValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public IntRangeValidator(final int min, final int max, final boolean nullable, final boolean allowExpressions) {
    super(ModelType.INT, nullable, allowExpressions, false);
    this.min = min;
    this.max = max;
}
 
Example 9
Source File: WorkerAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    Resource resource = context.readResourceFromRoot(address.subAddress(0, address.size() - 1));
    ModelNode workers = Resource.Tools.readModel(resource).get(IOExtension.WORKER_PATH.getKey());
    int allWorkerCount = workers.asList().size();
    final String name = context.getCurrentAddressValue();
    final XnioWorker.Builder builder = Xnio.getInstance().createWorkerBuilder();

    final OptionMap.Builder optionMapBuilder = OptionMap.builder();

    for (OptionAttributeDefinition attr : WorkerResourceDefinition.ATTRIBUTES) {
        Option option = attr.getOption();
        ModelNode value = attr.resolveModelAttribute(context, model);
        if (!value.isDefined()) {
            continue;
        }
        if (attr.getType() == ModelType.INT) {
            optionMapBuilder.set((Option<Integer>) option, value.asInt());
        } else if (attr.getType() == ModelType.LONG) {
            optionMapBuilder.set(option, value.asLong());
        } else if (attr.getType() == ModelType.BOOLEAN) {
            optionMapBuilder.set(option, value.asBoolean());
        }
    }
    builder.populateFromOptions(optionMapBuilder.getMap());
    builder.setWorkerName(name);

    ModelNode ioThreadsModel = WORKER_IO_THREADS.resolveModelAttribute(context, model);
    ModelNode coreTaskThreadsModel = WORKER_TASK_CORE_THREADS.resolveModelAttribute(context, model);
    ModelNode maxTaskThreadsModel = WORKER_TASK_MAX_THREADS.resolveModelAttribute(context, model);
    int cpuCount = getCpuCount();
    int ioThreadsCalculated = getSuggestedIoThreadCount();
    int workerThreads = builder.getMaxWorkerPoolSize();
    int coreWorkerThreads = coreTaskThreadsModel.asInt();
    if (!ioThreadsModel.isDefined() && !maxTaskThreadsModel.isDefined()) {
        workerThreads = getWorkerThreads(name, allWorkerCount);
        builder.setWorkerIoThreads(ioThreadsCalculated);
        builder.setCoreWorkerPoolSize(coreWorkerThreads);
        builder.setMaxWorkerPoolSize(workerThreads);
        IOLogger.ROOT_LOGGER.printDefaults(name, ioThreadsCalculated, workerThreads, cpuCount);
    } else {
        if (!ioThreadsModel.isDefined()) {
            builder.setWorkerIoThreads(ioThreadsCalculated);
            IOLogger.ROOT_LOGGER.printDefaultsIoThreads(name, ioThreadsCalculated, cpuCount);
        }
        if (!maxTaskThreadsModel.isDefined()) {
            workerThreads = getWorkerThreads(name, allWorkerCount);
            builder.setCoreWorkerPoolSize(coreWorkerThreads);
            builder.setMaxWorkerPoolSize(workerThreads);
            IOLogger.ROOT_LOGGER.printDefaultsWorkerThreads(name, workerThreads, cpuCount);
        }
    }

    registerMax(context, name, workerThreads);

    final CapabilityServiceBuilder<?> capBuilder = context.getCapabilityServiceTarget().addCapability(IO_WORKER_RUNTIME_CAPABILITY);
    final Consumer<XnioWorker> workerConsumer = capBuilder.provides(IO_WORKER_RUNTIME_CAPABILITY);
    final Supplier<ExecutorService> executorSupplier = capBuilder.requiresCapability("org.wildfly.management.executor", ExecutorService.class);
    capBuilder.setInstance(new WorkerService(workerConsumer, executorSupplier, builder));
    capBuilder.setInitialMode(ServiceController.Mode.ON_DEMAND);
    capBuilder.install();
}