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;
|
package ru.otus.ioservice.example.swing;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
@ConditionalOnBean(SwingIOService.class)
|
@ConditionalOnBean(SwingIOService.class)
|
||||||
@Service
|
@Service
|
||||||
public class MessageSystem {
|
public class MessageSystem {
|
||||||
private final LinkedBlockingQueue<String> inputQueue;
|
private final BlockingQueue<String> inputQueue;
|
||||||
private final LinkedBlockingQueue<String> outputQueue;
|
private final BlockingQueue<String> outputQueue;
|
||||||
|
|
||||||
public MessageSystem() {
|
public MessageSystem() {
|
||||||
inputQueue = new LinkedBlockingQueue<>();
|
inputQueue = new LinkedBlockingQueue<>();
|
||||||
outputQueue = new LinkedBlockingQueue<>();
|
outputQueue = new LinkedBlockingQueue<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
public void putToInputQueue(String message) {
|
public void putToInputQueue(String message) {
|
||||||
inputQueue.put(message);
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
inputQueue.offer(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
public void putToOutputQueue(String message) {
|
public void putToOutputQueue(String message) {
|
||||||
outputQueue.put(message);
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
outputQueue.offer(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
public String takeFromInputQueue() {
|
public String takeFromInputQueue() {
|
||||||
return inputQueue.take();
|
return takeFromQueue(inputQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
public String takeFromOutputQueue() {
|
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;
|
package ru.otus.ioservice.example.swing;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.otus.ioservice.example.api.IOService;
|
import ru.otus.ioservice.example.api.IOService;
|
||||||
@@ -12,13 +11,11 @@ import ru.otus.ioservice.example.api.IOService;
|
|||||||
public class SwingIOService implements IOService {
|
public class SwingIOService implements IOService {
|
||||||
private final MessageSystem ms;
|
private final MessageSystem ms;
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
@Override
|
@Override
|
||||||
public void out(String message) {
|
public void out(String message) {
|
||||||
ms.putToOutputQueue(message);
|
ms.putToOutputQueue(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
@Override
|
@Override
|
||||||
public String readString() {
|
public String readString() {
|
||||||
return ms.takeFromInputQueue();
|
return ms.takeFromInputQueue();
|
||||||
|
|||||||
+3
-1
@@ -1,5 +1,6 @@
|
|||||||
package ru.otus.ioservice.example.swing;
|
package ru.otus.ioservice.example.swing;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -8,6 +9,7 @@ import ru.otus.ioservice.example.poll.PollService;
|
|||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@ConditionalOnProperty(name = "use.console", havingValue = "false")
|
@ConditionalOnProperty(name = "use.console", havingValue = "false")
|
||||||
@Configuration
|
@Configuration
|
||||||
public class UIConfig {
|
public class UIConfig {
|
||||||
@@ -20,7 +22,7 @@ public class UIConfig {
|
|||||||
PollMainForm mainForm = new PollMainForm(ms);
|
PollMainForm mainForm = new PollMainForm(ms);
|
||||||
mainForm.init();
|
mainForm.init();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.error("Error during main form initialization", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
pollService.poll();
|
pollService.poll();
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ class CommonHwTest {
|
|||||||
|
|
||||||
private static final String CONFIGURATION_ANNOTATION_NAME = "org.springframework.context.annotation.Configuration";
|
private static final String CONFIGURATION_ANNOTATION_NAME = "org.springframework.context.annotation.Configuration";
|
||||||
|
|
||||||
@DisplayName("")
|
|
||||||
@Test
|
@Test
|
||||||
void shouldNotContainConfigurationAnnotationAboveItSelf() {
|
void shouldNotContainConfigurationAnnotationAboveItSelf() {
|
||||||
assertThat(AppProperties.class.isAnnotationPresent(Configuration.class))
|
assertThat(AppProperties.class.isAnnotationPresent(Configuration.class))
|
||||||
|
|||||||
Reference in New Issue
Block a user