-
Notifications
You must be signed in to change notification settings - Fork 430
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 #2278 from hongwei1/develop
feauter/implement our own database logic
- Loading branch information
Showing
5 changed files
with
161 additions
and
63 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
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
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
49 changes: 49 additions & 0 deletions
49
obp-api/src/main/scala/code/scheduler/DatabaseConnectionPoolScheduler.scala
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package code.scheduler | ||
|
||
import bootstrap.liftweb.CustomProtoDBVendor | ||
import code.actorsystem.ObpLookupSystem | ||
import code.util.Helper.MdcLoggable | ||
import java.util.concurrent.TimeUnit | ||
import scala.concurrent.duration._ | ||
|
||
|
||
object DatabaseConnectionPoolScheduler extends MdcLoggable { | ||
|
||
private lazy val actorSystem = ObpLookupSystem.obpLookupSystem | ||
implicit lazy val executor = actorSystem.dispatcher | ||
private lazy val scheduler = actorSystem.scheduler | ||
|
||
def start(vendor: CustomProtoDBVendor, interval: Long): Unit = { | ||
scheduler.schedule( | ||
initialDelay = Duration(interval, TimeUnit.SECONDS), | ||
interval = Duration(interval, TimeUnit.SECONDS), | ||
runnable = new Runnable { | ||
def run(): Unit = { | ||
clearAllConnections(vendor) | ||
// vendor.logAllConnectionsStatus //This is only to be used for debugging . | ||
} | ||
} | ||
) | ||
} | ||
|
||
def clearAllConnections(vendor: CustomProtoDBVendor) = { | ||
val connectionBox = vendor.createOne | ||
try { | ||
if (connectionBox.isEmpty) { | ||
vendor.closeAllConnections_!() | ||
logger.debug("ThreadPoolConnectionsScheduler.clearAllConnections") | ||
} | ||
} catch { | ||
case e => logger.debug(s"ThreadPoolConnectionsScheduler.clearAllConnections() method throwed exception, details is $e") | ||
}finally { | ||
try { | ||
if (connectionBox.isDefined) | ||
connectionBox.head.close() | ||
} catch { | ||
case e =>logger.debug(s"ThreadPoolConnectionsScheduler.clearAllConnections.close method throwed exception, details is $e") | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
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