@@ -49,7 +49,6 @@ public static void main( String[] args ) throws Exception
4949
5050 public void run () {
5151 sendCounterData ();
52-
5352 for (int i = 0 ; i < TARGET_SITES .length ; i ++) {
5453 final String site = TARGET_SITES [i ];
5554 InternetObject obj = statusMap .get (site );
@@ -85,46 +84,60 @@ public void cancelled() {
8584
8685 private void sendCounterData () {
8786 try {
88- JSONObject rootJson = new JSONObject ();
89- JSONObject objectJson = new JSONObject ();
90- rootJson .put ("object" , objectJson );
91- objectJson .put ("host" , InetAddress .getLocalHost ().getHostName ());
92- objectJson .put ("name" , "Google_Timer" );
93- objectJson .put ("type" , "google" );
94- objectJson .put ("address" , InetAddress .getLocalHost ().getHostAddress ());
95-
96- JSONArray countersArray = new JSONArray ();
97- rootJson .put ("counters" , countersArray );
87+ JSONArray jsonArray = new JSONArray ();
9888 for (String key : statusMap .keySet ()) {
9989 InternetObject obj = statusMap .get (key );
90+ JSONObject element = null ;
91+ JSONObject objectJson = null ;
92+ JSONArray countersArray = null ;
10093 JSONObject counterJson = null ;
10194 switch (obj .status ) {
10295 case DONE :
96+ element = new JSONObject ();
97+ objectJson = new JSONObject ();
98+ element .put ("object" , objectJson );
99+ objectJson .put ("host" , InetAddress .getLocalHost ().getHostName ());
100+ objectJson .put ("name" , key .substring (key .lastIndexOf ("/" ) + 1 ));
101+ objectJson .put ("type" , "website" );
102+ objectJson .put ("address" , InetAddress .getLocalHost ().getHostAddress ());
103+ countersArray = new JSONArray ();
104+ element .put ("counters" , countersArray );
103105 counterJson = new JSONObject ();
104- counterJson .put ("name" , key . substring ( key . lastIndexOf ( "/" ) + 1 ) );
106+ counterJson .put ("name" , "WebTime" );
105107 counterJson .put ("value" , obj .endTime - obj .startTime );
108+ countersArray .put (counterJson );
106109 obj .status = WebStatusEnum .READY ;
107110 break ;
108111 case ING :
112+ element = new JSONObject ();
113+ objectJson = new JSONObject ();
114+ element .put ("object" , objectJson );
115+ objectJson .put ("host" , InetAddress .getLocalHost ().getHostName ());
116+ objectJson .put ("name" , key .substring (key .lastIndexOf ("/" ) + 1 ));
117+ objectJson .put ("type" , "website" );
118+ objectJson .put ("address" , InetAddress .getLocalHost ().getHostAddress ());
119+ countersArray = new JSONArray ();
120+ element .put ("counters" , countersArray );
109121 counterJson = new JSONObject ();
110- counterJson .put ("name" , key . substring ( key . lastIndexOf ( "/" ) + 1 ) );
122+ counterJson .put ("name" , "WebTime" );
111123 counterJson .put ("value" , System .currentTimeMillis () - obj .startTime );
124+ countersArray .put (counterJson );
112125 break ;
113126 case FAILED :
114127 obj .status = WebStatusEnum .READY ;
115128 break ;
116129 case READY :
117130 break ;
118131 }
119- if (counterJson != null ) {
120- countersArray .put (counterJson );
132+ if (element != null ) {
133+ jsonArray .put (element );
121134 }
122135 }
123136
124137 HttpResponse <JsonNode > response = Unirest .post ("http://127.0.0.1:6180/counter" )
125138 .header ("accept" , "application/json" )
126139 .header ("content-type" , "application/json" )
127- .body (rootJson ).asJson ();
140+ .body (jsonArray ).asJson ();
128141
129142 } catch (Exception e1 ) {
130143 e1 .printStackTrace ();
@@ -138,18 +151,15 @@ private void sendCounterData() {
138151 private static int registerMetadata () throws UnirestException {
139152 JSONObject rootJson = new JSONObject ();
140153 JSONObject objectJson = new JSONObject ();
141- objectJson .put ("type" , "google " );
142- objectJson .put ("display" , "Google Webtime " );
154+ objectJson .put ("type" , "website " );
155+ objectJson .put ("display" , "WebSite " );
143156 rootJson .put ("object" , objectJson );
144157 JSONArray counterArray = new JSONArray ();
145158 rootJson .put ("counters" , counterArray );
146- for (int i = 0 ; i < TARGET_SITES .length ; i ++) {
147- JSONObject counterMap = new JSONObject ();
148- counterArray .put (counterMap );
149- String site = TARGET_SITES [i ];
150- counterMap .put ("name" , site .substring (site .lastIndexOf ("/" ) + 1 ));
151- counterMap .put ("unit" , "ms" );
152- }
159+ JSONObject counterMap = new JSONObject ();
160+ counterArray .put (counterMap );
161+ counterMap .put ("name" , "WebTime" );
162+ counterMap .put ("unit" , "ms" );
153163
154164
155165 HttpResponse <JsonNode > response = Unirest .post ("http://127.0.0.1:6180/register" )
0 commit comments