View Javadoc

1   package org.jscsi.target.connection.stage;
2   
3   
4   import java.io.IOException;
5   import java.security.DigestException;
6   
7   import org.jscsi.exception.InternetSCSIException;
8   import org.jscsi.parser.ProtocolDataUnit;
9   import org.jscsi.target.connection.Connection;
10  import org.jscsi.target.connection.TargetSession;
11  import org.jscsi.target.connection.phase.TargetPhase;
12  import org.jscsi.target.settings.Settings;
13  import org.jscsi.target.settings.SettingsException;
14  
15  
16  /**
17   * This class is an abstract super-class for stages of the (see {@link Connection} for a description of the relationship
18   * between sessions, connections, phases, and sessions).
19   * <p>
20   * The stage is started by calling the {@link #execute(ProtocolDataUnit)} method with the first {@link ProtocolDataUnit}
21   * to be processed as part of the stage.
22   * 
23   * @author Andreas Ergenzinger
24   */
25  public abstract class TargetStage {
26  
27      /**
28       * The phase this stage is a part of.
29       */
30      protected final TargetPhase targetPhase;
31  
32      /**
33       * The connection the {@link org.jscsi.target.connection.phase.TargetFullFeaturePhase} is a part of
34       */
35      protected final Connection connection;
36  
37      /**
38       * The session the {@link #connection} is a part of.
39       */
40      protected final TargetSession session;
41  
42      /**
43       * The current {@link Settings} of {@link #connection}.
44       */
45      protected final Settings settings;
46  
47      /**
48       * The abstract constructor.
49       * 
50       * @param targetPhase the phase this stage is a part of
51       */
52      public TargetStage (TargetPhase targetPhase) {
53          this.targetPhase = targetPhase;
54          this.connection = targetPhase.getTargetConnection();
55          this.session = connection.getTargetSession();
56          this.settings = connection.getSettings();
57      }
58  
59      /**
60       * Starts the stage. This method contains the operational logic required for the receiving, processing and sending
61       * of PDUs which is needed to successfully complete the represented iSCSI stage.
62       * 
63       * @param pdu the first {@link ProtocolDataUnit} to be processed in the stage
64       * @throws IOException if the connection was closed unexpectedly
65       * @throws InterruptedException
66       * @throws InternetSCSIException if a PDU has violated the iSCSI standard
67       * @throws DigestException if a digest error was detected
68       * @throws SettingsException if the program has attempted to access a value from settings which has not been
69       *             negotiated and which does not have a default value
70       */
71      public abstract void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException;
72  
73      /**
74       * Getting connection of this stage.
75       * 
76       * @return the related Connection of this stage.
77       */
78      public Connection getConnection () {
79          return connection;
80      }
81  
82  }