Skip to content

Commit

Permalink
improved logging, ignore /health
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Dec 16, 2021
1 parent f9f88e0 commit c2b40e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
Expand Up @@ -70,7 +70,8 @@ public HazelCastSession createSession(String sessionId) {
return (HazelCastSession) super.createSession(sessionId);
}

public void commit(Session session) throws IOException {
public boolean commit(Session session) throws IOException {
long start = System.currentTimeMillis();
if (((HazelCastSession) session).isDirty()) {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
Expand All @@ -79,23 +80,31 @@ public void commit(Session session) throws IOException {
String site = Utils.getSiteName(session.getSession());
SessionData sessionData = new SessionData(session.getId(), site, bos.toByteArray());
getPersistentSessions().set(session.getId(), sessionData);
log.debug("saved: " + sessionData + " with TTL of " + session.getMaxInactiveInterval() + " seconds");
if (log.isDebugEnabled()) {
log.debug(String.format("Saved %s in %dms", sessionData, System.currentTimeMillis() - start));
}
return true;
}
}
return false;
}

@Override
public HazelCastSession findSession(String id) throws IOException {
HazelCastSession session = (HazelCastSession) super.findSession(id);
if (null == session) {

long start = System.currentTimeMillis();

// the calls are performed in a pessimistic lock block to prevent concurrency problems whilst finding
// sessions
getPersistentSessions().lock(id);
try {
SessionData sessionData = getPersistentSessions().get(id);
if (null == sessionData) {
log.debug(String.format("Session %s not found in map %s", id, mapName));
if (log.isDebugEnabled()) {
log.debug(String.format("Session %s not found in map %s", id, mapName));
}
} else {
try (ByteArrayInputStream is = new ByteArrayInputStream(sessionData.getData());
ObjectInputStream ois = Utils.getObjectInputStream(is, sessionData.getSite(),
Expand All @@ -105,7 +114,10 @@ public HazelCastSession findSession(String id) throws IOException {
session.access();
session.endAccess();
session.setClean();
log.debug("loaded: " + sessionData);
if (log.isDebugEnabled()) {
log.debug(String.format("Loaded %s in %dms", sessionData,
System.currentTimeMillis() - start));
}
add(session);
} catch (ClassNotFoundException e) {
log.error("Error loading session" + id, e);
Expand Down
Expand Up @@ -36,28 +36,24 @@ public class HazelcastSessionTrackerValve extends ValveBase {

private final Log log = Utils.getLog(HazelcastSessionTrackerValve.class);

protected Pattern filter = Pattern.compile("^/template/.*$");
protected Pattern filter = Pattern.compile("^(/template/.*)|((/health)(\\?.*)?)$");

@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
if (isRequestWithoutSession(request.getDecodedRequestURI())) {
getNext().invoke(request, response);
return;
}

long start = System.currentTimeMillis();
try {
getNext().invoke(request, response);
} finally {
HazelcastManager manager = (HazelcastManager) request.getContext().getManager();
Session session = request.getSessionInternal(false);
if (session != null) {
manager.commit(session);
}
long duration = System.currentTimeMillis() - start;
if (log.isDebugEnabled() && duration > 0) {
log.debug(String.format("handling session %s for %s took %dms", session.getId(),
request.getServletPath(), duration));
if (isRequestWithoutSession(request.getDecodedRequestURI())) {
long start = System.currentTimeMillis();
Session session = request.getSessionInternal(false);
if (null != session) {
HazelcastManager manager = (HazelcastManager) request.getContext().getManager();
boolean committed = manager.commit(session);
if (log.isDebugEnabled()) {
log.debug(String.format("handling session %s for %s took %dms (committed: %s)", session.getId(),
request.getServletPath(), System.currentTimeMillis() - start, committed));
}
}
}
}
}
Expand Down

0 comments on commit c2b40e2

Please sign in to comment.