View Javadoc

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.state;
20  
21  
22  import org.jscsi.exception.InternetSCSIException;
23  import org.jscsi.initiator.connection.Connection;
24  import org.jscsi.parser.ProtocolDataUnit;
25  import org.jscsi.parser.ProtocolDataUnitFactory;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  
30  /**
31   * <h1>IState</h1>
32   * <p/>
33   * Each inherited state must implement this interface.
34   * 
35   * @author Volker Wildi
36   */
37  public interface IState {
38  
39      // --------------------------------------------------------------------------
40      // --------------------------------------------------------------------------
41  
42      /**
43       * This method is always invoked, when a request message must be send or response message must be received and then
44       * parsed.
45       * 
46       * @throws InternetSCSIException if any violation of the iSCSI Standard (RfC3720) has emerged.
47       */
48      public void execute () throws InternetSCSIException;
49  
50      /**
51       * This method shows if another state is following this one.
52       * 
53       * @return <code>true</code>, if another state must follow this state. Else an final state is reached.
54       */
55      public boolean nextStateFollowing ();
56  
57      /**
58       * This method checks the correctness of the given <code>ProtocolDataUnit</code> instance within the current state
59       * of a connection.
60       * 
61       * @param protocolDataUnit The <code>ProtocolDataUnit</code> instance to check.
62       * @return <code>Exception</code> if any problem occured with the PDU, <code>null</code> otherwise.
63       */
64      public Exception isCorrect (final ProtocolDataUnit protocolDataUnit);
65  
66      // --------------------------------------------------------------------------
67      // --------------------------------------------------------------------------
68      // --------------------------------------------------------------------------
69      // --------------------------------------------------------------------------
70  
71  }
72  
73  
74  /**
75   * <h1>AbstractState</h1>
76   * <p/>
77   * Each connection state must extend this abstract class to support some basic features.
78   * 
79   * @author Volker Wildi
80   */
81  abstract class AbstractState implements IState {
82  
83      // --------------------------------------------------------------------------
84      // --------------------------------------------------------------------------
85  
86      /** The Logger interface. */
87      protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractState.class);
88  
89      // --------------------------------------------------------------------------
90      // --------------------------------------------------------------------------
91  
92      /** The context connection used by all message kinds. */
93      protected final Connection connection;
94  
95      /** Factory to create the <code>ProtocolDataUnit</code> instances. */
96      protected final ProtocolDataUnitFactory protocolDataUnitFactory = new ProtocolDataUnitFactory();
97  
98      /** boolean to mark following states. */
99      protected boolean stateFollowing;
100 
101     // --------------------------------------------------------------------------
102     // --------------------------------------------------------------------------
103 
104     /** {@inheritDoc} */
105     public Exception isCorrect (final ProtocolDataUnit protocolDataUnit) {
106 
107         return null;
108     }
109 
110     // --------------------------------------------------------------------------
111     // --------------------------------------------------------------------------
112 
113     /**
114      * Constructor, which each subclass must implement to set the context connection correctly.
115      * 
116      * @param initConnection The connection, which is used for the message transmission.
117      */
118     protected AbstractState (final Connection initConnection) {
119 
120         connection = initConnection;
121     }
122 
123     /**
124      * {@inheritDoc}
125      */
126     public boolean nextStateFollowing () {
127         return this.stateFollowing;
128     }
129 
130     // --------------------------------------------------------------------------
131     // --------------------------------------------------------------------------
132     // --------------------------------------------------------------------------
133     // --------------------------------------------------------------------------
134 
135 }