Transaction

The Transaction container.

class Transaction.Transaction(application, request=None)

Bases: object

The Transaction container.

A transaction serves as:

  • A container for all objects involved in the transaction. The objects include application, request, response, session and servlet.

  • A message dissemination point. The messages include awake(), respond() and sleep().

When first created, a transaction has no session. However, it will create or retrieve one upon being asked for session().

The life cycle of a transaction begins and ends with Application’s dispatchRequest().

__init__(application, request=None)
application()

Get the corresponding application.

awake()

Send awake() to the session (if there is one) and the servlet.

Currently, the request and response do not partake in the awake()-respond()-sleep() cycle. This could definitely be added in the future if any use was demonstrated for it.

die()

End transaction.

This method should be invoked when the entire transaction is finished with. Currently, this is invoked by the Application. This method removes references to the different objects in the transaction, breaking cyclic reference chains and speeding up garbage collection.

dump(file=None)

Dump debugging info to stdout.

duration()

Return the duration, in seconds, of the transaction.

This is basically the response end time minus the request start time.

error()

Return Exception instance if there was any.

errorOccurred()

Check whether a server error occurred.

hasSession()

Return true if the transaction has a session.

request()

Get the corresponding request.

respond()

Respond to the request.

response()

Get the corresponding response.

servlet()

Return the current servlet that is processing.

Remember that servlets can be nested.

session()

Return the session for the transaction.

A new transaction is created if necessary. Therefore, this method never returns None. Use hasSession() if you want to find out if a session already exists.

setError(err)

Set Exception instance.

Invoked by the application if an Exception is raised to the application level.

setResponse(response)

Set the corresponding response.

setServlet(servlet)

Set the servlet for processing the transaction.

setSession(session)

Set the session for the transaction.

sleep()

Send sleep() to the session and the servlet.

Note that sleep() is sent in reverse order as awake() (which is typical for shutdown/cleanup methods).

writeExceptionReport(handler)

Write extra information to the exception report.