package net.hyperic.sigar.cmd;

import net.hyperic.sigar.ResourceLimit;
import net.hyperic.sigar.SigarException;

/**
 * Display system resource limits.
 */
public class Ulimit extends SigarCommandBase {

    public Ulimit(Shell shell) {
        super(shell);
    }

    public Ulimit() {
        super();
    }

    public String getUsageShort() {
        return "Display system resource limits";
    }

    private static String format(long val) {
        if (val == ResourceLimit.INFINITY()) {
            return "unlimited";
        }
        else {
            return String.valueOf(val);
        }
    }

    public void output(String[] args) throws SigarException {
        ResourceLimit rlimit = this.sigar.getResourceLimit();

        println("core file size......." +
                format(rlimit.getCoreCur()));
        println("data seg size........" +
                format(rlimit.getDataCur()));
        println("file size............" +
                format(rlimit.getFileSizeCur()));
        println("max memory size......" +
                format(rlimit.getMemoryCur()));
        println("open files..........." +
                format(rlimit.getOpenFilesCur()));
        println("stack size..........." +
                format(rlimit.getStackCur()));
        println("cpu time............." +
                format(rlimit.getCpuCur()));
        println("max user processes..." +
                format(rlimit.getProcessesCur()));
        println("virual memory........" +
                format(rlimit.getVirtualMemoryCur()));
    }

    public static void main(String[] args) throws Exception {
        new Ulimit().processCommand(args);
    }
}

@@ -105,16 +105,62 @@
 ception;
+%0Aimport net.hyperic.sigar.jmx.SigarInvokerJMX;
 %0A%0A/**%0A *
@@ -244,16 +244,83 @@
 Base %7B%0A%0A
+    private SigarInvokerJMX invoker;%0A    private String mode;%0A    %0A
     publ
@@ -709,32 +709,220 @@
        %7D%0A    %7D%0A%0A
+    private String getValue(String attr)%0A        throws SigarException %7B%0A        Long val = (Long)this.invoker.invoke(attr + this.mode);%0A        return format(val.longValue());%0A    %7D%0A    %0A
     public void 
@@ -967,24 +967,25 @@
 ption %7B%0A
+%0A
         
 Resource
@@ -980,45 +980,81 @@
     
-ResourceLimit rlimit = this.sigar.get
+this.invoker =%0A            SigarInvokerJMX.getInstance(this.proxy, %22Type=
 Reso
@@ -1066,21 +1066,57 @@
 imit
-(
+%22
 );%0A%0A   
+ 
+    this.mode = %22Cur%22;%0A        %0A
      
+   
 prin
@@ -1148,51 +1148,24 @@
 .%22 +
-%0A                format(rlimit.getCoreCur()
+ getValue(%22Core%22
 ));%0A
@@ -1209,51 +1209,24 @@
 .%22 +
-%0A                format(rlimit.getDataCur()
+ getValue(%22Data%22
 ));%0A
@@ -1270,50 +1270,27 @@
 .%22 +
-%0A                format(rlimit.get
+ getValue(%22
 FileSize
 Cur(
@@ -1285,21 +1285,17 @@
 FileSize
-Cur()
+%22
 ));%0A    
@@ -1335,55 +1335,28 @@
 .%22 +
-%0A                format(rlimit.get
+ getValue(%22
 Memory
-Cur(
+%22
 ))
-)
 ;%0A  
@@ -1398,42 +1398,19 @@
 .%22 +
-%0A                format(rlimit.get
+ getValue(%22
 Open
@@ -1414,23 +1414,19 @@
 penFiles
-Cur(
+%22
 ))
-)
 ;%0A      
@@ -1464,52 +1464,25 @@
 .%22 +
-%0A                format(rlimit.getStackCur()
+ getValue(%22Stack%22
 ));%0A
@@ -1526,50 +1526,23 @@
 .%22 +
-%0A                format(rlimit.getCpuCur()
+ getValue(%22Cpu%22
 ));%0A
@@ -1586,42 +1586,19 @@
 .%22 +
-%0A                format(rlimit.get
+ getValue(%22
 Proc
@@ -1602,21 +1602,17 @@
 rocesses
-Cur()
+%22
 ));%0A    
@@ -1652,42 +1652,19 @@
 .%22 +
-%0A                format(rlimit.get
+ getValue(%22
 Virt
@@ -1676,13 +1676,9 @@
 mory
-Cur()
+%22
 ));%0A

use invoker