wwndesc  1.0-76
WWNDesc.java
Go to the documentation of this file.
1 /* smallfoot.org is owned by allan.clark */
2 package org.smallfoot.wwn;
3 
4 import java.math.BigInteger;
5 
6 /**
7  * @file
8  *
9  * WWNDesc is the basic abstract ancestor: every descriptor is a descendent class extending
10  * this one, adding logic to the toString() function's output. toString() may choose to
11  * use the brief variable return a more brief output. Additionally, when called from
12  * WWNDescription.getWWNDescriptor(), a static function is often used to choose whether
13  * an instance of the WWNDesc descendent should be created.
14  */
15 
16 /**
17  * WWNDesc is the basic generic class from which each vendor-specific pattern is built upon; similar to an abstract parent but populated methods
18  */
19 public class WWNDesc
20 {
21  protected BigInteger wwn; /**< the WWN that the instance tried to describe */
22  protected boolean brief; /**< whether a more brief output should be offered in @ref toString() (ie the difference between "VMax-HK192601234-12gB" and "VMax-1234-12gB") .. the class may choose to ignore this value */
23 
24  protected DevRole role = DevRole.TARGET; /**< role of the device: Target, Switch, Initiator */
25 
26  /**
27  * create an instance with @ref brief set to false. This is a convenience function to support the older constructor model
28  *
29  * @throw java.lang.NullPointerException if the given wwn is null
30  *
31  * @param wwn the WWN to evaluate and describe
32  */
33  public WWNDesc(String wwn)
34  {
35  this(false, wwn);
36  }
37  /**
38  * create an instance with the given WWN. Values given to the constructor are simply copied to internal variables for later use
39  *
40  * @throw java.lang.NullPointerException if the given wwn is null
41  *
42  * @param brief whether an abbreviated description is requested
43  * @param wwn the WWN to evaluate and describe
44  */
45  public WWNDesc(boolean brief, String wwn)
46  {
47  this (brief, wwn, DevRole.TARGET);
48  }
49  /**
50  * create an instance with the given WWN. Values given to the constructor are simply copied to internal variables for later use
51  *
52  * @throw java.lang.NullPointerException if the given wwn is null
53  *
54  * @param brief whether an abbreviated description is requested
55  * @param wwn the WWN to evaluate and describe
56  * @param role the device role to assign
57  */
58  public WWNDesc(boolean brief, String wwn, DevRole role)
59  {
60  if (null == wwn) throw new java.lang.NullPointerException("wwn value must not be null");
61 
62  this.wwn = new BigInteger(wwn.replaceAll(":",""),16);
63  this.brief = brief;
64  this.role = role;
65  }
66  /**
67  * describe the WWN: produce a short (shorter if this.brief = true) description suitable for use as an alias for this WWN
68  *
69  * @return the alias for the WWN constructed from the WWN bit fields
70  */
71  public String toString()
72  {
73  return null;
74  }
75 
76  /**
77  * describe the WWPN's unique port label/index
78  *
79  * @return the unique name for the port WWPN
80  */
81  public String descPort()
82  {
83  return null;
84  }
85 
86  /** simple pass-thru class to define internal value for a Initiator in an idempotent way */
87  public static class WWNDescInitiator extends WWNDesc
88  {
89  /** @copydoc WWNDesc#WWNDesc(String) */
90  public WWNDescInitiator(String wwn)
91  {
92  super(false, wwn, DevRole.INITIATOR); /**< create a new Initiator device without brief naming capability */
93  }
94  /** @copydoc WWNDesc#WWNDesc(boolean,String) */
95  public WWNDescInitiator(boolean brief, String wwn)
96  {
97  super(brief, wwn, DevRole.INITIATOR); /**< create a new Initiator device with given brief capability */
98  }
99  /**
100  * convenience function to use bit-masks to check for membership in this role
101  *
102  * @param role the role to check
103  *
104  * @return true if the given role includes Initiator
105  */
106  public static boolean isA(int role)
107  {
108  return ( 0 < (role & DevRole.INITIATORbit) ); /**< lightweight method to check for membership in this role */
109  }
110  }
111 
112  /** simple pass-thru class to define internal value for a Switch in an idempotent way */
113  public static class WWNDescSwitch extends WWNDesc
114  {
115  /** @copydoc WWNDesc#WWNDesc(String) */
116  public WWNDescSwitch(String wwn)
117  {
118  super(false, wwn, DevRole.SWITCH); /**< create a new Switch device without brief naming capability */
119  }
120  /** @copydoc WWNDesc#WWNDesc(boolean,String) */
121  public WWNDescSwitch(boolean brief, String wwn)
122  {
123  super(brief, wwn, DevRole.SWITCH); /**< create a new Switch device with given brief capability */
124  }
125  /**
126  * convenience function to use bit-masks to check for membership in this role
127  *
128  * @param role the role to check
129  *
130  * @return true if the given role includes Switch
131  */
132  public static boolean isA(int role)
133  {
134  return ( 0 < (role & DevRole.SWITCHbit) ); /**< lightweight method to check for membership in this role */
135  }
136  }
137 
138  /** simple pass-thru class to define internal value for a Target in an idempotent way */
139  public static class WWNDescTarget extends WWNDesc
140  {
141  /** @copydoc WWNDesc#WWNDesc(String) */
142  public WWNDescTarget(String wwn)
143  {
144  super(false, wwn, DevRole.TARGET); /**< create a new Target device without brief naming capability */
145  }
146  /** @copydoc WWNDesc#WWNDesc(boolean,String) */
147  public WWNDescTarget(boolean brief, String wwn)
148  {
149  super(brief, wwn, DevRole.TARGET); /**< create a new Target device with given brief capability */
150  }
151  /**
152  * convenience function to use bit-masks to check for membership in this role
153  *
154  * @param role the role to check
155  *
156  * @return true if the given role includes Switch
157  */
158  public static boolean isA(int role)
159  {
160  return ( 0 < (role & DevRole.TARGETbit) ); /**< lightweight method to check for membership in this role */
161  }
162  }
163 }
WWNDescSwitch(boolean brief, String wwn)
create an instance with the given WWN.
Definition: WWNDesc.java:121
WWNDesc(boolean brief, String wwn)
create an instance with the given WWN.
Definition: WWNDesc.java:45
simple pass-thru class to define internal value for a Switch in an idempotent way ...
Definition: WWNDesc.java:113
WWNDescInitiator(boolean brief, String wwn)
create an instance with the given WWN.
Definition: WWNDesc.java:95
String descPort()
describe the WWPN's unique port label/index
Definition: WWNDesc.java:81
static boolean isA(int role)
convenience function to use bit-masks to check for membership in this role
Definition: WWNDesc.java:106
static boolean isA(int role)
convenience function to use bit-masks to check for membership in this role
Definition: WWNDesc.java:158
WWNDesc(String wwn)
create an instance with brief set to false.
Definition: WWNDesc.java:33
DevRole role
role of the device: Target, Switch, Initiator
Definition: WWNDesc.java:24
WWNDescTarget(boolean brief, String wwn)
create an instance with the given WWN.
Definition: WWNDesc.java:147
WWNDesc(boolean brief, String wwn, DevRole role)
create an instance with the given WWN.
Definition: WWNDesc.java:58
boolean brief
whether a more brief output should be offered in toString() (ie the difference between "VMax-HK192601...
Definition: WWNDesc.java:22
static final DevRole INITIATOR
a device that initiates a storage request: a server, or a Storage Virtualizer port that talks to back...
Definition: DevRole.java:65
WWNDescSwitch(String wwn)
create an instance with brief set to false.
Definition: WWNDesc.java:116
This class seeks to provide simple bitfield type-checking of a device in a fabric so that I can use t...
Definition: DevRole.java:18
WWNDesc is the basic generic class from which each vendor-specific pattern is built upon; similar to ...
Definition: WWNDesc.java:19
WWNDescInitiator(String wwn)
create an instance with brief set to false.
Definition: WWNDesc.java:90
static final DevRole SWITCH
a device that routes/passes traffic: Switch, NPV device/back-of-rack, FCR
Definition: DevRole.java:67
static boolean isA(int role)
convenience function to use bit-masks to check for membership in this role
Definition: WWNDesc.java:132
static final DevRole TARGET
a device that offers storage via >1 LUNs ; contrast a TAPE offers only one LUN
Definition: DevRole.java:63
simple pass-thru class to define internal value for a Initiator in an idempotent way ...
Definition: WWNDesc.java:87
String toString()
describe the WWN: produce a short (shorter if this.brief = true) description suitable for use as an a...
Definition: WWNDesc.java:71
simple pass-thru class to define internal value for a Target in an idempotent way ...
Definition: WWNDesc.java:139
BigInteger wwn
the WWN that the instance tried to describe
Definition: WWNDesc.java:21
WWNDescTarget(String wwn)
create an instance with brief set to false.
Definition: WWNDesc.java:142