// Path: src/main/java/com/adeptj/runtime/common/Times.java
// public final class Times {
// 
//     // No instances, just utility methods.
//     private Times() {
//     }
// 
//     /**
//      * Returns elapsed time in milliseconds from the provided time in nanoseconds.
//      *
//      * @param startTime time in nanoseconds
//      * @return elapsed time in milliseconds
//      */
//     public static long elapsedMillis(final long startTime) {
//         return NANOSECONDS.toMillis(System.nanoTime() - startTime);
//     }
// 
//     /**
//      * Returns elapsed time in seconds from the provided time in milliseconds.
//      *
//      * @param startTime time in milliseconds
//      * @return elapsed time in seconds
//      */
//     public static long elapsedSeconds(final long startTime) {
//         return MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime);
//     }
// }


import com.adeptj.runtime.common.Times;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;
import java.time.Instant;
import java.util.Date;
import java.util.Optional;
                sessionListener().ifPresent(listener -> listener.sessionCreated(event));
                break;
            case SESSION_DESTROYED:
                logSessionDestroyed(event);
                sessionListener().ifPresent(listener -> listener.sessionDestroyed(event));
                break;
            default:
                // NO-OP
                break;
        }
    }

    // <<---------- HttpSessionIdListener ---------->>

    public static void handleSessionIdChangedEvent(HttpSessionEvent event, String oldSessionId) {
        sessionIdListener().ifPresent(listener -> listener.sessionIdChanged(event, oldSessionId));
    }

    private static void logSessionCreated(HttpSessionEvent event) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Created HttpSession with id: [{}], @Time: [{}]",
                    event.getSession().getId(),
                    Date.from(Instant.ofEpochMilli(event.getSession().getCreationTime())));
        }
    }

    private static void logSessionDestroyed(HttpSessionEvent event) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Destroyed HttpSession with id: [{}], active for: [{}] seconds.",
                    event.getSession().getId(),
// Path: src/main/java/com/adeptj/runtime/common/Times.java
// public final class Times {
// 
//     // No instances, just utility methods.
//     private Times() {
//     }
// 
//     /**
//      * Returns elapsed time in milliseconds from the provided time in nanoseconds.
//      *
//      * @param startTime time in nanoseconds
//      * @return elapsed time in milliseconds
//      */
//     public static long elapsedMillis(final long startTime) {
//         return NANOSECONDS.toMillis(System.nanoTime() - startTime);
//     }
// 
//     /**
//      * Returns elapsed time in seconds from the provided time in milliseconds.
//      *
//      * @param startTime time in milliseconds
//      * @return elapsed time in seconds
//      */
//     public static long elapsedSeconds(final long startTime) {
//         return MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime);
//     }
// }


// Path: src/main/java/com/adeptj/runtime/osgi/HttpSessionEvents.java
import com.adeptj.runtime.common.Times;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;
import java.time.Instant;
import java.util.Date;
import java.util.Optional;

                sessionListener().ifPresent(listener -> listener.sessionCreated(event));
                break;
            case SESSION_DESTROYED:
                logSessionDestroyed(event);
                sessionListener().ifPresent(listener -> listener.sessionDestroyed(event));
                break;
            default:
                // NO-OP
                break;
        }
    }

    // <<---------- HttpSessionIdListener ---------->>

    public static void handleSessionIdChangedEvent(HttpSessionEvent event, String oldSessionId) {
        sessionIdListener().ifPresent(listener -> listener.sessionIdChanged(event, oldSessionId));
    }

    private static void logSessionCreated(HttpSessionEvent event) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Created HttpSession with id: [{}], @Time: [{}]",
                    event.getSession().getId(),
                    Date.from(Instant.ofEpochMilli(event.getSession().getCreationTime())));
        }
    }

    private static void logSessionDestroyed(HttpSessionEvent event) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Destroyed HttpSession with id: [{}], active for: [{}] seconds.",
                    event.getSession().getId(),
                    Times.elapsedSeconds(event.getSession().getCreationTime()));