if (!state.isLogonReceived()) { if (state.isLogonSendNeeded()) { if (generateLogon()) { getLog().onEvent("Initiated logon request"); } else { getLog().onEvent("Error during logon request initiation");
String msgType = message.getHeader().getString(MsgType.FIELD);  try {  String beginString = message.getHeader().getString(BeginString.FIELD);  if (!beginString.equals(sessionID.getBeginString())) { throw new UnsupportedVersion(); }  if (dataDictionary != null) { dataDictionary.validate(message); }  if (msgType.equals(MsgType.LOGON)) { nextLogon(message); } else if (msgType.equals(MsgType.HEARTBEAT)) { nextHeartBeat(message); } else if (msgType.equals(MsgType.TEST_REQUEST)) { nextTestRequest(message); } else if (msgType.equals(MsgType.SEQUENCE_RESET)) { nextSequenceReset(message); } else if (msgType.equals(MsgType.LOGOUT)) { nextLogout(message); } else if (msgType.equals(MsgType.RESEND_REQUEST)) { nextResendRequest(message); } else if (msgType.equals(MsgType.REJECT)) { nextReject(message); } else { if (!verify(message)) { return;
    public synchronized void next() throws IOException {        if (!enabled) {            if (isLoggedOn()) {                if (!state.isLogoutSent()) {                    getLog().onEvent("Initiated logout request");                    generateLogout(state.getLogoutReason());                }            } else {                return;            }        }        if (!checkSessionTime()) {            reset();            return;        }        if (!state.isLogonReceived()) {            if (state.isLogonSendNeeded()) {                if (generateLogon()) {                    getLog().onEvent("Initiated logon request");                } else {                    getLog().onEvent("Error during logon request initiation");                }            } else if (state.isLogonAlreadySent() && state.isLogonTimedOut()) {                getLog().onEvent("Timed out waiting for logon response");                disconnect();            }            return;        }        if (state.getHeartBeatInterval() == 0) {            return;        }        if (state.isLogoutTimedOut()) {            getLog().onEvent("Timed out waiting for logout response");            disconnect();        }        if (state.isWithinHeartBeat()) {            return;        }        if (state.isTimedOut()) {            getLog().onEvent("Timed out waiting for heartbeat");            disconnect();        } else {            if (state.isTestRequestNeeded()) {                generateTestRequest("TEST");                state.incrementTestRequestCounter();                getLog().onEvent("Sent test request TEST");            } else if (state.isHeartBeatNeeded()) {                generateHeartbeat();            }        }    }