반응형
TB_BOARD 생성
create table TB_BOARD (
boardID int(11) not null,
boardName varchar(100) not null,
boardType varchar(100),
severity int(11),
primary key (BOARD_ID)
)ENGINE=InnoDB DEFAULT CHARACTER SET UTF8 COLLATE UTF8_GENERAL_CI;
ServerMain.java 생성
RMI 를 위해 ServerInterface에 Remote 상속 후
select 쿼리를 실행을 위한 List코드 작성
Severity.java
Serverity로 보드의 상태를 알 수 있다
public static int CRITICAL = 0;
public static int MAJOR = 1;
public static int MINOR = 2;
public static int NORMAL = 3;
public static Severity CRI = new Severity(CRITICAL);
public static Severity MAJ = new Severity(MAJOR);
public static Severity MIN = new Severity(MINOR);
public static Severity NOM = new Severity(NORMAL);
private int value;
private Severity(int value) {
this.value = value;
}
public static Severity[] items = {CRI, MAJ, MIN, NOM};
@Override
public String toString() {
if (this.value == CRITICAL)
return "CRITICAL";
else if (this.value == MAJOR)
return "MAJOR";
else if (this.value == MINOR)
return "MINOR";
else if (this.value == NORMAL)
return "NORMAL";
return null;
}
클라이언트 Panel에서 보드가 삽입될 좌표 설정
private void initData() {
// 연동에 의해 board 정보 조회
boardList = getBoardData();
LOGGER.debug("boardList:" + boardList);
for (BoardVo oneBoardVo : boardList) {
int boardId = oneBoardVo.getBoardId();
BoardPanel boardPanel = new BoardPanel(oneBoardVo);
this.add(boardPanel, null);
LOGGER.debug(String.format("+++ TestPanel에 boardPanel(%s, %s) 추가",
boardPanel.getWidth(), boardPanel.getHeight()));
boardPanel.repaint();
int boardWidth = boardPanel.getBoardWidth();
int boardHeight = boardPanel.getBoardHeight();
LOGGER.debug(String.format("boardId:%s, boardWidth:%s, boardHeight:%s", boardId, boardWidth, boardHeight));
if (boardId < 2) {
boardPanel.setBounds(BOARD_START_X + (BoardPanel.BOARD_WIDTH * (boardId % SLOT_NUM)),
TOP_BOARD_START_Y,
boardPanel.getBoardWidth(),
boardPanel.getBoardHeight());
}
else if (boardId < 20) {
LOGGER.debug("startX:" + (BOARD_START_X + (BoardPanel.BOARD_WIDTH * (boardId % SLOT_NUM))));
boardPanel.setBounds(BOARD_START_X + (BoardPanel.BOARD_WIDTH * (boardId % SLOT_NUM)),
BOTTOM_BOARD_START_Y,
boardPanel.getBoardWidth(),
boardPanel.getBoardHeight());
}
else {
boardPanel.setBounds(BOARD_START_X + (BoardPanel.BOARD_WIDTH * (boardId % SLOT_NUM)),
TOP_BOARD_START_Y,
boardPanel.getBoardWidth(),
boardPanel.getBoardHeight());
}
LOGGER.debug("--- TestPanel에 boardPanel 추가");
}
}
ClientPanel/getBoardData()
DB에서 보드 정보를 가져오는 역할을 수행하고 initData로 호출된다
setToolTipText 메서드로 마우스를 올리면 보드정보를 알 수 있다.
private void initComponent() throws Exception {
this.setToolTipText(boardVo.getBoardName()+boardVo.getBoardId());
}
initAlarmGenerator() // 랜덤 쓰레드
private void initAlarmGenerator() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
int boardId = (int)(Math.random() * 38);
int severity = (int)(Math.random() * 4);
Severity sev = Severity.items[severity];
BoardVo severityRandom = new BoardVo();
severityRandom.setBoardId(boardId);
severityRandom.setSeverity(severity);
LOGGER.debug("boardId:" + boardId + ", severity:" + sev);
try {
client.pushAlarm(severityRandom);
Thread.sleep(100);
}
catch (Exception ex) {
}
}
}
});
t.start();
}
반응형
'인턴' 카테고리의 다른 글
[인턴 OJT 21일차] RMI 채팅, RackView 코드리뷰 (0) | 2023.01.11 |
---|---|
[인턴 OJT 19일차] RMI (0) | 2023.01.09 |
[인턴 OJT 18일차] 소켓 주소록 피드백 (0) | 2023.01.09 |
[인턴 OJT 17일차] 소켓을 활용한 주소록과 흐름 (0) | 2023.01.09 |
[인턴 OJT 16일차] socket (0) | 2023.01.09 |