dk.i1.diameter.session
Class ACHandler

Object
  extended by dk.i1.diameter.session.ACHandler

public class ACHandler
extends Object

A utility class for dealing with accounting. It supports sub-sessions, interim accounting and other common stuff. It can be used for incorporating into session classes. The session must dispatch ACAs to it. The class uses the sub-session 0 for the session itself and it is always present. It is the responsibility of the user to update the the usage data in the SubSession instances and/or override the collectACRInfo() method. Acct-Realtime-Required semantics are not directly supported.


Nested Class Summary
static class ACHandler.SubSession
          A collection of data belonging to a (sub-)session.
 
Field Summary
 Integer acct_application_id
          The acct-application-id to include in ACRs.
 String acct_multi_session_id
          The acct-multi-session-id to include in ACRs, if any
 
Constructor Summary
ACHandler(BaseSession base_session)
          Constructor for ACHandler
 
Method Summary
 long calcNextTimeout()
          Calculate the next time that handleTimeouts() should be called.
 void collectACRInfo(Message acr, ACHandler.SubSession ss, int record_type)
          Collect information and put it into an ACR.
 long createSubSession()
          Creates a sub-session.
 void handleACA(Message answer)
          Process an ACA
 void handleTimeout()
          Process timeouts, if any.
 void sendEvent()
          Send an event record for the whole session.
 void sendEvent(AVP[] avps)
          Send an event record for the whole session with an additional set of AVPs Implemented as sendEvent(0,null)
 void sendEvent(long subsession_id)
          Send an event record for the sub-session with an additional set of AVPs Implemented as sendEvent(subsession_id,null)
 void sendEvent(long subsession_id, AVP[] avps)
          Send an event record for the sub-session with an additional set of AVPs collectACR() will be called and the AVPs will then be added to the ACR, and then sent.
 void startSession()
          Start accounting for the session This will result in the ACR start-record being sent.
 void startSubSession(long subsession_id)
          Start sub-session accounting for the specified sub-session.
 void stopSession()
          Stop accounting.
 void stopSubSession(long subsession_id)
          Stop a sub-session.
 ACHandler.SubSession subSession(long subsession_id)
          Retrieve a sub-session by id
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

acct_multi_session_id

public String acct_multi_session_id
The acct-multi-session-id to include in ACRs, if any


acct_application_id

public Integer acct_application_id
The acct-application-id to include in ACRs. If not set, then collectACRInfo() must be overridden to add a vendor-specific-application AVP

Constructor Detail

ACHandler

public ACHandler(BaseSession base_session)
Constructor for ACHandler

Parameters:
base_session - The BaseSession (or subclass thereof) for which the accounting should be produced.
Method Detail

calcNextTimeout

public long calcNextTimeout()
Calculate the next time that handleTimeouts() should be called. The timeout is calcualted based on the earliest timeout of interim for any of the subsessions


handleTimeout

public void handleTimeout()
Process timeouts, if any. Accounting-interim requests may get sent.


createSubSession

public long createSubSession()
Creates a sub-session. Creates a subsession with a unique sub-session-id. It is the responsibility of the caller call startSubSession() afterward. The Sub-session is not automatically started.

Returns:
ID of the sub-session

subSession

public ACHandler.SubSession subSession(long subsession_id)
Retrieve a sub-session by id

Parameters:
subsession_id - The sub-session id
Returns:
The sub-session, or null if not found.

startSubSession

public void startSubSession(long subsession_id)
Start sub-session accounting for the specified sub-session. This will result in the ACR start-record being sent.

Parameters:
subsession_id - The sub-session id

stopSubSession

public void stopSubSession(long subsession_id)
Stop a sub-session. The sub-session is stopped (accounting-stop ACR will be generated) and the sub-session will be removed.

Parameters:
subsession_id - The sub-session id

startSession

public void startSession()
Start accounting for the session This will result in the ACR start-record being sent.


stopSession

public void stopSession()
Stop accounting. Stop accounting by sending ACRs (stop records) for all sub-sessions and deleting them, and then finally sending a ACR stop-record for the whole session.


sendEvent

public void sendEvent()
Send an event record for the whole session. Implemented as sendEvent(0,null)


sendEvent

public void sendEvent(AVP[] avps)
Send an event record for the whole session with an additional set of AVPs Implemented as sendEvent(0,null)


sendEvent

public void sendEvent(long subsession_id)
Send an event record for the sub-session with an additional set of AVPs Implemented as sendEvent(subsession_id,null)


sendEvent

public void sendEvent(long subsession_id,
                      AVP[] avps)
Send an event record for the sub-session with an additional set of AVPs collectACR() will be called and the AVPs will then be added to the ACR, and then sent.


handleACA

public void handleACA(Message answer)
Process an ACA


collectACRInfo

public void collectACRInfo(Message acr,
                           ACHandler.SubSession ss,
                           int record_type)
Collect information and put it into an ACR. This implementation puts the following AVPs into the ACR: session-id, origin-host, origin-realm, destination-realm, acct-record-type accounting-record-number, acct-application-id (unless null), accounting-sub-session-id (unless it is for the whole session), acct-interim-interval (maybe), event-timestamp. For interim and stop records the following AVPs are added (if non-null) acct-session-time, accounting-input-octets, accounting-output-octets, accounting-input-packets, accounting-output-packets

Subclasses probably want to override this to add session-type specific AVPs.

Parameters:
acr - The ACR message being constructed
ss - The sub-session
record_type - The record type (start/interim/stop/event)