1 package org.jscsi.target.settings; 2 3 /** 4 * Instances of this class contain all session-wide and connection-specific parameters that are either declared by the 5 * initiator or negotiated in the text parameter negotiation stages. 6 * 7 * @author Andreas Ergenzinger 8 */ 9 public final class Settings { 10 11 /** 12 * The {@link #settingsId} variable allows to compare the age of different {@link Settings} objects - newer 13 * instances have a higher {@link #settingsId}. 14 * <p> 15 * What it is really used for, however, is for determining if the buffered {@link Settings} object, which can be 16 * accessed via {@link ConnectionSettingsNegotiator#getSettings()} is up to date or if it has to be replaced. 17 * 18 * @see ConnectionSettingsNegotiator#getSettings() 19 * @see SessionSettingsNegotiator#getCurrentSettingsId() 20 */ 21 private final long settingsId; 22 23 // connection parameters 24 /** 25 * The <code>DataDigest</code> parameter. 26 */ 27 private final String dataDigest; 28 29 /** 30 * The <code>HeaderDigest</code> parameter. 31 */ 32 private final String headerDigest; 33 34 /** 35 * The <code>IFMarker</code> parameter. 36 */ 37 private final Boolean ifMarker; 38 39 /** 40 * The <code>IFMarkInt</code> parameter. 41 */ 42 private final Integer ifMarkInt; 43 44 /** 45 * The <code>MaxRecvDataSegmentLength</code> parameter. 46 */ 47 private final Integer maxRecvDataSegmentLength; 48 49 /** 50 * The <code>OFMarker</code> parameter. 51 */ 52 private final Boolean ofMarker; 53 54 /** 55 * The <code>OFMarkInt</code> parameter. 56 */ 57 private final Integer ofMarkInt; 58 59 // session parameters 60 61 /** 62 * The <code>TargetName</code> parameter 63 */ 64 private final String targetName; 65 66 /** 67 * The <code>DataPDUInOrder</code> parameter. 68 */ 69 private final Boolean dataPduInOrder; 70 71 /** 72 * The <code>DataSequenceInOrder</code> parameter. 73 */ 74 private final Boolean dataSequenceInOrder; 75 76 /** 77 * The <code>DefaultTime2Retain</code> parameter. 78 */ 79 private final Integer defaultTime2Retain; 80 81 /** 82 * The <code>DefaultTime2Wait</code> parameter. 83 */ 84 private final Integer defaultTime2Wait; 85 86 /** 87 * The <code>ErrorRecoveryLevel</code> parameter. 88 */ 89 private final Integer errorRecoveryLevel; 90 91 /** 92 * The <code>FirstBurstLength</code> parameter. 93 */ 94 private final Integer firstBurstLength; 95 96 /** 97 * The <code>ImmediateData</code> parameter. 98 */ 99 private final Boolean immediateData; 100 101 /** 102 * The <code>InitialR2T</code> parameter. 103 */ 104 private final Boolean initialR2T; 105 106 /** 107 * The <code>InitiatorAlias</code> parameter. 108 */ 109 private final String initiatorAlias; 110 111 /** 112 * The <code>InitiatorName</code> parameter. 113 */ 114 private final String initiatorName; 115 116 /** 117 * The <code>MaxBurstLength</code> parameter. 118 */ 119 private final Integer maxBurstLength; 120 121 /** 122 * The <code>MaxConnections</code> parameter. 123 */ 124 private final Integer maxConnections; 125 126 /** 127 * The <code>MaxOutstandingR2T</code> parameter. 128 */ 129 private final Integer maxOutstandingR2T; 130 131 /** 132 * The <code>SessionType</code> parameter. 133 */ 134 private final String sessionType; 135 136 /** 137 * Throws a {@link SettingsException} if the parameter is <code>null</code>. 138 * 139 * @param member the member variable to check 140 * @throws SettingsException if the parameter is <code>null</code> 141 */ 142 private static void checkIfNull (Object member) throws SettingsException { 143 if (member == null) throw new SettingsException(); 144 } 145 146 /** 147 * The constructor based on the builder pattern. 148 * 149 * @param c {@link ConnectionSettingsBuilderComponent} with the current connection-specific parameters 150 * @param s {@link SessionSettingsBuilderComponent} with the current session-wide parameters 151 */ 152 Settings (final ConnectionSettingsBuilderComponent c, final SessionSettingsBuilderComponent s) { 153 settingsId = s.settingsId; 154 // connection parameters 155 dataDigest = c.dataDigest; 156 headerDigest = c.headerDigest; 157 ifMarker = c.ifMarker; 158 ifMarkInt = c.ifMarkInt; 159 maxRecvDataSegmentLength = c.maxRecvDataSegmentLength; 160 ofMarker = c.ofMarker; 161 ofMarkInt = c.ofMarkInt; 162 targetName = c.targetName; 163 // session parameters 164 165 dataPduInOrder = s.dataPduInOrder; 166 dataSequenceInOrder = s.dataSequenceInOrder; 167 defaultTime2Retain = s.defaultTime2Retain; 168 defaultTime2Wait = s.defaultTime2Wait; 169 errorRecoveryLevel = s.errorRecoveryLevel; 170 firstBurstLength = s.firstBurstLength; 171 immediateData = s.immediateData; 172 initialR2T = s.initialR2T; 173 initiatorAlias = s.initiatorAlias; 174 initiatorName = s.initiatorName; 175 maxBurstLength = s.maxBurstLength; 176 maxConnections = s.maxConnections; 177 maxOutstandingR2T = s.maxOutstandingR2T; 178 sessionType = s.sessionType; 179 } 180 181 /** 182 * Returns the {@link #settingsId}. 183 * 184 * @return the {@link #settingsId} 185 */ 186 long getSettingsId () { 187 return settingsId; 188 } 189 190 /** 191 * Returns the value of the <code>DataDigest</code> parameter. 192 * 193 * @return the value of the <code>DataDigest</code> parameter 194 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 195 */ 196 public String getDataDigest () throws SettingsException { 197 checkIfNull(dataDigest); 198 return dataDigest; 199 } 200 201 /** 202 * Returns the value of the <code>HeaderDigest</code> parameter. 203 * 204 * @return the value of the <code>HeaderDigest</code> parameter 205 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 206 */ 207 public String getHeaderDigest () throws SettingsException { 208 checkIfNull(headerDigest); 209 return headerDigest; 210 } 211 212 /** 213 * Returns the value of the <code>IFMarker</code> parameter. 214 * 215 * @return the value of the <code>IFMarker</code> parameter 216 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 217 */ 218 public boolean getIfMarker () throws SettingsException { 219 checkIfNull(ifMarker); 220 return ifMarker; 221 } 222 223 /** 224 * Returns the value of the <code>IFMarkInt</code> parameter. 225 * 226 * @return the value of the <code>IFMarkInt</code> parameter 227 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 228 */ 229 public int getIfMarkInt () throws SettingsException { 230 checkIfNull(ifMarkInt); 231 return ifMarkInt; 232 } 233 234 /** 235 * Returns the value of the <code>MaxRecvDataSegmentLenght</code> parameter. 236 * 237 * @return the value of the <code>MaxRecvDataSegmentLenght</code> parameter 238 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 239 */ 240 public int getMaxRecvDataSegmentLength () throws SettingsException { 241 checkIfNull(maxRecvDataSegmentLength); 242 return maxRecvDataSegmentLength; 243 } 244 245 /** 246 * Returns the value of the <code>OFMarker</code> parameter. 247 * 248 * @return the value of the <code>OFMarker</code> parameter 249 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 250 */ 251 public boolean getOfMarker () throws SettingsException { 252 checkIfNull(ofMarker); 253 return ofMarker; 254 } 255 256 /** 257 * Returns the value of the <code>OFMarkInt</code> parameter. 258 * 259 * @return the value of the <code>OFMarkInt</code> parameter 260 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 261 */ 262 public int getOfMarkInt () throws SettingsException { 263 checkIfNull(ofMarkInt); 264 return ofMarkInt; 265 } 266 267 /** 268 * Returns the value of the <code>DataPDUInOrder</code> parameter. 269 * 270 * @return the value of the <code>DataPDUInOrder</code> parameter 271 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 272 */ 273 public boolean getDataPduInOrder () throws SettingsException { 274 checkIfNull(dataPduInOrder); 275 return dataPduInOrder; 276 } 277 278 /** 279 * Returns the value of the <code>DataSequenceInOrder</code> parameter. 280 * 281 * @return the value of the <code>DataSequenceInOrder</code> parameter 282 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 283 */ 284 public boolean getDataSequenceInOrder () throws SettingsException { 285 checkIfNull(dataSequenceInOrder); 286 return dataSequenceInOrder; 287 } 288 289 /** 290 * Returns the value of the <code>ErrorRecoveryLevel</code> parameter. 291 * 292 * @return the value of the <code>ErrorRecoveryLevel</code> parameter 293 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 294 */ 295 public int getErrorRecoveryLevel () throws SettingsException { 296 checkIfNull(errorRecoveryLevel); 297 return errorRecoveryLevel; 298 } 299 300 /** 301 * Returns the value of the <code>DefaultTime2Retain</code> parameter. 302 * 303 * @return the value of the <code>DefaultTime2Retain</code> parameter 304 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 305 */ 306 public int getDefaultTime2Retain () throws SettingsException { 307 checkIfNull(defaultTime2Retain); 308 return defaultTime2Retain; 309 } 310 311 /** 312 * Returns the value of the <code>DefaultTime2Wait</code> parameter. 313 * 314 * @return the value of the <code>DefaultTime2Wait</code> parameter 315 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 316 */ 317 public int getDefaultTime2Wait () throws SettingsException { 318 checkIfNull(defaultTime2Wait); 319 return defaultTime2Wait; 320 } 321 322 /** 323 * Returns the value of the <code>FirstBurstLength</code> parameter. 324 * 325 * @return the value of the <code>FirstBurstLength</code> parameter 326 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 327 */ 328 public int getFirstBurstLength () throws SettingsException { 329 checkIfNull(firstBurstLength); 330 return firstBurstLength; 331 } 332 333 /** 334 * Returns the value of the <code>ImmediateData</code> parameter. 335 * 336 * @return the value of the <code>ImmediateData</code> parameter 337 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 338 */ 339 public boolean getImmediateData () throws SettingsException { 340 checkIfNull(immediateData); 341 return immediateData; 342 } 343 344 /** 345 * Returns the value of the <code>InitialR2T</code> parameter. 346 * 347 * @return the value of the <code>InitialR2T</code> parameter 348 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 349 */ 350 public boolean getInitialR2T () throws SettingsException { 351 checkIfNull(initialR2T); 352 return initialR2T; 353 } 354 355 /** 356 * Returns the value of the <code>InitiatorAlias</code> parameter. 357 * 358 * @return the value of the <code>InitiatorAlias</code> parameter 359 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 360 */ 361 public String getInitiatorAlias () throws SettingsException { 362 checkIfNull(initiatorAlias); 363 return initiatorAlias; 364 } 365 366 /** 367 * Returns the value of the <code>InitiatorName</code> parameter. 368 * 369 * @return the value of the <code>InitiatorName</code> parameter 370 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 371 */ 372 public String getInitiatorName () throws SettingsException { 373 checkIfNull(initiatorName); 374 return initiatorName; 375 } 376 377 /** 378 * Returns the value of the <code>MaxBurstLength</code> parameter. 379 * 380 * @return the value of the <code>MaxBurstLength</code> parameter 381 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 382 */ 383 public int getMaxBurstLength () throws SettingsException { 384 checkIfNull(maxBurstLength); 385 return maxBurstLength; 386 } 387 388 /** 389 * Returns the value of the <code>MaxConnections</code> parameter. 390 * 391 * @return the value of the <code>MaxConnections</code> parameter 392 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 393 */ 394 public int getMaxConnections () throws SettingsException { 395 checkIfNull(maxConnections); 396 return maxConnections; 397 } 398 399 /** 400 * Returns the value of the <code>MaxOutstandingR2T</code> parameter. 401 * 402 * @return the value of the <code>MaxOutstandingR2T</code> parameter 403 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 404 */ 405 public int getMaxOutstandingR2T () throws SettingsException { 406 checkIfNull(maxOutstandingR2T); 407 return maxOutstandingR2T; 408 } 409 410 /** 411 * Returns the value of the <code>SessionType</code> parameter. 412 * 413 * @return the value of the <code>SessionType</code> parameter 414 * @throws SettingsException if the parameter has not been declared or negotiated and there is no default value 415 */ 416 public String getSessionType () throws SettingsException { 417 checkIfNull(maxOutstandingR2T); 418 return sessionType; 419 } 420 421 public String getTargetName () throws SettingsException { 422 return targetName; 423 } 424 }