1 4 package com.tc.net.protocol.transport; 5 6 import com.tc.logging.TCLogger; 7 import com.tc.util.Assert; 8 9 class MessageTransportStatus { 10 private MessageTransportState state; 11 private TCLogger logger; 12 13 MessageTransportStatus(MessageTransportState initialState, TCLogger logger) { 14 this.state = initialState; 15 this.logger = logger; 16 } 17 18 synchronized void reset() { 19 state = MessageTransportState.STATE_START; 20 } 21 22 private void stateChange(MessageTransportState newState) { 23 24 if (logger.isDebugEnabled()) { 25 logger.debug("Changing from " + state.toString() + " to " + newState.toString()); 26 } 27 28 Assert.eval(!isEnd()); 29 state = newState; 30 } 31 32 synchronized void synSent() { 33 stateChange(MessageTransportState.STATE_SYN_SENT); 34 } 35 36 synchronized void synAckError() { 37 stateChange(MessageTransportState.STATE_SYN_ACK_ERROR); 38 } 39 40 synchronized void established() { 41 stateChange(MessageTransportState.STATE_ESTABLISHED); 42 } 43 44 synchronized void end() { 45 stateChange(MessageTransportState.STATE_END); 46 } 47 48 synchronized boolean isStart() { 49 return this.state.equals(MessageTransportState.STATE_START); 50 } 51 52 public boolean isRestart() { 53 return this.state.equals(MessageTransportState.STATE_RESTART); 54 } 55 56 synchronized boolean isSynSent() { 57 return this.state.equals(MessageTransportState.STATE_SYN_SENT); 58 } 59 60 synchronized boolean isEstablished() { 61 return this.state.equals(MessageTransportState.STATE_ESTABLISHED); 62 } 63 64 synchronized boolean isEnd() { 65 return this.state.equals(MessageTransportState.STATE_END); 66 } 67 68 public String toString() { 69 return state.toString(); 70 } 71 72 } | Popular Tags |