diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java index e203afe..7f1d6f7 100644 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/noauthprobe/dao/NoAuthProbeDAO.java @@ -4,12 +4,10 @@ import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.noauthprobe.NoAuthProbe; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.util.Date; import java.util.List; /** @@ -28,7 +26,7 @@ public interface NoAuthProbeDAO extends JpaRepository { // @Query("SELECT n FROM NoAuthProbe n WHERE n.tempProbeKey = :tempProbeKey") // @Query("select m from Member m WHERE m.email = :#{#m2.email}") - @Modifying(clearAutomatically = true) - @Query("UPDATE NoAuthProbe n set n.connectDate = :connectDate, n.connectAddress = :connectAddress where n.tempProbeKey = :tempProbeKey") - int saveConnect(@Param("tempProbeKey") String tempProbeKey, @Param("connectDate") Date connectDate, @Param("connectAddress") String connectAddress); + // @Modifying(clearAutomatically = true) + // @Query("UPDATE NoAuthProbe n set n.connectDate = :connectDate, n.connectAddress = :connectAddress where n.tempProbeKey = :tempProbeKey") + // int saveConnect(@Param("tempProbeKey") String tempProbeKey, @Param("connectDate") Date connectDate, @Param("connectAddress") String connectAddress); } diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java index 35daea9..229703c 100644 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java +++ b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java @@ -221,11 +221,21 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { } public void onConnect(String tempKey, String connectAddress) throws OverflowException { - this.noAuthProbeDAO.saveConnect(tempKey, new Date(), connectAddress); + NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey); + noAuthProbe.setConnectDate(new Date()); + noAuthProbe.setConnectAddress(connectAddress); + noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe); + + messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onConnect", tempKey, connectAddress); } public void onDisconnect(String tempKey) throws OverflowException { - this.noAuthProbeDAO.saveConnect(tempKey, null, null); + NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findByTempProbeKey(tempKey); + noAuthProbe.setConnectDate(null); + noAuthProbe.setConnectAddress(null); + noAuthProbe = this.noAuthProbeDAO.save(noAuthProbe); + + messagePublisher.publishToDomainMembers(noAuthProbe.getDomain().getId(), "NoAuthProbeService.onDisconnect", tempKey); } } diff --git a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java index 2a43749..5345516 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/dao/ProbeDAO.java @@ -4,12 +4,8 @@ import com.loafle.overflow.model.domain.Domain; import com.loafle.overflow.model.probe.Probe; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import java.util.Date; import java.util.List; @@ -22,7 +18,7 @@ public interface ProbeDAO extends JpaRepository { Probe findByProbeKey(String probeKey); List findAllByDomainOrderByIdDesc(Domain domain); - @Modifying(clearAutomatically = true) - @Query("UPDATE Probe p set p.connectDate = :connectDate, p.connectAddress = :connectAddress where p.probeKey = :probeKey") - int saveConnect(@Param("probeKey") String probeKey, @Param("connectDate") Date connectDate, @Param("connectAddress") String connectAddress); + // @Modifying(clearAutomatically = true) + // @Query("UPDATE Probe p set p.connectDate = :connectDate, p.connectAddress = :connectAddress where p.probeKey = :probeKey") + // int saveConnect(@Param("probeKey") String probeKey, @Param("connectDate") Date connectDate, @Param("connectAddress") String connectAddress); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java index 7169346..d8c1f60 100644 --- a/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java +++ b/src/main/java/com/loafle/overflow/central/module/probe/service/CentralProbeService.java @@ -1,5 +1,6 @@ package com.loafle.overflow.central.module.probe.service; +import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.module.probe.dao.ProbeDAO; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.domain.Domain; @@ -20,6 +21,8 @@ public class CentralProbeService implements ProbeService { @Autowired private ProbeDAO probeDAO; + @Autowired + private MessagePublisher messagePublisher; public Probe regist(Probe probe) throws OverflowException { return this.probeDAO.save(probe); @@ -73,11 +76,20 @@ public class CentralProbeService implements ProbeService { } public void onConnect(String probeKey, String connectAddress) throws OverflowException { - this.probeDAO.saveConnect(probeKey, new Date(), connectAddress); + Probe probe = this.probeDAO.findByProbeKey(probeKey); + probe.setConnectDate(new Date()); + probe.setConnectAddress(connectAddress); + probe = this.probeDAO.save(probe); + + messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onConnect", probeKey, connectAddress); } public void onDisconnect(String probeKey) throws OverflowException { - this.probeDAO.saveConnect(probeKey, null, null); - } + Probe probe = this.probeDAO.findByProbeKey(probeKey); + probe.setConnectDate(null); + probe.setConnectAddress(null); + probe = this.probeDAO.save(probe); + messagePublisher.publishToDomainMembers(probe.getDomain().getId(), "ProbeService.onDisconnect", probeKey); + } }