View Javadoc

1   package org.jscsi.target.connection.stage.fullfeature;
2   
3   
4   import java.io.IOException;
5   import java.security.DigestException;
6   
7   import org.jscsi.exception.InternetSCSIException;
8   import org.jscsi.parser.BasicHeaderSegment;
9   import org.jscsi.parser.ProtocolDataUnit;
10  import org.jscsi.parser.logout.LogoutResponse;
11  import org.jscsi.target.connection.TargetPduFactory;
12  import org.jscsi.target.connection.phase.TargetFullFeaturePhase;
13  import org.jscsi.target.settings.SettingsException;
14  
15  
16  /**
17   * A stage for processing logout requests.
18   * <p>
19   * Since <code>MaxConnections</code> is currently limited to <code>1</code>, all logout requests will be treated as
20   * requests to close the session.
21   * 
22   * @author Andreas Ergenzinger
23   */
24  public final class LogoutStage extends TargetFullFeatureStage {
25  
26      public LogoutStage (TargetFullFeaturePhase targetFullFeaturePhase) {
27          super(targetFullFeaturePhase);
28      }
29  
30      @Override
31      public void execute (ProtocolDataUnit pdu) throws IOException , InterruptedException , InternetSCSIException , DigestException , SettingsException {
32  
33          final BasicHeaderSegment bhs = pdu.getBasicHeaderSegment();
34          final int initiatorTaskTag = bhs.getInitiatorTaskTag();
35  
36          final ProtocolDataUnit responsePDU = TargetPduFactory.createLogoutResponsePdu(LogoutResponse.CONNECTION_CLOSED_SUCCESSFULLY, initiatorTaskTag, (short) settings.getDefaultTime2Wait(),// time2Wait
37                  (short) settings.getDefaultTime2Retain());// time2Retain
38  
39          connection.sendPdu(responsePDU);
40      }
41  
42  }