StatefulServletContext

public class StatefulServletContext

A StatefulServletContext represents a context of a stateful servlet. A stateful servlet has two states, a halted state and a running state.

Author:Hugo Y. K. Lam

See also: StatefulServletContextListener

Constructors

StatefulServletContext

public StatefulServletContext()

Creates a new instance of StatefulServletContext.

Methods

acquire

public synchronized void acquire()

Acquires a permission from this context. Any servlet which employs this stateful context must call this method before processing any requests.

Throws:
  • UnavailableException – if the context is currently halted.

addContextListener

public boolean addContextListener(Object contextListener)

Adds a context listener for receiving events from this context.

Parameters:
  • contextListener – the stateful servlet context listener.
Returns:

true if the operation is successful, false otherwise.

getContextListeners

public Collection getContextListeners()

Gets all the stateful servlet context listeners in this context.

Returns:all the stateful servlet context listeners in this context.

getCurrentThreadCount

public int getCurrentThreadCount()

Gets the current count of threads running under this context.

Returns:the current count of threads running under this context.

getRequestEncoding

public String getRequestEncoding()

Gets the request encoding that the servlet should use.

Returns:the request encoding.

getResponseEncoding

public String getResponseEncoding()

Gets the response encoding that the servlet should use.

Returns:the response encoding.

halt

public synchronized boolean halt()

Halts this context. The calling thread will be blocked until a lock on the context has been acquired and no more threads are running under this context. Nothing will be done if the servlet is already halted.

Returns:true if and only if this context is not halted or being halted.

isHalted

public boolean isHalted()

Checks if the context is currently halted.

Returns:true if the servlet is currently halted.

isHalting

public boolean isHalting()

Checks if the context is currently being halted.

Returns:true if the servlet is currently being halted.

release

public synchronized void release()

Releases a permission to this context. Any servlet which employs this stateful context must call this method after processing any requests.

resume

public synchronized boolean resume()

Resumes this context. The calling thread will be blocked until a lock on the context has been acquired. Nothing will be done if the servlet is not halted.

Returns:true if and only if this context is halted and not being halted.

setRequestEncoding

public void setRequestEncoding(String requestEncoding)

Sets the request encoding that the servlet should use.

Parameters:
  • requestEncoding – the request encoding.

setResponseEncoding

public void setResponseEncoding(String responseEncoding)

Sets the response encoding that the servlet should use.

Parameters:
  • responseEncoding – the response encoding.