Skip to content

Commit

Permalink
ATS-19 properly implement findSessions()
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Nov 11, 2019
1 parent 93a2390 commit ee1ccc7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/main/java/org/appng/tomcat/session/Utils.java
Expand Up @@ -20,6 +20,7 @@
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand All @@ -28,6 +29,8 @@

import org.apache.catalina.Container;
import org.apache.catalina.Context;
import org.apache.catalina.Manager;
import org.apache.catalina.Session;
import org.apache.catalina.connector.Request;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
Expand Down Expand Up @@ -216,4 +219,19 @@ public static String getContextName(Context context) {
return "/" + engineName + "/" + hostName + contextName;
}

public static Session[] findSessions(Manager manager, String[] keys, Log log) {
List<Session> sessions = new ArrayList<>();
for (String key : keys) {
try {
Session session = manager.findSession(key);
if (null != session) {
sessions.add(session);
}
} catch (IOException e) {
log.warn(String.format("Error loading session: %s", key));
}
}
return sessions.toArray(new Session[0]);
}

}
Expand Up @@ -72,6 +72,16 @@ public Session findSession(String id) throws IOException {
}
}

@Override
public Session[] findSessions() {
try {
return Utils.findSessions(this, getStore().keys(), log);
} catch (IOException e) {
log.error("error finding sessions!", e);
}
return new Session[0];
}

@Override
public String getName() {
if (this.name == null) {
Expand Down
Expand Up @@ -22,14 +22,14 @@
import org.apache.catalina.Session;
import org.apache.catalina.session.PersistentManagerBase;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.appng.tomcat.session.Utils;

/**
* A {@link Manager} implementation that uses a {@link MongoStore}
*/
public final class MongoPersistentManager extends PersistentManagerBase {

private static final Log log = LogFactory.getLog(MongoPersistentManager.class);
private static final Log log = Utils.getLog(MongoPersistentManager.class);

/**
* The descriptive information about this implementation.
Expand Down Expand Up @@ -107,6 +107,16 @@ public Session findSession(String id) throws IOException {
return session;
}

@Override
public Session[] findSessions() {
try {
return Utils.findSessions(this, getStore().keys(), log);
} catch (IOException e) {
log.error("error finding sessions!", e);
}
return new Session[0];
}

protected synchronized void startInternal() throws LifecycleException {
log.info("[" + this.getName() + "]: Starting.");
super.startInternal();
Expand Down
Expand Up @@ -420,6 +420,16 @@ public RedisSession findSession(String id) throws IOException {
return session;
}

@Override
public Session[] findSessions() {
try {
return Utils.findSessions(this, keys(), log);
} catch (IOException e) {
log.error("error finding sessions!", e);
}
return new Session[0];
}

public void clear() {
Jedis jedis = null;
Boolean error = true;
Expand Down

0 comments on commit ee1ccc7

Please sign in to comment.