// Path: bitcoin-neo4j/project-back-end/src/main/java/com/oakinvest/b2g/util/status/ApplicationStatus.java
// @SuppressWarnings("unused")
// @Component
// @JsonSerialize(as = ApplicationStatus.class)
// public class ApplicationStatus {
// 
//     /**
//      * Non available value.
//      */
//     private static final String NON_AVAILABLE_VALUE_STRING = "n/a";
// 
//     /**
//      * Non available value.
//      */
//     private static final int NON_AVAILABLE_VALUE_NUMBER = -1;
// 
//     /**
//      * Number of blocks in Bitcoin core (NON_AVAILABLE_VALUE_NUMBER means no value has been set yet).
//      */
//     private int blockCountInBlockchain = NON_AVAILABLE_VALUE_NUMBER;
// 
//     /**
//      * Number of blocks in neo4j (NON_AVAILABLE_VALUE_NUMBER means no value has been set yet).
//      */
//     private int blockCountInNeo4j = NON_AVAILABLE_VALUE_NUMBER;
// 
//     /**
//      * Status of the block being processed.
//      */
//     @SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
//     @Autowired
//     private CurrentBlockStatus currentBlockStatus;
// 
//     /**
//      * Last block process duration (NON_AVAILABLE_VALUE_NUMBER means no value has been set yet).
//      */
//     private float lastBlockProcessDuration = NON_AVAILABLE_VALUE_NUMBER;
// 
//     /**
//      * Last error message (if no error, value is set to NON_AVAILABLE_VALUE_STRING).
//      */
//     private String lastErrorMessage = NON_AVAILABLE_VALUE_STRING;
// 
//     /**
//      * Gets blockCountInBlockchain.
//      *
//      * @return value of blockCountInBlockchain
//      */
//     public int getBlockCountInBlockchain() {
//         return blockCountInBlockchain;
//     }
// 
//     /**
//      * Sets blockCountInBlockchain.
//      *
//      * @param newBlocksCountInBitcoinCore blockCountInBlockchain
//      */
//     public void setBlockCountInBlockchain(final int newBlocksCountInBitcoinCore) {
//         blockCountInBlockchain = newBlocksCountInBitcoinCore;
//     }
// 
//     /**
//      * Gets blockCountInNeo4j.
//      *
//      * @return value of blockCountInNeo4j
//      */
//     public int getBlockCountInNeo4j() {
//         return blockCountInNeo4j;
//     }
// 
//     /**
//      * Sets blockCountInNeo4j.
//      *
//      * @param newBlocksCountInNeo4j blockCountInNeo4j
//      */
//     public void setBlockCountInNeo4j(final int newBlocksCountInNeo4j) {
//         blockCountInNeo4j = newBlocksCountInNeo4j;
//     }
// 
//     /**
//      * Gets currentBlockStatus.
//      *
//      * @return value of currentBlockStatus
//      */
//     public CurrentBlockStatus getCurrentBlockStatus() {
//         return currentBlockStatus;
//     }
// 
//     /**
//      * Sets currentBlockStatus.
//      *
//      * @param newCurrentBlockStatus currentBlockStatus
//      */
//     public void setCurrentBlockStatus(final CurrentBlockStatus newCurrentBlockStatus) {
//         currentBlockStatus = newCurrentBlockStatus;
//     }
// 
//     /**
//      * Gets lastBlockProcessDuration.
//      *
//      * @return value of lastBlockProcessDuration
//      */
//     public float getLastBlockProcessDuration() {
//         return lastBlockProcessDuration;
//     }
// 
//     /**
//      * Sets lastBlockProcessDuration.
//      *
//      * @param newAverageBlockProcessDuration lastBlockProcessDuration
//      */
//     public void setLastBlockProcessDuration(final float newAverageBlockProcessDuration) {
//         lastBlockProcessDuration = newAverageBlockProcessDuration;
//     }
// 
//     /**
//      * Gets lastErrorMessage.
//      *
//      * @return value of lastErrorMessage
//      */
//     public String getLastErrorMessage() {
//         return lastErrorMessage;
//     }
// 
//     /**
//      * Sets lastErrorMessage.
//      *
//      * @param newLastErrorMessage lastErrorMessage
//      */
//     public void setLastErrorMessage(final String newLastErrorMessage) {
//         lastErrorMessage = newLastErrorMessage;
//     }
// 
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import com.oakinvest.b2g.util.status.ApplicationStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import java.io.IOException;
package com.oakinvest.b2g.test.util.status;



/**
 * Status web socket session handler.
 */
public class StatusWebSocketSessionHandler extends TextWebSocketHandler {

    /**
     * Logger.
     */
    private final Logger log = LoggerFactory.getLogger(StatusWebSocketSessionHandler.class);

    /**
     * Object to Json mapper.
     */
    private final ObjectMapper mapper = new ObjectMapper();

    /**
     * Last status of the application.
     */
    private ApplicationStatus lastStatus;

    /**
     * True is a new message has been received.
     */
    private boolean newMessageReceived = false;

    @Override
    protected void handleTextMessage(final WebSocketSession session, final TextMessage message) {
        try {
            lastStatus = mapper.readValue(message.getPayload(), ApplicationStatus.class);
            newMessageReceived = true;
        } catch (IOException e) {
            log.error("Error getting message", e);
        }
    }

    /**
     * Wait for a new message from a websocket and returns it.
     * @return new status
     */
    public ApplicationStatus getNewMessage() {
        // We wait until a new message is here.
        while (!newMessageReceived) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                log.error("Error sleeping", e);
            }
        }
        newMessageReceived = false;
// Path: bitcoin-neo4j/project-back-end/src/main/java/com/oakinvest/b2g/util/status/ApplicationStatus.java
// @SuppressWarnings("unused")
// @Component
// @JsonSerialize(as = ApplicationStatus.class)
// public class ApplicationStatus {
// 
//     /**
//      * Non available value.
//      */
//     private static final String NON_AVAILABLE_VALUE_STRING = "n/a";
// 
//     /**
//      * Non available value.
//      */
//     private static final int NON_AVAILABLE_VALUE_NUMBER = -1;
// 
//     /**
//      * Number of blocks in Bitcoin core (NON_AVAILABLE_VALUE_NUMBER means no value has been set yet).
//      */
//     private int blockCountInBlockchain = NON_AVAILABLE_VALUE_NUMBER;
// 
//     /**
//      * Number of blocks in neo4j (NON_AVAILABLE_VALUE_NUMBER means no value has been set yet).
//      */
//     private int blockCountInNeo4j = NON_AVAILABLE_VALUE_NUMBER;
// 
//     /**
//      * Status of the block being processed.
//      */
//     @SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
//     @Autowired
//     private CurrentBlockStatus currentBlockStatus;
// 
//     /**
//      * Last block process duration (NON_AVAILABLE_VALUE_NUMBER means no value has been set yet).
//      */
//     private float lastBlockProcessDuration = NON_AVAILABLE_VALUE_NUMBER;
// 
//     /**
//      * Last error message (if no error, value is set to NON_AVAILABLE_VALUE_STRING).
//      */
//     private String lastErrorMessage = NON_AVAILABLE_VALUE_STRING;
// 
//     /**
//      * Gets blockCountInBlockchain.
//      *
//      * @return value of blockCountInBlockchain
//      */
//     public int getBlockCountInBlockchain() {
//         return blockCountInBlockchain;
//     }
// 
//     /**
//      * Sets blockCountInBlockchain.
//      *
//      * @param newBlocksCountInBitcoinCore blockCountInBlockchain
//      */
//     public void setBlockCountInBlockchain(final int newBlocksCountInBitcoinCore) {
//         blockCountInBlockchain = newBlocksCountInBitcoinCore;
//     }
// 
//     /**
//      * Gets blockCountInNeo4j.
//      *
//      * @return value of blockCountInNeo4j
//      */
//     public int getBlockCountInNeo4j() {
//         return blockCountInNeo4j;
//     }
// 
//     /**
//      * Sets blockCountInNeo4j.
//      *
//      * @param newBlocksCountInNeo4j blockCountInNeo4j
//      */
//     public void setBlockCountInNeo4j(final int newBlocksCountInNeo4j) {
//         blockCountInNeo4j = newBlocksCountInNeo4j;
//     }
// 
//     /**
//      * Gets currentBlockStatus.
//      *
//      * @return value of currentBlockStatus
//      */
//     public CurrentBlockStatus getCurrentBlockStatus() {
//         return currentBlockStatus;
//     }
// 
//     /**
//      * Sets currentBlockStatus.
//      *
//      * @param newCurrentBlockStatus currentBlockStatus
//      */
//     public void setCurrentBlockStatus(final CurrentBlockStatus newCurrentBlockStatus) {
//         currentBlockStatus = newCurrentBlockStatus;
//     }
// 
//     /**
//      * Gets lastBlockProcessDuration.
//      *
//      * @return value of lastBlockProcessDuration
//      */
//     public float getLastBlockProcessDuration() {
//         return lastBlockProcessDuration;
//     }
// 
//     /**
//      * Sets lastBlockProcessDuration.
//      *
//      * @param newAverageBlockProcessDuration lastBlockProcessDuration
//      */
//     public void setLastBlockProcessDuration(final float newAverageBlockProcessDuration) {
//         lastBlockProcessDuration = newAverageBlockProcessDuration;
//     }
// 
//     /**
//      * Gets lastErrorMessage.
//      *
//      * @return value of lastErrorMessage
//      */
//     public String getLastErrorMessage() {
//         return lastErrorMessage;
//     }
// 
//     /**
//      * Sets lastErrorMessage.
//      *
//      * @param newLastErrorMessage lastErrorMessage
//      */
//     public void setLastErrorMessage(final String newLastErrorMessage) {
//         lastErrorMessage = newLastErrorMessage;
//     }
// 
// }


// Path: bitcoin-neo4j/project-back-end/src/test/java/com/oakinvest/b2g/test/util/status/StatusWebSocketSessionHandler.java
import com.fasterxml.jackson.databind.ObjectMapper;
import com.oakinvest.b2g.util.status.ApplicationStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import java.io.IOException;

package com.oakinvest.b2g.test.util.status;



/**
 * Status web socket session handler.
 */
public class StatusWebSocketSessionHandler extends TextWebSocketHandler {

    /**
     * Logger.
     */
    private final Logger log = LoggerFactory.getLogger(StatusWebSocketSessionHandler.class);

    /**
     * Object to Json mapper.
     */
    private final ObjectMapper mapper = new ObjectMapper();

    /**
     * Last status of the application.
     */
    private ApplicationStatus lastStatus;

    /**
     * True is a new message has been received.
     */
    private boolean newMessageReceived = false;

    @Override
    protected void handleTextMessage(final WebSocketSession session, final TextMessage message) {
        try {
            lastStatus = mapper.readValue(message.getPayload(), ApplicationStatus.class);
            newMessageReceived = true;
        } catch (IOException e) {
            log.error("Error getting message", e);
        }
    }

    /**
     * Wait for a new message from a websocket and returns it.
     * @return new status
     */
    public ApplicationStatus getNewMessage() {
        // We wait until a new message is here.
        while (!newMessageReceived) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                log.error("Error sleeping", e);
            }
        }
        newMessageReceived = false;
        return lastStatus;