Author: saminda
Date: Thu Jan 24 01:09:56 2008
New Revision: 12810

Log:

d or uuid that send with the announcement when fetch or re-fetch the url in
     *                     ?start or ?refresh query parameter iff id is not NULL


Modified:
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/announcement/Announcement.java

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/announcement/Announcement.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/announcement/Announcement.java
  (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/announcement/Announcement.java
  Thu Jan 24 01:09:56 2008
@@ -38,9 +38,19 @@
     private static long TTL = 1000 * 60 * 60 * 24;
 
     /**
+     * Refresh query parameter.
+     */
+    private static String REFRESH = "refresh";
+
+    /**
+     * Strat query parameter.
+     */
+    private static String START = "start";
+
+    /**
      * This method will return a string based on the "announcement" URL. 
Following is the state
      * space associated with this method.
-     *
+     * <p/>
      * Internally content will be obtain by HTTP GET interface. If the process 
is executed
      * successfully the return string will be cached in announcementCache with 
the key
      * "announcement". For all successive similar announcement urls, if 
content is available in
@@ -49,32 +59,34 @@
      * result with in the system will cause to send back NULL object for the 
given "announcement".
      * In this implementation, error will not be recorded.
      *
+     * @param id           id or uuid that send with the announcement when 
fetch or re-fetch the url in
+     *                     ?start or ?refresh query parameter iff id is not 
NULL
      * @param announcement URL to be located
      * @return String {Serialized XML}
      */
-    public String get(String announcement) {
+    public String get(String id, String announcement) {
         if (announcementCache.containsKey(announcement)) {
             URLContent urlContent = announcementCache.get(announcement);
             long lastModifiedTime = urlContent.getLastModifiedTime();
             long currentTime = System.currentTimeMillis();
             if (currentTime - lastModifiedTime > TTL) {
-                //new one
-                return createContent(announcement);
+                //re-fetch
+                return createContent(id, REFRESH, announcement);
             } else {
                 // send the old one;
                 return urlContent.getCachedContent();
             }
         } else {
-            // brand new one;
-            return createContent(announcement);
+            // fetch brand new one;
+            return createContent(id, START, announcement);
         }
     }
 
-    private String createContent(String announcement) {
+    private String createContent(String id, String queryParam, String 
announcement) {
         long currentTime = System.currentTimeMillis();
         String urlContentString;
         try {
-            urlContentString = getUrlContent(announcement);
+            urlContentString = getUrlContent(id, queryParam,announcement);
             if (urlContentString == null) {
                 return null;
             }
@@ -86,8 +98,14 @@
         }
     }
 
-    private String getUrlContent(String url) throws IOException {
-        URL announcementURL = new URL(url);
+    private String getUrlContent(String id, String queryParam, String url) 
throws IOException {
+        String tmpUrl;
+        if (id != null && id.length() != 0) {
+            tmpUrl = url + "?" + queryParam + "=" + id;
+        } else {
+            tmpUrl = url;
+        }
+        URL announcementURL = new URL(tmpUrl);
         HttpURLConnection httpCon;
         URLConnection urlConnection = announcementURL.openConnection();
         if (urlConnection instanceof HttpURLConnection) {
@@ -116,7 +134,7 @@
         byte[] buffer = new byte[1024];
         int c;
         while ((c = in.read(buffer)) != -1) {
-           bos.write(buffer,0,c);
+            bos.write(buffer, 0, c);
         }
         return new String(bos.toByteArray());
     }

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to