33import com .codenameart .rocketmerger .q .DBQueue ;
44import com .codenameart .rocketmerger .q .DBWriter ;
55import lombok .extern .log4j .Log4j2 ;
6+ import lombok .extern .slf4j .Slf4j ;
67import org .springframework .beans .factory .annotation .Autowired ;
78import org .springframework .boot .SpringApplication ;
89import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
10+ import org .springframework .context .ApplicationContext ;
911import org .springframework .context .annotation .ComponentScan ;
1012import org .springframework .http .HttpStatus ;
1113import org .springframework .stereotype .Controller ;
1618import javax .annotation .PostConstruct ;
1719import java .util .List ;
1820import java .util .TimeZone ;
21+ import java .util .concurrent .ExecutorService ;
22+ import java .util .concurrent .Executors ;
1923
2024/**
2125 * Created by Artem on 18.12.2017.
2226 */
23- @ Log4j2
27+ @ Slf4j
2428@ Controller
2529@ EnableAutoConfiguration
2630@ ComponentScan
@@ -32,6 +36,9 @@ public class Webhook {
3236 @ Autowired
3337 DBWriter dbWriter ;
3438
39+ @ Autowired
40+ private ApplicationContext context ;
41+
3542 public static void main (String [] args ) throws Exception {
3643 SpringApplication .run (Webhook .class , args );
3744 }
@@ -40,13 +47,16 @@ public static void main(String[] args) throws Exception {
4047 @ ResponseStatus (HttpStatus .OK )
4148 void process (@ RequestBody List <Message > payload ) {
4249 TimeZone .setDefault (TimeZone .getTimeZone ("UTC" ));
50+ log .debug ("Message received" );
4351 payload .stream ().map (Message ::getMessage ).forEach (dbQueue ::offer );
4452 }
4553
4654 @ PostConstruct
4755 public void startDBLoop () {
56+ ExecutorService executorService = Executors .newFixedThreadPool (5 );
4857 for (int i = 0 ; i < 10 ; i ++) {
49- dbWriter .startLoop ();
58+ DBWriter bean = context .getBean (DBWriter .class );
59+ executorService .execute (bean );
5060 }
5161 }
5262}
0 commit comments