-
-
Save bleis-tift/5705211 to your computer and use it in GitHub Desktop.
仕事の片手間に単純に書き換えただけなのでアレだけど。Scalaってシャドウイングできたっけ・・・レベル
This file contains hidden or 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
class AgentRuntime(profile: Properties, holder: ServiceBindingHolder[MicroRuntimeServiceBinder]) { | |
def startAgent(name: String, args: Array[AnyRef]): Future[AgentController] = | |
for { | |
binder <- holder.getServiceBinder() | |
binder <- createContainer(binder) | |
binder <- startAgentCore(name, args, binder) | |
} yield MicroRuntime.getAgent(name) | |
private def startAgentCore[T <: Agent](name: String, args: Array[AnyRef], | |
serviceBinder: MicroRuntimeServiceBinder): Future[MicroRuntimeServiceBinder] = { | |
val p = Promise[MicroRuntimeServiceBinder] | |
serviceBinder.startAgent(name, classOf[T].getCanonicalName, args, new RuntimeCallback[Void] { | |
def onFailure(t: Throwable) { | |
p.failure(t) | |
} | |
def onSuccess(_null: Void) { | |
p.success(serviceBinder) | |
} | |
}) | |
p.future | |
} | |
private def createContainer(serviceBinder: MicroRuntimeServiceBinder): Future[MicroRuntimeServiceBinder] = { | |
MicroRuntime.isRunning match { | |
case true => future(serviceBinder) | |
case false => { | |
val p = Promise[MicroRuntimeServiceBinder]() | |
serviceBinder.startAgentContainer(profile, new RuntimeCallback[Void] { | |
def onFailure(t: Throwable) { | |
p.failure(t) | |
} | |
def onSuccess(_null: Void) { | |
p.success(serviceBinder) | |
} | |
}) | |
p.future | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment