Skip to content

Commit 5b55675

Browse files
author
Victor Santiago Martinez Picardo
committed
Autowire service.
1 parent a425215 commit 5b55675

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>com.em7</groupId>
1212
<artifactId>wol</artifactId>
13-
<version>0.0.8</version>
13+
<version>0.0.9</version>
1414
<packaging>jar</packaging>
1515
<name>wol</name>
1616
<description>Wake on Lan</description>

src/main/java/com/em7/wol/controller/devices/DevicesController.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
package com.em7.wol.controller.devices;
22

33

4+
import com.em7.wol.dto.out.OutDeviceDTO;
45
import com.em7.wol.service.PingService;
56
import com.em7.wol.util.RestUtils;
67
import com.google.gson.Gson;
78
import com.google.gson.GsonBuilder;
89
import com.google.gson.reflect.TypeToken;
9-
import com.em7.wol.dto.out.OutDeviceDTO;
1010
import lombok.extern.slf4j.Slf4j;
11+
import org.springframework.beans.factory.annotation.Autowired;
1112
import org.springframework.beans.factory.annotation.Value;
1213
import org.springframework.core.io.Resource;
1314
import org.springframework.stereotype.Controller;
1415
import org.springframework.ui.Model;
1516
import org.springframework.web.bind.annotation.*;
1617

17-
import javax.annotation.PostConstruct;
1818
import javax.servlet.http.HttpServletRequest;
19-
import java.io.IOException;
20-
import java.io.InputStreamReader;
21-
import java.io.Reader;
2219
import java.lang.reflect.Type;
2320
import java.net.HttpURLConnection;
24-
import java.net.InetAddress;
2521
import java.net.URL;
26-
import java.util.ArrayList;
2722
import java.util.List;
2823

2924

@@ -40,6 +35,9 @@ public class DevicesController {
4035
@Value("${shutdown.port}")
4136
private Integer shutdownPort;
4237

38+
@Autowired
39+
private PingService pingService;
40+
4341
@RequestMapping(value = "/getDevices", method = RequestMethod.GET)
4442
@ResponseBody
4543
public List<OutDeviceDTO> getDevices(HttpServletRequest request) {
@@ -78,7 +76,6 @@ public List<OutDeviceDTO> getAllDevices() {
7876
List<OutDeviceDTO> outDeviceDTOs = gson.fromJson(RestUtils.asString(deviceListJSON), listType);
7977

8078
try {
81-
PingService pingService = new PingService();
8279
pingService.pingDevicesConcurrently(outDeviceDTOs);
8380
} catch (Exception e) {
8481
String methodName = new Object() {}.getClass().getEnclosingMethod().getName();

src/main/java/com/em7/wol/service/PingService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.em7.wol.service;
22

33
import com.em7.wol.dto.out.OutDeviceDTO;
4+
import org.springframework.beans.factory.annotation.Value;
45
import org.springframework.stereotype.Service;
56

67
import java.io.IOException;
@@ -15,12 +16,12 @@
1516
@Service
1617
public class PingService {
1718

18-
private final Integer shutdownPort = 7801;
19+
@Value("${shutdown.port}")
20+
private Integer shutdownPort;
1921

2022
public void pingDevicesConcurrently(List<OutDeviceDTO> outDeviceDTOs) {
2123
// Create a thread pool with a fixed number of threads (can be customized)
2224
ExecutorService executorService = Executors.newFixedThreadPool(10);
23-
2425
try {
2526
// Loop through each device and submit a callable task to the executor
2627
for (OutDeviceDTO device : outDeviceDTOs) {

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=0.0.8
1+
version=0.0.9
22
spring.profiles.active=default
33

44
wol.user=admin

0 commit comments

Comments
 (0)