mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-05-30 10:50:42 +00:00
examples update 2
This commit is contained in:
+17
-11
@@ -1,39 +1,45 @@
|
||||
package ru.otus.ioservice.example.swing;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
@ConditionalOnBean(SwingIOService.class)
|
||||
@Service
|
||||
public class MessageSystem {
|
||||
private final LinkedBlockingQueue<String> inputQueue;
|
||||
private final LinkedBlockingQueue<String> outputQueue;
|
||||
private final BlockingQueue<String> inputQueue;
|
||||
private final BlockingQueue<String> outputQueue;
|
||||
|
||||
public MessageSystem() {
|
||||
inputQueue = new LinkedBlockingQueue<>();
|
||||
outputQueue = new LinkedBlockingQueue<>();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void putToInputQueue(String message) {
|
||||
inputQueue.put(message);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
inputQueue.offer(message);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void putToOutputQueue(String message) {
|
||||
outputQueue.put(message);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
outputQueue.offer(message);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public String takeFromInputQueue() {
|
||||
return inputQueue.take();
|
||||
return takeFromQueue(inputQueue);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public String takeFromOutputQueue() {
|
||||
return outputQueue.take();
|
||||
return takeFromQueue(outputQueue);
|
||||
}
|
||||
|
||||
private String takeFromQueue(BlockingQueue<String> queue) {
|
||||
try {
|
||||
return queue.take();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-3
@@ -1,7 +1,6 @@
|
||||
package ru.otus.ioservice.example.swing;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.otus.ioservice.example.api.IOService;
|
||||
@@ -12,13 +11,11 @@ import ru.otus.ioservice.example.api.IOService;
|
||||
public class SwingIOService implements IOService {
|
||||
private final MessageSystem ms;
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void out(String message) {
|
||||
ms.putToOutputQueue(message);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public String readString() {
|
||||
return ms.takeFromInputQueue();
|
||||
|
||||
+3
-1
@@ -1,5 +1,6 @@
|
||||
package ru.otus.ioservice.example.swing;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -8,6 +9,7 @@ import ru.otus.ioservice.example.poll.PollService;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@Slf4j
|
||||
@ConditionalOnProperty(name = "use.console", havingValue = "false")
|
||||
@Configuration
|
||||
public class UIConfig {
|
||||
@@ -20,7 +22,7 @@ public class UIConfig {
|
||||
PollMainForm mainForm = new PollMainForm(ms);
|
||||
mainForm.init();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("Error during main form initialization", e);
|
||||
}
|
||||
});
|
||||
pollService.poll();
|
||||
|
||||
@@ -19,7 +19,6 @@ class CommonHwTest {
|
||||
|
||||
private static final String CONFIGURATION_ANNOTATION_NAME = "org.springframework.context.annotation.Configuration";
|
||||
|
||||
@DisplayName("")
|
||||
@Test
|
||||
void shouldNotContainConfigurationAnnotationAboveItSelf() {
|
||||
assertThat(AppProperties.class.isAnnotationPresent(Configuration.class))
|
||||
|
||||
Reference in New Issue
Block a user