From 6ff5a3a7e95447d15d1daf0cbfd4f7a626f7fbab Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 20 Oct 2016 12:37:22 +1100 Subject: [PATCH] Issue #1017 --- .../session/GCloudSessionDataStore.java | 34 +++++++++++++++++-- .../InfinispanSessionDataStore.java | 13 +++++++ .../nosql/mongodb/MongoSessionDataStore.java | 11 ++++++ .../server/session/AbstractSessionCache.java | 10 ++++++ .../session/AbstractSessionDataStore.java | 15 +++++++- .../jetty/server/session/DatabaseAdaptor.java | 11 +++++- .../session/DefaultSessionIdManager.java | 25 ++++++++++++-- .../server/session/FileSessionDataStore.java | 9 +++++ .../server/session/JDBCSessionDataStore.java | 25 +++++++++++++- .../jetty/server/session/SessionHandler.java | 10 ++++++ 10 files changed, 156 insertions(+), 7 deletions(-) diff --git a/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java b/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java index 72fa3ce5d10..a82d77c360f 100644 --- a/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java +++ b/jetty-gcloud/jetty-gcloud-session-manager/src/main/java/org/eclipse/jetty/gcloud/session/GCloudSessionDataStore.java @@ -73,6 +73,7 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore protected boolean _dsProvided = false; protected boolean _indexesPresent = false; protected EntityDataModel _model; + protected boolean _modelProvided; private String _namespace; @@ -300,6 +301,18 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore checkNotNull(attributes); _attributes = attributes; } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return String.format("%s==%s:%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",this.getClass().getName(), + _kind,_accessed,_attributes,_contextPath,_cookieSetTime,_createTime,_expiry,_id,_lastAccessed,_lastNode,_maxInactive,_vhost); + } + + } @@ -356,7 +369,9 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore public void setEntityDataModel(EntityDataModel model) { + updateBean(_model, model); _model = model; + _modelProvided = true; } @@ -413,7 +428,10 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore } if (_model == null) + { _model = new EntityDataModel(); + addBean(_model,true); + } _keyFactory = _datastore.newKeyFactory().kind(_model.getKind()); @@ -430,15 +448,17 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore @Override protected void doStop() throws Exception { + super.doStop(); if (!_dsProvided) _datastore = null; - super.doStop(); + if (!_modelProvided) + _model = null; } public void setDatastore (Datastore datastore) { _datastore = datastore; - _dsProvided = true; + _dsProvided = true; } public int getMaxResults() @@ -926,6 +946,16 @@ public class GCloudSessionDataStore extends AbstractSessionDataStore { return true; } + + + /** + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#toString() + */ + @Override + public String toString() + { + return String.format("%s[namespace=%s,backoff=%d,maxRetries=%d,maxResults=%d,indexes=%b]",super.toString(), _namespace, _backoff, _maxRetries, _maxResults,_indexesPresent); + } } diff --git a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java index 560a38cf08a..d50f8883fbf 100644 --- a/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java +++ b/jetty-infinispan/src/main/java/org/eclipse/jetty/session/infinispan/InfinispanSessionDataStore.java @@ -311,4 +311,17 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore { return _infinispanIdleTimeoutSec; } + + + + /** + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#toString() + */ + @Override + public String toString() + { + return String.format("%s[cache=%s,idleTimeoutSec=%d]",super.toString(), (_cache==null?"":_cache.getName()),_infinispanIdleTimeoutSec); + } + + } diff --git a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java index 620ed915c62..9c2019f9f45 100644 --- a/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java +++ b/jetty-nosql/src/main/java/org/eclipse/jetty/nosql/mongodb/MongoSessionDataStore.java @@ -689,4 +689,15 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore return true; } + + /** + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#toString() + */ + @Override + public String toString() + { + return String.format("%s[collection=%s]", super.toString(),getDBCollection()); + } + + } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java index fd7c2b7ee76..db825bb078d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java @@ -19,6 +19,7 @@ package org.eclipse.jetty.server.session; +import java.io.IOException; import java.util.Collections; import java.util.Set; @@ -26,6 +27,7 @@ import javax.servlet.http.HttpServletRequest; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.Locker.Lock; @@ -782,4 +784,12 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements } return session; } + + + @Override + public String toString() + { + return String.format("%s@%x[evict=%d,removeUnloadable=%b,saveOnCreate=%b,saveOnInactiveEvict=%b]", + this.getClass().getName(),this.hashCode(),_evictionPolicy,_removeUnloadableSessions,_saveOnCreate,_saveOnInactiveEviction); + } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStore.java index c2f2b9353be..c5e1277e3d8 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionDataStore.java @@ -23,13 +23,14 @@ package org.eclipse.jetty.server.session; import java.util.Set; import org.eclipse.jetty.util.component.AbstractLifeCycle; +import org.eclipse.jetty.util.component.ContainerLifeCycle; /** * AbstractSessionDataStore * * */ -public abstract class AbstractSessionDataStore extends AbstractLifeCycle implements SessionDataStore +public abstract class AbstractSessionDataStore extends ContainerLifeCycle implements SessionDataStore { protected SessionContext _context; //context associated with this session data store protected int _gracePeriodSec = 60 * 60; //default of 1hr @@ -146,4 +147,16 @@ public abstract class AbstractSessionDataStore extends AbstractLifeCycle impleme _gracePeriodSec = sec; } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return String.format("%s@%x[passivating=%b,graceSec=%d]",this.getClass().getName(),this.hashCode(),isPassivating(),getGracePeriodSec()); + + } + + } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java index 456764a8dfb..17c7bbe5201 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DatabaseAdaptor.java @@ -302,5 +302,14 @@ public class DatabaseAdaptor else return DriverManager.getConnection(_connectionUrl); } - + + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return String.format("%s[jndi=%s,driver=%s]", super.toString(),_jndiName, _driverClassName); + } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java index 9ee4635e6aa..ef24e4b2e47 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/DefaultSessionIdManager.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.SessionIdManager; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.component.AbstractLifeCycle; +import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -48,7 +49,7 @@ import org.eclipse.jetty.util.log.Logger; * * @see HouseKeeper */ -public class DefaultSessionIdManager extends AbstractLifeCycle implements SessionIdManager +public class DefaultSessionIdManager extends ContainerLifeCycle implements SessionIdManager { private final static Logger LOG = Log.getLogger("org.eclipse.jetty.server.session"); @@ -63,6 +64,7 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio protected long _reseed=100000L; protected Server _server; protected HouseKeeper _houseKeeper; + protected boolean _ownHouseKeeper; /* ------------------------------------------------------------ */ @@ -112,8 +114,9 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio */ public void setSessionHouseKeeper (HouseKeeper houseKeeper) { + updateBean(_houseKeeper, houseKeeper); _houseKeeper = houseKeeper; - _houseKeeper.setSessionIdManager(this); + _houseKeeper.setSessionIdManager(this); } @@ -344,8 +347,10 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio if (_houseKeeper == null) { LOG.warn("No SessionScavenger set, using defaults"); + _ownHouseKeeper = true; _houseKeeper = new HouseKeeper(); _houseKeeper.setSessionIdManager(this); + addBean(_houseKeeper,true); } _houseKeeper.start(); @@ -359,6 +364,11 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio protected void doStop() throws Exception { _houseKeeper.stop(); + if (_ownHouseKeeper) + { + _houseKeeper = null; + } + _random = null; } /* ------------------------------------------------------------ */ @@ -499,4 +509,15 @@ public class DefaultSessionIdManager extends AbstractLifeCycle implements Sessio } return handlers; } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return String.format("%s[worker=%s]", super.toString(),_workerName); + } + + } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java index 5a5bb6219f5..06c3e13cca9 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/FileSessionDataStore.java @@ -455,6 +455,15 @@ public class FileSessionDataStore extends AbstractSessionDataStore } } + /** + * @see org.eclipse.jetty.server.session.AbstractSessionDataStore#toString() + */ + @Override + public String toString() + { + return String.format("%s[dir=%s,deleteUnrestorableFiles=%b]",super.toString(),_storeDir,_deleteUnrestorableFiles); + } + } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java index ec23c7e200a..bae2e89e0c0 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/JDBCSessionDataStore.java @@ -53,6 +53,7 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore protected boolean _initialized = false; private DatabaseAdaptor _dbAdaptor; private SessionTableSchema _sessionTableSchema; + private boolean _schemaProvided; @@ -616,6 +617,19 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore statement.executeUpdate(getCreateIndexOverSessionStatementAsString(index2)); } } + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return String.format("%s[%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s]",super.toString(), + _schemaName,_tableName,_idColumn,_contextPathColumn,_virtualHostColumn,_cookieTimeColumn,_createTimeColumn, + _expiryTimeColumn,_accessTimeColumn,_lastAccessTimeColumn,_lastNodeColumn,_lastSavedTimeColumn,_maxIntervalColumn); + } + + + } @@ -647,6 +661,9 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore protected void doStop() throws Exception { super.doStop(); + _initialized = false; + if (!_schemaProvided) + _sessionTableSchema = null; } @@ -660,7 +677,10 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore //taking the defaults if one not set if (_sessionTableSchema == null) + { _sessionTableSchema = new SessionTableSchema(); + addBean(_sessionTableSchema,true); + } _dbAdaptor.initialize(); _sessionTableSchema.setDatabaseAdaptor(_dbAdaptor); @@ -981,13 +1001,16 @@ public class JDBCSessionDataStore extends AbstractSessionDataStore public void setDatabaseAdaptor (DatabaseAdaptor dbAdaptor) { checkStarted(); + updateBean(_dbAdaptor, dbAdaptor); _dbAdaptor = dbAdaptor; } public void setSessionTableSchema (SessionTableSchema schema) { - checkStarted(); + checkStarted(); + updateBean(_sessionTableSchema, schema); _sessionTableSchema = schema; + _schemaProvided = true; } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java index b05991e9d58..00e648520fe 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java @@ -1681,5 +1681,15 @@ public class SessionHandler extends ScopedHandler baseRequest.setSession(session); } + + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() + { + return String.format("%s%d==dftMaxIdleSec=%d", this.getClass().getName(),this.hashCode(),_dftMaxIdleSecs); + } + }