From f022b2df1af2b54681b0c8841e1bfdef3a3f2c76 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Tue, 25 Dec 2018 03:13:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B0=D1=8F=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=81=D0=B8=D1=8F=20=D1=81=D0=BB=D1=83=D1=88=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8F=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Научил программу работать в двух потоках. Первый поток слушает все сообещния от сервера и записывает их в отдельный класс. Другой поток раз в какое-то время обращается к этому классу и что-то делает --- .../org/sadtech/consultant/entity/Message.java | 18 ++++++++++++++++++ .../repository/MessageRepository.java | 8 ++++++++ .../consultant/service/MessageService.java | 8 ++++++++ .../service/impl/MessageServiceImpl.java | 16 ++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 src/main/java/org/sadtech/consultant/entity/Message.java create mode 100644 src/main/java/org/sadtech/consultant/repository/MessageRepository.java create mode 100644 src/main/java/org/sadtech/consultant/service/MessageService.java create mode 100644 src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java diff --git a/src/main/java/org/sadtech/consultant/entity/Message.java b/src/main/java/org/sadtech/consultant/entity/Message.java new file mode 100644 index 0000000..454188f --- /dev/null +++ b/src/main/java/org/sadtech/consultant/entity/Message.java @@ -0,0 +1,18 @@ +package org.sadtech.consultant.entity; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Data +@Entity +public class Message { + + @Id + private Long idMess; + private Long idUser; + private String text; + + +} diff --git a/src/main/java/org/sadtech/consultant/repository/MessageRepository.java b/src/main/java/org/sadtech/consultant/repository/MessageRepository.java new file mode 100644 index 0000000..aa0ec3b --- /dev/null +++ b/src/main/java/org/sadtech/consultant/repository/MessageRepository.java @@ -0,0 +1,8 @@ +package org.sadtech.consultant.repository; + +import org.sadtech.consultant.entity.Message; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MessageRepository extends JpaRepository { + +} diff --git a/src/main/java/org/sadtech/consultant/service/MessageService.java b/src/main/java/org/sadtech/consultant/service/MessageService.java new file mode 100644 index 0000000..b40658e --- /dev/null +++ b/src/main/java/org/sadtech/consultant/service/MessageService.java @@ -0,0 +1,8 @@ +package org.sadtech.consultant.service; + +import org.sadtech.consultant.entity.Message; + +public interface MessageService { + + void addMessage(Message message); +} diff --git a/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java b/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java new file mode 100644 index 0000000..e752d1e --- /dev/null +++ b/src/main/java/org/sadtech/consultant/service/impl/MessageServiceImpl.java @@ -0,0 +1,16 @@ +package org.sadtech.consultant.service.impl; + +import org.sadtech.consultant.entity.Message; +import org.sadtech.consultant.repository.MessageRepository; +import org.sadtech.consultant.service.MessageService; +import org.springframework.beans.factory.annotation.Autowired; + +public class MessageServiceImpl implements MessageService { + + @Autowired + private MessageRepository repository; + + public void addMessage(Message message) { + repository.saveAndFlush(message); + } +}