Skip to content

Commit

Permalink
Merge pull request #102 from 22hours/Server/TaskEx
Browse files Browse the repository at this point in the history
Server/task ex
  • Loading branch information
jongwuner authored Apr 30, 2020
2 parents 9ffe062 + 8bf523e commit f50ac4b
Show file tree
Hide file tree
Showing 154 changed files with 62,301 additions and 70 deletions.
2 changes: 1 addition & 1 deletion dev/Server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = 'com.hours22'
version = '3.5.1'
version = '3.7.0'
sourceCompatibility = '1.8'

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public HttpMessageConverter<String> responseBodyConverter() {
return new StringHttpMessageConverter(Charset.forName("UTF-8"));
}

@Bean
FilterRegistrationBean shallowEtagBean () {
FilterRegistrationBean frb = new FilterRegistrationBean();
frb.setFilter(new ShallowEtagHeaderFilter());
frb.addUrlPatterns("/mobile/*");
frb.setOrder(2);
return frb;
}
//@Bean
//FilterRegistrationBean shallowEtagBean () {
// FilterRegistrationBean frb = new FilterRegistrationBean();
// frb.setFilter(new ShallowEtagHeaderFilter());
// frb.addUrlPatterns("/mobile/*");
// frb.setOrder(2);
// return frb;
//}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.hours22.system_monitor_ver11.async;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

Expand All @@ -11,36 +10,138 @@
@Configuration
@EnableAsync
public class SpringAsyncConfig {

@Bean(name = "threadPoolPcOffExecutor")
//Common
@Bean(name = "threadPoolHome")
public Executor threadPoolHomeExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("Home-");
taskExecutor.initialize();
return taskExecutor;
}

//PC
@Bean(name = "threadPoolPcData")
public Executor threadPoolPcDataExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("PcData-");
taskExecutor.initialize();
return taskExecutor;
}

@Bean(name = "threadPoolPcPowerOff")
public Executor threadPoolPcOffExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(30);
taskExecutor.setQueueCapacity(10);
taskExecutor.setThreadNamePrefix("ExecutorPcOff-");
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("PcPowerOff-");
taskExecutor.initialize();
return taskExecutor;
}

@Bean(name = "threadPoolPcMsgExecutor")
public Executor threadPoolPcMsgExecutor() {
@Bean(name = "threadPoolPCPowerOffMsg")
public Executor threadPoolPcPowerOffMsgExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(30);
taskExecutor.setQueueCapacity(10);
taskExecutor.setThreadNamePrefix("ExecutorPcMsg-");
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("PCPowerOffMsg-");
taskExecutor.initialize();
return taskExecutor;
}

@Bean(name = "threadPoolPCPowerOffMsgReturn")
public Executor threadPoolPcMsgReturnExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("PCPowerOffMsg-Return-");
taskExecutor.initialize();
return taskExecutor;
}

@Bean(name = "threadPoolMobileOffExecutor")
public Executor threadPoolMobileExecutor() {
// Mobile
@Bean(name = "threadPoolMobileGetPcs")
public Executor threadPoolMobileGetPcsExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(30);
taskExecutor.setMaxPoolSize(20);
taskExecutor.setQueueCapacity(10);
taskExecutor.setThreadNamePrefix("ExecutorMobileOff-");
taskExecutor.setThreadNamePrefix("MobilePcs-");
taskExecutor.initialize();
return taskExecutor;
}

@Bean(name = "threadPoolMobileGetPcData")
public Executor threadPoolMobileGetPcDataExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("MobilePcData-");
taskExecutor.initialize();
return taskExecutor;
}


@Bean(name = "threadPoolMobilePowerOff")
public Executor threadPoolMobileExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("MobilePowerOff-");
taskExecutor.initialize();
return taskExecutor;
}

@Bean(name = "threadPoolMobileLogin")
public Executor threadPoolMobileLoginExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("MobileLogin-");
taskExecutor.initialize();
return taskExecutor;
}

@Bean(name = "threadPoolMobileClass")
public Executor threadPoolMobileClassExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("MobileClass-");
taskExecutor.initialize();
return taskExecutor;
}

@Bean(name = "threadPoolMobileClassId")
public Executor threadPoolMobileClassIdExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("MobileClassId-");
taskExecutor.initialize();
return taskExecutor;
}

@Bean(name = "threadPoolMobileClassPowerOff")
public Executor threadPoolMobileClassPowerOffExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(100);
taskExecutor.setQueueCapacity(30);
taskExecutor.setThreadNamePrefix("MobileClassPowerOff-");
taskExecutor.initialize();
return taskExecutor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

import javax.servlet.AsyncContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -20,7 +27,7 @@
import com.hours22.system_monitor_ver11.client.ServerTimer;

@Controller
@RequestMapping(value = "/async/callable", method = RequestMethod.GET)
//@RequestMapping(value = "/async/callable", method = RequestMethod.GET)
public class AsyncTestController {

String InterruptKey = null;
Expand Down Expand Up @@ -91,4 +98,19 @@ public void GetThreadIdTest(@PathVariable String thName) {
}
}
}

@Async("threadPoolHome")
@RequestMapping(value = "/test22", method = RequestMethod.GET)
public CompletableFuture<ResponseEntity<Map<String, String>>> GetThreadIdTest22() {
Map<String, String> map = new HashMap<String, String>();
map.put("key", "1");
map.put("keys", "2");


String info = "123123123";
System.out.println("ID : "+Thread.currentThread().getId());
System.out.println("NAME : "+Thread.currentThread().getName());
System.out.println(info);
return CompletableFuture.completedFuture(ResponseEntity.accepted().body(map));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
Expand Down Expand Up @@ -51,19 +54,19 @@ public class CommonController {

SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");


@CrossOrigin("*")
@RequestMapping(value = "/", method = RequestMethod.GET)
public ResponseEntity<String> GetIndex(WebRequest req, HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html;charset=UTF-8");
@Async(value = "threadPoolHome")
@RequestMapping(value = "/")
public CompletableFuture<String> GetIndex(WebRequest req, HttpServletRequest request, HttpServletResponse response) throws IOException {
if (req.checkNotModified(cache.GetCache())) {
return null;
}
String msg = "Welcome 22Hours!<br>" + "This is system-monitor project. Version 3.0<br>" + "서버작업중 by jongchu. 2020-04-08<br><br><br><br>";

System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : / <- GET method [Client Ip : "+ cic.getClientIp(request) +" ] at " + transFormat.format(new Date()));
cache.SetCache(req.getHeader("If-None-Match"));
return new ResponseEntity<String>(msg, HttpStatus.OK);
return CompletableFuture.completedFuture("index.html");
}

@RequestMapping(value = "/testpage", method = RequestMethod.GET)
Expand All @@ -76,15 +79,15 @@ public ResponseEntity<String> GetIndex(WebRequest req, HttpServletRequest reques


@RequestMapping(value = "/pc/{id}", method = RequestMethod.GET)
public @ResponseBody String GetPcInstanceData(HttpServletRequest req, HttpServletResponse response, @PathVariable String id) throws IOException {
public CompletableFuture<ResponseEntity<String>> GetPcInstanceData(HttpServletRequest req, HttpServletResponse response, @PathVariable String id) throws IOException {
System.out.println("--------------------------------------------------------------------------------------------");
System.out.println("Input : /pc/"+ id +" <- GET method [Client Ip : "+ cic.getClientIp(req) + " ] at " + transFormat.format(new Date()));

//lc.getConnection();
String res = lc.getConnectionHgetall(id);
//lc.getConnectionExit();

return res;
return CompletableFuture.completedFuture(ResponseEntity.ok().body(res));
}

@RequestMapping(value = "/pc/{id}", method = RequestMethod.POST)
Expand Down
Loading

0 comments on commit f50ac4b

Please sign in to comment.