src/com/shrewdify/diaroser/impl/PeerImpl.java
@Override
		public byte[] processCCRE(byte[] b) throws IOException, NoSpaceException,SQLException,ArithmeticException {
			byte temp[] = Arrays.copyOfRange(b, Constants.ZERO, Constants.TWENTY);
			HashSet<Avp> avpset = null;
			Hashtable<Integer, Avp> hs = par.decodeAvpSet(b, Constants.TWENTY);
			int validity=par.checkValid(hs, uri);
			if(validity>0){
				String senderNumber = par.digNumber(par.bytesToOctetString((par.decodeAvpSet(par.decodeAvpSet(par.decodeAvpSet(hs.get(Dictionary.SERVICE_INFORMATION).getData(), 0).get(877).getData(), 0).get(886).rawData,0).get(897).rawData)));
				String receiverNumber = par.digNumber(par.bytesToOctetString((par.decodeAvpSet(par.decodeAvpSet(par.decodeAvpSet(hs.get(Dictionary.SERVICE_INFORMATION).getData(), 0).get(877).getData(), 0).get(1201).rawData,0).get(897).rawData)));
				int userBalance = db.readUserBalance(senderNumber);
				int chargeAmount = db.getEventBillingUnits(senderNumber,
						receiverNumber);
				int getUnittoMess = Constants.MINUSONE;
				int resCode = Constants.NOBALANCE_CODE;
				if (userBalance > Constants.ZERO) {
					if (!(userBalance <= Constants.ZERO || userBalance < chargeAmount)) {
						userBalance = userBalance - chargeAmount;
						boolean balUpd = db.updateUserBalance(senderNumber,
								0, userBalance);
						if (balUpd) {
							getUnittoMess = Constants.ONE;
							resCode = Constants.SUCCESS_CODE;
						} else {
							resCode = Constants.UNKNOWN_ERROR_CODE;
						}
					}
				}
				System.out.println("Message request");
				avpset = par.copyforResponse(1, resCode, hs);
				Avp a = new Avp(Dictionary.GRANTED_SERVICE_UNITS, (short) Constants.EIGHTY, Constants.ZERO, par.encodeAvp(new Avp(Dictionary.CC_TIME,
						(short) Constants.EIGHTY, Constants.ZERO, par.int32ToBytes(getUnittoMess))));
				a = new Avp(Dictionary.MULTIPLE_SERVICES_CREDIT_CONTROL, (short) Constants.EIGHTY, Constants.ZERO, par.encodeAvp(a));
				avpset.add(a);
				byte spack[] = par.merge(par.encodeAvpSet(avpset), temp);
				log.info("Result for CCRE "+senderNumber+"----->"+receiverNumber+" is "+resCode +" and total charge is "+userBalance);
				log.debug("Processed CCRE Request");
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				HashMap<String,String> cdrData = new HashMap<String, String>();
				cdrData.put(Constants.SRC_USERNAME, senderNumber);
				cdrData.put(Constants.SRC_HOSTNAME, "truphone");
				cdrData.put(Constants.BNUMBER, receiverNumber);
				cdrData.put(Constants.START_TIME, sdf.format(new Date(System.currentTimeMillis())));
				cdrData.put(Constants.END_TIME, sdf.format(new Date(System.currentTimeMillis())));
				cdrData.put(Constants.ACCOUNT, "abcdef");
				cdrData.put(Constants.AMOUNTCONSUMED, "" + chargeAmount);
				cdrData.put(Constants.RATECARD, "" + 1);
				cdrData.put(Constants.INITIAL_CHARGE, "" + 0);
				cdrData.put(Constants.CHARGEMODE, "" + 2);
				cdrData.put(Constants.TIMECONSUMED, ""+ 1);
				boolean loc=false;
				try {
					loc=cDRQueue.getLock();
					while(!loc){
						loc=cDRQueue.getLock();
						delay(1);
					}
					if(loc)
						cDRQueue.add(cdrData);
				}
				catch(Exception e){
					e.printStackTrace();
				}
				finally{
					if(loc){
						cDRQueue.lock.unlock();
						delay(1);
					}
				}	
				return spack;
			}else{
				return handleError(validity,hs,temp);
			}
		}
/**
		 * 
		 * It returns the response for Credit Control Request Event by processing from bytes. 
		 * It separates the header from bytes and process the request from it and Sends response.   
		 * 
		 */
It returns the response for Credit Control Request Event by processing from bytes.
It separates the header from bytes and process the request from it and Sends response.
It returns the response for Credit Control Request Event by processing from bytes . It separates the header from bytes and process the request from it and Sends response .
@Override
		public byte[] processCCRE(byte[] b) throws IOException, NoSpaceException,SQLException,ArithmeticException {
			byte temp[] = Arrays.copyOfRange(b, Constants.ZERO, Constants.TWENTY);
			HashSet<Avp> avpset = null;
			Hashtable<Integer, Avp> hs = par.decodeAvpSet(b, Constants.TWENTY);
			int validity=par.checkValid(hs, uri);
			if(validity>0){
				String senderNumber = par.digNumber(par.bytesToOctetString((par.decodeAvpSet(par.decodeAvpSet(par.decodeAvpSet(hs.get(Dictionary.SERVICE_INFORMATION).getData(), 0).get(877).getData(), 0).get(886).rawData,0).get(897).rawData)));
				String receiverNumber = par.digNumber(par.bytesToOctetString((par.decodeAvpSet(par.decodeAvpSet(par.decodeAvpSet(hs.get(Dictionary.SERVICE_INFORMATION).getData(), 0).get(877).getData(), 0).get(1201).rawData,0).get(897).rawData)));
				int userBalance = db.readUserBalance(senderNumber);
				int chargeAmount = db.getEventBillingUnits(senderNumber,
						receiverNumber);
				int getUnittoMess = Constants.MINUSONE;
				int resCode = Constants.NOBALANCE_CODE;
				if (userBalance > Constants.ZERO) {
					if (!(userBalance <= Constants.ZERO || userBalance < chargeAmount)) {
						userBalance = userBalance - chargeAmount;
						boolean balUpd = db.updateUserBalance(senderNumber,
								0, userBalance);
						if (balUpd) {
							getUnittoMess = Constants.ONE;
							resCode = Constants.SUCCESS_CODE;
						} else {
							resCode = Constants.UNKNOWN_ERROR_CODE;
						}
					}
				}
				System.out.println("Message request");
				avpset = par.copyforResponse(1, resCode, hs);
				Avp a = new Avp(Dictionary.GRANTED_SERVICE_UNITS, (short) Constants.EIGHTY, Constants.ZERO, par.encodeAvp(new Avp(Dictionary.CC_TIME,
						(short) Constants.EIGHTY, Constants.ZERO, par.int32ToBytes(getUnittoMess))));
				a = new Avp(Dictionary.MULTIPLE_SERVICES_CREDIT_CONTROL, (short) Constants.EIGHTY, Constants.ZERO, par.encodeAvp(a));
				avpset.add(a);
				byte spack[] = par.merge(par.encodeAvpSet(avpset), temp);
				log.info("Result for CCRE "+senderNumber+"----->"+receiverNumber+" is "+resCode +" and total charge is "+userBalance);
				log.debug("Processed CCRE Request");
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				HashMap<String,String> cdrData = new HashMap<String, String>();
				cdrData.put(Constants.SRC_USERNAME, senderNumber);
				cdrData.put(Constants.SRC_HOSTNAME, "truphone");
				cdrData.put(Constants.BNUMBER, receiverNumber);
				cdrData.put(Constants.START_TIME, sdf.format(new Date(System.currentTimeMillis())));
				cdrData.put(Constants.END_TIME, sdf.format(new Date(System.currentTimeMillis())));
				cdrData.put(Constants.ACCOUNT, "abcdef");
				cdrData.put(Constants.AMOUNTCONSUMED, "" + chargeAmount);
				cdrData.put(Constants.RATECARD, "" + 1);
				cdrData.put(Constants.INITIAL_CHARGE, "" + 0);
				cdrData.put(Constants.CHARGEMODE, "" + 2);
				cdrData.put(Constants.TIMECONSUMED, ""+ 1);
				boolean loc=false;
				try {
					loc=cDRQueue.getLock();
					while(!loc){
						loc=cDRQueue.getLock();
						delay(1);
					}
					if(loc)
						cDRQueue.add(cdrData);
				}
				catch(Exception e){
					e.printStackTrace();
				}
				finally{
					if(loc){
						cDRQueue.lock.unlock();
						delay(1);
					}
				}	
				return spack;
			}else{
				return handleError(validity,hs,temp);
			}
		}
@ Override public byte [ ] processCCRE ( byte [ ] b ) throws IOException , NoSpaceException , SQLException , ArithmeticException { byte temp [ ] = Arrays . copyOfRange ( b , Constants . ZERO , Constants . TWENTY ) ; HashSet < Avp > avpset = null ; Hashtable < Integer , Avp > hs = par . decodeAvpSet ( b , Constants . TWENTY ) ; int validity = par . checkValid ( hs , uri ) ; if ( validity > 0 ) { String senderNumber = par . digNumber ( par . bytesToOctetString ( ( par . decodeAvpSet ( par . decodeAvpSet ( par . decodeAvpSet ( hs . get ( Dictionary . SERVICE_INFORMATION ) . getData ( ) , 0 ) . get ( 877 ) . getData ( ) , 0 ) . get ( 886 ) . rawData , 0 ) . get ( 897 ) . rawData ) ) ) ; String receiverNumber = par . digNumber ( par . bytesToOctetString ( ( par . decodeAvpSet ( par . decodeAvpSet ( par . decodeAvpSet ( hs . get ( Dictionary . SERVICE_INFORMATION ) . getData ( ) , 0 ) . get ( 877 ) . getData ( ) , 0 ) . get ( 1201 ) . rawData , 0 ) . get ( 897 ) . rawData ) ) ) ; int userBalance = db . readUserBalance ( senderNumber ) ; int chargeAmount = db . getEventBillingUnits ( senderNumber , receiverNumber ) ; int getUnittoMess = Constants . MINUSONE ; int resCode = Constants . NOBALANCE_CODE ; if ( userBalance > Constants . ZERO ) { if ( ! ( userBalance <= Constants . ZERO || userBalance < chargeAmount ) ) { userBalance = userBalance - chargeAmount ; boolean balUpd = db . updateUserBalance ( senderNumber , 0 , userBalance ) ; if ( balUpd ) { getUnittoMess = Constants . ONE ; resCode = Constants . SUCCESS_CODE ; } else { resCode = Constants . UNKNOWN_ERROR_CODE ; } } } System . out . println ( "Message request" ) ; avpset = par . copyforResponse ( 1 , resCode , hs ) ; Avp a = new Avp ( Dictionary . GRANTED_SERVICE_UNITS , ( short ) Constants . EIGHTY , Constants . ZERO , par . encodeAvp ( new Avp ( Dictionary . CC_TIME , ( short ) Constants . EIGHTY , Constants . ZERO , par . int32ToBytes ( getUnittoMess ) ) ) ) ; a = new Avp ( Dictionary . MULTIPLE_SERVICES_CREDIT_CONTROL , ( short ) Constants . EIGHTY , Constants . ZERO , par . encodeAvp ( a ) ) ; avpset . add ( a ) ; byte spack [ ] = par . merge ( par . encodeAvpSet ( avpset ) , temp ) ; log . info ( "Result for CCRE " + senderNumber + "----->" + receiverNumber + " is " + resCode + " and total charge is " + userBalance ) ; log . debug ( "Processed CCRE Request" ) ; SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) ; HashMap < String , String > cdrData = new HashMap < String , String > ( ) ; cdrData . put ( Constants . SRC_USERNAME , senderNumber ) ; cdrData . put ( Constants . SRC_HOSTNAME , "truphone" ) ; cdrData . put ( Constants . BNUMBER , receiverNumber ) ; cdrData . put ( Constants . START_TIME , sdf . format ( new Date ( System . currentTimeMillis ( ) ) ) ) ; cdrData . put ( Constants . END_TIME , sdf . format ( new Date ( System . currentTimeMillis ( ) ) ) ) ; cdrData . put ( Constants . ACCOUNT , "abcdef" ) ; cdrData . put ( Constants . AMOUNTCONSUMED , "" + chargeAmount ) ; cdrData . put ( Constants . RATECARD , "" + 1 ) ; cdrData . put ( Constants . INITIAL_CHARGE , "" + 0 ) ; cdrData . put ( Constants . CHARGEMODE , "" + 2 ) ; cdrData . put ( Constants . TIMECONSUMED , "" + 1 ) ; boolean loc = false ; try { loc = cDRQueue . getLock ( ) ; while ( ! loc ) { loc = cDRQueue . getLock ( ) ; delay ( 1 ) ; } if ( loc ) cDRQueue . add ( cdrData ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } finally { if ( loc ) { cDRQueue . lock . unlock ( ) ; delay ( 1 ) ; } } return spack ; } else { return handleError ( validity , hs , temp ) ; } }
It returns the response for Credit Control Request Event by processing from bytes.
It returns the response for Credit Control Request Event by processing from bytes .