-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic handling of stream disconnections and node renewal fail on clie…
…nt for automated recovery
- Loading branch information
1 parent
30faf9c
commit d7ce053
Showing
10 changed files
with
177 additions
and
10 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
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
37 changes: 37 additions & 0 deletions
37
src/orbit-client/src/main/kotlin/orbit/client/mesh/NodeLeaseRenewalHandler.kt
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,37 @@ | ||
/* | ||
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved. | ||
This file is part of the Orbit Project <https://www.orbit.cloud>. | ||
See license in LICENSE. | ||
*/ | ||
|
||
package orbit.client.mesh | ||
|
||
import kotlinx.coroutines.launch | ||
import mu.KotlinLogging | ||
import orbit.client.OrbitClient | ||
import orbit.util.concurrent.SupervisorScope | ||
import orbit.util.di.ExternallyConfigured | ||
|
||
interface NodeLeaseRenewalFailedHandler { | ||
fun onLeaseRenewalFailed() | ||
} | ||
|
||
class RestartOnNodeRenewalFailure(private val orbitClient: OrbitClient, private val supervisorScope: SupervisorScope) : NodeLeaseRenewalFailedHandler { | ||
val logger = KotlinLogging.logger { } | ||
|
||
object RestartOnNodeRenewalFailureSingleton : ExternallyConfigured<NodeLeaseRenewalFailedHandler> { | ||
override val instanceType = RestartOnNodeRenewalFailure::class.java | ||
} | ||
|
||
override fun onLeaseRenewalFailed() { | ||
supervisorScope.launch { | ||
logger.info { "Beginning Orbit restart..." } | ||
orbitClient.stop().join() | ||
orbitClient.start().join() | ||
logger.info { "Restart complete" } | ||
|
||
} | ||
} | ||
} | ||
|
||
class NodeLeaseRenewalFailed(msg: String) : Throwable(msg) |
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
14 changes: 14 additions & 0 deletions
14
src/orbit-client/src/main/kotlin/orbit/client/net/ClientState.kt
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,14 @@ | ||
/* | ||
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved. | ||
This file is part of the Orbit Project <https://www.orbit.cloud>. | ||
See license in LICENSE. | ||
*/ | ||
|
||
package orbit.client.net | ||
|
||
enum class ClientState { | ||
IDLE, | ||
CONNECTING, | ||
CONNECTED, | ||
STOPPING | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
Copyright (C) 2015 - 2019 Electronic Arts Inc. All rights reserved. | ||
This file is part of the Orbit Project <https://www.orbit.cloud>. | ||
See license in LICENSE. | ||
*/ | ||
|
||
package orbit.client | ||
|
||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.runBlocking | ||
import mu.KotlinLogging | ||
import orbit.client.actor.GreeterActor | ||
import orbit.client.actor.createProxy | ||
import orbit.client.net.OrbitServiceLocator | ||
fun main() { | ||
val logger = KotlinLogging.logger { } | ||
val targetUri = "orbit://localhost:50056/test" | ||
|
||
val client = OrbitClient( | ||
OrbitClientConfig( | ||
serviceLocator = OrbitServiceLocator(targetUri), | ||
packages = listOf("orbit.client.actor") | ||
) | ||
) | ||
|
||
runBlocking { | ||
client.start().join() | ||
val greeter = client.actorFactory.createProxy<GreeterActor>() | ||
do { | ||
try { | ||
val result = greeter.greetAsync("Joe").await() | ||
logger.info { result } | ||
}catch(e: Throwable) { | ||
logger.error { e } | ||
} | ||
delay(10000) | ||
} while(true) | ||
} | ||
} |