protected void setData(Map<String, Object> data) { if (data != null) { this.data = data; this.crc = checksum(); } }
@Override public Session regenerateId() { if (oldId == null) { // keep track of just the first one since the // regeneration during the remaining lifecycle are ephemeral oldId = id; } // ids are stored in hex, so the original size is half of the hex encoded length id = generateId(prng, oldId.length() / 2); renewed = true; return this; }
@Override public void start() throws Exception { Router router = Router.router(vertx); router.route().handler(CookieHandler.create()); router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx))); router.route().handler(routingContext -> { Session session = routingContext.session(); Integer cnt = session.get("hitcount"); cnt = (cnt == null ? 0 : cnt) + 1; session.put("hitcount", cnt); routingContext.response().putHeader("content-type", "text/html") .end("<html><body><h1>Hitcount: " + cnt + "</h1></body></html>"); }); vertx.createHttpServer().requestHandler(router).listen(8080); } }
@Override public void setUp() throws Exception { super.setUp(); VertxOptions options = new VertxOptions(); options.setClustered(true); options.setClusterManager(getClusterManager()); startNodes(numNodes, options); store = ClusteredSessionStore.create(vertices[0], 3000); }
/** * Create a Session store given a backend and configuration JSON. * * @param vertx vertx instance * @return the store or runtime exception */ static SessionStore create(Vertx vertx) { return create(vertx, new JsonObject()); }
@Test public void testRetryTimeout() throws Exception { assertTrue(doTestSessionRetryTimeout() < 3000); } }
@Test public void testRetryTimeout() throws Exception { long val = doTestSessionRetryTimeout(); assertTrue(String.valueOf(val), val >= 3000 && val < 5000); } }
@Override public Session put(String key, Object obj) { final Map<String, Object> data = data(); // nulls are handled as remove actions if (obj == null) { data.remove(key); } else { data.put(key, obj); } return this; }
@Override public Map<String, Object> data() { if (data == null) { synchronized (this) { // double check since there could already been someone in the lock if (data == null) { data = new ConcurrentHashMap<>(); if (destroyed) { // pretty much should behave as a regeneration regenerateId(); destroyed = false; } } } } return data; }
protected void setData(JsonObject data) { if (data != null) { setData(data.getMap()); } }
protected SessionStore getSessionStore() { return LocalSessionStore.create(vertx); }
public void incrementVersion() { int old = this.crc; // update the checksum crc = checksum(); if (this.crc != old) { ++version; } }
public AbstractSession(PRNG random, long timeout, int length) { this.prng = random; this.id = generateId(prng, length); this.timeout = timeout; this.lastAccessed = System.currentTimeMillis(); }
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
@Override public void setUp() throws Exception { super.setUp(); store = LocalSessionStore.create(vertx); }
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));
router.route().handler(SessionHandler.create(LocalSessionStore.create(vertx)));