/*******************************************************************************
 * Copyright (C) 2016 Push Technology Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/

package com.pushtechnology.adapters.rest.adapter;

import java.util.concurrent.atomic.AtomicBoolean;

import javax.annotation.PreDestroy;

import com.pushtechnology.diffusion.client.session.Session;

/**
 * Listener for loss of the session. Invokes the task passed into it when the session closes before the listener.
 *
 * @author Push Technology Limited
 */
public final class SessionLostListener implements Session.Listener, AutoCloseable {
    private final AtomicBoolean isActive = new AtomicBoolean(true);

    private final Runnable shutdownTask;

    /**
     * Constructor.
     */
    public SessionLostListener(Runnable shutdownTask) {
        this.shutdownTask = shutdownTask;
    }

    @Override
    public void onSessionStateChanged(Session session, Session.State oldState, Session.State newState) {
        if (isActive.get() && newState.isClosed()) {
            shutdownTask.run();
        }
    }

    @PreDestroy
    @Override
    public void close() {
        isActive.set(false);
    }
}

@@ -890,16 +890,74 @@
 stroy;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 import c
@@ -1008,16 +1008,16 @@
 ession;%0A
-
 %0A/**%0A * 
@@ -1253,16 +1253,106 @@
 eable %7B%0A
+    private static final Logger LOG = LoggerFactory.getLogger(SessionLostListener.class);%0A
     priv
@@ -1763,24 +1763,83 @@
 Closed()) %7B%0A
+            LOG.warn(%22Session %7B%7D has been lost%22, session);%0A
             
@@ -1943,26 +1943,127 @@
     
-isActive.set(false
+LOG.info(%22Closing session loss listener%22);%0A        isActive.set(false);%0A        LOG.info(%22Closed session loss listener%22
 );%0A 

Add additional logging to session loss listener.