use of net.java.slee.resource.diameter.cca.events.avp.CcUnitType in project charging-server by RestComm.
the class DiameterChargingServerSbb method getRequestedUnits.
private ArrayList<CreditControlUnit> getRequestedUnits(RoCreditControlRequest ccr, RequestedServiceUnitAvp rsu, long[] serviceIds) {
ArrayList<CreditControlUnit> ccRequestedUnits = new ArrayList<CreditControlUnit>();
long requestedUnits = 0;
for (int i = 0; i < CcUnitType.values().length; i++) {
CcUnitType type = CcUnitType.fromInt(i);
// MONEY is not supported by 3GPP. TODO: Add support for non 3GPP ?
if (type == CcUnitType.MONEY) {
continue;
}
String methodName = "getCreditControl" + toCamelCase(type.toString());
try {
Method m = rsu.getClass().getMethod(methodName, new Class[0]);
requestedUnits = (Long) m.invoke(rsu, new Object[0]);
if (tracer.isInfoEnabled() && requestedUnits != Long.MIN_VALUE) {
tracer.info("[><] " + sidString + " Requested Units of type '" + type + "' in CCR = " + requestedUnits);
}
if (requestedUnits >= 0) {
CreditControlUnit ccUnit = new CreditControlUnit();
ccUnit.setUnitType(type);
if (performRating) {
double rateForService = getRateForService(ccr, serviceIds[0], type.getValue(), requestedUnits);
ccUnit.setRateForService(rateForService);
// FIXME: This is not right. Rating should convert to monetary units...
ccUnit.setRequestedAmount((long) Math.ceil(requestedUnits * rateForService));
} else {
ccUnit.setRequestedAmount(requestedUnits);
}
ccUnit.setRequestedUnits(requestedUnits);
ccRequestedUnits.add(ccUnit);
}
} catch (Exception e) {
tracer.severe("[xx] " + sidString + " Unable to retrieve/invoke '" + methodName + "' for extracting Requested Units of type " + type, e);
}
}
return ccRequestedUnits;
}
use of net.java.slee.resource.diameter.cca.events.avp.CcUnitType in project charging-server by RestComm.
the class DiameterChargingServerSbb method collectUsedUnits.
private ArrayList<CreditControlUnit> collectUsedUnits(UsedServiceUnitAvp[] usuAvps, ArrayList<CreditControlUnit> reservedCCUnits) {
if (tracer.isInfoEnabled()) {
tracer.info("[><] " + sidString + " Collecting " + usuAvps.length + " Used Units AVPs.");
}
ArrayList<CreditControlUnit> usedCCUnits = new ArrayList<CreditControlUnit>();
for (UsedServiceUnitAvp usuAvp : usuAvps) {
for (int n = 0; n < CcUnitType.values().length; n++) {
CcUnitType type = CcUnitType.fromInt(n);
// MONEY is not supported by 3GPP
if (type == CcUnitType.MONEY) {
continue;
}
String methodName = "getCreditControl" + toCamelCase(type.toString());
try {
Method m = usuAvp.getClass().getMethod(methodName);
long value = (Long) m.invoke(usuAvp);
if (value == Long.MIN_VALUE) {
// It means the AVP was not present.. no null or NoSuchAvpException :(
continue;
}
if (tracer.isInfoEnabled()) {
tracer.info("[><] " + sidString + " Got " + value + " Used Units of type '" + type.toString() + "' ");
}
CreditControlUnit ccUnit = new CreditControlUnit();
ccUnit.setUnitType(type);
ccUnit.setUsedUnits(ccUnit.getUsedUnits() + value);
// If we can find Reserved Units and Rate Information, let's fill with it
for (CreditControlUnit reservedCCUnit : reservedCCUnits) {
if (reservedCCUnit.getUnitType() == type) {
// Copy the reserved amount from the last session into this session so that ABMF can update used units.
ccUnit.setReservedUnits(reservedCCUnit.getReservedUnits());
ccUnit.setReservedAmount(reservedCCUnit.getReservedAmount());
ccUnit.setUsedAmount((long) Math.ceil(reservedCCUnit.getRateForService() * ccUnit.getUsedUnits()));
ccUnit.setRateForService(reservedCCUnit.getRateForService());
}
}
usedCCUnits.add(ccUnit);
} catch (Exception e) {
tracer.severe("[xx] " + sidString + " Unable to retrieve/invoke '" + methodName + "' for extracting Used Units of type " + type, e);
}
}
}
return usedCCUnits;
}
Aggregations