resourcemonitor.java

来自「First of all, the Applet-phone is a SIP 」· Java 代码 · 共 60 行

JAVA
60
字号
/* * ResourceMonitor.java * * Created on July 28, 2003, 9:45 AM */package gov.nist.security.bcs.monitor;import org.apache.log4j.Logger;/** * Class monitoring the instruction resources allocated for a service * @author DERUELLE Jean */public class ResourceMonitor {    /** log4j logging*/    private static Logger logger = Logger.getLogger(ResourceMonitor.class);    /**the number of instructions read at this time*/    private int currentInstructionCount=0;        /**the service*/    private String service=null;         /**the access control context of the jvm with wich we will check the resource permission*/    private java.security.AccessControlContext context=null;    /**      * Creates a new instance of ResourceMonitor      * @param mainClass - the main class where is the resource monitor     */    public ResourceMonitor(String mainClass) {        service=mainClass;        SecurityManager securityManager=System.getSecurityManager();        if (securityManager != null)             context = (java.security.AccessControlContext) securityManager.getSecurityContext();      }        /**     * This is called before a basic block is entered.      * @param instructionCount -the number of instructions executed in the basic block.           */    public void countInstructions(int instructionCount) {        currentInstructionCount +=instructionCount;                         try{            gov.nist.security.permissions.InstructionResourcePermission instructionResourcePermission=new gov.nist.security.permissions.InstructionResourcePermission(Integer.toString(currentInstructionCount),"allowed");            //System.out.println("Checking in your group policy file for the following RESOURCE PERMISSION : "+ instructionResourcePermission);            context.checkPermission(instructionResourcePermission);                          }        catch(Exception e){            System.out.println("The service "+service+" has overstepped its instructions limits ");                        System.out.println("The service "+service+" is exited");                        System.exit(1);         }                                                                 }        /**     *  Reinitializes the currentInstructionCount to zero     */    public void restartCounting(){        currentInstructionCount=0;            }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?