Example usage for org.apache.lucene.util.automaton Automaton ramBytesUsed

List of usage examples for org.apache.lucene.util.automaton Automaton ramBytesUsed

Introduction

In this page you can find the example usage for org.apache.lucene.util.automaton Automaton ramBytesUsed.

Prototype

@Override
    public long ramBytesUsed() 

Source Link

Usage

From source file:org.elasticsearch.xpack.core.security.authz.permission.FieldPermissions.java

License:Open Source License

/** Constructor that enables field-level security based on include/exclude rules. Exclude rules
 *  have precedence over include rules. */
FieldPermissions(FieldPermissionsDefinition fieldPermissionsDefinition, Automaton permittedFieldsAutomaton) {
    if (permittedFieldsAutomaton.isDeterministic() == false && permittedFieldsAutomaton.getNumStates() > 1) {
        // we only accept deterministic automata so that the CharacterRunAutomaton constructor
        // directly wraps the provided automaton
        throw new IllegalArgumentException("Only accepts deterministic automata");
    }//ww w .  j a v  a  2  s  .  c  o m
    this.fieldPermissionsDefinition = fieldPermissionsDefinition;
    this.originalAutomaton = permittedFieldsAutomaton;
    this.permittedFieldsAutomaton = new CharacterRunAutomaton(permittedFieldsAutomaton);
    // we cache the result of isTotal since this might be a costly operation
    this.permittedFieldsAutomatonIsTotal = Operations.isTotal(permittedFieldsAutomaton);

    long ramBytesUsed = BASE_FIELD_PERM_DEF_BYTES;

    for (FieldGrantExcludeGroup group : fieldPermissionsDefinition.getFieldGrantExcludeGroups()) {
        ramBytesUsed += BASE_FIELD_GROUP_BYTES + BASE_HASHSET_ENTRY_SIZE;
        if (group.getGrantedFields() != null) {
            ramBytesUsed += RamUsageEstimator.shallowSizeOf(group.getGrantedFields());
        }
        if (group.getExcludedFields() != null) {
            ramBytesUsed += RamUsageEstimator.shallowSizeOf(group.getExcludedFields());
        }
    }
    ramBytesUsed += permittedFieldsAutomaton.ramBytesUsed();
    ramBytesUsed += runAutomatonRamBytesUsed(permittedFieldsAutomaton);
    this.ramBytesUsed = ramBytesUsed;
}