01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.net.protocol.transport;
05:
06: import com.tc.logging.TCLogger;
07: import com.tc.util.Assert;
08:
09: class MessageTransportStatus {
10: private MessageTransportState state;
11: private TCLogger logger;
12:
13: MessageTransportStatus(MessageTransportState initialState,
14: TCLogger logger) {
15: this .state = initialState;
16: this .logger = logger;
17: }
18:
19: synchronized void reset() {
20: state = MessageTransportState.STATE_START;
21: }
22:
23: private void stateChange(MessageTransportState newState) {
24:
25: if (logger.isDebugEnabled()) {
26: logger.debug("Changing from " + state.toString() + " to "
27: + newState.toString());
28: }
29:
30: Assert.eval(!isEnd());
31: state = newState;
32: }
33:
34: synchronized void synSent() {
35: stateChange(MessageTransportState.STATE_SYN_SENT);
36: }
37:
38: synchronized void synAckError() {
39: stateChange(MessageTransportState.STATE_SYN_ACK_ERROR);
40: }
41:
42: synchronized void established() {
43: stateChange(MessageTransportState.STATE_ESTABLISHED);
44: }
45:
46: synchronized void end() {
47: stateChange(MessageTransportState.STATE_END);
48: }
49:
50: synchronized boolean isStart() {
51: return this .state.equals(MessageTransportState.STATE_START);
52: }
53:
54: public boolean isRestart() {
55: return this .state.equals(MessageTransportState.STATE_RESTART);
56: }
57:
58: synchronized boolean isSynSent() {
59: return this .state.equals(MessageTransportState.STATE_SYN_SENT);
60: }
61:
62: synchronized boolean isEstablished() {
63: return this .state
64: .equals(MessageTransportState.STATE_ESTABLISHED);
65: }
66:
67: synchronized boolean isEnd() {
68: return this .state.equals(MessageTransportState.STATE_END);
69: }
70:
71: public String toString() {
72: return state.toString();
73: }
74:
75: }
|