Package org.jainslee.resources.diameter.cca
The Diameter CCA Resource Adaptor type based on RFC 4006.
The DiameterCcaProvider
provider interface provides
methods to obtain a factory class to create Diameter Credit Control AVPs and Diameter messages.
SBBs can obtain a DiameterCcaProvider
instance via JNDI after
specifying an appropriate <resource-adaptor-entity-binding> entry in the SBB deployment descriptor.
Client Functionality -- Sending Diameter Credit Control requests
Asynchronous Requests
The DiameterCcaProvider interface provides a method to create a
CreditControlClientSessionActivity
on which asynchronous Diameter requests can then be sent.
Diameter credit control activities are created using the
createClientSessionActivity()
method or the
createClientSessionActivity(DiameterIdentity, DiameterIdentity)
method. The CreditControlClientSessionActivity
returned can be used to send asynchronous requests. When answers are received by the Diameter stack,
CreditControlAnswer
events are fired on the activity.
Synchronous Requests
Note: The synchronous API should only be used for simple test services that are not expected to run at high loads. The resource adaptor does not currently implement timeouts for synchronous requests, so SBBs may block indefinitely. Services that use the synchronous model also do not scale well.
The DiameterCcaProvider interface also has methods which will send a Diameter request then block until the answer
is received. A CreditControlAnswer
instance will be the
return value of the method call. See the DiameterCcaProvider
class for details. Several methods on this interface are deprecated and are retained only for backwards
compatibility. The will be removed in a future release.
Example
The following code fragment demonstrates an initial Credit Control Request being created and sent.
The diameterCcaProvider
variable contains the RA SBB provider interface retrieved from JNDI.
CreditControlMessageFactory messageFactory = diameterCcaProvider.getCreditControlMessageFactory(); CreditControlRequest ccr = messageFactory.createCreditControlRequest(); SubscriptionId subscriptionId = messageFactory.createSubscriptionId(); subscriptionId.setSubscriptionIdType(SubscriptionIdType.END_USER_E164); subscriptionId.setSubscriptionIdData(subscriptionAddress); ccr.setSubscriptionId(subscriptionId); RequestedServiceUnit rsu = messageFactory.createRequestedServiceUnit(); rsu.setCcTime(10); ccr.setRequestedServiceUnit(rsu); CreditControlClientSessionActivity activity = diameterCcaProvider.createClientSessionActivity(null, new DiameterIdentity("opencloud")); ActivityContextInterface diameterACI = diameterCcaACIFactory.getActivityContextInterface(activity); diameterACI.attach(getSbbLocalObject()); activity.sendInitialCreditControlRequest(ccr);
Client Functionality -- Receiving Diameter Credit Control Answers
The following code fragment demonstrates a Credit Control Answer being received by an SBB.public void onCreditControlAnswer(CreditControlAnswer cca, ActivityContextInterface aci) { switch ((int) cca.getResultCode()) { case DiameterCcaResultCode.DIAMETER_CREDIT_CONTROL_NOT_APPLICABLE: // ... do behaviour required for billing not applicable ... break; case DiameterResultCode.DIAMETER_AUTHORIZATION_REJECTED: // insufficient credit // ... do behaviour required for insufficient credit ... break; case DiameterResultCode.DIAMETER_SUCCESS: GrantedServiceUnit gsu = cca.getGrantedServiceUnit(); final long ccTime = gsu.getCcTime(); // invalid response if (ccTime == 0) { // ... handle error: illegal Diameter CCA Answer (GSU CC Time = 0) } break; default: // ... handle error: illegal Diameter CCA Answer, unknown result code } }
Server Functionality -- Receiving Diameter Credit Control Requests
The following code fragment demonstrates a Credit Control Request being received by an SBB, and an answer being sent using the same activity.public void onCreditControlRequestInitial(CreditControlRequest event, ActivityContextInterface aci) { // do logic for CCR-Initial CreditControlServerSessionActivity activity = (CreditControlServerSessionActivity) aci.getActivity(); CreditControlAnswer cca = activity.createCreditControlAnswer(); cca.setResultCode(DiameterResultCode.DIAMETER_SUCCESS); cca.setCcRequestType(CcRequestType.INITIAL_REQUEST); try { activity.sendCreditControlAnswer(cca); } catch (SendException e) { // ... handle error: SendException sending answer } } public void onCreditControlRequestUpdate(CreditControlRequest event, ActivityContextInterface aci) { // do logic for CCR-Update CreditControlServerSessionActivity activity = (CreditControlServerSessionActivity) aci.getActivity(); CreditControlAnswer cca = activity.createCreditControlAnswer(); cca.setResultCode(DiameterResultCode.DIAMETER_SUCCESS); cca.setCcRequestType(CcRequestType.UPDATE_REQUEST); try { activity.sendCreditControlAnswer(cca); } catch (SendException e) { // ... handle error: SendException sending answer } } public void onCreditControlRequestTermination(CreditControlRequest event, ActivityContextInterface aci) { // do logic for CCR-Termination CreditControlServerSessionActivity activity = (CreditControlServerSessionActivity) aci.getActivity(); CreditControlAnswer cca = activity.createCreditControlAnswer(); cca.setResultCode(DiameterResultCode.DIAMETER_SUCCESS); cca.setCcRequestType(CcRequestType.TERMINATION_REQUEST); try { activity.sendCreditControlAnswer(cca); } catch (SendException e) { // ... handle error: SendException sending answer } }
-
Interface Summary Interface Description CreditControlClientSessionActivity A CreditControlClientSessionActivity represents a charging control session for Credit Control clients.CreditControlMessageFactory Factory to support the creation of concrete instances for Diameter Credit Control applications.CreditControlServerSessionActivity A CreditControlServerSessionActivity represents a charging control session for Credit Control servers.CreditControlSessionActivity Superinterface for Credit Control activities.DiameterCcaActivityContextInterfaceFactory Interface to obtain an ActivityContextInterface for a CCA activity.DiameterCcaProvider The SBB interface for the Diameter CCA Resource Adaptor.Versions -
Class Summary Class Description CreditControlSessionState Enumeration of CCA session statesDiameterCcaAvpCodes Diameter CCA AVP codes constants.DiameterCcaResultCode Diameter CCA Result Codes defined by RFC 4006.