Coverage Report - net.admin4j.vo.MemoryUtilizationVO
 
Classes in this File Line Coverage Branch Coverage Complexity
MemoryUtilizationVO
100%
15/15
N/A
1
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.vo;
 15  
 
 16  
 import java.io.Serializable;
 17  
 
 18  
 /**
 19  
  * Describes memory utilization of the current runtime VM recorded at a specific point in time.
 20  
  * @author D. Ashmore
 21  
  * @since 1.0
 22  
  */
 23  
 public class MemoryUtilizationVO extends BaseVO implements Serializable {
 24  
 
 25  
     private static final long serialVersionUID = -2708169198765518131L;
 26  
     
 27  
     private long currentMemoryAllocatedInBytes;
 28  
     private long freeCurrentMemoryInbytes;
 29  
     private long maxMemoryInBytes;
 30  
     
 31  
     public MemoryUtilizationVO(long currentMemoryAllocatedInBytes, 
 32  30
             long freeMemoryInbytes, long maxMemoryInBytes) {
 33  30
         this.currentMemoryAllocatedInBytes = currentMemoryAllocatedInBytes;
 34  30
         this.freeCurrentMemoryInbytes = freeMemoryInbytes;
 35  30
         this.maxMemoryInBytes = maxMemoryInBytes;
 36  30
     }
 37  
     
 38  
     public long getMemoryInUseInBytes() {
 39  141
         return this.getCurrentMemoryAllocatedInBytes() - this.getFreeCurrentMemoryInbytes();
 40  
     }
 41  
     
 42  
     public long getFreeAvailableMemoryInBytes() {
 43  30
         return this.getMaxMemoryInBytes() - this.getMemoryInUseInBytes();
 44  
     }
 45  
     
 46  
     public double getFreeAvailableMemoryInMb() {
 47  21
         return (double)(this.getMaxMemoryInBytes() - this.getMemoryInUseInBytes()) / (double) 1024000 ;
 48  
     }
 49  
     
 50  
     public long getPercentMemoryAvailable() {
 51  30
         return (100 * this.getFreeAvailableMemoryInBytes()) / this.getMaxMemoryInBytes();
 52  
     }
 53  
     
 54  
     public long getPercentMemoryUsed() {
 55  15
         return 100 - this.getPercentMemoryAvailable();
 56  
     } 
 57  
     
 58  
     public long getCurrentMemoryAllocatedInBytes() {
 59  141
         return currentMemoryAllocatedInBytes;
 60  
     }
 61  
     
 62  
     public long getFreeCurrentMemoryInbytes() {
 63  141
         return freeCurrentMemoryInbytes;
 64  
     }
 65  
     
 66  
     public long getMaxMemoryInBytes() {
 67  87
         return maxMemoryInBytes;
 68  
     }
 69  
     
 70  
     public long getMaxMemoryInBytesInMb() {
 71  6
         return this.getMaxMemoryInBytes() / 1024000 ;
 72  
     }
 73  
 
 74  
     /* (non-Javadoc)
 75  
      * @see net.admin4j.vo.BaseVO#clone()
 76  
      */
 77  
     @Override
 78  
     public Object clone() throws CloneNotSupportedException {
 79  3
         return new MemoryUtilizationVO(currentMemoryAllocatedInBytes, 
 80  
             this.freeCurrentMemoryInbytes, maxMemoryInBytes);
 81  
     }
 82  
 
 83  
 }