Example #1
0
  @Override
  protected boolean applyUpdateToRuntime(
      OperationContext context,
      ModelNode operation,
      String attributeName,
      ModelNode resolvedValue,
      ModelNode currentValue,
      org.jboss.as.controller.AbstractWriteAttributeHandler.HandbackHolder<Void> handbackHolder)
      throws OperationFailedException {

    if (attributeName.equals(TrackerExtension.TICK)) {
      final String suffix =
          PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS))
              .getLastElement()
              .getValue();
      TrackerService service =
          (TrackerService)
              context
                  .getServiceRegistry(true)
                  .getRequiredService(TrackerService.createServiceName(suffix))
                  .getValue();
      service.setTick(resolvedValue.asLong());
      context.completeStep();
    }

    return false;
  }
Example #2
0
 public final List<Long> longListValue() {
   List<ModelNode> listValue = listValue();
   List<Long> result = new ArrayList<Long>(listValue.size());
   for (ModelNode value : listValue) {
     result.add(value.asLong());
   }
   return Collections.unmodifiableList(result);
 }
  /**
   * Creates and returns a {@link org.jboss.dmr.ModelNode} using the given {@code value} after first
   * validating the node against {@link #getValidator() this object's validator}.
   *
   * <p>If {@code value} is {@code null} and a {@link #getDefaultValue() default value} is
   * available, the value of that default value will be used.
   *
   * @param value the value. Will be {@link String#trim() trimmed} before use if not {@code null}.
   * @param location current location of the parser's {@link javax.xml.stream.XMLStreamReader}. Used
   *     for any exception message
   * @return {@code ModelNode} representing the parsed value
   * @throws javax.xml.stream.XMLStreamException if {@code value} is not valid
   */
  public ModelNode parse(final String value, final Location location) throws XMLStreamException {

    final String trimmed = value == null ? null : value.trim();
    ModelNode node;
    if (trimmed != null) {
      if (isAllowExpression()) {
        node = ParseUtils.parsePossibleExpression(trimmed);
      } else {
        node = new ModelNode().set(trimmed);
      }
      if (node.getType() != ModelType.EXPRESSION) {
        // Convert the string to the expected type
        switch (getType()) {
          case BIG_DECIMAL:
            node.set(node.asBigDecimal());
            break;
          case BIG_INTEGER:
            node.set(node.asBigInteger());
            break;
          case BOOLEAN:
            node.set(node.asBoolean());
            break;
          case BYTES:
            node.set(node.asBytes());
            break;
          case DOUBLE:
            node.set(node.asDouble());
            break;
          case INT:
            node.set(node.asInt());
            break;
          case LONG:
            node.set(node.asLong());
            break;
        }
      }
    } else if (getDefaultValue().isDefined()) {
      node = new ModelNode().set(getDefaultValue());
    } else {
      node = new ModelNode();
    }

    try {
      getValidator().validateParameter(getXmlName(), node);
    } catch (OperationFailedException e) {
      throw new XMLStreamException(e.getFailureDescription().toString(), location);
    }

    return node;
  }
Example #4
0
 public static ModelNode parseAttributeValue(
     final String value, final boolean isExpressionAllowed, final ModelType attributeType) {
   final String trimmed = value == null ? null : value.trim();
   ModelNode node;
   if (trimmed != null) {
     if (isExpressionAllowed && isExpression(trimmed)) {
       node = new ModelNode(new ValueExpression(trimmed));
     } else {
       if (attributeType == STRING || attributeType == PROPERTY) {
         node = new ModelNode().set(value);
       } else {
         node = new ModelNode().set(trimmed);
       }
     }
     if (node.getType() != ModelType.EXPRESSION) {
       // Convert the string to the expected type
       switch (attributeType) {
         case BIG_DECIMAL:
           node.set(node.asBigDecimal());
           break;
         case BIG_INTEGER:
           node.set(node.asBigInteger());
           break;
         case BOOLEAN:
           node.set(node.asBoolean());
           break;
         case BYTES:
           node.set(node.asBytes());
           break;
         case DOUBLE:
           node.set(node.asDouble());
           break;
         case INT:
           node.set(node.asInt());
           break;
         case LONG:
           node.set(node.asLong());
           break;
       }
     }
   } else {
     node = new ModelNode();
   }
   return node;
 }
Example #5
0
 public static Long asLong(
     final SimpleAttributeDefinition attr, ModelNode node, OperationContext context)
     throws OperationFailedException {
   ModelNode resolvedNode = attr.resolveModelAttribute(context, node);
   return resolvedNode.isDefined() ? resolvedNode.asLong() : null;
 }