mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 15:06:50 +00:00
refactor/removed ObpActorInit.scala
This commit is contained in:
parent
f22763c3bd
commit
76fd73f769
@ -1,53 +0,0 @@
|
||||
package code.actorsystem
|
||||
|
||||
import akka.util.Timeout
|
||||
import code.api.APIFailure
|
||||
import code.api.util.APIUtil
|
||||
import code.util.Helper.MdcLoggable
|
||||
import net.liftweb.common._
|
||||
|
||||
import com.openbankproject.commons.ExecutionContext.Implicits.global
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.{Await, Future}
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
trait ObpActorInit extends MdcLoggable{
|
||||
// Default is 3 seconds, which should be more than enough for slower systems
|
||||
val ACTOR_TIMEOUT: Long = APIUtil.getPropsAsLongValue("remotedata.timeout").openOr(3)
|
||||
|
||||
val actorName = CreateActorNameFromClassName(this.getClass.getName)
|
||||
val actor = ObpLookupSystem.getActor(actorName)
|
||||
logger.debug(s"Create this Actor: $actorName: ${actor}")
|
||||
val TIMEOUT = (ACTOR_TIMEOUT seconds)
|
||||
implicit val timeout = Timeout(ACTOR_TIMEOUT * (1000 milliseconds))
|
||||
|
||||
/**
|
||||
* This function extracts the payload from Future and wraps it to Box.
|
||||
* It is used for Old Style Endpoints at Kafka connector.
|
||||
* @param f The payload wrapped into Future
|
||||
* @tparam T The type of the payload
|
||||
* @return The payload wrapped into Box
|
||||
*/
|
||||
def extractFutureToBox[T: ClassTag](f: Future[Any]): Box[T] = {
|
||||
val r: Future[Box[T]] = f.map {
|
||||
case f@ (_: ParamFailure[_] | _: APIFailure) => Empty ~> f
|
||||
case f: Failure => f
|
||||
case Empty => Empty
|
||||
case t: T => Full(t)
|
||||
case _ => Empty ~> APIFailure("future extraction to box failed", 501)
|
||||
}
|
||||
|
||||
Await.result(r, TIMEOUT)
|
||||
|
||||
}
|
||||
|
||||
def getValueFromFuture[T](f: Future[T]): T = {
|
||||
Await.result(f, TIMEOUT)
|
||||
}
|
||||
|
||||
def CreateActorNameFromClassName(c: String): String = {
|
||||
val n = c.replaceFirst("^.*Remotedata", "").replaceAll("\\$.*", "")
|
||||
Character.toLowerCase(n.charAt(0)) + n.substring(1)
|
||||
}
|
||||
|
||||
}
|
||||
@ -28,34 +28,6 @@ trait ObpLookupSystem extends MdcLoggable {
|
||||
obpLookupSystem
|
||||
}
|
||||
|
||||
def getKafkaActor(actorName: String) = {
|
||||
|
||||
val actorPath: String = {
|
||||
val hostname = ObpActorConfig.localHostname
|
||||
val port = ObpActorConfig.localPort
|
||||
val props_hostname = Helper.getHostname
|
||||
if (port == 0) {
|
||||
logger.error("Failed to connect to local Kafka actor")
|
||||
}
|
||||
s"akka.tcp://ObpActorSystem_${props_hostname}@${hostname}:${port}/user/${actorName}"
|
||||
}
|
||||
|
||||
this.obpLookupSystem.actorSelection(actorPath)
|
||||
}
|
||||
|
||||
def getKafkaActorChild(actorName: String, actorChildName: String) = {
|
||||
val actorPath: String = {
|
||||
val hostname = ObpActorConfig.localHostname
|
||||
val port = ObpActorConfig.localPort
|
||||
val props_hostname = Helper.getHostname
|
||||
if (port == 0) {
|
||||
logger.error("Failed to connect to local Kafka actor")
|
||||
}
|
||||
s"akka.tcp://ObpActorSystem_${props_hostname}@${hostname}:${port}/user/${actorName}/${actorChildName}"
|
||||
}
|
||||
this.obpLookupSystem.actorSelection(actorPath)
|
||||
}
|
||||
|
||||
def getActor(actorName: String) = {
|
||||
|
||||
val actorPath: String = {
|
||||
|
||||
@ -691,8 +691,6 @@ trait Connector extends MdcLoggable {
|
||||
callContext: Option[CallContext]
|
||||
): OBPReturnType[Box[PhysicalCardTrait]] = Future{(Failure{setUnimplementedError(nameOf(updatePhysicalCard _))}, callContext)}
|
||||
|
||||
|
||||
//Note: introduce v210 here, is for kafka connectors, use callContext and return Future.
|
||||
def makePaymentv210(fromAccount: BankAccount,
|
||||
toAccount: BankAccount,
|
||||
transactionRequestId: TransactionRequestId,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user