src/com/shrewdify/diaroser/impl/PeerImpl.java
@Override
		public byte[] processCCRU(byte[] b) throws IOException, NoSpaceException,SQLException,ArithmeticException {
			log.debug("Processing CCRU Request");
			HashSet<Avp> avpset = new HashSet<Avp>();
			byte temp[] = Arrays.copyOfRange(b, Constants.ZERO, Constants.TWENTY);
			Hashtable<Integer, Avp> hs = par.decodeAvpSet(b, Constants.TWENTY);
			int validity=par.checkValid(hs, uri);
			if (validity>Constants.ZERO) {
				log.debug("Processing Valid CCRU Request");
				String sessionid = ("" + par
						.bytesToOctetString(hs.get(Dictionary.SESSION_ID).rawData)) + uri;
				
				Hashtable<String, String> params = null;
				synchronized (sessions) {
					params=sessions.get(sessionid);	
				}
				String mncCode = params.get(Constants.MCC), mccCode = params
						.get(Constants.MNC);
				;
				
				int balance = Integer.valueOf(params
						.remove(Constants.REMAINING_BALANCE));
				int reservedUnit = Integer.valueOf(params
						.remove(Constants.RESERVED_BALANCE));
				int chargePerUnit = Integer.valueOf(params
						.get(Constants.CHARGE_PER_PERIOD));
				int grantedUnits = Integer.valueOf(params
						.get(Constants.GRANTED_UNITS));
				int timePeriod = Integer.valueOf(params
						.get(Constants.TIME_PERIOD));
				int rescode;

				int wrresUnits = (int) par.bytesToInt((par.decodeAvpSet((par
						.decodeAvpSet(hs.get(Dictionary.MULTIPLE_SERVICES_CREDIT_CONTROL).getData(), 0)).get(Dictionary.USED_SERVICE_UNIT)
						.getData(), 0)).get(Dictionary.CC_TIME).getData());

				if (mccCode.equals(Config.unBillMcc)
						&& mncCode.equals(Config.unBillMnc)) {
					grantedUnits = timePeriod;
					rescode = Constants.SUCCESS_CODE;
				} else {
					String results[] = bill(balance, chargePerUnit, timePeriod,
							(int) grantedUnits, (int) wrresUnits,
							params.get(Constants.SUBSCRIPTIONID), 0);
					grantedUnits = Integer.parseInt(results[2]);
					rescode = Integer.parseInt(results[0]);
					if (rescode != Constants.SUCCESS_CODE) {
						sessions.remove(sessionid);
					}
					//DecimalFormat df = new DecimalFormat("#.##");
					balance = Integer.valueOf(results[1]);
					reservedUnit += Integer.valueOf(results[3]);
				}
				params.put(Constants.RESERVED_BALANCE, "" + reservedUnit);
				params.put(Constants.REMAINING_BALANCE, "" + balance);
				params.put(Constants.GRANTED_UNITS, "" + grantedUnits);
				params.put(Constants.LASTACCESSTIME, "" + System.currentTimeMillis());
				avpset = par.copyforResponse(1, (int) rescode, hs);
				Avp a = new Avp(Dictionary.MULTIPLE_SERVICES_CREDIT_CONTROL, (short) 0, 0, par.encodeAvp(new Avp(Dictionary.GRANTED_SERVICE_UNITS,
						(short) 0, 0, par.encodeAvp(new Avp(Dictionary.CC_TIME, (short) 0, 0,
								par.int32ToBytes((int) grantedUnits))))));
				avpset.add(a);
				synchronized (sessions) {
					sessions.put(sessionid, params);
				}
				byte spack[] = par.merge(par.encodeAvpSet(avpset), temp);
				handleFault(sessionid, params.toString());
				log.info("Result for CCRU "+params.get(Constants.ANUMBER)+"----->"+params.get(Constants.BNUMBER)+" is "+rescode);
				log.debug("Processed CCRU Request and generated CCA");
				return spack;
			}
			else{
				return handleError(validity,hs,temp);
			}

		}
/**
		 * It process the Update Requests , it extracts Sender No, Receiver No, Mcc Code, Mnc Code from the stored sessions, tariff rates and
		 *  before calculating the units to allocate it updates it balance with comparing reserved units and used units  then allocates units to requests and generate response.
		 *   Before returning the response it store all the information to session.		 * 
		 *  
		 */
It process the Update Requests , it extracts Sender No, Receiver No, Mcc Code, Mnc Code from the stored sessions, tariff rates and
before calculating the units to allocate it updates it balance with comparing reserved units and used units  then allocates units to requests and generate response.
Before returning the response it store all the information to session.
It process the Update Requests it extracts Sender No Receiver No Mcc Code Mnc Code from the stored sessions tariff rates and before calculating the units to allocate it updates it balance with comparing reserved units and used units then allocates units to requests and generate response . Before returning the response it store all the information to session .
@Override
		public byte[] processCCRU(byte[] b) throws IOException, NoSpaceException,SQLException,ArithmeticException {
			log.debug("Processing CCRU Request");
			HashSet<Avp> avpset = new HashSet<Avp>();
			byte temp[] = Arrays.copyOfRange(b, Constants.ZERO, Constants.TWENTY);
			Hashtable<Integer, Avp> hs = par.decodeAvpSet(b, Constants.TWENTY);
			int validity=par.checkValid(hs, uri);
			if (validity>Constants.ZERO) {
				log.debug("Processing Valid CCRU Request");
				String sessionid = ("" + par
						.bytesToOctetString(hs.get(Dictionary.SESSION_ID).rawData)) + uri;
				Hashtable<String, String> params = null;
				synchronized (sessions) {
					params=sessions.get(sessionid);	
				}
				String mncCode = params.get(Constants.MCC), mccCode = params
						.get(Constants.MNC);
				;
				int balance = Integer.valueOf(params
						.remove(Constants.REMAINING_BALANCE));
				int reservedUnit = Integer.valueOf(params
						.remove(Constants.RESERVED_BALANCE));
				int chargePerUnit = Integer.valueOf(params
						.get(Constants.CHARGE_PER_PERIOD));
				int grantedUnits = Integer.valueOf(params
						.get(Constants.GRANTED_UNITS));
				int timePeriod = Integer.valueOf(params
						.get(Constants.TIME_PERIOD));
				int rescode;
				int wrresUnits = (int) par.bytesToInt((par.decodeAvpSet((par
						.decodeAvpSet(hs.get(Dictionary.MULTIPLE_SERVICES_CREDIT_CONTROL).getData(), 0)).get(Dictionary.USED_SERVICE_UNIT)
						.getData(), 0)).get(Dictionary.CC_TIME).getData());
				if (mccCode.equals(Config.unBillMcc)
						&& mncCode.equals(Config.unBillMnc)) {
					grantedUnits = timePeriod;
					rescode = Constants.SUCCESS_CODE;
				} else {
					String results[] = bill(balance, chargePerUnit, timePeriod,
							(int) grantedUnits, (int) wrresUnits,
							params.get(Constants.SUBSCRIPTIONID), 0);
					grantedUnits = Integer.parseInt(results[2]);
					rescode = Integer.parseInt(results[0]);
					if (rescode != Constants.SUCCESS_CODE) {
						sessions.remove(sessionid);
					}
					balance = Integer.valueOf(results[1]);
					reservedUnit += Integer.valueOf(results[3]);
				}
				params.put(Constants.RESERVED_BALANCE, "" + reservedUnit);
				params.put(Constants.REMAINING_BALANCE, "" + balance);
				params.put(Constants.GRANTED_UNITS, "" + grantedUnits);
				params.put(Constants.LASTACCESSTIME, "" + System.currentTimeMillis());
				avpset = par.copyforResponse(1, (int) rescode, hs);
				Avp a = new Avp(Dictionary.MULTIPLE_SERVICES_CREDIT_CONTROL, (short) 0, 0, par.encodeAvp(new Avp(Dictionary.GRANTED_SERVICE_UNITS,
						(short) 0, 0, par.encodeAvp(new Avp(Dictionary.CC_TIME, (short) 0, 0,
								par.int32ToBytes((int) grantedUnits))))));
				avpset.add(a);
				synchronized (sessions) {
					sessions.put(sessionid, params);
				}
				byte spack[] = par.merge(par.encodeAvpSet(avpset), temp);
				handleFault(sessionid, params.toString());
				log.info("Result for CCRU "+params.get(Constants.ANUMBER)+"----->"+params.get(Constants.BNUMBER)+" is "+rescode);
				log.debug("Processed CCRU Request and generated CCA");
				return spack;
			}
			else{
				return handleError(validity,hs,temp);
			}
		}
@ Override public byte [ ] processCCRU ( byte [ ] b ) throws IOException , NoSpaceException , SQLException , ArithmeticException { log . debug ( "Processing CCRU Request" ) ; HashSet < Avp > avpset = new HashSet < Avp > ( ) ; byte temp [ ] = Arrays . copyOfRange ( b , Constants . ZERO , Constants . TWENTY ) ; Hashtable < Integer , Avp > hs = par . decodeAvpSet ( b , Constants . TWENTY ) ; int validity = par . checkValid ( hs , uri ) ; if ( validity > Constants . ZERO ) { log . debug ( "Processing Valid CCRU Request" ) ; String sessionid = ( "" + par . bytesToOctetString ( hs . get ( Dictionary . SESSION_ID ) . rawData ) ) + uri ; Hashtable < String , String > params = null ; synchronized ( sessions ) { params = sessions . get ( sessionid ) ; } String mncCode = params . get ( Constants . MCC ) , mccCode = params . get ( Constants . MNC ) ; ; int balance = Integer . valueOf ( params . remove ( Constants . REMAINING_BALANCE ) ) ; int reservedUnit = Integer . valueOf ( params . remove ( Constants . RESERVED_BALANCE ) ) ; int chargePerUnit = Integer . valueOf ( params . get ( Constants . CHARGE_PER_PERIOD ) ) ; int grantedUnits = Integer . valueOf ( params . get ( Constants . GRANTED_UNITS ) ) ; int timePeriod = Integer . valueOf ( params . get ( Constants . TIME_PERIOD ) ) ; int rescode ; int wrresUnits = ( int ) par . bytesToInt ( ( par . decodeAvpSet ( ( par . decodeAvpSet ( hs . get ( Dictionary . MULTIPLE_SERVICES_CREDIT_CONTROL ) . getData ( ) , 0 ) ) . get ( Dictionary . USED_SERVICE_UNIT ) . getData ( ) , 0 ) ) . get ( Dictionary . CC_TIME ) . getData ( ) ) ; if ( mccCode . equals ( Config . unBillMcc ) && mncCode . equals ( Config . unBillMnc ) ) { grantedUnits = timePeriod ; rescode = Constants . SUCCESS_CODE ; } else { String results [ ] = bill ( balance , chargePerUnit , timePeriod , ( int ) grantedUnits , ( int ) wrresUnits , params . get ( Constants . SUBSCRIPTIONID ) , 0 ) ; grantedUnits = Integer . parseInt ( results [ 2 ] ) ; rescode = Integer . parseInt ( results [ 0 ] ) ; if ( rescode != Constants . SUCCESS_CODE ) { sessions . remove ( sessionid ) ; } balance = Integer . valueOf ( results [ 1 ] ) ; reservedUnit += Integer . valueOf ( results [ 3 ] ) ; } params . put ( Constants . RESERVED_BALANCE , "" + reservedUnit ) ; params . put ( Constants . REMAINING_BALANCE , "" + balance ) ; params . put ( Constants . GRANTED_UNITS , "" + grantedUnits ) ; params . put ( Constants . LASTACCESSTIME , "" + System . currentTimeMillis ( ) ) ; avpset = par . copyforResponse ( 1 , ( int ) rescode , hs ) ; Avp a = new Avp ( Dictionary . MULTIPLE_SERVICES_CREDIT_CONTROL , ( short ) 0 , 0 , par . encodeAvp ( new Avp ( Dictionary . GRANTED_SERVICE_UNITS , ( short ) 0 , 0 , par . encodeAvp ( new Avp ( Dictionary . CC_TIME , ( short ) 0 , 0 , par . int32ToBytes ( ( int ) grantedUnits ) ) ) ) ) ) ; avpset . add ( a ) ; synchronized ( sessions ) { sessions . put ( sessionid , params ) ; } byte spack [ ] = par . merge ( par . encodeAvpSet ( avpset ) , temp ) ; handleFault ( sessionid , params . toString ( ) ) ; log . info ( "Result for CCRU " + params . get ( Constants . ANUMBER ) + "----->" + params . get ( Constants . BNUMBER ) + " is " + rescode ) ; log . debug ( "Processed CCRU Request and generated CCA" ) ; return spack ; } else { return handleError ( validity , hs , temp ) ; } }
It process the Update Requests , it extracts Sender No, Receiver No, Mcc Code, Mnc Code from the stored sessions, tariff rates and
  before calculating the units to allocate it updates it balance with comparing reserved units and used units  then allocates units to requests and generate response.
It process the Update Requests it extracts Sender No Receiver No Mcc Code Mnc Code from the stored sessions tariff rates and before calculating the units to allocate it updates it balance with comparing reserved units and used units then allocates units to requests and generate response .
//DecimalFormat df = new DecimalFormat("#.##");