diff --git a/hs_err_pid6924.log b/hs_err_pid6924.log
new file mode 100644
index 0000000..d7fbe92
--- /dev/null
+++ b/hs_err_pid6924.log
@@ -0,0 +1,201 @@
+#
+# There is insufficient memory for the Java Runtime Environment to continue.
+# Native memory allocation (mmap) failed to map 130023424 bytes for Failed to commit area from 0x0000000084200000 to 0x000000008be00000 of length 130023424.
+# Possible reasons:
+# The system is out of physical RAM or swap space
+# The process is running with CompressedOops enabled, and the Java Heap may be blocking the growth of the native heap
+# Possible solutions:
+# Reduce memory load on the system
+# Increase physical memory or swap space
+# Check if swap backing store is full
+# Decrease Java heap size (-Xmx/-Xms)
+# Decrease number of Java threads
+# Decrease Java thread stack sizes (-Xss)
+# Set larger code cache with -XX:ReservedCodeCacheSize=
+# This output file may be truncated or incomplete.
+#
+# Out of Memory Error (t:/workspace/open/src/hotspot/os/windows/os_windows.cpp:3269), pid=6924, tid=19396
+#
+# JRE version: (11.0.1+13) (build )
+# Java VM: Java HotSpot(TM) 64-Bit Server VM (11.0.1+13-LTS, mixed mode, aot, sharing, tiered, compressed oops, g1 gc, windows-amd64)
+# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
+#
+
+--------------- S U M M A R Y ------------
+
+Command Line: -XX:TieredStopAtLevel=1 -Xverify:none -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:D:\program files\IntelliJ IDEA 2019.2.1\lib\idea_rt.jar=62820:D:\program files\IntelliJ IDEA 2019.2.1\bin -Dfile.encoding=UTF-8 kr.hs.dsm.java.taxipot_backend.TaxipotBackendApplication
+
+Host: Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz, 8 cores, 7G, Windows 10 , 64 bit Build 18362 (10.0.18362.329)
+Time: Tue Nov 26 23:34:45 2019 ¢¥eCN©öI¡¾©ö C¡ÍA¨ª¨öA elapsed time: 0 seconds (0d 0h 0m 0s)
+
+--------------- T H R E A D ---------------
+
+Current thread (0x0000027404b27800): JavaThread "Unknown thread" [_thread_in_vm, id=19396, stack(0x000000d28d700000,0x000000d28d800000)]
+
+Stack: [0x000000d28d700000,0x000000d28d800000]
+Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
+V [jvm.dll+0x63c21a]
+V [jvm.dll+0x7797df]
+V [jvm.dll+0x77adca]
+V [jvm.dll+0x77b483]
+V [jvm.dll+0x2627f8]
+V [jvm.dll+0x6396ca]
+V [jvm.dll+0x62dfa5]
+V [jvm.dll+0x31699c]
+V [jvm.dll+0x316822]
+V [jvm.dll+0x31c096]
+V [jvm.dll+0x36842f]
+V [jvm.dll+0x367e50]
+V [jvm.dll+0x2f38b8]
+V [jvm.dll+0x2f4a16]
+V [jvm.dll+0x752da7]
+V [jvm.dll+0x7544ef]
+V [jvm.dll+0x375269]
+V [jvm.dll+0x7394a9]
+V [jvm.dll+0x3e467d]
+V [jvm.dll+0x3e6951]
+C [java.exe+0x3603]
+C [java.exe+0x178dc]
+C [KERNEL32.DLL+0x17bd4]
+C [ntdll.dll+0x6ced1]
+
+
+--------------- P R O C E S S ---------------
+
+Threads class SMR info:
+_java_thread_list=0x000002740494c300, length=0, elements={
+}
+
+Java Threads: ( => current thread )
+
+Other Threads:
+ 0x0000027404b3d800 GCTaskThread "GC Thread#0" [stack: 0x000000d28d800000,0x000000d28d900000] [id=20588]
+ 0x0000027404b6e000 ConcurrentGCThread "G1 Main Marker" [stack: 0x000000d28d900000,0x000000d28da00000] [id=14400]
+ 0x0000027404b70800 ConcurrentGCThread "G1 Conc#0" [stack: 0x000000d28da00000,0x000000d28db00000] [id=1352]
+
+[error occurred during error reporting (printing all threads), id 0xc0000005, EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007fffd1cf2137]
+
+VM state:not at safepoint (not fully initialized)
+
+VM Mutex/Monitor currently owned by a thread: ([mutex/lock_event])
+[0x0000027404b25d10] Heap_lock - owner thread: 0x0000027404b27800
+
+Heap address: 0x0000000084200000, size: 1982 MB, Compressed Oops mode: Non-zero based: 0x0000000084200000
+Narrow klass base: 0x0000000000000000, Narrow klass shift: 0
+
+GC Heap History (0 events):
+No events
+
+Deoptimization events (0 events):
+No events
+
+Classes redefined (0 events):
+No events
+
+Internal exceptions (0 events):
+No events
+
+Events (0 events):
+No events
+
+
+Dynamic libraries:
+0x00007ff6db420000 - 0x00007ff6db467000 D:\Program Files\Java\bin\java.exe
+0x00007ff832600000 - 0x00007ff8327f0000 C:\WINDOWS\SYSTEM32\ntdll.dll
+0x00007ff8311f0000 - 0x00007ff8312a2000 C:\WINDOWS\System32\KERNEL32.DLL
+0x00007ff82f630000 - 0x00007ff82f8d3000 C:\WINDOWS\System32\KERNELBASE.dll
+0x00007ff831610000 - 0x00007ff8316b3000 C:\WINDOWS\System32\ADVAPI32.dll
+0x00007ff832190000 - 0x00007ff83222e000 C:\WINDOWS\System32\msvcrt.dll
+0x00007ff8322a0000 - 0x00007ff832337000 C:\WINDOWS\System32\sechost.dll
+0x00007ff8316c0000 - 0x00007ff8317e0000 C:\WINDOWS\System32\RPCRT4.dll
+0x00007ff830700000 - 0x00007ff830894000 C:\WINDOWS\System32\USER32.dll
+0x00007ff82fa10000 - 0x00007ff82fa31000 C:\WINDOWS\System32\win32u.dll
+0x00007ff8306d0000 - 0x00007ff8306f6000 C:\WINDOWS\System32\GDI32.dll
+0x00007ff8303f0000 - 0x00007ff830584000 C:\WINDOWS\System32\gdi32full.dll
+0x00007ff82f590000 - 0x00007ff82f62e000 C:\WINDOWS\System32\msvcp_win.dll
+0x00007ff8305b0000 - 0x00007ff8306aa000 C:\WINDOWS\System32\ucrtbase.dll
+0x00007ff8264d0000 - 0x00007ff8264da000 C:\WINDOWS\SYSTEM32\VERSION.dll
+0x00007ff81d9a0000 - 0x00007ff81dc25000 C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.18362.476_none_e6c4b11b130f2595\COMCTL32.dll
+0x00007ff831930000 - 0x00007ff831c66000 C:\WINDOWS\System32\combase.dll
+0x00007ff82f8e0000 - 0x00007ff82f960000 C:\WINDOWS\System32\bcryptPrimitives.dll
+0x00007ff8308a0000 - 0x00007ff8308ce000 C:\WINDOWS\System32\IMM32.DLL
+0x00007ff81c970000 - 0x00007ff81c986000 D:\Program Files\Java\bin\vcruntime140.dll
+0x00007ffff3a00000 - 0x00007ffff3aaa000 D:\Program Files\Java\bin\msvcp140.dll
+0x00007fffd19f0000 - 0x00007fffd2532000 D:\Program Files\Java\bin\server\jvm.dll
+0x00007ff832340000 - 0x00007ff832348000 C:\WINDOWS\System32\PSAPI.DLL
+0x00007ff829cb0000 - 0x00007ff829cd4000 C:\WINDOWS\SYSTEM32\WINMM.dll
+0x00007ff81a260000 - 0x00007ff81a269000 C:\WINDOWS\SYSTEM32\WSOCK32.dll
+0x00007ff8315a0000 - 0x00007ff83160f000 C:\WINDOWS\System32\WS2_32.dll
+0x00007ff829c80000 - 0x00007ff829cad000 C:\WINDOWS\SYSTEM32\winmmbase.dll
+0x00007ff830370000 - 0x00007ff8303ba000 C:\WINDOWS\System32\cfgmgr32.dll
+0x00007ff82f4e0000 - 0x00007ff82f4f1000 C:\WINDOWS\System32\kernel.appcore.dll
+0x00007ff81c950000 - 0x00007ff81c961000 D:\Program Files\Java\bin\verify.dll
+0x00007ff82de10000 - 0x00007ff82e004000 C:\WINDOWS\SYSTEM32\DBGHELP.DLL
+0x00007ff8171a0000 - 0x00007ff8171ca000 C:\WINDOWS\SYSTEM32\dbgcore.DLL
+0x00007ff80ce80000 - 0x00007ff80cea9000 D:\Program Files\Java\bin\java.dll
+0x00007ff805f40000 - 0x00007ff805f6f000 D:\Program Files\Java\bin\instrument.dll
+0x00007ff81c480000 - 0x00007ff81c496000 D:\Program Files\Java\bin\zip.dll
+0x00007ff81d040000 - 0x00007ff81d04a000 D:\Program Files\Java\bin\jimage.dll
+
+dbghelp: loaded successfully - version: 4.0.5 - missing functions: none
+symbol engine: initialized successfully - sym options: 0x614 - pdb path: .;D:\Program Files\Java\bin;C:\WINDOWS\SYSTEM32;C:\WINDOWS\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.18362.476_none_e6c4b11b130f2595;D:\Program Files\Java\bin\server
+
+VM Arguments:
+jvm_args: -XX:TieredStopAtLevel=1 -Xverify:none -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:D:\program files\IntelliJ IDEA 2019.2.1\lib\idea_rt.jar=62820:D:\program files\IntelliJ IDEA 2019.2.1\bin -Dfile.encoding=UTF-8
+java_command: kr.hs.dsm.java.taxipot_backend.TaxipotBackendApplication
+java_class_path (initial): D:\Github\Server\TaxiPot_Backend\target\classes;C:\Users\nwar0\.m2\repository\org\springframework\boot\spring-boot-starter-data-rest\2.1.7.RELEASE\spring-boot-starter-data-rest-2.1.7.RELEASE.jar;C:\Users\nwar0\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.7.RELEASE\spring-boot-starter-web-2.1.7.RELEASE.jar;C:\Users\nwar0\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.7.RELEASE\spring-boot-starter-json-2.1.7.RELEASE.jar;C:\Users\nwar0\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.9\jackson-datatype-jdk8-2.9.9.jar;C:\Users\nwar0\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.9\jackson-datatype-jsr310-2.9.9.jar;C:\Users\nwar0\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.9\jackson-module-parameter-names-2.9.9.jar;C:\Users\nwar0\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.7.RELEASE\spring-boot-starter-tomcat-2.1.7.RELEASE.jar;C:\Users\nwar0\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.22\tomcat-embed-core-9.0.22.jar;C:\Users\nwar0\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.22\tomcat-embed-el-9.0.22.jar;C:\Users\nwar0\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.22\tomcat-embed-websocket-9.0.22.jar;C:\Users\nwar0\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.17.Final\hibernate-validator-6.0.17.Final.jar;C:\Users\nwar0\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\nwar0\.m2\repository\org\springframework\spring-web\5.1.9.RELEASE\spring-web-5.1.9.RELEASE.jar;C:\Users\nwar0\.m2\repository\org\springframework\spring-webmvc\5.1.9.RELEASE\spring-webmvc-5.1.9.RELEASE.jar;C:\Users\nwar0\.m2\repository\org\springframework\spring-expression\5.1.9.RELEASE\spring-expression-5.1.9.RELEASE.jar;C:\Users\nwar0\.m2\repository\org\springframework\data\spring-data-rest-webmvc\3.1.10.REL
+Launcher Type: SUN_STANDARD
+
+[Global flags]
+ bool BytecodeVerificationLocal = false {product} {command line}
+ bool BytecodeVerificationRemote = false {product} {command line}
+ intx CICompilerCount = 4 {product} {ergonomic}
+ uint ConcGCThreads = 2 {product} {ergonomic}
+ uint G1ConcRefinementThreads = 8 {product} {ergonomic}
+ size_t G1HeapRegionSize = 1048576 {product} {ergonomic}
+ uintx GCDrainStackTargetSize = 64 {product} {ergonomic}
+ size_t InitialHeapSize = 130023424 {product} {ergonomic}
+ bool ManagementServer = true {product} {command line}
+ size_t MarkStackSize = 4194304 {product} {ergonomic}
+ size_t MaxHeapSize = 2078277632 {product} {ergonomic}
+ size_t MinHeapDeltaBytes = 1048576 {product} {ergonomic}
+ uintx NonNMethodCodeHeapSize = 7549744 {pd product} {ergonomic}
+ uintx NonProfiledCodeHeapSize = 244108496 {pd product} {ergonomic}
+ uintx ProfiledCodeHeapSize = 0 {pd product} {ergonomic}
+ uintx ReservedCodeCacheSize = 251658240 {pd product} {ergonomic}
+ bool SegmentedCodeCache = true {product} {ergonomic}
+ intx TieredStopAtLevel = 1 {product} {command line}
+ bool UseCompressedClassPointers = true {lp64_product} {ergonomic}
+ bool UseCompressedOops = true {lp64_product} {ergonomic}
+ bool UseG1GC = true {product} {ergonomic}
+ bool UseLargePagesIndividualAllocation = false {pd product} {ergonomic}
+
+Logging:
+Log output configuration:
+ #0: stdout all=warning uptime,level,tags
+ #1: stderr all=off uptime,level,tags
+
+Environment Variables:
+JAVA_HOME=D:\program files\java
+CLASSPATH=D:\program files\java\lib
+PATH=C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;D:\program files\java\bin;C:\Program Files\dotnet\;D:\Git\cmd;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\MySQL\MySQL Server 8.0\bin;;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;D:\NodeJS\;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\nwar0\AppData\Local\Microsoft\WindowsApps;C:\Users\nwar0\AppData\Local\GitHubDesktop\bin;D:\Microsoft_VS_Code\Microsoft VS Code\bin;C:\Users\nwar0\AppData\Roaming\npm
+USERNAME=nwar0
+OS=Windows_NT
+PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
+
+
+
+--------------- S Y S T E M ---------------
+
+OS: Windows 10 , 64 bit Build 18362 (10.0.18362.329)
+
+CPU:total 8 (initial active 8) (4 cores per cpu, 2 threads per core) family 6 model 158 stepping 10, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, clmul, erms, 3dnowpref, lzcnt, ht, tsc, tscinvbit, bmi1, bmi2, adx, fma
+
+Memory: 4k page, system-wide physical 7925M (520M free)
+TotalPageFile size 21204M (AvailPageFile size 22M)
+current process WorkingSet (physical memory assigned to process): 10M, peak: 10M
+current process commit charge ("private bytes"): 57M, peak: 181M
+
+vm_info: Java HotSpot(TM) 64-Bit Server VM (11.0.1+13-LTS) for windows-amd64 JRE (11.0.1+13-LTS), built on Oct 6 2018 13:20:16 by "mach5one" with MS VC++ 15.5 (VS2017)
+
+END.
diff --git a/pom.xml b/pom.xml
index 5b7ab08..ebef5ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,10 @@
springfox-swagger-ui
2.9.2
+
+ org.springframework.boot
+ spring-boot-starter-websocket
+
diff --git a/src/main/java/kr/hs/dsm/java/taxipot_backend/SocketConfigure.java b/src/main/java/kr/hs/dsm/java/taxipot_backend/SocketConfigure.java
new file mode 100644
index 0000000..8c5ae55
--- /dev/null
+++ b/src/main/java/kr/hs/dsm/java/taxipot_backend/SocketConfigure.java
@@ -0,0 +1,20 @@
+package kr.hs.dsm.java.taxipot_backend;
+
+import kr.hs.dsm.java.taxipot_backend.socket.SocketHandler;
+import kr.hs.dsm.java.taxipot_backend.socket.SocketRepository;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.socket.config.annotation.EnableWebSocket;
+import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
+import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
+
+@Configuration
+@EnableWebSocket
+public class SocketConfigure implements WebSocketConfigurer {
+
+ SocketRepository repository = new SocketRepository();
+
+ @Override
+ public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
+ webSocketHandlerRegistry.addHandler(new SocketHandler(repository),"/ws/socket").setAllowedOrigins("*");
+ }
+}
diff --git a/src/main/java/kr/hs/dsm/java/taxipot_backend/controller/TaxipotRestController.java b/src/main/java/kr/hs/dsm/java/taxipot_backend/controller/TaxipotRestController.java
index 7e51709..8e715d0 100644
--- a/src/main/java/kr/hs/dsm/java/taxipot_backend/controller/TaxipotRestController.java
+++ b/src/main/java/kr/hs/dsm/java/taxipot_backend/controller/TaxipotRestController.java
@@ -57,16 +57,23 @@ public TaxiPot joinTaxipot(@PathVariable("roomId")Integer roomId, @RequestParam(
@RequestMapping(method = RequestMethod.GET, path = "/findRoom")
public List findTaxipotList(@RequestParam long depart_time, @RequestParam float start_latitude, @RequestParam float start_longitude, @RequestParam float end_latitude, @RequestParam float end_longitude, @RequestParam float radius, @RequestParam int age, @RequestParam boolean isMan){
+ System.out.println("departTime : " + depart_time + " start_latitude : " + start_latitude + " startLongitude : " + start_longitude + " endLatitude : " +end_latitude + " endLongitude : " + end_longitude + " radius : " + radius + "age : " + age + "isMan : " + isMan);
List list = taxipotRepository.findByDepartTimeGreaterThanEqualAndEndAgeGreaterThanEqualAndAndStartAgeIsLessThanEqual(depart_time,age,age);
List correctList = new ArrayList<>();
for(TaxiPot item : list) {
+ //System.out.println("filtering... \n before taxiPot : " + item.toString() + "\n");
if(isMan == item.isGender_man() || (!isMan) == item.isGender_woman()) {
+ System.out.println("start distance : " + getCoordinates(item.getStart_longtitude() - start_longitude, item.getStart_latitude() - start_latitude) + "\narrive distance : " + getCoordinates(item.getEnd_longtitude() - start_longitude, item.getEnd_latitude() - start_latitude) + "\n");
if (isInRadious(start_longitude, item.getStart_longtitude(), start_latitude, item.getStart_latitude(), radius) && isInRadious(end_longitude, item.getEnd_longtitude(), end_latitude, item.getEnd_latitude(), radius)) {
correctList.add(item);
+ System.out.println("add : " + item.toString() + "\n");
+ } else {
+ System.out.println("remove : " + item.toString() + "\n");
}
}
}
- return list;
+ System.out.println("result : " + correctList);
+ return correctList;
}
@RequestMapping(method = RequestMethod.GET, path = "/test")
diff --git a/src/main/java/kr/hs/dsm/java/taxipot_backend/entity/TaxiPot.java b/src/main/java/kr/hs/dsm/java/taxipot_backend/entity/TaxiPot.java
index cd1bdd1..3258d79 100644
--- a/src/main/java/kr/hs/dsm/java/taxipot_backend/entity/TaxiPot.java
+++ b/src/main/java/kr/hs/dsm/java/taxipot_backend/entity/TaxiPot.java
@@ -146,50 +146,22 @@ public int getEndAge() {
@Override
public String toString() {
- return "{\n" +
- " \"departTime\": " +
- departTime +
- "\n" +
- " \"end_age\": " +
- endAge +
- "\n" +
- " \"end_latitude\": " +
- end_latitude +
- "\n" +
- " \"end_longtitude\": " +
- end_longtitude +
- "\n" +
- " \"first_seat\": " +
- first_seat +
- "\n" +
- " \"fourth_seat\": " +
- fourth_seat +
- "\n" +
- " \"gender_man\": " +
- gender_man +
- "\n" +
- " \"gender_woman\": " +
- gender_woman +
- "\n" +
- " \"room_id\": " +
- room_id +
- "\n" +
- " \"second_seat\": " +
- second_seat +
- "\n" +
- " \"start_age\": " +
- startAge +
- "\n" +
- " \"start_latitude\": " +
- start_latitude +
- "\n" +
- " \"start_longtitude\": " +
- start_longtitude +
- "\n" +
- " \"third_seat\": " +
- third_seat +
- "\n" +
- "}";
+ return "TaxiPot{" +
+ "room_id=" + room_id +
+ ", start_longtitude=" + start_longtitude +
+ ", start_latitude=" + start_latitude +
+ ", end_longtitude=" + end_longtitude +
+ ", end_latitude=" + end_latitude +
+ ", departTime=" + departTime +
+ ", gender_man=" + gender_man +
+ ", gender_woman=" + gender_woman +
+ ", startAge=" + startAge +
+ ", endAge=" + endAge +
+ ", first_seat='" + first_seat + '\'' +
+ ", second_seat='" + second_seat + '\'' +
+ ", third_seat='" + third_seat + '\'' +
+ ", fourth_seat='" + fourth_seat + '\'' +
+ '}';
}
public History toHistory(String userId) {
diff --git a/src/main/java/kr/hs/dsm/java/taxipot_backend/scheduler/ScheduleTask.java b/src/main/java/kr/hs/dsm/java/taxipot_backend/scheduler/ScheduleTask.java
index 38f4386..17da522 100644
--- a/src/main/java/kr/hs/dsm/java/taxipot_backend/scheduler/ScheduleTask.java
+++ b/src/main/java/kr/hs/dsm/java/taxipot_backend/scheduler/ScheduleTask.java
@@ -8,7 +8,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
@@ -51,4 +54,11 @@ private void saveToHistory(History item) {
historyRepository.save(item);
}
}
+ @Bean
+ public TaskScheduler taskScheduler() {
+ ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
+ taskScheduler.setPoolSize(10);
+ taskScheduler.initialize();
+ return taskScheduler;
+ }
}
diff --git a/src/main/java/kr/hs/dsm/java/taxipot_backend/socket/SocketHandler.java b/src/main/java/kr/hs/dsm/java/taxipot_backend/socket/SocketHandler.java
new file mode 100644
index 0000000..1255595
--- /dev/null
+++ b/src/main/java/kr/hs/dsm/java/taxipot_backend/socket/SocketHandler.java
@@ -0,0 +1,87 @@
+package kr.hs.dsm.java.taxipot_backend.socket;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.socket.CloseStatus;
+import org.springframework.web.socket.TextMessage;
+import org.springframework.web.socket.WebSocketSession;
+import org.springframework.web.socket.handler.TextWebSocketHandler;
+
+public class SocketHandler extends TextWebSocketHandler {
+ SocketRepository socketRepo;
+ Logger logger = LoggerFactory.getLogger(SocketHandler.class);
+
+ public SocketHandler(SocketRepository socketRepo) {
+ this.socketRepo = socketRepo;
+ }
+
+ @Override
+ public void afterConnectionEstablished(WebSocketSession session) throws Exception {
+ session.sendMessage(new TextMessage("Connect"));
+ }
+
+ @Override
+ protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
+ String[] strings = splitMessage(message, ","); // {roomId},{command},{message}
+ for(String item : strings) {
+ System.out.println(item+"\n");
+ }
+ switch (strings[1]) {
+ case "JOIN": {
+ createSocket(strToInt(strings[0]));
+ joinToSocket(strToInt(strings[0]), session, strToInt(strings[2]));
+ break;
+ }
+ case "MESSAGE": {
+ isExistSocket(strToInt(strings[0]));
+ applyMessage(session, strToInt(strings[0]),strings[2]);
+ break;
+ }
+ case "DISCONNECT": {
+ isExistSocket(strToInt(strings[0]));
+ disconnect(session, strToInt(strings[0]));
+ break;
+ }
+ default: {
+ session.sendMessage(new TextMessage("Command Error!"));
+ }
+ }
+ }
+
+ @Override
+ public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
+ super.afterConnectionClosed(session, status);
+ }
+
+ private void createSocket(int roomId) {
+ if(!socketRepo.getSocketMap().containsKey(roomId)) {
+ socketRepo.getSocketMap().put(roomId, TaxiPotSocket.create(roomId));
+ }
+ }
+
+ private void joinToSocket(int roomId, WebSocketSession session, int seat_num) {
+ socketRepo.getSocketMap().get(roomId).join(session, seat_num);
+ }
+
+ private void isExistSocket(int room_Id) throws Exception{
+ if(!socketRepo.getSocketMap().containsKey(room_Id)) throw new Exception("Socket Not Exist.");
+ }
+
+ private void applyMessage(WebSocketSession session, int room_id, String message) {
+ logger.info(room_id + " : " + message);
+ socketRepo.getSocketMap().get(room_id).onMessage(session,message);
+ }
+
+ private int strToInt(String string) {
+ return Integer.valueOf(string);
+ }
+
+ private String[] splitMessage(TextMessage message, String regex) {
+ return message.getPayload().split(regex);
+ }
+
+ private void disconnect(WebSocketSession session, int room_id) {
+ socketRepo.getSocketMap().get(room_id).onClose(session);
+ }
+
+}
diff --git a/src/main/java/kr/hs/dsm/java/taxipot_backend/socket/SocketRepository.java b/src/main/java/kr/hs/dsm/java/taxipot_backend/socket/SocketRepository.java
new file mode 100644
index 0000000..5ff9845
--- /dev/null
+++ b/src/main/java/kr/hs/dsm/java/taxipot_backend/socket/SocketRepository.java
@@ -0,0 +1,12 @@
+package kr.hs.dsm.java.taxipot_backend.socket;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class SocketRepository {
+ Map socketMap = new HashMap<>();
+
+ public Map getSocketMap() {
+ return socketMap;
+ }
+}
diff --git a/src/main/java/kr/hs/dsm/java/taxipot_backend/socket/TaxiPotSocket.java b/src/main/java/kr/hs/dsm/java/taxipot_backend/socket/TaxiPotSocket.java
new file mode 100644
index 0000000..e7e95f8
--- /dev/null
+++ b/src/main/java/kr/hs/dsm/java/taxipot_backend/socket/TaxiPotSocket.java
@@ -0,0 +1,82 @@
+package kr.hs.dsm.java.taxipot_backend.socket;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.socket.TextMessage;
+import org.springframework.web.socket.WebSocketSession;
+
+import java.io.IOException;
+
+public class TaxiPotSocket {
+ static Logger logger = LoggerFactory.getLogger(TaxiPotSocket.class);
+ private static WebSocketSession[] sessions = new WebSocketSession[4];
+
+ private TaxiPotSocket(int socket_id) {
+
+ }
+
+ public static TaxiPotSocket create(int socket_id) {
+ return new TaxiPotSocket(socket_id);
+ }
+
+ public void join(WebSocketSession session, int seat_num) {
+ if(sessions[seat_num]==null) {
+ sessions[seat_num] = session;
+ return;
+ }
+ }
+
+ public void onOpen(WebSocketSession session) {
+ try {
+ session.sendMessage(new TextMessage("Connection Established"));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void onMessage(WebSocketSession session, String message) {
+ logger.info(message);
+
+ for(WebSocketSession receive : sessions) {
+ sendMessage(checkReceiver(receive,session),message);
+ }
+ }
+
+ public void onError(Throwable t, WebSocketSession session) {
+ logger.info(t.getMessage() + "\nsessionId : " + session.getId());
+ }
+
+ public void onClose(WebSocketSession session) {
+ for(WebSocketSession receive : sessions) {
+ sendMessage(checkReceiver(receive,session),"REMOVE");
+ }
+ }
+
+ private void sendMessage(WebSocketSession receiver, String message) {
+ try{
+ receiver.sendMessage(new TextMessage(getSessionIndex(receiver) + ":" +message));
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ logger.info(e.getMessage());
+ }
+ }
+
+ private int getSessionIndex(WebSocketSession session) {
+ for(int i=0; i<4; i++) {
+ sessions[i].equals(session);
+ return i;
+ }
+ throw new NullPointerException("session not found");
+ }
+
+ private WebSocketSession checkReceiver(WebSocketSession receive, WebSocketSession session) {
+ if(receive==null) {
+ return null;
+ }
+ if(receive.equals(session)){
+ return null;
+ }
+ return receive;
+ }
+}
diff --git a/src/test/java/kr/hs/dsm/java/taxipot_backend/TaxipotBackendApplicationTests.java b/src/test/java/kr/hs/dsm/java/taxipot_backend/TaxipotBackendApplicationTests.java
index f950b4f..286b076 100644
--- a/src/test/java/kr/hs/dsm/java/taxipot_backend/TaxipotBackendApplicationTests.java
+++ b/src/test/java/kr/hs/dsm/java/taxipot_backend/TaxipotBackendApplicationTests.java
@@ -2,10 +2,29 @@
import org.junit.Test;
+import java.util.Date;
+
public class TaxipotBackendApplicationTests {
@Test
public void contextLoads() throws Exception{
- System.out.println(isInRadious(0,5,0,12,13));
+ Date date = new Date(1573570369412L);
+ System.out.println(date.getYear());
+ System.out.println(date.getMonth());
+ System.out.println(date.getDate());
+ System.out.println(date.getHours());
+ System.out.println(date.getMinutes());
+ Date date1 = new Date();
+ System.out.println(date1.getYear());
+ System.out.println(date1.getMonth());
+ System.out.println(date1.getDate());
+ System.out.println(date1.getHours());
+ System.out.println(date1.getMinutes());
+ Date date3 = new Date(1572739200000L);
+ System.out.println(date3.getYear());
+ System.out.println(date3.getMonth());
+ System.out.println(date3.getDate());
+ System.out.println(date3.getHours());
+ System.out.println(date3.getMinutes());
}
private double getCoordinates(float x, float y){
return Math.pow((double)x,2) + Math.pow((double)y,2);