001 /**
002 * Copyright (C) 2009-2013 Barchart, Inc. <http://www.barchart.com/>
003 *
004 * All rights reserved. Licensed under the OSI BSD License.
005 *
006 * http://www.opensource.org/licenses/bsd-license.php
007 */
008 package com.barchart.udt;
009
010 import org.slf4j.Logger;
011 import org.slf4j.LoggerFactory;
012
013 /**
014 * status of underlying UDT native socket as reported by
015 * {@link SocketUDT#getStatus0()}
016 * <p>
017 * keep in sync with udt.h UDTSTATUS enum; see:
018 * <p>
019 * "enum UDTSTATUS { INIT = 1, OPENED = 2, LISTENING = 3, CONNECTING = 4, CONNECTED = 5, BROKEN = 6, CLOSING = 7, CLOSED = 8, NONEXIST = 9 };"
020 */
021 public enum StatusUDT {
022
023 /** note: keep the order */
024
025 //
026
027 /** newly created socket; both connector and acceptor */
028 INIT(1), //
029
030 /** bound socket; both connector and acceptor */
031 OPENED(2), //
032
033 /** bound and listening acceptor socket */
034 LISTENING(3), //
035
036 /** bound connector socket trying to connect */
037 CONNECTING(4), //
038
039 /** bound and connected connector socket */
040 CONNECTED(5), //
041
042 /** acceptor socket after close(), connector socket after remote unreachable */
043 BROKEN(6), //
044
045 /** connector socket while close() is in progress */
046 CLOSING(7), //
047
048 /** connector socket after close() is done */
049 CLOSED(8), //
050
051 /** trying to check status on socket that was closed and removed */
052 NONEXIST(9), //
053
054 /** non udt constant, catch-all value */
055 UNKNOWN(100), //
056
057 ;
058
059 protected static final Logger log = LoggerFactory
060 .getLogger(StatusUDT.class);
061
062 private final int code;
063
064 private StatusUDT(final int code) {
065 this.code = code;
066 }
067
068 public int getCode() {
069 return code;
070 }
071
072 public static final StatusUDT from(final int code) {
073
074 switch (code) {
075 case 1:
076 return INIT;
077 case 2:
078 return OPENED;
079 case 3:
080 return LISTENING;
081 case 4:
082 return CONNECTING;
083 case 5:
084 return CONNECTED;
085 case 6:
086 return BROKEN;
087 case 7:
088 return CLOSING;
089 case 8:
090 return CLOSED;
091 case 9:
092 return NONEXIST;
093 default:
094 log.error("unexpected code={}", code);
095 return UNKNOWN;
096 }
097
098 }
099
100 }