Reputation: 2849
Suppose I have a Corda service:
@CordaService
class MyService(serviceHub: AppServiceHub) : SingletonSerializeAsToken()
Is there a way to check if my node is in Drain mode inside this service?
I tried to find this information inside AppServiceHub
instance, but could not.
I found out that there is also a class ServiceHubInternal
which has nodeProperties.flowsDrainingMode.isEnabled()
exactly what I need. But I don't know how can I get an instance of ServiceHubInternal
inside Corda Service.
Even if I try a suggested solution to add corda-node
as a dependency and try to cast ServiceHubInternal sHI = (ServiceHubInternal) getServiceHub();
I get ClassCastException - net.corda.node.internal.AbstractNode$AppServiceHubImpl cannot be cast to net.corda.node.services.api.ServiceHubInternal
UPDATE
Well interestingly, when I do the same thing inside the Flow itself it works, so the serviceHub
inside FlowLogic
can be casted to ServiceHubInternal
but the one inside CordaService
cannot. is it the way it should work? Are there any workarounds to get the ServiceHubInternal
instance inside CordaService ?
Can anyone help me with this please?
Upvotes: 0
Views: 145
Reputation: 1831
You need the corda-node
dependency to access ServiceHubInternal
.
Add below to you build.gradle file in dependencies section:
cordaCompile "$corda_release_group:corda-node:$corda_release_version"
You should now be able to access ServiceHubInternal and check for draining mode as below:
ServiceHubInternal sHI = (ServiceHubInternal) getServiceHub();
sHI.getNodeProperties().getFlowsDrainingMode().isEnabled();
Upvotes: 2