Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] Injecting timestamps using AOP

Hi,

        IN our project we have a reporting module for our communication layer. Briefly speaking about it, we have time stamps to calculate the time it takes to read from the

Socket, time to read from an intermediate queue system and time to update the DB. And right now we are planning to separate the core functionality of our communication layer and the reporting module using AOP.

One of the methods we use is as below..



public String readAsyncMessage(long messageid) throws IOException {

                        System.out.println("I am in Read Socket");

                        Date startTime=new java.util.Date();

                        long befSocReadTime =  System.currentTimeMillis();                   

                        inputStream = super.getInputStream();

                        byte[] responseData = new byte[BUFFER_LENGTH];

                        BufferedReader in = new BufferedReader(new InputStreamReader(

                                                inputStream));

                        Date afterReadTime=new java.util.Date();

                        long aftSocReadTime =  (System.currentTimeMillis()-befSocReadTime);               

                        String line;

                        StringBuffer sb  = new StringBuffer();

                        String xmlString = null;

                                               

                        boolean check = true;

                        while (check == true && (line = in.readLine()) != null) {

                                    System.out.println("In AgenSocketTest: " + line);

                                               

                                    sb.append(line);

                                   

                                    System.out.println("SB from socket = " + sb.toString());

            xmlString = sb.toString();

                                   

                                   

                                    String result=MetricsDAO.checkMessage(line);

                                    Map m = new HashMap();

                                    m.put("MsgStatus",result);

                                    m.put("StartTime",startTime);

                                    m.put("AftRdTime",afterReadTime);

                                    m.put("SocReadTime",new Long(aftSocReadTime));

                                    m.put("Msg",line);

                                    m.put("MsgID",new Long(messageid));

                                   

                                    SetValueObjects.setReportValueObjects(m);

                                    /*mVO.setmessageStatus(result);

                                    mVO.setsocConnTime(startTime);                                             

                                    mVO.setafterConnTime(afterReadTime);                                     

                                    mVO.setsocReadTime(aftSocReadTime);

                                    mVO.setmessageText(line);*/

                                    //MetricsDAO.logSocketMetricReports(result,startTime,afterReadTime,aftSocReadTime);

                                    Map messageMap = new HashMap();

                                    messageMap.put("Message",xmlString);

                                    messageMap.put("StartTime",startTime);

                                   

                                   

                                    SetValueObjects.setMessageReportValueObjects(messageMap);

                                   

                                    /*try {

                                                MCPCommunicationMessageDAO.updateMessageStatus(xmlString,startTime);

                                    } catch (Exception e) {

                                                e.printStackTrace();

                                    }*/

                                   

                                   

                                    sb.delete(0, sb.length() - 1);

                                    check = false;

                        }

                        return xmlString;

            }





As you can see we have time stamps to calculate the time it takes to read from the socket in the above method.

I wanted to know if we could inject these timestamps using AOP or if there is any alternative of achieving the same.

Thanks in advance.



Manoj





Back to the top