View Javadoc

1   package org.jscsi.target.connection;
2   
3   
4   import org.jscsi.target.settings.TextKeyword;
5   
6   
7   /**
8    * The {@link SessionType} of a {@link TargetSession} determines which stages can be reached in the Full Feature Phase.
9    * 
10   * @author Andreas Ergenzinger
11   */
12  public enum SessionType {
13  
14      /**
15       * The session is a discovery session. The initiator is only allowed to issue request a list of available target and
16       * close the connection.
17       */
18      DISCOVERY(TextKeyword.DISCOVERY),
19      /**
20       * The session is a normal session. The initiator is allowed to issue all supported commands.
21       */
22      NORMAL(TextKeyword.NORMAL);
23  
24      /**
25       * The session type as a text parameter negotiation <i>value</i> (as used in <i>key-value</> pairs).
26       */
27      private final String value;
28  
29      /**
30       * The constructor.
31       * 
32       * @param value the text parameter negotiation <i>value</i> (as used in <i>key-value</> pairs) describing this
33       *            session type.
34       */
35      private SessionType (final String value) {
36          this.value = value;
37      }
38  
39      public final String getValue () {
40          return value;
41      }
42  
43      /**
44       * Returns a {@link SessionType} based on the <i>value</i>, which must be either <code>Discovery</code> or
45       * <code>Normal</code>. Otherwise the method will return <code>null</code>.
46       * 
47       * @param value <code>Discovery</code> or <code>Normal</code>
48       * @return the specified {@link SessionType} or <code>null</code>
49       */
50      public static final SessionType getSessionType (final String value) {
51          final SessionType[] values = values();
52          for (SessionType s : values)
53              if (s.value.equals(value)) return s;
54          return null;
55      }
56  }