objects name resgistration patch, useful with the nameserver



Hi,

we have developed a system to register a object using a name. this way you
can register the NameService in an ORB and access it using a fixed corbaloc.
The CORBA key is replaced with the name of the object:

        corbaloc:iiop:1 2 localhost:4444/NameService
	
	The easiest way to test it is to execute the orbit-name-server-2
with a key:

./orbit-name-server-2 --key=NameService --ORBIIOPIPv4=1
-ORBIIOPIPName=localhost+-ORBIIOPIPSock=4444 -ORBIIOPUNIX=0 -ORBCorbaloc=1

Afterwards execute the name-resolve example to test the connection, you can
use the orbit name-server examples:

./name-resolve-server
-ORBNamingIOR=corbaloc:iiop:1 2 localhost:4444/NameService
./name-resolve-client
-ORBNamingIOR=corbaloc:iiop:1 2 localhost:4444/NameService
We have been using it for 2 months without problem. I've also attached a
script to start the orbit-name-server-2, it is implemented to be installed
on debian.

We also want to acknowledge Frank for his help developing this patch ;-).

We wope this patch helps somebody.

-- 

Alejandro García Castro
mailto: acastro igalia com
http://www.igalia.com
#!/bin/sh
#
# This  shell script  takes care  of starting  and stopping  the build
# process on  dedicated build  machines. It lives  in /etc/init.d
# and follows the Debian Linux  conventions for rc scripts.  Modify it
# to suit your local conventions.
#

# description: Corba name server, you have to install an orbit release that
# allows you to register a key object with a name 

HOST_NAME=localhost
PORT=4444
NAME_SERVER=/usr/bin/orbit-name-server-2

name_server_args="--key=NameService -ORBIIOPIPv4=1 \
-ORBIIOPIPName=$HOST_NAME -ORBIIOPIPSock=$PORT \
-ORBCorbaloc=1 -ORBIIOPUNIX=0"

[ -x $NAME_SERVER ] || exit 0

case "$1" in
  start)
	echo -n "Starting Orbit Name server: "
	echo $NAME_SERVER
	start-stop-daemon --start --background --exec $NAME_SERVER \
	                  -- $name_server_args
	echo "started."
	;;
  stop)
	echo -n "Stopping Orbit Name server:  "
	killall $NAME_SERVER
	echo "stopped."
	;;
   *)
    	echo "Usage: orbit_name_server_init {start|stop}"
	exit 1
esac

exit 0


Index: include/orbit/orb-core/corba-orb-type.h
===================================================================
RCS file: /cvs/gnome/ORBit2/include/orbit/orb-core/corba-orb-type.h,v
retrieving revision 1.19
diff -u -r1.19 corba-orb-type.h
--- include/orbit/orb-core/corba-orb-type.h	4 Apr 2003 01:40:35 -0000	1.19
+++ include/orbit/orb-core/corba-orb-type.h	19 Aug 2004 12:00:23 -0000
@@ -67,6 +67,7 @@
 	GSList                         *servers;
 	GSList                         *profiles;
 	GPtrArray                      *adaptors;
+	GHashTable                     *forw_binds;
 	GSList                         *current_invocations;
 	gpointer                        default_ctx;
 	GHashTable                     *initial_refs;
Index: src/orb/orb-core/corba-object.c
===================================================================
RCS file: /cvs/gnome/ORBit2/src/orb/orb-core/corba-object.c,v
retrieving revision 1.104
diff -u -r1.104 corba-object.c
--- src/orb/orb-core/corba-object.c	13 Aug 2004 10:37:27 -0000	1.104
+++ src/orb/orb-core/corba-object.c	19 Aug 2004 12:00:24 -0000
@@ -353,6 +353,9 @@
 	OBJECT_LOCK (obj);
 	IOP_delete_profiles (obj->orb, &obj->forward_locations);
 	obj->forward_locations = profiles;
+
+	giop_connection_unref (obj -> connection);
+	obj -> connection = NULL;
 	OBJECT_UNLOCK (obj);
 
 	retval = ORBit_object_get_connection (obj);
Index: src/orb/orb-core/corba-orb.c
===================================================================
RCS file: /cvs/gnome/ORBit2/src/orb/orb-core/corba-orb.c,v
retrieving revision 1.104
diff -u -r1.104 corba-orb.c
--- src/orb/orb-core/corba-orb.c	8 May 2004 20:42:19 -0000	1.104
+++ src/orb/orb-core/corba-orb.c	19 Aug 2004 12:00:24 -0000
@@ -389,6 +389,13 @@
 	retval->default_giop_version = GIOP_LATEST;
 
 	retval->adaptors = g_ptr_array_new ();
+
+	/* init the forward bind hashtable*/
+	retval->forw_binds = g_hash_table_new_full (
+		g_str_hash, g_str_equal,
+		g_free,
+		NULL); 
+
 	ORBit_init_internals (retval, ev);
 	/* FIXME, handle exceptions */ 
 
@@ -1227,6 +1234,9 @@
 		}
 	}
 
+	/* destroy the forward bind hashtable*/
+	g_hash_table_destroy (orb->forw_binds);
+	
 	orb->life_flags |= ORBit_LifeF_Destroyed;
 
 	ORBit_RootObject_release (orb);
@@ -1295,7 +1305,13 @@
 		     CORBA_Object                obj,
 		     CORBA_Environment          *ev)
 {
-	g_warning ("ORBit_ORB_forw_bind NYI");
+	
+	if (obj)
+		g_hash_table_insert (orb->forw_binds, objkey->_buffer, obj);
+	else {
+		g_hash_table_remove(orb->forw_binds, objkey->_buffer);
+	}
+	
 }
 
 gboolean
Index: src/orb/poa/orbit-adaptor.c
===================================================================
RCS file: /cvs/gnome/ORBit2/src/orb/poa/orbit-adaptor.c,v
retrieving revision 1.26
diff -u -r1.26 orbit-adaptor.c
--- src/orb/poa/orbit-adaptor.c	9 Feb 2004 20:24:17 -0000	1.26
+++ src/orb/poa/orbit-adaptor.c	19 Aug 2004 12:00:25 -0000
@@ -173,6 +173,38 @@
 	return adaptor;
 }
 
+static CORBA_Object
+ORBit_forw_bind_find (CORBA_ORB orb, ORBit_ObjectKey *objkey)
+{
+	CORBA_Object object = NULL;
+	gchar *objectId = (gchar *) g_malloc0 (sizeof(gchar)*objkey->_length);
+
+	if (!objkey)
+		return NULL;
+
+	memcpy (objectId, objkey->_buffer, objkey->_length);
+
+	LINK_MUTEX_LOCK (ORBit_RootObject_lifecycle_lock);
+	{
+		const gchar *typeid;
+		object = g_hash_table_lookup (orb->forw_binds, objectId);
+		
+		if (object) {
+			typeid = g_quark_to_string (object->type_qid);
+			if (!typeid) {
+				g_assert(g_hash_table_remove(orb->forw_binds,
+							     objectId));
+				object = NULL;
+			}
+		}
+	}
+	LINK_MUTEX_UNLOCK (ORBit_RootObject_lifecycle_lock);
+	
+	g_free (objectId);
+	
+	return object;
+}
+ 
 void
 ORBit_handle_locate_request (CORBA_ORB orb, GIOPRecvBuffer *recv_buffer)
 {
@@ -221,26 +253,44 @@
 	adaptor = ORBit_adaptor_find (orb, objkey);
 
 	if (!adaptor || !objkey) {
-		CORBA_Environment env;
-
-		CORBA_exception_init (&env);
-
-		tprintf ("Error: failed to find adaptor or objkey for "
-			 "object while invoking method '%s'",
-			 giop_recv_buffer_get_opname (recv_buffer));
+		CORBA_Object forw_obj = ORBit_forw_bind_find (orb, objkey);
+		if (forw_obj) {			
+			GIOPSendBuffer *send_buffer = 
+				giop_send_buffer_use_reply
+				(recv_buffer->giop_version,
+				 giop_recv_buffer_get_request_id (recv_buffer),
+				 GIOP_LOCATION_FORWARD);
+			
+			ORBit_marshal_object(send_buffer, forw_obj);
+
+			giop_send_buffer_write (send_buffer, recv_buffer->connection, FALSE);
+			giop_send_buffer_unuse (send_buffer);
+
+			giop_recv_buffer_unuse (recv_buffer);
+		}
+		else {
+			
+			CORBA_Environment env;
+			
+			CORBA_exception_init (&env);
+
+			tprintf ("Error: failed to find adaptor or objkey for "
+				 "object while invoking method '%s'",
+				 giop_recv_buffer_get_opname (recv_buffer));
+		
+			CORBA_exception_set_system (
+				&env, ex_CORBA_OBJECT_NOT_EXIST, 
+				CORBA_COMPLETED_NO);
+			ORBit_recv_buffer_return_sys_exception (recv_buffer, &env);
+			
+			CORBA_exception_free (&env);
+		}
 		
-		CORBA_exception_set_system (
-			&env, ex_CORBA_OBJECT_NOT_EXIST, 
-			CORBA_COMPLETED_NO);
-		ORBit_recv_buffer_return_sys_exception (recv_buffer, &env);
-
-		CORBA_exception_free (&env);
-
 	} else {
 		dprintf (MESSAGES, "p %d: handle request '%s'\n",
 			 getpid (),
 			 giop_recv_buffer_get_opname (recv_buffer));
-
+		
 		adaptor->handle_request (adaptor, recv_buffer, objkey);
 	}
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]