SE547: Security Automata: Limit Open Files [19/20] Previous pageContentsNext page

class LimitFiles extends Policy {
    private int openFiles = 0; 
    private int maxOpen = 0;
    LimitFiles(int max) {
       maxOpen = max;
    }
    Suggestion query(Action a) { 
      aswitch (a) {
        case <* *.*.fileOpen(..)>:
           if (++openFiles <= maxOpen) 
               return Suggestion.OK();
           else
               return Suggestion.Halt();
        case <* *.*.fileClose(..)>:
           --openFiles;
           return Suggestion.OK();
        default:
           return new UnregSuggestion(this, a);
      }
    }
}

Previous pageContentsNext page