]> rtime.felk.cvut.cz Git - frescor/forb.git/commitdiff
Added function for checking for stale object references
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 24 Oct 2008 18:06:05 +0000 (20:06 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 24 Oct 2008 18:06:05 +0000 (20:06 +0200)
It is called forb_object_is_stale()

src/forb.c
src/forb.h

index b37986ed6a1a04b97fab31afb38ed48da8517ffd..47ea6a8d9019aafc17d9aa51d1b3a22445d9d1b6 100644 (file)
@@ -258,6 +258,42 @@ forb_server_id_init(forb_server_id *server_id)
        forb_uuid_generate((forb_uuid_t*)server_id->uuid);
 }
 
+/** 
+ * Checks whether the @a object is stale. Stale object is an object
+ * reference whose server cannot be contacted to handle requests.
+ * 
+ * @param object Object reference to check.
+ * 
+ * @return True if the object is stale, false otherwise.
+ */
+bool forb_object_is_stale(forb_object object)
+{
+       forb_orb remote_orb;
+       struct forb_env env;
+       bool stale = true;
+       
+       remote_orb = forb_get_orb_of(object);
+       if (!remote_orb) {      /* This shohuld never happen */
+               goto err;
+       }
+       /* TODO: Check not only the ORB, but also whether the object
+        * is still registered with the remote orb. */
+       forb_orb_is_alive(remote_orb, &env);
+       if (env.major == FORB_EX_COMM_FAILURE) {
+               /* Orb is not alive */
+               stale = true;
+       } else {
+               if (forb_exception_occured(&env)) {
+                       ul_logerr("%s: unexpected exception: %s\n", __FUNCTION__, forb_strerror(&env));
+               }
+               stale = false;  
+       }
+
+       forb_object_release(remote_orb);
+err:
+       return stale;
+}
+
 /** 
  * 
  * 
@@ -301,8 +337,6 @@ replace_regref_if_stale(forb_orb orb, const char *fn, const char *objref)
        int fd, ret = 0; 
        char str[100];
        forb_object object;
-       forb_orb remote_orb;
-       CORBA_Environment env;
        
        fd = open(fn, O_RDWR);
        if (fd < 0) {
@@ -323,25 +357,14 @@ replace_regref_if_stale(forb_orb orb, const char *fn, const char *objref)
                /* We are done for now */
                goto unlock_err;
        }
-       remote_orb = forb_get_orb_of(object);
-       if (!remote_orb) {      /* This shohuld never happen */
-               ret = -1;
-               goto object_release_err;
-       }
-       forb_orb_is_alive(remote_orb, &env);
-       if (env.major == FORB_EX_COMM_FAILURE) {
+       if (forb_object_is_stale(object)) {
                /* Orb is not alive */
-               rewrite_regref(fd, objref);
+               ret = rewrite_regref(fd, objref);
        } else {
-               if (forb_exception_occured(&env)) {
-                       ul_logerr("%s: unexpected exception: %s\n", __FUNCTION__, forb_strerror(&env));
-               }
                /* Reference's FORB is alive :-( */
                ret = 1;        
        }
 
-       forb_object_release(remote_orb);
-object_release_err:
        forb_object_release(object);
 unlock_err:    
        lockf(fd, F_ULOCK, 0);
@@ -501,6 +524,11 @@ forb_resolve_reference(const forb_orb orb, const char *name)
        str[ret] = '\0';
        object = forb_string_to_object(orb, str);
        close(fd);
+
+       if (forb_object_is_stale(object)) {
+               forb_object_release(object);
+               object = NULL;
+       }
        
        return object;
 }
index 0824bb1123f037cca4391fb144a76fa00cc95e93..52a6cbd364fe183d93f4a04108821bf726ffd1a8 100644 (file)
@@ -199,6 +199,8 @@ forb_string_to_object(const forb_orb orb, const char *string);
 char *
 forb_object_to_string(const forb_object obj);
 
+bool forb_object_is_stale(forb_object object);
+
 forb_orb
 forb_get_orb_of(const forb_object obj);