diff --git a/ratpack-cassandra/src/main/java/smartthings/ratpack/cassandra/CassandraService.java b/ratpack-cassandra/src/main/java/smartthings/ratpack/cassandra/CassandraService.java index 2d11173..10fa19c 100644 --- a/ratpack-cassandra/src/main/java/smartthings/ratpack/cassandra/CassandraService.java +++ b/ratpack-cassandra/src/main/java/smartthings/ratpack/cassandra/CassandraService.java @@ -121,6 +121,20 @@ public Promise execute(Statement statement) { }); } + public Promise closeSession() { + return Promise.async(downstream -> { + CloseFuture closeFuture = session.closeAsync(); + downstream.accept(closeFuture); + }); + } + + public Promise closeCluster() { + return Promise.async(downstream -> { + CloseFuture closeFuture = cluster.closeAsync(); + downstream.accept(closeFuture); + }); + } + @Override public void onStart(StartEvent event) throws Exception { connect(); @@ -128,7 +142,20 @@ public void onStart(StartEvent event) throws Exception { @Override public void onStop(StopEvent event) throws Exception { - session.closeAsync(); + closeSession() + .mapError(error -> { + logger.error("CassandraService error closing session", error); + return null; + }) + .flatMap(ignore -> { + logger.info("CassandraService session closed"); + return closeCluster(); + }) + .mapError(error -> { + logger.error("CassandraService error closing cluster", error); + return null; + }) + .then(ignore -> logger.info("CassandraService cluster closed")); } public Session getSession() {