From 4be1ae4130a0a728feec09dbfd512f51dcc0ae92 Mon Sep 17 00:00:00 2001 From: jangdongsin Date: Tue, 22 Oct 2024 14:20:41 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AF=B8=EC=82=AC=EC=9A=A9=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C,=20=ED=81=B4=EB=9E=98=EC=8A=A4,=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 - .../client/config/RunnerConfiguration.java | 18 +- .../server/service/CollectClientService.java | 10 - .../munjaon/client/server/service/Server.java | 195 ------------------ .../java/com/munjaon/client/util/XmlUtil.java | 125 ----------- 5 files changed, 8 insertions(+), 341 deletions(-) delete mode 100644 src/main/java/com/munjaon/client/server/service/Server.java delete mode 100644 src/main/java/com/munjaon/client/util/XmlUtil.java diff --git a/build.gradle b/build.gradle index f932074..e23ef09 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,6 @@ dependencies { implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' -// runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' diff --git a/src/main/java/com/munjaon/client/config/RunnerConfiguration.java b/src/main/java/com/munjaon/client/config/RunnerConfiguration.java index 838cbc9..a0441b0 100644 --- a/src/main/java/com/munjaon/client/config/RunnerConfiguration.java +++ b/src/main/java/com/munjaon/client/config/RunnerConfiguration.java @@ -25,16 +25,7 @@ public class RunnerConfiguration { System.setProperty("ROOTPATH", serverConfig.getServerRootPath()); System.setProperty("DBMS", serverConfig.getString("DB.DBMS")); PropertyLoader.load(); -// try { -// String[] array = serverConfig.getStringArray("test.list"); -// if (array != null && array.length > 0) { -// for (String s : array) { -// System.out.println("List : " + s); -// } -// } -// } catch (ConfigurationException e) { -// throw new RuntimeException(e); -// } + return args -> System.out.println("Runner Bean #1 : " + serverConfig.getServerProperyFile()); } @@ -49,6 +40,7 @@ public class RunnerConfiguration { } catch (Exception e) { throw new RuntimeException(e); } + return args -> System.out.println("Runner Bean #2"); } @@ -63,6 +55,7 @@ public class RunnerConfiguration { } catch (Exception e) { throw new RuntimeException(e); } + return args -> System.out.println("Runner Bean #2"); } @@ -77,6 +70,7 @@ public class RunnerConfiguration { } catch (Exception e) { throw new RuntimeException(e); } + return args -> System.out.println("Runner Bean #2"); } @@ -91,6 +85,7 @@ public class RunnerConfiguration { } catch (Exception e) { throw new RuntimeException(e); } + return args -> System.out.println("Runner Bean #2"); } @@ -105,6 +100,7 @@ public class RunnerConfiguration { } catch (Exception e) { throw new RuntimeException(e); } + return args -> System.out.println("Runner Bean #2"); } @@ -118,6 +114,7 @@ public class RunnerConfiguration { } catch (Exception e) { throw new RuntimeException(e); } + return args -> System.out.println("Runner Bean #2"); } @@ -131,6 +128,7 @@ public class RunnerConfiguration { } catch (Exception e) { throw new RuntimeException(e); } + return args -> System.out.println("Runner Bean #2"); } } diff --git a/src/main/java/com/munjaon/client/server/service/CollectClientService.java b/src/main/java/com/munjaon/client/server/service/CollectClientService.java index 10211c0..e0848ad 100644 --- a/src/main/java/com/munjaon/client/server/service/CollectClientService.java +++ b/src/main/java/com/munjaon/client/server/service/CollectClientService.java @@ -183,15 +183,6 @@ public class CollectClientService extends Service { this.deliverList = new ArrayList<>(); } this.deliverList.add(msgId); -// if (this.deliverBuilder == null) { -// return; -// } -// -// if (this.deliverBuilder.isEmpty()) { -// this.deliverBuilder.append(msgId); -// } else { -// this.deliverBuilder.append(",").append(msgId); -// } } private void messageService() { @@ -605,7 +596,6 @@ public class CollectClientService extends Service { private void linkCheckService() { if (System.currentTimeMillis() - lastPacketSendTime < Packet.LINK_CHECK_CYCLE) { -// saveSystemLog("LinkCheck Is Not"); return; } diff --git a/src/main/java/com/munjaon/client/server/service/Server.java b/src/main/java/com/munjaon/client/server/service/Server.java deleted file mode 100644 index 4eb448c..0000000 --- a/src/main/java/com/munjaon/client/server/service/Server.java +++ /dev/null @@ -1,195 +0,0 @@ -package com.munjaon.client.server.service; - -import com.munjaon.client.server.packet.Packet; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.nio.channels.SelectionKey; -import java.nio.channels.Selector; -import java.nio.channels.ServerSocketChannel; -import java.nio.channels.SocketChannel; -import java.util.Iterator; -import java.util.concurrent.Executors; - -public class Server implements Runnable { - private InetSocketAddress listenAddress; - // 메시지는 개행으로 구분한다. - private static char CR = (char) 0x0D; - private static char LF = (char) 0x0A; - // ip와 port 설정 - public Server(String address, int port) { - listenAddress = new InetSocketAddress(address, port); - } - // Thread 실행. - public void run() { - // 셀렉터 설정 - try (Selector selector = Selector.open()) { - // 채널 설정 - try (ServerSocketChannel serverChannel = ServerSocketChannel.open()) { - System.out.println("ServerSocketChannel is open"); - // non-Blocking 설정 - serverChannel.configureBlocking(false); - System.out.println("serverChannel.configureBlocking(false) >> "); - // 서버 ip, port 설정 - serverChannel.socket().bind(listenAddress); - System.out.println("serverChannel.socket().bind(listenAddress) >> "); - // 채널에 accept 대기 설정 - serverChannel.register(selector, SelectionKey.OP_ACCEPT); - System.out.println("serverChannel.register(selector, SelectionKey.OP_ACCEPT) >> "); - // 셀렉터가 있을 경우. -// while (selector.select() > 0) { - while (true) { - if (selector.select(10000) == 0) { - System.out.println("selector.select() == 0"); - continue; - } - System.out.println("selector.select() > 0 >> "); - // 셀렉터 키 셋를 가져온다. - Iterator keys = selector.selectedKeys().iterator(); - // 키가 있으면.. - while (keys.hasNext()) { - SelectionKey key = keys.next(); - //키 셋에서 제거. - keys.remove(); - if (!key.isValid()) { - continue; - } - // 접속일 경우.. - if (key.isAcceptable()) { - this.accept(selector, key); - // 수신일 경우.. - } else if (key.isReadable()) { - this.receive(selector, key); - // 발신일 경우.. - } else if (key.isWritable()) { - this.send(selector, key); - } - } - } - } - } catch (IOException e) { - e.printStackTrace(); - } - } - // 접속시 호출 함수.. - private void accept(Selector selector, SelectionKey key) { - try { - // 키 채널을 가져온다. - ServerSocketChannel serverChannel = (ServerSocketChannel) key.channel(); - // accept을 해서 Socket 채널을 가져온다. - SocketChannel channel = serverChannel.accept(); - channel.configureBlocking(false); - // 소켓 취득 - Socket socket = channel.socket(); - SocketAddress remoteAddr = socket.getRemoteSocketAddress(); - System.out.println("Connected to: " + remoteAddr); - // 접속 Socket 단위로 사용되는 Buffer; - StringBuffer sb = new StringBuffer(); - sb.append("Welcome server!\r\n>"); - // Socket 채널을 channel에 송신 등록한다 - channel.register(selector, SelectionKey.OP_WRITE, sb); - } catch (IOException e) { - e.printStackTrace(); - } - } - // 수신시 호출 함수.. - private void receive(Selector selector, SelectionKey key) { - try { - // 키 채널을 가져온다. - SocketChannel channel = (SocketChannel) key.channel(); - // 연결이 끊겼는지 확인 - if ((channel.isConnected() || channel.isOpen()) == false) { - System.out.println("java connection reset by client: "); - // 키 닫기 - key.cancel(); - // 소켓 채널 닫기 - channel.close(); - // 종료 - return; - } - // 채널 Non-blocking 설정 - channel.configureBlocking(false); - // 소켓 취득 - Socket socket = channel.socket(); - // Byte 버퍼 생성 - ByteBuffer buffer = ByteBuffer.allocate(1024); - // ***데이터 수신*** - int size = channel.read(buffer); - // 수신 크기가 없으면 소켓 접속 종료. - if (size == -1) { - SocketAddress remoteAddr = socket.getRemoteSocketAddress(); - System.out.println("Connection closed by client: " + remoteAddr); - // 소켓 채널 닫기 - channel.close(); - // 소켓 닫기 - socket.close(); - // 키 닫기 - key.attach(null); - key.cancel(); - return; - } - // ByteBuffer -> byte[] - byte[] data = new byte[size]; - System.arraycopy(buffer.array(), 0, data, 0, size); - // StringBuffer 취득 - StringBuffer sb = (StringBuffer) key.attachment(); - // 버퍼에 수신된 데이터 추가 - sb.append(new String(data)); - // 데이터 끝이 개행 일 경우. - if (sb.length() > 2 && sb.charAt(sb.length() - 2) == CR && sb.charAt(sb.length() - 1) == LF) { - // 개행 삭제 - sb.setLength(sb.length() - 2); - // 메시지를 콘솔에 표시한다. - String msg = sb.toString(); - System.out.println(msg); - // exit 경우 접속을 종료한다. - if ("exit".equals(msg)) { - // 소켓 채널 닫기 - channel.close(); - // 소켓 닫기 - socket.close(); - // 키 닫기 - key.cancel(); - return; - } - // Echo - 메시지> 의 형태로 재 전송. - sb.insert(0, "Echo - "); - sb.append("\r\n>"); - // Socket 채널을 channel에 송신 등록한다 - channel.register(selector, SelectionKey.OP_WRITE, sb); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - // 발신시 호출 함수 - private void send(Selector selector, SelectionKey key) { - try { - // 키 채널을 가져온다. - SocketChannel channel = (SocketChannel) key.channel(); - // 채널 Non-blocking 설정 - channel.configureBlocking(false); - // StringBuffer 취득 - StringBuffer sb = (StringBuffer) key.attachment(); - String data = sb.toString(); - // StringBuffer 초기화 - sb.setLength(0); - // byte 형식으로 변환 - ByteBuffer buffer = ByteBuffer.wrap(data.getBytes(Packet.AGENT_CHARACTER_SET)); - // ***데이터 송신*** - channel.write(buffer); - // Socket 채널을 channel에 수신 등록한다 - channel.register(selector, SelectionKey.OP_READ, sb); - } catch (IOException e) { - e.printStackTrace(); - } - } - // 시작 함수 - public static void main(String[] args) { - // 포트는 10000을 Listen한다. - Executors.newSingleThreadExecutor().execute(new Server("localhost", 10000)); - } -} diff --git a/src/main/java/com/munjaon/client/util/XmlUtil.java b/src/main/java/com/munjaon/client/util/XmlUtil.java deleted file mode 100644 index 4752aee..0000000 --- a/src/main/java/com/munjaon/client/util/XmlUtil.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.munjaon.client.util; - -import org.jdom2.Document; -import org.jdom2.Element; -import org.jdom2.JDOMException; -import org.jdom2.input.SAXBuilder; -import org.jdom2.output.Format; -import org.jdom2.output.XMLOutputter; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.StringReader; -import java.util.List; - -public class XmlUtil { -// private static Document getDOMParsedDocument(final String fileName) { -// Document document = null; -// try { -// -// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); -// //If want to make namespace aware. -// //factory.setNamespaceAware(true); -// DocumentBuilder documentBuilder = factory.newDocumentBuilder(); -// document = documentBuilder.parse(new File("C:\\Docs\\JDS\\ITN\\MMS01Header.xml")); -// -// NodeList nodeList = document.getDocumentElement().getChildNodes(); -// for (int i = 0; i < nodeList.getLength(); i++) { -// Node node = nodeList.item(i); -// if (node.getNodeType() == Node.ELEMENT_NODE) { -// Element elem = (Element) node; -// System.out.println("createDate : " + elem.getAttribute("createDate")); -// System.out.println("getTagName : " + elem.getTagName()); -// System.out.println("getNodeName : " + elem.getNodeName()); -// System.out.println("getTextContent : " + elem.getTextContent()); -//// String createDate = elem.getElementsByTagName("createDate").item(0).getChildNodes().item(0).getNodeValue(); -//// System.out.println("createDate : " + createDate); -//// String PopCounter = elem.getElementsByTagName("PopCounter").item(0).getChildNodes().item(0).getNodeValue(); -//// System.out.println("PopCounter : " + PopCounter); -//// Double salary = Double.parseDouble(elem.getElementsByTagName("salary").item(0).getChildNodes().item(0).getNodeValue()); -// } -// } -// } -// catch (IOException | SAXException | ParserConfigurationException e) { -// e.printStackTrace(); -// } -// return document; -// } - - private static Document getSaxParsedDocument(final String fileName) { - Document document = null; - - String xml = "" - + " \r\n" - + " " - + " Gambardella, Matthew " - + "XML Developer's Guide" - + " Computer" - + " 44.95 " - + "2000-10-01 " - + "An in-depth look at creating applications with XML. " - + "" - + " " - + " Ralls, Kim" - + " Midnight Rain" - + " Fantasy" - + " 5.95" - + " 2000-12-16" - + " A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world." - + " \r\n" - + "\r\n"; - try { - - SAXBuilder sax = new SAXBuilder(); - // String that contains XML - Document doc = (Document) sax.build(new File("C:\\Docs\\JDS\\ITN\\MMS01Header.xml")); -// org.jdom2.Document doc = sax.build(new StringReader(xml)); - - Element rootNode = doc.getRootElement(); - List bookElements = rootNode.getChildren(); - System.out.println("bookElements: " + bookElements); - for(Element bookElement : bookElements){ - String name = bookElement.getName(); - String value = bookElement.getValue(); - System.out.println(name + " : " + value); - } - - } catch (IOException | JDOMException e) { - e.printStackTrace(); - } - return document; - } - - private static void writeSimpleXml() throws JDOMException, IOException { - - String xml = "mkyong"; - SAXBuilder sb = new SAXBuilder(); - Document doc = sb.build(new StringReader(xml)); - - - Document docFile = new Document(); - - Element rootElement = new Element("ReadQueue"); - rootElement.addContent(new Element("createDate").setText("20240527")); - rootElement.addContent(new Element("PopCounter").setText(Integer.toString(0))); - - docFile.setRootElement(rootElement); - - // default in compact mode - // XMLOutputter xmlOutputter = new XMLOutputter(); - - // pretty print format - XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat()); - - // output to console - FileOutputStream fileOutputStream = new FileOutputStream("C:\\Docs\\JDS\\ITN\\file.xml"); - xmlOutputter.output(docFile, fileOutputStream); - - } - public static void main(String[] args) throws IOException, JDOMException { -// XmlUtil.getDOMParsedDocument("C:\\Docs\\JDS\\ITN\\MMS01Header.xml"); - XmlUtil.getSaxParsedDocument("C:\\Docs\\JDS\\ITN\\MMS01Header.xml"); - XmlUtil.writeSimpleXml(); - } -}