mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-17 06:59:29 +00:00
* #1317 Add Special Case Pattern To focus on pattern itself, I implement DB and maintenance lock by the singleton instance. * #1317 Add special cases unit tests Assert the logger output (ref: https://stackoverflow.com/a/52229629) * #1317 Add README.md Add Special Case Pattern README * #1317 Format: add a new line to end of file Co-authored-by: Subhrodip Mohanta <subhrodipmohanta@gmail.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.iluwatar.specialcase;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MaintenanceLock {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MaintenanceLock.class);
|
||||
|
||||
private static MaintenanceLock instance;
|
||||
private boolean lock = true;
|
||||
|
||||
/**
|
||||
* Get the instance of MaintenanceLock.
|
||||
*
|
||||
* @return singleton instance of MaintenanceLock
|
||||
*/
|
||||
public static MaintenanceLock getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (MaintenanceLock.class) {
|
||||
if (instance == null) {
|
||||
instance = new MaintenanceLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean isLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
public void setLock(boolean lock) {
|
||||
this.lock = lock;
|
||||
LOGGER.info("Maintenance lock is set to: " + lock);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user