-
-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1658 from steve-community/refactor_reduce_statefu…
…lness reduce state in application
- Loading branch information
Showing
2 changed files
with
3 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.mail.Authenticator; | ||
import jakarta.mail.Message; | ||
import jakarta.mail.MessagingException; | ||
|
@@ -35,11 +34,9 @@ | |
import jakarta.mail.Transport; | ||
import jakarta.mail.internet.InternetAddress; | ||
import jakarta.mail.internet.MimeMessage; | ||
|
||
import java.util.Properties; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.locks.Lock; | ||
import java.util.concurrent.locks.ReadWriteLock; | ||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
|
||
/** | ||
* @author Sevket Goekay <[email protected]> | ||
|
@@ -52,31 +49,8 @@ public class MailService { | |
@Autowired private SettingsRepository settingsRepository; | ||
@Autowired private ScheduledExecutorService executorService; | ||
|
||
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); | ||
private final Lock readLock = readWriteLock.readLock(); | ||
private final Lock writeLock = readWriteLock.writeLock(); | ||
|
||
private MailSettings settings; | ||
private Session session; | ||
|
||
@PostConstruct | ||
public void loadSettingsFromDB() { | ||
writeLock.lock(); | ||
try { | ||
settings = settingsRepository.getMailSettings(); | ||
} finally { | ||
writeLock.unlock(); | ||
} | ||
session = createSession(getSettings()); | ||
} | ||
|
||
public MailSettings getSettings() { | ||
readLock.lock(); | ||
try { | ||
return this.settings; | ||
} finally { | ||
readLock.unlock(); | ||
} | ||
return settingsRepository.getMailSettings(); | ||
} | ||
|
||
public void sendTestMail() { | ||
|
@@ -99,6 +73,7 @@ public void sendAsync(String subject, String body) { | |
|
||
public void send(String subject, String body) throws MessagingException { | ||
MailSettings settings = getSettings(); | ||
Session session = createSession(getSettings()); | ||
|
||
Message mail = new MimeMessage(session); | ||
mail.setSubject("[SteVe] " + subject); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters