}
public String save(Session data) {
if (data.invalid()) throw new IllegalStateException("Session invalidated");
String sid = sessionId(data);
Session session = makeSession(sid, data);
Date now = clock.now();
session.updatedAt(now);
sessions.put(sid, session);
if (sid.equals(data.id())) {
listener.sessionSaved(sid);
} else {
session.createdAt(now);
listener.sessionCreated(sid);
}
return sid;
}