This example demonstrates the OK
status determination for a series of successful service executions.
static void ok () { final Service service = Services .context () .service ( Services.name ( "service.local" ) ); assert service.getStatus () == UNKNOWN; while ( service.getStatus () != OK ) { service .start () .succeed () .stop (); } }
This example demonstrates the DEGRADED
status determination for a series of retried service calls.
static void degraded () { final Service service = Services .context () .service ( Services.name ( "service.remote" ) ); assert service.getStatus () != DEGRADED; while ( service.getStatus () != DEGRADED ) { service .call () .elapsed () .retry () .succeeded (); } }
This example demonstrates the DEFECTIVE
status determination for a series of unsuccessful service calls.
static void defective () { final Service service = Services .context () .service ( Services.name ( "service.remote" ) ); assert service.getStatus () != DEFECTIVE; while ( service.getStatus () != DEFECTIVE ) { service .call () .failed (); } }
This example demonstrates the DOWN
status determination for a series of disconnected service errors as well as how to subscribe to the notification of such change.
static void down () { final Services.Name name = Services.name ( "service.remote" ); final Context context = Services.context (); final AtomicBoolean guard = new AtomicBoolean ( false ); context .subscribe ( ( n, registrar ) -> { if ( n == name ) { registrar .accept ( ( orientation, status ) -> { if ( status == DOWN ) guard.set ( true ); } ); } }, Status.class ); final Service service = context.service ( name ); assert DOWN != service.getStatus (); while ( !guard.get () ) { service .call () .disconnected () .failed (); } }