Search in sources :

Example 21 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.

the class SeekCursorTest method shouldCatchupRootWhenRootNodeHasTooNewGeneration.

@Test
public void shouldCatchupRootWhenRootNodeHasTooNewGeneration() throws Exception {
    // given
    long id = cursor.getCurrentPageId();
    long generation = node.generation(cursor);
    MutableBoolean triggered = new MutableBoolean(false);
    Supplier<Root> rootCatchup = () -> {
        triggered.setTrue();
        return new Root(id, generation);
    };
    // when
    try (SeekCursor<MutableLong, MutableLong> seek = new SeekCursor<>(cursor, node, from, to, layout, stableGeneration, unstableGeneration, generationSupplier, rootCatchup, generation - 1)) {
    // do nothing
    }
    // then
    assertTrue(triggered.getValue());
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.Test)

Example 22 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.

the class QueryTranslator method asyncCreateAndRunJob.

private void asyncCreateAndRunJob(IHyracksClientConnection hcc, IStatementCompiler compiler, IMetadataLocker locker, ResultDelivery resultDelivery, String clientContextId, IStatementExecutorContext ctx, ResultSetId resultSetId, MutableBoolean printed) {
    Mutable<JobId> jobId = new MutableObject<>(JobId.INVALID);
    try {
        createAndRunJob(hcc, jobId, compiler, locker, resultDelivery, id -> {
            final ResultHandle handle = new ResultHandle(id, resultSetId);
            ResultUtil.printStatus(sessionOutput, AbstractQueryApiServlet.ResultStatus.RUNNING);
            ResultUtil.printResultHandle(sessionOutput, handle);
            synchronized (printed) {
                printed.setTrue();
                printed.notify();
            }
        }, clientContextId, ctx);
    } catch (Exception e) {
        if (JobId.INVALID.equals(jobId.getValue())) {
            // compilation failed
            ResultUtil.printStatus(sessionOutput, AbstractQueryApiServlet.ResultStatus.FAILED);
            ResultUtil.printError(sessionOutput.out(), e);
        } else {
            GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, resultDelivery.name() + " job with id " + jobId.getValue() + " " + "failed", e);
        }
    } finally {
        synchronized (printed) {
            if (printed.isFalse()) {
                printed.setTrue();
                printed.notify();
            }
        }
    }
}
Also used : ResultHandle(org.apache.asterix.app.result.ResultHandle) JobId(org.apache.hyracks.api.job.JobId) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 23 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.

the class Operation method compareBools.

public static void compareBools(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
    MutableBoolean b1 = objectPool.boolPool.get();
    MutableBoolean b2 = objectPool.boolPool.get();
    boolean compResult = false;
    v1.isBooleanValue(b1);
    v2.isBooleanValue(b2);
    switch(op) {
        case OpKind_LESS_THAN_OP:
            compResult = (b1.compareTo(b2) < 0);
            break;
        case OpKind_LESS_OR_EQUAL_OP:
            compResult = (b1.compareTo(b2) <= 0);
            break;
        case OpKind_EQUAL_OP:
            compResult = (b1.booleanValue() == b2.booleanValue());
            break;
        case OpKind_META_EQUAL_OP:
            compResult = (b1.booleanValue() == b2.booleanValue());
            break;
        case OpKind_NOT_EQUAL_OP:
            compResult = (b1.booleanValue() != b2.booleanValue());
            break;
        case OpKind_META_NOT_EQUAL_OP:
            compResult = (b1.booleanValue() != b2.booleanValue());
            break;
        case OpKind_GREATER_THAN_OP:
            compResult = (b1.compareTo(b2) > 0);
            break;
        case OpKind_GREATER_OR_EQUAL_OP:
            compResult = (b1.compareTo(b2) >= 0);
            break;
        default:
            // should not get here
            throw new HyracksDataException("Should not get here");
    }
    result.setBooleanValue(compResult);
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 24 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.

the class Operation method doLogical.

public static int doLogical(int op, Value v1, Value v2, Value result, ClassAdObjectPool objectPool) throws HyracksDataException {
    MutableBoolean b1 = objectPool.boolPool.get();
    MutableBoolean b2 = objectPool.boolPool.get();
    // first coerece inputs to boolean if they are considered equivalent
    if (!v1.isBooleanValue(b1) && v1.isBooleanValueEquiv(b1)) {
        v1.setBooleanValue(b1.booleanValue());
    }
    if (!v2.isBooleanValue(b2) && v2.isBooleanValueEquiv(b2)) {
        v2.setBooleanValue(b2);
    }
    ValueType vt1 = v1.getType();
    ValueType vt2 = v2.getType();
    if (vt1 != ValueType.UNDEFINED_VALUE && vt1 != ValueType.ERROR_VALUE && vt1 != ValueType.BOOLEAN_VALUE) {
        result.setErrorValue();
        return SigValues.SIG_CHLD1.ordinal();
    }
    if (vt2 != ValueType.UNDEFINED_VALUE && vt2 != ValueType.ERROR_VALUE && vt2 != ValueType.BOOLEAN_VALUE) {
        result.setErrorValue();
        return SigValues.SIG_CHLD2.ordinal();
    }
    // handle unary operator
    if (op == OpKind_LOGICAL_NOT_OP) {
        if (vt1 == ValueType.BOOLEAN_VALUE) {
            result.setBooleanValue(!b1.booleanValue());
        } else {
            result.setValue(v1);
        }
        return SigValues.SIG_CHLD1.ordinal();
    }
    if (op == OpKind_LOGICAL_OR_OP) {
        if (vt1 == ValueType.BOOLEAN_VALUE && b1.booleanValue()) {
            result.setBooleanValue(true);
            return SigValues.SIG_CHLD1.ordinal();
        } else if (vt1 == ValueType.ERROR_VALUE) {
            result.setErrorValue();
            return SigValues.SIG_CHLD1.ordinal();
        } else if (vt1 == ValueType.BOOLEAN_VALUE && !b1.booleanValue()) {
            result.setValue(v2);
        } else if (vt2 != ValueType.BOOLEAN_VALUE) {
            result.setValue(v2);
        } else if (b2.booleanValue()) {
            result.setBooleanValue(true);
        } else {
            result.setUndefinedValue();
        }
        return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
    } else if (op == OpKind_LOGICAL_AND_OP) {
        if (vt1 == ValueType.BOOLEAN_VALUE && !b1.booleanValue()) {
            result.setBooleanValue(false);
            return SigValues.SIG_CHLD1.ordinal();
        } else if (vt1 == ValueType.ERROR_VALUE) {
            result.setErrorValue();
            return SigValues.SIG_CHLD1.ordinal();
        } else if (vt1 == ValueType.BOOLEAN_VALUE && b1.booleanValue()) {
            result.setValue(v2);
        } else if (vt2 != ValueType.BOOLEAN_VALUE) {
            result.setValue(v2);
        } else if (!b2.booleanValue()) {
            result.setBooleanValue(false);
        } else {
            result.setUndefinedValue();
        }
        return (SigValues.SIG_CHLD1.ordinal() | SigValues.SIG_CHLD2.ordinal());
    }
    throw new HyracksDataException("Shouldn't reach here");
}
Also used : ValueType(org.apache.asterix.external.classad.Value.ValueType) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 25 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project asterixdb by apache.

the class Value method convertValueToRealValue.

public static boolean convertValueToRealValue(Value value, Value realValue, ClassAdObjectPool objectPool) throws HyracksDataException {
    boolean could_convert;
    AMutableCharArrayString buf = objectPool.strPool.get();
    int endIndex;
    char end;
    AMutableInt64 ivalue = objectPool.int64Pool.get();
    ClassAdTime atvalue = objectPool.classAdTimePool.get();
    MutableBoolean bvalue = objectPool.boolPool.get();
    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(ivalue.getLongValue());
            could_convert = true;
            break;
        case REAL_VALUE:
            realValue.setValue(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:
            // Make gcc's -Wuninitalized happy
            could_convert = false;
            throw new HyracksDataException("Should not reach here");
    }
    return could_convert;
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) AMutableInt64(org.apache.asterix.om.base.AMutableInt64) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)28 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)11 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)8 Test (org.junit.Test)7 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)6 IOException (java.io.IOException)4 ClassAd (org.apache.asterix.external.classad.ClassAd)4 MutableInt (org.apache.commons.lang3.mutable.MutableInt)4 CompilationException (org.apache.asterix.common.exceptions.CompilationException)3 AMutableCharArrayString (org.apache.asterix.external.classad.AMutableCharArrayString)3 ExprList (org.apache.asterix.external.classad.ExprList)3 Value (org.apache.asterix.external.classad.Value)3 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 TimeoutException (java.util.concurrent.TimeoutException)2 ResultHandle (org.apache.asterix.app.result.ResultHandle)2 ACIDException (org.apache.asterix.common.exceptions.ACIDException)2 AsterixException (org.apache.asterix.common.exceptions.AsterixException)2 IDataset (org.apache.asterix.common.metadata.IDataset)2 ExprTree (org.apache.asterix.external.classad.ExprTree)2