List of usage examples for org.apache.commons.lang3.mutable MutableBoolean booleanValue
public boolean booleanValue()
From source file:asterix.parser.classad.ClassAd.java
public boolean privateGetExternalReferences(ExprTree expr, ClassAd ad, EvalState state, Map<ClassAd, TreeSet<String>> refs) throws HyracksDataException { switch (expr.getKind()) { case LITERAL_NODE: // no external references here return (true); case ATTRREF_NODE: { ClassAd start = new ClassAd(); ExprTreeHolder tree = new ExprTreeHolder(); ExprTreeHolder result = new ExprTreeHolder(); AMutableCharArrayString attr = new AMutableCharArrayString(); Value val = new Value(); MutableBoolean abs = new MutableBoolean(); ((AttributeReference) expr).getComponents(tree, attr, abs); // establish starting point for attribute search if (tree.getInnerTree() == null) { start = abs.booleanValue() ? state.getRootAd() : state.getCurAd(); if (abs.booleanValue() && (start == null)) {// NAC - circularity so no root return false; // NAC } // NAC } else {/*from w w w .jav a 2 s .c om*/ if (!tree.publicEvaluate(state, val)) return (false); // if the tree evals to undefined, the external references // are in the tree part if (val.isUndefinedValue()) { return (privateGetExternalReferences(tree, ad, state, refs)); } // otherwise, if the tree didn't evaluate to a classad, // we have a problem if (!val.isClassAdValue(start)) return (false); // make sure that we are starting from a "valid" scope if (!refs.containsKey(start) && start != this) { return (false); } } // lookup for attribute ClassAd curAd = state.getCurAd(); TreeSet<String> pitr = refs.get(start); if (pitr == null) { pitr = new TreeSet<String>(); refs.put(start, pitr); } switch (start.lookupInScope(attr.toString(), result, state)) { case EVAL_ERROR_Int: // some error return (false); case EVAL_UNDEF_Int: // attr is external pitr.add(attr.toString()); state.setCurAd(curAd); return (true); case EVAL_OK_Int: { // attr is internal; find external refs in result boolean rval = privateGetExternalReferences(result, ad, state, refs); state.setCurAd(curAd); return (rval); } case EVAL_FAIL_Int: default: // enh?? return (false); } } case OP_NODE: { // recurse on subtrees AMutableInt32 opKind = new AMutableInt32(0); ExprTreeHolder t1 = new ExprTreeHolder(); ExprTreeHolder t2 = new ExprTreeHolder(); ExprTreeHolder t3 = new ExprTreeHolder(); ((Operation) expr).getComponents(opKind, t1, t2, t3); if (t1.getInnerTree() != null && !privateGetExternalReferences(t1, ad, state, refs)) { return (false); } if (t2.getInnerTree() != null && !privateGetExternalReferences(t2, ad, state, refs)) { return (false); } if (t3.getInnerTree() != null && !privateGetExternalReferences(t3, ad, state, refs)) { return (false); } return (true); } case FN_CALL_NODE: { // recurse on subtrees AMutableCharArrayString fnName = new AMutableCharArrayString(); ExprList args = new ExprList(); ((FunctionCall) expr).getComponents(fnName, args); for (ExprTree exprTree : args.getExprList()) { if (!privateGetExternalReferences(exprTree, ad, state, refs)) { return (false); } } return (true); } case CLASSAD_NODE: { // recurse on subtrees HashMap<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>(); ((ClassAd) expr).getComponents(attrs); for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) { if (!privateGetExternalReferences(entry.getValue(), ad, state, refs)) { return (false); } } return (true); } case EXPR_LIST_NODE: { // recurse on subtrees ExprList exprs = new ExprList(); ((ExprList) expr).getComponents(exprs); for (ExprTree exprTree : exprs.getExprList()) { if (!privateGetExternalReferences(exprTree, ad, state, refs)) { return (false); } } return (true); } default: return false; } }
From source file:asterix.parser.classad.ClassAd.java
public boolean privateGetExternalReferences(ExprTree expr, ClassAd ad, EvalState state, TreeSet<String> refs, boolean fullNames) throws HyracksDataException { if (expr.isTreeHolder()) { expr = ((ExprTreeHolder) expr).getInnerTree(); }// w w w.j a v a2s . co m switch (expr.getKind()) { case LITERAL_NODE: // no external references here return (true); case ATTRREF_NODE: { ClassAd start = new ClassAd(); ExprTreeHolder tree = new ExprTreeHolder(); ExprTreeHolder result = new ExprTreeHolder(); AMutableCharArrayString attr = new AMutableCharArrayString(); Value val = new Value(); MutableBoolean abs = new MutableBoolean(); ((AttributeReference) expr).getComponents(tree, attr, abs); // establish starting point for attribute search if (tree.getInnerTree() == null) { start = abs.booleanValue() ? state.getRootAd() : state.getCurAd(); if (abs.booleanValue() && (start == null)) {// NAC - circularity so no root return false; // NAC } // NAC } else { if (!tree.publicEvaluate(state, val)) { return (false); } // if the tree evals to undefined, the external references // are in the tree part if (val.isUndefinedValue()) { if (fullNames) { AMutableCharArrayString fullName = new AMutableCharArrayString(); if (tree.getInnerTree() != null) { ClassAdUnParser unparser = new PrettyPrint(); unparser.unparse(fullName, tree); fullName.appendChar('.'); } fullName.appendString(attr); refs.add(fullName.toString()); return true; } else { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetExternalReferences(tree, ad, state, refs, fullNames); state.incrementDepth(); return ret; } } // otherwise, if the tree didn't evaluate to a classad, // we have a problem if (!val.isClassAdValue(start)) { return (false); } } // lookup for attribute ClassAd curAd = state.getCurAd(); switch (start.lookupInScope(attr.toString(), result, state)) { case EVAL_ERROR_Int: // some error return (false); case EVAL_UNDEF_Int: // attr is external refs.add(attr.toString()); state.setCurAd(curAd); return (true); case EVAL_OK_Int: { // attr is internal; find external refs in result if (state.getDepthRemaining() <= 0) { state.setCurAd(curAd); return false; } state.decrementDepth(); boolean rval = privateGetExternalReferences(result, ad, state, refs, fullNames); state.incrementDepth(); state.setCurAd(curAd); return (rval); } case EVAL_FAIL_Int: default: // enh?? return (false); } } case OP_NODE: { // recurse on subtrees AMutableInt32 opKind = new AMutableInt32(0); ExprTreeHolder t1 = new ExprTreeHolder(); ExprTreeHolder t2 = new ExprTreeHolder(); ExprTreeHolder t3 = new ExprTreeHolder(); ((Operation) expr).getComponents(opKind, t1, t2, t3); if (t1.getInnerTree() != null && !privateGetExternalReferences(t1, ad, state, refs, fullNames)) { return (false); } if (t2.getInnerTree() != null && !privateGetExternalReferences(t2, ad, state, refs, fullNames)) { return (false); } if (t3.getInnerTree() != null && !privateGetExternalReferences(t3, ad, state, refs, fullNames)) { return (false); } return (true); } case FN_CALL_NODE: { // recurse on subtrees AMutableCharArrayString fnName = new AMutableCharArrayString(); ExprList args = new ExprList(); ((FunctionCall) expr).getComponents(fnName, args); for (ExprTree tree : args.getExprList()) { if (!privateGetExternalReferences(tree, ad, state, refs, fullNames)) { return (false); } } return (true); } case CLASSAD_NODE: { // recurse on subtrees Map<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>(); ((ClassAd) expr).getComponents(attrs); for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetExternalReferences(entry.getValue(), ad, state, refs, fullNames); state.incrementDepth(); if (!ret) { return (false); } } return (true); } case EXPR_LIST_NODE: { // recurse on subtrees ExprList exprs = new ExprList(); ((ExprList) expr).getComponents(exprs); for (ExprTree exprTree : exprs.getExprList()) { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetExternalReferences(exprTree, ad, state, refs, fullNames); state.incrementDepth(); if (!ret) { return (false); } } return (true); } default: return false; } }
From source file:asterix.parser.classad.ClassAd.java
public boolean privateGetInternalReferences(ExprTree expr, ClassAd ad, EvalState state, TreeSet<String> refs, boolean fullNames) throws HyracksDataException { switch (expr.getKind()) { //nothing to be found here! case LITERAL_NODE: { return true; }//from w ww. ja va 2s .c o m case ATTRREF_NODE: { ClassAd start = new ClassAd(); ExprTreeHolder tree = new ExprTreeHolder(); ExprTreeHolder result = new ExprTreeHolder(); AMutableCharArrayString attr = new AMutableCharArrayString(); Value val = new Value(); MutableBoolean abs = new MutableBoolean(); ((AttributeReference) expr).getComponents(tree, attr, abs); //figuring out which state to base this off of if (tree.getInnerTree() == null) { start = abs.booleanValue() ? state.getRootAd() : state.getCurAd(); //remove circularity if (abs.booleanValue() && (start == null)) { return false; } } else { boolean orig_inAttrRefScope = state.isInAttrRefScope(); state.setInAttrRefScope(true); boolean rv = privateGetInternalReferences(tree, ad, state, refs, fullNames); state.setInAttrRefScope(orig_inAttrRefScope); if (!rv) { return false; } if (!tree.publicEvaluate(state, val)) { return false; } // TODO Do we need extra handling for list values? // Should types other than undefined, error, or list // cause a failure? if (val.isUndefinedValue()) { return true; } //otherwise, if the tree didn't evaluate to a classad, //we have a problemo, mon. //TODO: but why? if (!val.isClassAdValue(start)) { return false; } } ClassAd curAd = state.getCurAd(); switch (start.lookupInScope(attr.toString(), result, state)) { case EVAL_ERROR_Int: return false; //attr is external, so let's find the internals in that //result //JUST KIDDING case EVAL_UNDEF_Int: { //boolean rval = _GetInternalReferences(result, ad, state, refs, fullNames); //state.getCurAd() = curAd; return true; } case EVAL_OK_Int: { //whoo, it's internal. // Check whether the attribute was found in the root // ad for this evaluation and that the attribute isn't // one of our special ones (self, parent, my, etc.). // If the ad actually has an attribute with the same // name as one of our special attributes, then count // that as an internal reference. // TODO LookupInScope() knows whether it's returning // the expression of one of the special attributes // or that of an attribute that actually appears in // the ad. If it told us which one, then we could // avoid the Lookup() call below. if (state.getCurAd() == state.getRootAd() && state.getCurAd().lookup(attr.toString()) != null) { refs.add(attr.toString()); } if (state.getDepthRemaining() <= 0) { state.setCurAd(curAd); return false; } state.decrementDepth(); boolean rval = privateGetInternalReferences(result, ad, state, refs, fullNames); state.incrementDepth(); //TODO: Does this actually matter? state.setCurAd(curAd); return rval; } case EVAL_FAIL_Int: default: // "enh??" return false; } } case OP_NODE: { //recurse on subtrees AMutableInt32 op = new AMutableInt32(0); ExprTreeHolder t1 = new ExprTreeHolder(); ExprTreeHolder t2 = new ExprTreeHolder(); ExprTreeHolder t3 = new ExprTreeHolder(); ((Operation) expr).getComponents(op, t1, t2, t3); if (t1.getInnerTree() != null && !privateGetInternalReferences(t1, ad, state, refs, fullNames)) { return false; } if (t2.getInnerTree() != null && !privateGetInternalReferences(t2, ad, state, refs, fullNames)) { return false; } if (t3.getInnerTree() != null && !privateGetInternalReferences(t3, ad, state, refs, fullNames)) { return false; } return true; } case FN_CALL_NODE: { //recurse on the subtrees! AMutableCharArrayString fnName = new AMutableCharArrayString(); ExprList args = new ExprList(); ((FunctionCall) expr).getComponents(fnName, args); for (ExprTree exprTree : args.getExprList()) { if (!privateGetInternalReferences(exprTree, ad, state, refs, fullNames)) { return false; } } return true; } case CLASSAD_NODE: { //also recurse on subtrees... HashMap<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>(); // If this ClassAd is only being used here as the scoping // for an attribute reference, don't recurse into all of // its attributes. if (state.isInAttrRefScope()) { return true; } ((ClassAd) expr).getComponents(attrs); for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetInternalReferences(entry.getValue(), ad, state, refs, fullNames); state.incrementDepth(); if (!ret) { return false; } } return true; } case EXPR_LIST_NODE: { ExprList exprs = new ExprList(); ((ExprList) expr).getComponents(exprs); for (ExprTree exprTree : exprs.getExprList()) { if (state.getDepthRemaining() <= 0) { return false; } state.decrementDepth(); boolean ret = privateGetInternalReferences(exprTree, ad, state, refs, fullNames); state.incrementDepth(); if (!ret) { return false; } } return true; } default: return false; } }
From source file:asterix.parser.classad.Value.java
public static boolean convertValueToIntegerValue(Value value, Value integerValue) throws HyracksDataException { boolean could_convert; AMutableCharArrayString buf = new AMutableCharArrayString(); char end;//w w w . j a v a 2s . c om AMutableInt64 ivalue = new AMutableInt64(0); AMutableDouble rtvalue = new AMutableDouble(0); ClassAdTime atvalue = new ClassAdTime(); MutableBoolean bvalue = new MutableBoolean(); NumberFactor nf; switch (value.getType()) { case UNDEFINED_VALUE: integerValue.setUndefinedValue(); could_convert = false; break; case ERROR_VALUE: case CLASSAD_VALUE: case LIST_VALUE: case SLIST_VALUE: integerValue.setErrorValue(); could_convert = false; break; case STRING_VALUE: could_convert = true; value.isStringValue(buf); int endIndex = buf.fistNonDigitChar(); if (endIndex < 0) { // no non digit ivalue.setValue(Long.parseLong(buf.toString())); nf = NumberFactor.NO_FACTOR; break; } else { ivalue.setValue(Long.parseLong(buf.substr(0, endIndex))); end = buf.charAt(endIndex); switch (Character.toUpperCase(end)) { case 'B': nf = NumberFactor.B_FACTOR; break; case 'K': nf = NumberFactor.K_FACTOR; break; case 'M': nf = NumberFactor.M_FACTOR; break; case 'G': nf = NumberFactor.G_FACTOR; break; case 'T': nf = NumberFactor.T_FACTOR; break; case '\0': nf = NumberFactor.NO_FACTOR; break; default: nf = NumberFactor.NO_FACTOR; break; } if (could_convert) { integerValue .setIntegerValue((long) ((ivalue.getLongValue() * Value.ScaleFactor[nf.ordinal()]))); } } break; case BOOLEAN_VALUE: value.isBooleanValue(bvalue); integerValue.setIntegerValue(bvalue.booleanValue() ? 1 : 0); could_convert = true; break; case INTEGER_VALUE: integerValue.copyFrom(value); could_convert = true; break; case REAL_VALUE: value.isRealValue(rtvalue); integerValue.setIntegerValue((long) rtvalue.getDoubleValue()); could_convert = true; break; case ABSOLUTE_TIME_VALUE: value.isAbsoluteTimeValue(atvalue); integerValue.setIntegerValue(atvalue.getTimeInMillis() / 1000L); could_convert = true; break; case RELATIVE_TIME_VALUE: value.isRelativeTimeValue(atvalue); integerValue.setIntegerValue((atvalue.getTime() / 1000L)); could_convert = true; break; default: could_convert = false; // Make gcc's -Wuninitalized happy throw new HyracksDataException("Should not reach here"); } return could_convert; }
From source file:asterix.parser.classad.Operation.java
public boolean shortCircuit(EvalState state, Value arg1, Value result) throws HyracksDataException { MutableBoolean arg1_bool = new MutableBoolean(); switch (opKind) { case OpKind_LOGICAL_OR_OP: if (arg1.isBooleanValueEquiv(arg1_bool) && arg1_bool.booleanValue()) { result.setBooleanValue(true); return true; }// w ww . j ava2 s . c o m break; case OpKind_LOGICAL_AND_OP: if (arg1.isBooleanValueEquiv(arg1_bool) && !arg1_bool.booleanValue()) { result.setBooleanValue(false); return true; } break; case OpKind_TERNARY_OP: if (arg1.isBooleanValueEquiv(arg1_bool)) { if (arg1_bool.booleanValue()) { if (child2 != null) { return child2.publicEvaluate(state, result); } } else { if (child3 != null) { return child3.publicEvaluate(state, result); } } } break; default: // no-op break; } return false; }
From source file:asterix.parser.classad.Value.java
public static boolean convertValueToRealValue(Value value, Value realValue) throws HyracksDataException { boolean could_convert; AMutableCharArrayString buf = new AMutableCharArrayString(); int endIndex; char end;/*from ww w . j a va 2 s . c o m*/ AMutableInt64 ivalue = new AMutableInt64(0); ClassAdTime atvalue = new ClassAdTime(); MutableBoolean bvalue = new MutableBoolean(); double rvalue; NumberFactor nf = NumberFactor.NO_FACTOR; switch (value.getType()) { case UNDEFINED_VALUE: realValue.setUndefinedValue(); could_convert = false; break; case ERROR_VALUE: case CLASSAD_VALUE: case LIST_VALUE: case SLIST_VALUE: realValue.setErrorValue(); could_convert = false; break; case STRING_VALUE: could_convert = true; value.isStringValue(buf); endIndex = buf.fistNonDoubleDigitChar(); if (endIndex < 0) { // no non digit String buffString = buf.toString(); if (buffString.contains("INF")) { buffString = buffString.replace("INF", "Infinity"); } rvalue = Double.parseDouble(buffString); nf = NumberFactor.NO_FACTOR; } else { rvalue = Double.parseDouble(buf.substr(0, endIndex)); end = buf.charAt(endIndex); switch (Character.toUpperCase(end)) { case 'B': nf = NumberFactor.B_FACTOR; break; case 'K': nf = NumberFactor.K_FACTOR; break; case 'M': nf = NumberFactor.M_FACTOR; break; case 'G': nf = NumberFactor.G_FACTOR; break; case 'T': nf = NumberFactor.T_FACTOR; break; case '\0': nf = NumberFactor.NO_FACTOR; break; default: nf = NumberFactor.NO_FACTOR; break; } } if (could_convert) { realValue.setRealValue(rvalue * Value.ScaleFactor[nf.ordinal()]); } break; case BOOLEAN_VALUE: value.isBooleanValue(bvalue); realValue.setRealValue(bvalue.booleanValue() ? 1.0 : 0.0); could_convert = true; break; case INTEGER_VALUE: value.isIntegerValue(ivalue); realValue.setRealValue((double) ivalue.getLongValue()); could_convert = true; break; case REAL_VALUE: realValue.copyFrom(value); could_convert = true; break; case ABSOLUTE_TIME_VALUE: value.isAbsoluteTimeValue(atvalue); realValue.setRealValue(atvalue.getTimeInMillis() / 1000.0); could_convert = true; break; case RELATIVE_TIME_VALUE: value.isRelativeTimeValue(atvalue); realValue.setRealValue(atvalue.getRelativeTime() / 1000.0); could_convert = true; break; default: could_convert = false; // Make gcc's -Wuninitalized happy throw new HyracksDataException("Should not reach here"); } return could_convert; }
From source file:asterix.parser.classad.Operation.java
public static int doArithmetic(int op, Value v1, Value v2, Value result) throws HyracksDataException { AMutableInt64 i1 = new AMutableInt64(0); AMutableInt64 i2 = new AMutableInt64(0); ClassAdTime t1 = new ClassAdTime(); AMutableDouble r1 = new AMutableDouble(0); MutableBoolean b1 = new MutableBoolean(); // ensure the operands have arithmetic types if ((!v1.isIntegerValue() && !v1.isRealValue() && !v1.isAbsoluteTimeValue() && !v1.isRelativeTimeValue() && !v1.isBooleanValue()) || (op != OpKind_UNARY_MINUS_OP && !v2.isBooleanValue() && !v2.isIntegerValue() && !v2.isRealValue() && !v2.isAbsoluteTimeValue() && !v2.isRelativeTimeValue())) { result.setErrorValue();/*w w w .j a v a 2 s. co m*/ return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); } // take care of the unary arithmetic operators if (op == OpKind_UNARY_MINUS_OP) { if (v1.isIntegerValue(i1)) { result.setIntegerValue((-1L) * i1.getLongValue()); return SigValues.SIG_CHLD1.ordinal(); } else if (v1.isRealValue(r1)) { result.setRealValue((-1) * r1.getDoubleValue()); return SigValues.SIG_CHLD1.ordinal(); } else if (v1.isRelativeTimeValue(t1)) { t1.setValue((-1) * t1.getTimeInMillis()); result.setRelativeTimeValue(t1); return (SigValues.SIG_CHLD1.ordinal()); } else if (v1.isBooleanValue(b1)) { result.setBooleanValue(!b1.booleanValue()); } else if (v1.isExceptional()) { // undefined or error --- same as operand result.copyFrom(v1); return SigValues.SIG_CHLD1.ordinal(); } // unary minus not defined on any other operand type result.setErrorValue(); return (SigValues.SIG_CHLD1.ordinal()); } // perform type promotions and proceed with arithmetic switch (coerceToNumber(v1, v2)) { case INTEGER_VALUE: v1.isIntegerValue(i1); v2.isIntegerValue(i2); switch (op) { case OpKind_ADDITION_OP: result.setIntegerValue(i1.getLongValue() + i2.getLongValue()); return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); case OpKind_SUBTRACTION_OP: result.setIntegerValue(i1.getLongValue() - i2.getLongValue()); return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); case OpKind_MULTIPLICATION_OP: result.setIntegerValue(i1.getLongValue() * i2.getLongValue()); return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); case OpKind_DIVISION_OP: if (i2.getLongValue() != 0L) { result.setIntegerValue(i1.getLongValue() / i2.getLongValue()); } else { result.setErrorValue(); } return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); case OpKind_MODULUS_OP: if (i2.getLongValue() != 0) { result.setIntegerValue(i1.getLongValue() % i2.getLongValue()); } else { result.setErrorValue(); } return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal()); default: // should not reach here throw new HyracksDataException("Should not get here"); } case REAL_VALUE: { return (doRealArithmetic(op, v1, v2, result)); } case ABSOLUTE_TIME_VALUE: case RELATIVE_TIME_VALUE: { return (doTimeArithmetic(op, v1, v2, result)); } default: // should not get here throw new HyracksDataException("Should not get here"); } }
From source file:asterix.parser.classad.Operation.java
public boolean flattenSpecials(EvalState state, Value val, ExprTreeHolder tree) throws HyracksDataException { ExprTreeHolder fChild1 = new ExprTreeHolder(); ExprTreeHolder fChild2 = new ExprTreeHolder(); ExprTreeHolder fChild3 = new ExprTreeHolder(); Value eval1 = new Value(); Value eval2 = new Value(); Value eval3 = new Value(); switch (opKind) { case OpKind_UNARY_PLUS_OP: case OpKind_UNARY_MINUS_OP: case OpKind_PARENTHESES_OP: case OpKind_LOGICAL_NOT_OP: case OpKind_BITWISE_NOT_OP: if (!child1.publicFlatten(state, eval1, fChild1)) { tree.setInnerTree(null);/* ww w. j a va 2 s .com*/ return false; } if (fChild1.getInnerTree() != null) { tree.setInnerTree(Operation.createOperation(opKind, fChild1)); return (tree.getInnerTree() != null); } else { privateDoOperation(opKind, eval1, null, null, true, false, false, val); tree.setInnerTree(null); eval1.clear(); return true; } case OpKind_TERNARY_OP: // Flatten the selector expression if (!child1.publicFlatten(state, eval1, fChild1)) { tree.setInnerTree(null); return false; } // check if selector expression collapsed to a non-undefined value if (fChild1.getInnerTree() == null && !eval1.isUndefinedValue()) { MutableBoolean b = new MutableBoolean(); // if the selector is not boolean-equivalent, propagate error if (!eval1.isBooleanValueEquiv(b)) { val.setErrorValue(); eval1.clear(); tree.setInnerTree(null); return true; } // eval1 is either a real or an integer if (b.booleanValue()) { return child2.publicFlatten(state, val, tree); } else { return child3.publicFlatten(state, val, tree); } } else { // Flatten arms of the if expression if (!child2.publicFlatten(state, eval2, fChild2) || !child3.publicFlatten(state, eval3, fChild3)) { // clean up tree.setInnerTree(null); return false; } // if any arm collapsed into a value, make it a Literal if (fChild2.getInnerTree() == null) fChild2.setInnerTree(Literal.createLiteral(eval2)); if (fChild3.getInnerTree() == null) fChild3.setInnerTree(Literal.createLiteral(eval3)); if (fChild2.getInnerTree() == null || fChild3.getInnerTree() == null) { tree.setInnerTree(null); ; return false; } // fChild1 may be NULL if child1 Flattened to UNDEFINED if (fChild1.getInnerTree() == null) { fChild1.setInnerTree(child1.copy()); } tree.setInnerTree(Operation.createOperation(opKind, fChild1, fChild2, fChild3)); if (tree.getInnerTree() == null) { return false; } return true; } case OpKind_SUBSCRIPT_OP: // Flatten both arguments if (!child1.publicFlatten(state, eval1, fChild1) || !child2.publicFlatten(state, eval2, fChild2)) { tree.setInnerTree(null); return false; } // if both arguments Flattened to values, Evaluate now if (fChild1.getInnerTree() == null && fChild2.getInnerTree() == null) { privateDoOperation(opKind, eval1, eval2, null, true, true, false, val); tree.setInnerTree(null); return true; } // otherwise convert Flattened values into literals if (fChild1.getInnerTree() == null) fChild1.setInnerTree(Literal.createLiteral(eval1)); if (fChild2.getInnerTree() == null) fChild2.setInnerTree(Literal.createLiteral(eval2)); if (fChild1.getInnerTree() == null || fChild2.getInnerTree() == null) { tree.setInnerTree(null); return false; } tree.setInnerTree(Operation.createOperation(opKind, fChild1, fChild2)); if (tree.getInnerTree() == null) { return false; } return true; default: throw new HyracksDataException("Should not get here"); } }
From source file:functionaltests.RestSmartProxyTest.java
@Test(timeout = TEN_MINUTES) public void testInErrorEventsReception() throws Exception { TaskFlowJob job = createInErrorJob(); final Semaphore semaphore = new Semaphore(0); printJobXmlRepresentation(job);//www . ja va 2 s. com final MutableBoolean taskHasBeenInError = new MutableBoolean(false); final MutableBoolean restartedFromErrorEventReceived = new MutableBoolean(false); SchedulerEventListenerExtended listener = new SchedulerEventListenerExtended() { @Override public void schedulerStateUpdatedEvent(SchedulerEvent eventType) { System.out.println("RestSmartProxyTest.schedulerStateUpdatedEvent " + eventType); } @Override public void jobSubmittedEvent(JobState job) { System.out.println("RestSmartProxyTest.jobSubmittedEvent"); } @Override public void jobStateUpdatedEvent(NotificationData<JobInfo> notification) { JobStatus status = notification.getData().getStatus(); System.out.println("RestSmartProxyTest.jobStateUpdatedEvent, eventType=" + notification.getEventType() + ", jobStatus=" + status); if (notification.getEventType() == SchedulerEvent.JOB_RESTARTED_FROM_ERROR) { restartedFromErrorEventReceived.setTrue(); } if (status == JobStatus.IN_ERROR) { semaphore.release(); } } @Override public void taskStateUpdatedEvent(NotificationData<TaskInfo> notification) { TaskStatus status = notification.getData().getStatus(); System.out.println("RestSmartProxyTest.taskStateUpdatedEvent, taskStatus=" + status); if (status == TaskStatus.WAITING_ON_ERROR || status == TaskStatus.IN_ERROR) { // IN_ERROR previously taskHasBeenInError.setTrue(); } } @Override public void usersUpdatedEvent(NotificationData<UserIdentification> notification) { System.out.println("RestSmartProxyTest.usersUpdatedEvent " + notification.getData()); } @Override public void pullDataFinished(String jobId, String taskName, String localFolderPath) { System.out.println("RestSmartProxyTest.pullDataFinished"); } @Override public void pullDataFailed(String jobId, String taskName, String remoteFolder_URL, Throwable t) { System.out.println("RestSmartProxyTest.pullDataFailed"); } @Override public void jobUpdatedFullDataEvent(JobState job) { System.out.println("RestSmartProxyTest.jobUpdatedFullDataEvent"); } }; restSmartProxy.addEventListener(listener); JobId jobId = restSmartProxy.submit(job, inputLocalFolder.getAbsolutePath(), pushUrl, outputLocalFolder.getAbsolutePath(), pullUrl, false, false); // the next line blocks until jobStateUpdatedEvent is called on the // listener // with job status set to IN_ERROR semaphore.acquire(); String jobIdAsString = jobId.value(); System.out.println("Restarting all In-Error tasks"); restSmartProxy.restartAllInErrorTasks(jobIdAsString); assertThat(restartedFromErrorEventReceived.booleanValue()).isTrue(); assertThat(taskHasBeenInError.booleanValue()).isTrue(); }
From source file:org.apache.asterix.app.translator.QueryTranslator.java
public void handleDatasetDropStatement(AqlMetadataProvider metadataProvider, Statement stmt, IHyracksClientConnection hcc) throws Exception { DropDatasetStatement stmtDelete = (DropDatasetStatement) stmt; String dataverseName = getActiveDataverse(stmtDelete.getDataverseName()); String datasetName = stmtDelete.getDatasetName().getValue(); MutableObject<ProgressState> progress = new MutableObject<>(ProgressState.NO_PROGRESS); MutableObject<MetadataTransactionContext> mdTxnCtx = new MutableObject<>( MetadataManager.INSTANCE.beginTransaction()); MutableBoolean bActiveTxn = new MutableBoolean(true); metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue()); MetadataLockManager.INSTANCE.dropDatasetBegin(dataverseName, dataverseName + "." + datasetName); List<JobSpecification> jobsToExecute = new ArrayList<>(); try {/*w w w . ja va 2 s . c o m*/ Dataset ds = MetadataManager.INSTANCE.getDataset(mdTxnCtx.getValue(), dataverseName, datasetName); if (ds == null) { if (stmtDelete.getIfExists()) { MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue()); return; } else { throw new AlgebricksException("There is no dataset with this name " + datasetName + " in dataverse " + dataverseName + "."); } } doDropDataset(ds, datasetName, metadataProvider, mdTxnCtx, jobsToExecute, dataverseName, bActiveTxn, progress, hcc); MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue()); } catch (Exception e) { if (bActiveTxn.booleanValue()) { abort(e, e, mdTxnCtx.getValue()); } if (progress.getValue() == ProgressState.ADDED_PENDINGOP_RECORD_TO_METADATA) { // #. execute compensation operations // remove the all indexes in NC try { for (JobSpecification jobSpec : jobsToExecute) { JobUtils.runJob(hcc, jobSpec, true); } } catch (Exception e2) { // do no throw exception since still the metadata needs to be compensated. e.addSuppressed(e2); } // remove the record from the metadata. mdTxnCtx.setValue(MetadataManager.INSTANCE.beginTransaction()); metadataProvider.setMetadataTxnContext(mdTxnCtx.getValue()); try { MetadataManager.INSTANCE.dropDataset(metadataProvider.getMetadataTxnContext(), dataverseName, datasetName); MetadataManager.INSTANCE.commitTransaction(mdTxnCtx.getValue()); } catch (Exception e2) { e.addSuppressed(e2); abort(e, e2, mdTxnCtx.getValue()); throw new IllegalStateException("System is inconsistent state: pending dataset(" + dataverseName + "." + datasetName + ") couldn't be removed from the metadata", e); } } throw e; } finally { MetadataLockManager.INSTANCE.dropDatasetEnd(dataverseName, dataverseName + "." + datasetName); } }