1//
2//  ========================================================================
3//  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4//  ------------------------------------------------------------------------
5//  All rights reserved. This program and the accompanying materials
6//  are made available under the terms of the Eclipse Public License v1.0
7//  and Apache License v2.0 which accompanies this distribution.
8//
9//      The Eclipse Public License is available at
10//      http://www.eclipse.org/legal/epl-v10.html
11//
12//      The Apache License v2.0 is available at
13//      http://www.opensource.org/licenses/apache2.0.php
14//
15//  You may elect to redistribute this code under either of these licenses.
16//  ========================================================================
17//
18
19package org.eclipse.jetty.server;
20
21import javax.servlet.http.HttpServletRequest;
22import javax.servlet.http.HttpSession;
23
24import org.eclipse.jetty.util.component.LifeCycle;
25
26/** Session ID Manager.
27 * Manages session IDs across multiple contexts.
28 */
29public interface SessionIdManager extends LifeCycle
30{
31    /**
32     * @param id The session ID without any cluster node extension
33     * @return True if the session ID is in use by at least one context.
34     */
35    public boolean idInUse(String id);
36
37    /**
38     * Add a session to the list of known sessions for a given ID.
39     * @param session The session
40     */
41    public void addSession(HttpSession session);
42
43    /**
44     * Remove session from the list of known sessions for a given ID.
45     * @param session
46     */
47    public void removeSession(HttpSession session);
48
49    /**
50     * Call {@link HttpSession#invalidate()} on all known sessions for the given id.
51     * @param id The session ID without any cluster node extension
52     */
53    public void invalidateAll(String id);
54
55    /**
56     * @param request
57     * @param created
58     * @return the new session id
59     */
60    public String newSessionId(HttpServletRequest request,long created);
61
62    public String getWorkerName();
63
64
65    /* ------------------------------------------------------------ */
66    /** Get a cluster ID from a node ID.
67     * Strip node identifier from a located session ID.
68     * @param nodeId
69     * @return the cluster id
70     */
71    public String getClusterId(String nodeId);
72
73    /* ------------------------------------------------------------ */
74    /** Get a node ID from a cluster ID and a request
75     * @param clusterId The ID of the session
76     * @param request The request that for the session (or null)
77     * @return The session ID qualified with the node ID.
78     */
79    public String getNodeId(String clusterId,HttpServletRequest request);
80
81}
82