1 /** 2 * Copyright (c) 2012, University of Konstanz, Distributed Systems Group All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 5 * following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of 6 * conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, 7 * this list of conditions and the following disclaimer in the documentation and/or other materials provided with the 8 * distribution. * Neither the name of the University of Konstanz nor the names of its contributors may be used to 9 * endorse or promote products derived from this software without specific prior written permission. 10 * 11 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 12 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 13 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 14 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 15 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 16 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 17 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 18 */ 19 package org.jscsi.initiator.connection; 20 21 22 import java.nio.ByteBuffer; 23 24 25 /** 26 * <h1>TargetCapacityInformations</h1> 27 * <p> 28 * This class encapsulates the informations about the capacity of an iSCSI Target. 29 * 30 * @author Volker Wildi 31 */ 32 public final class TargetCapacityInformations { 33 34 // -------------------------------------------------------------------------- 35 // -------------------------------------------------------------------------- 36 37 /** Multiplicator from bytes to mega bytes. */ 38 private static final int MEGA_BYTES = 1024 * 1024; 39 40 // -------------------------------------------------------------------------- 41 // -------------------------------------------------------------------------- 42 43 /** The number of blocks. */ 44 private long size; 45 46 /** The block size (in bytes). */ 47 private long blockSize; 48 49 // -------------------------------------------------------------------------- 50 // -------------------------------------------------------------------------- 51 52 /** 53 * Default constructor to create a new, empty <code>TargetCapacityInformations</code> object. 54 */ 55 public TargetCapacityInformations () { 56 57 } 58 59 // -------------------------------------------------------------------------- 60 // -------------------------------------------------------------------------- 61 62 /** 63 * Returns the number of blocks of the connected target. 64 * 65 * @return Number of blocks. 66 */ 67 public final long getSize () { 68 69 return size; 70 } 71 72 /** 73 * Returns the block size (in bytes). 74 * 75 * @return The size of one block (in bytes). 76 */ 77 public final long getBlockSize () { 78 79 return blockSize; 80 } 81 82 // -------------------------------------------------------------------------- 83 // -------------------------------------------------------------------------- 84 85 /** 86 * This method deserializes from <code>buf</code> the capacity informations of the iSCSI Target. 87 * 88 * @param buf The input buffer to read from. 89 */ 90 public final void deserialize (final ByteBuffer buf) { 91 size = buf.getInt(); 92 blockSize = buf.getInt(); 93 } 94 95 // -------------------------------------------------------------------------- 96 // -------------------------------------------------------------------------- 97 98 /** {@inheritDoc} */ 99 @Override 100 public final String toString () { 101 102 return "Block Size: " + blockSize + "B, Size: " + size + " blocks, Total Capacity: " + (size * blockSize) / MEGA_BYTES + " MB"; 103 } 104 105 // -------------------------------------------------------------------------- 106 // -------------------------------------------------------------------------- 107 // -------------------------------------------------------------------------- 108 // -------------------------------------------------------------------------- 109 }