/** * @param os the output stream to save to * @param id identity of the session * @param data the info of the session * @throws IOException */ protected void save(OutputStream os, String id, SessionData data) throws IOException { DataOutputStream out = new DataOutputStream(os); out.writeUTF(id); out.writeUTF(_context.getCanonicalContextPath()); out.writeUTF(_context.getVhost()); out.writeUTF(data.getLastNode()); out.writeLong(data.getCreated()); out.writeLong(data.getAccessed()); out.writeLong(data.getLastAccessed()); out.writeLong(data.getCookieSet()); out.writeLong(data.getExpiry()); out.writeLong(data.getMaxInactiveMs()); List<String> keys = new ArrayList<String>(data.getKeys()); out.writeInt(keys.size()); ObjectOutputStream oos = new ObjectOutputStream(out); for (String name:keys) { oos.writeUTF(name); oos.writeObject(data.getAttribute(name)); } }
protected void doUpdate (String id, SessionData data) throws Exception { try (Connection connection = _dbAdaptor.getConnection()) { connection.setAutoCommit(true); try (PreparedStatement statement = _sessionTableSchema.getUpdateSessionStatement(connection, data.getId(), _context)) { statement.setString(1, data.getLastNode());//should be my node id statement.setLong(2, data.getAccessed());//accessTime statement.setLong(3, data.getLastAccessed()); //lastAccessTime statement.setLong(4, data.getLastSaved()); //last saved time statement.setLong(5, data.getExpiry()); statement.setLong(6, data.getMaxInactiveMs()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(data.getAllAttributes()); oos.flush(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); statement.setBinaryStream(7, bais, bytes.length);//attribute map as blob statement.executeUpdate(); if (LOG.isDebugEnabled()) LOG.debug("Updated session "+data); } } }
statement.setString(4, data.getLastNode());//my node id statement.setLong(5, data.getAccessed());//accessTime statement.setLong(6, data.getLastAccessed()); //lastAccessTime
isd.setCookieSet(data.getCookieSet()); isd.setLastSaved(data.getLastSaved()); isd.setLastNode(data.getLastNode());
if (_context.getWorkerName().equals(sd.getLastNode()))
if (_context.getWorkerName().equals(sd.getLastNode()))
@Override public void write(ObjectDataOutput out, SessionData data) throws IOException { out.writeUTF(data.getId()); out.writeUTF(data.getContextPath()); out.writeUTF(data.getVhost()); out.writeLong(data.getAccessed()); out.writeLong(data.getLastAccessed()); out.writeLong(data.getCreated()); out.writeLong(data.getCookieSet()); out.writeUTF(data.getLastNode()); out.writeLong(data.getExpiry()); out.writeLong(data.getMaxInactiveMs()); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos)) { SessionData.serializeAttributes(data, oos); out.writeByteArray(baos.toByteArray()); } }
sets.put(getContextSubfield(__VERSION),version); sets.put(getContextSubfield(__LASTSAVED), data.getLastSaved()); sets.put(getContextSubfield(__LASTNODE), data.getLastNode()); sets.put(__MAX_IDLE, data.getMaxInactiveMs()); sets.put(__EXPIRY, data.getExpiry()); sets.put(getContextSubfield(__LASTNODE), data.getLastNode()); version = new Long(((Number)version).longValue() + 1); ((NoSqlSessionData)data).setVersion(version);
/** * Copy the info from the given sessiondata * * @param data the sessiondata to be copied */ public void copy (SessionData data) { if (data == null) return; //don't copy if no data if (data.getId() == null || !(getId().equals(data.getId()))) throw new IllegalStateException ("Can only copy data for same session id"); if (data == this) return; //don't copy ourself setLastNode(data.getLastNode()); setContextPath(data.getContextPath()); setVhost(data.getVhost()); setCookieSet(data.getCookieSet()); setCreated(data.getCreated()); setAccessed(data.getAccessed()); setLastAccessed(data.getLastAccessed()); setMaxInactiveMs(data.getMaxInactiveMs()); setExpiry(data.getExpiry()); setLastSaved(data.getLastSaved()); clearAllAttributes(); putAllAttributes(data.getAllAttributes()); }
.set(_model.getCreateTime(), session.getCreated()) .set(_model.getCookieSetTime(), session.getCookieSet()) .set(_model.getLastNode(),session.getLastNode()) .set(_model.getExpiry(), session.getExpiry()) .set(_model.getMaxInactive(), session.getMaxInactiveMs())