From 5e08b08265345d56b7419150f40c3b3e23800409 Mon Sep 17 00:00:00 2001 From: kirthika Date: Sat, 19 Dec 1998 06:19:16 +0000 Subject: *** empty log message *** --- TAO/examples/POA/On_Demand_Loading/Makefile | 2 +- TAO/examples/POA/On_Demand_Loading/README | 47 +++--- .../POA/On_Demand_Loading/Servant_Activator.cpp | 2 + .../POA/On_Demand_Loading/Servant_Locator.cpp | 182 +++++++++++++++++++++ .../POA/On_Demand_Loading/Servant_Locator.h | 84 ++++++++++ TAO/examples/POA/On_Demand_Loading/run_test.pl | 65 ++++++++ TAO/examples/POA/On_Demand_Loading/server.cpp | 17 +- TAO/examples/POA/On_Demand_Loading/svc.conf | 49 ++++++ 8 files changed, 409 insertions(+), 39 deletions(-) create mode 100644 TAO/examples/POA/On_Demand_Loading/Servant_Locator.cpp create mode 100644 TAO/examples/POA/On_Demand_Loading/Servant_Locator.h create mode 100755 TAO/examples/POA/On_Demand_Loading/run_test.pl create mode 100644 TAO/examples/POA/On_Demand_Loading/svc.conf (limited to 'TAO/examples/POA') diff --git a/TAO/examples/POA/On_Demand_Loading/Makefile b/TAO/examples/POA/On_Demand_Loading/Makefile index 4e63c0efcf5..a4184f88b50 100644 --- a/TAO/examples/POA/On_Demand_Loading/Makefile +++ b/TAO/examples/POA/On_Demand_Loading/Makefile @@ -4,7 +4,7 @@ BIN = server -MYFILES = Servant_Activator #Servant_Locator +MYFILES = Servant_Activator Servant_Locator SRC = $(addsuffix .cpp,$(MYFILES)) $(addsuffix .cpp, $(BIN)) OBJ = $(addsuffix .o,$(MYFILES)) diff --git a/TAO/examples/POA/On_Demand_Loading/README b/TAO/examples/POA/On_Demand_Loading/README index 771098d78a1..47616d1a547 100644 --- a/TAO/examples/POA/On_Demand_Loading/README +++ b/TAO/examples/POA/On_Demand_Loading/README @@ -7,17 +7,23 @@ This example deals with dynamically loading servants in a POA. A POA configured with the USE_SERVANT_MANAGER policy value relies on an application supplied Servant Manager object to supply object/server -associations. If the POA has the RETAIN value for the servant +associations. + +If the POA has the RETAIN value for the servant retention, the POA expects the Servant Manager to supply the Servant -Activator interface. +Activator interface. When the POA is created with the NON RETAIN value +for servant retention, the Servant_Locator interface takes over. -In this example, the Servant Activator interface is used. The servant -is an dynamically linkable library Dir_Service. This is an servant -that provides directory assistance. +In this example, the Servant Activator as well as the Servant_Loactor +interfaces are used. The servant is an dynamically linkable library +which is loaded on demand. The case of the Servantor Activator once the +servant is loaded, the Object to Servant association is added to the +Actiove Object Map maintained by the POA. This association becomes +invalid when the POA is destroyed or/and the Object i sdeactivated. +On the other hand, the Servant_Locator is called per operation request +from the client and the associations too are made per request and the +servant is destroyed per request too. -The client asks for directory assistance and at the server end the -Servant Actiavtor loads the dynamic linkable library on demand, -obtains the servant object that then answers the client's request. Note that the server need not be built with the library. The library name and the factory method which will be used to obtain the servant @@ -28,27 +34,12 @@ server along with the library. Execution: --------- -There are two process: - -1. Server -- which will handle any requests for directory assistance. -2. client -- needs the directory assistance. - -So run the server first and then the client process. + Run the run_test_pl script. example: - - > server -f ior_file - The ior_file is a file which stores the IOR, that is - the object reference of the server which identifies it in the endsystem. - - - > client -f ior_file -x - The server IOR is read by the client so that the - request can be targetted to the server. The -x option shuts down the - server when its request is answered. - - On giving the -o option, the area codes are displayed as part - of a oneway directory service. - + run_test_pl -f ior_file +The output will demonstrate the different actions performed by the +Servant_Manager via the Servant_Activator and the Servant_Locator +interfaces. diff --git a/TAO/examples/POA/On_Demand_Loading/Servant_Activator.cpp b/TAO/examples/POA/On_Demand_Loading/Servant_Activator.cpp index 9323c8bb46c..e7fa97787d0 100644 --- a/TAO/examples/POA/On_Demand_Loading/Servant_Activator.cpp +++ b/TAO/examples/POA/On_Demand_Loading/Servant_Activator.cpp @@ -191,6 +191,8 @@ MyFooServantActivator::create_objectId (const char *libname, const char *factory ACE_OS::strcat (format_string, ":"); ACE_OS::strcat (format_string, factory_method); + // The object ID is created. + PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ( format_string); diff --git a/TAO/examples/POA/On_Demand_Loading/Servant_Locator.cpp b/TAO/examples/POA/On_Demand_Loading/Servant_Locator.cpp new file mode 100644 index 00000000000..b168e458fa8 --- /dev/null +++ b/TAO/examples/POA/On_Demand_Loading/Servant_Locator.cpp @@ -0,0 +1,182 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/tests/POA/On_Demand_Loading +// +// = FILENAME +// Servant_Locator.cpp +// +// = DESCRIPTION +// Implementation of MyFooServantLocator class, used with a POA +// having a NON_RETAIN policy. +// +// = AUTHOR +// Kirthika Parameswaran +// +// ============================================================================ + +#include "Servant_Locator.h" +#include "MyFooServant.h" + +ACE_RCSID(On_Demand_Activation, Servant_Locator, "$Id$") + +// Initialization. + +MyFooServantLocator::MyFooServantLocator (CORBA::ORB_ptr orb) + : counter_ (0), + orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +// This method associates an servant with the ObjectID. + +PortableServer::Servant +MyFooServantLocator::preinvoke (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr poa, + const char * /* operation */, + PortableServer::ServantLocator::Cookie &cookie, + CORBA::Environment &env) +{ + // Convert ObjectID to String. + + CORBA::String_var s = PortableServer::ObjectId_to_string (oid); + // If ObjectID string has a Foo Substring create and return a + // MyFooServant. + + PortableServer::Servant servant = this->invoke_servant (s.in (), + poa, + 27); + if (servant != 0) + { + // Return the servant as the cookie , used as a check when + // postinvoke is called on this MyFooServantLocator. + + cookie = servant; + return servant; + } + else + { + TAO_THROW_ENV_RETURN (CORBA::OBJECT_NOT_EXIST (CORBA::COMPLETED_NO), env, 0); + } +} + +// Since the servant gets invoked per operation, the servant has to be destroyed per operation too. +// This is accomplished in the postinvoke method. + +void +MyFooServantLocator::postinvoke (const PortableServer::ObjectId & /* oid */, + PortableServer::POA_ptr /* poa */, + const char * /* operation */, + PortableServer::ServantLocator::Cookie cookie, + PortableServer::Servant servant, + CORBA::Environment &/* env */) +{ + // Check the passed servant with the cookie. + + PortableServer::Servant my_servant = (PortableServer::Servant) cookie; + ACE_ASSERT (servant == my_servant); + delete servant; + + // To avoid warning about unused variable with ACE_NDEBUG. + ACE_UNUSED_ARG (my_servant); +} + +// This method loads the dynamically linked library which is the +// servant and returns the servant object which is then used for other +// operations in the library. + +PortableServer::Servant +MyFooServantLocator::invoke_servant (const char *str, + PortableServer::POA_ptr poa, + long value) +{ + // The string format is dllname:factory_method which needs to be parsed. + parse_string (str); + + // Now that the library name is available we open the library. + + int retval = dll_.open (dllname_); + if (retval != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "%p", dll_.error ()), + 0); + + // The next step is to obtain the symbol for the function that will + // create the servant object and return it to us. + Servant_Creator_Prototype servant_creator; + servant_creator = (Servant_Creator_Prototype) dll_.symbol (create_symbol_.in ()); + + // Checking whether it is possible to create the servant. + if (servant_creator == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "%s", + dll_.error ()), + 0); + + // Now create and return the servant. + return servant_creator (this->orb_.in (), poa, value); +} + + +// The objectID is in a format of library:factory_method which has to +// be parsed and separated into tokens to be used. + +void +MyFooServantLocator::parse_string (const char *s) +{ + // The format of the object library:factory_method. This string is + // parsed to obtain the library name and the function name which + // will create trhe servant and return it to us. + + char str[BUFSIZ],func[BUFSIZ], libname [BUFSIZ]; + char at[2]; + + at[0]= ':'; + at[1]= '\0'; + + ACE_OS::strcpy (func, ""); + + // As strtok () puts a NULL in the position after it gives back a + // token, we make two copies of the input string. + ACE_OS::strcpy (str, s); + + // The strtok() method returns the string until ':' i.e. the + // function name. + ACE_OS::strcpy (libname, ACE_OS::strtok (str, at)); + + // Get to ':' and make func point to the next location in the + // string. + ACE_OS::strcpy (func, ACE_OS::strchr (s,':') + 1); + + // Assign the respective strings obtained. + + this->dllname_ = CORBA::string_dup (libname); + this->create_symbol_ = CORBA::string_dup (func); + + ACE_DEBUG ((LM_DEBUG, + "the servant library:%s\n the factory_method:%s\n ", + this->dllname_.in (), + this->create_symbol_.in ())); +} + +// This method returns an ObjectId when given an library name and the factory method +// to be invoked in the library.The format of the ObjectId is libname:factory_method. + +PortableServer::ObjectId_var +MyFooServantLocator::create_objectId (const char *libname, const char *factory_method) +{ + char format_string [BUFSIZ]; + + ACE_OS::strcpy (format_string, libname); + ACE_OS::strcat (format_string, ":"); + ACE_OS::strcat (format_string, factory_method); + + // The object ID is created. + + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId ( format_string); + + return oid; +} diff --git a/TAO/examples/POA/On_Demand_Loading/Servant_Locator.h b/TAO/examples/POA/On_Demand_Loading/Servant_Locator.h new file mode 100644 index 00000000000..002b3f6719b --- /dev/null +++ b/TAO/examples/POA/On_Demand_Loading/Servant_Locator.h @@ -0,0 +1,84 @@ +// $Id$ + +//================================================================================ +// +// = LIBRARY +// TAO/tests/POA/On_Demand_Loading +// +// = FILENAME +// Servant_Locator.h +// +// = DESCRIPTION +// Defines a MyFooServantLocator class , used with a POA having +// a NON_RETAIN policy. +// +// = AUTHOR +// Kirthika Parameswaran +// +//================================================================================== + +#include "tao/corba.h" +#include "ace/DLL.h" + +class MyFooServantLocator : public POA_PortableServer::ServantLocator +{ + // = TITLE + // This class is used by a POA with USE_SERVANT_MANAGER and + // NON_RETAIN policy. +public: + + typedef PortableServer::Servant (*Servant_Creator_Prototype) (CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, CORBA::Long value); + // This typedef is used to typecast the void* obtained on finding a + // symbol in the library. + + MyFooServantLocator (CORBA::ORB_ptr orb); + // constructor + + virtual PortableServer::Servant preinvoke (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr adapter, + const char *operation, + PortableServer::ServantLocator::Cookie &the_cookie, + CORBA::Environment &env); + // This method is invoked by a POA whenever it receives a request + // for MyFoo object that is not currently active. + + virtual void postinvoke (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr adapter, + const char *operation, + PortableServer::ServantLocator::Cookie the_cookie, + PortableServer::Servant the_servant, + CORBA::Environment &env); + // This method is invoked whenever a MyFooServant completes a + // request. + + PortableServer::ObjectId_var create_objectId (const char *libname, const char *factory_method); + // Returns an ObjectId when given an library name and the factory method to be invoked in the library. + +private: + + PortableServer::Servant invoke_servant (const char *str, + PortableServer::POA_ptr poa, + long value); + // Gets the servant on the preinvoke call by loading the appropriate library + // and getting the servant object. + + void parse_string (const char* s); + // Parse the string to obtain the library name and the symbol which + // will get us the servant pointer. + + int counter_; + // Counter for number of invocations of this. + + CORBA::ORB_var orb_; + // A reference to the ORB. + + CORBA::String_var dllname_; + // The name of the library containing the servant. + + CORBA::String_var create_symbol_; + // The symbol which on getting invoked will give us the servant + // pointer. + + ACE_DLL dll_; + // The library object. +}; diff --git a/TAO/examples/POA/On_Demand_Loading/run_test.pl b/TAO/examples/POA/On_Demand_Loading/run_test.pl new file mode 100755 index 00000000000..5eb668406b1 --- /dev/null +++ b/TAO/examples/POA/On_Demand_Loading/run_test.pl @@ -0,0 +1,65 @@ +#$Id$ +# -*- perl -*- +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +unshift @INC, '../../../../../ACE_wrappers/build/Sun_g++/bin'; +require ACEutils; + +$iorfile = "ior"; + +$oneway = ""; +$iterations = 100; + +# Parse the arguments +for ($i = 0; $i <= $#ARGV; $i++) +{ + SWITCH: + { + if ($ARGV[$i] eq "-h" || $ARGV[$i] eq "-?") + { + print "run_test [-h] [-i iterations] [-o] [-f ior file]\n"; + print "\n"; + print "-h -- prints this information\n"; + print "-f -- ior file\n"; + print "-i iterations -- specifies iterations\n"; + print "-o -- call issued are oneways\n"; + exit; + } + if ($ARGV[$i] eq "-o") + { + $oneway = "-o"; + last SWITCH; + } + if ($ARGV[$i] eq "-i") + { + $iterations = $ARGV[$i + 1]; + $i++; + last SWITCH; + } + if ($ARGV[$i] eq "-f") + { + $iorfile = $ARGV[$i + 1]; + $i++; + last SWITCH; + } + print "run_test: Unknown Option: ".$ARGV[$i]."\n"; + } +} + +$iorfile_1 = $iorfile."_1"; +$iorfile_2 = $iorfile."_2"; + +$SV = Process::Create ($EXEPREFIX."server$Process::EXE_EXT", "-f $iorfile"); + +ACE::waitforfile ($iorfile_1); +ACE::waitforfile ($iorfile_2); + +$status = system ("../Generic_Servant/client$Process::EXE_EXT $oneway -i $iterations -f $iorfile_1"); +$status = system ("../Generic_Servant/client$Process::EXE_EXT $oneway -i $iterations -f $iorfile_2 -x"); + +unlink $iorfile_1; +unlink $iorfile_2; + +exit $status; diff --git a/TAO/examples/POA/On_Demand_Loading/server.cpp b/TAO/examples/POA/On_Demand_Loading/server.cpp index a76dda0c63d..03ad458e4de 100644 --- a/TAO/examples/POA/On_Demand_Loading/server.cpp +++ b/TAO/examples/POA/On_Demand_Loading/server.cpp @@ -9,13 +9,13 @@ // Server to test the Servant Activator and Servant Locator for a POA. // // =AUTHOR -// Irfan Pyarali +// Kirthika Parameswaran // //============================================================================= #include "ace/streams.h" #include "Servant_Activator.h" -//#include "Servant_Locator.h" +#include "Servant_Locator.h" ACE_RCSID(On_Demand_Activation, server, "$Id$") @@ -267,9 +267,6 @@ main (int argc, char **argv) PortableServer::ObjectId_var first_foo_oid = servant_activator_impl.create_objectId ("MyFoo","create_MyFoo"); - // PortableServer::ObjectId_var first_foo_oid = - // PortableServer::string_to_ObjectId ("MyFoo:create_MyFoo"); - CORBA::Object_var first_foo = first_poa->create_reference_with_id (first_foo_oid.in (), "IDL:Foo:1.0", env); @@ -279,9 +276,9 @@ main (int argc, char **argv) return -1; } - /* MyFooServantLocator servant_locator_impl (orb.in ()); - PortableServer::ServantLocator_var servant_locator = - servant_locator_impl._this (env); + MyFooServantLocator servant_locator_impl (orb.in ()); + PortableServer::ServantLocator_var servant_locator = + servant_locator_impl._this (env); if (env.exception () != 0) { @@ -299,12 +296,12 @@ main (int argc, char **argv) env.print_exception ("PortableServer::POAManager::set_servant_manager"); return -1; } - */ + // Try to create a reference with user created ID in second_poa // which uses MyFooServantLocator. PortableServer::ObjectId_var second_foo_oid = - PortableServer::string_to_ObjectId ("secondFoo"); + servant_locator_impl.create_objectId ("MyFoo","create_MyFoo"); CORBA::Object_var second_foo = second_poa->create_reference_with_id (second_foo_oid.in (), diff --git a/TAO/examples/POA/On_Demand_Loading/svc.conf b/TAO/examples/POA/On_Demand_Loading/svc.conf new file mode 100644 index 00000000000..43c6a486c92 --- /dev/null +++ b/TAO/examples/POA/On_Demand_Loading/svc.conf @@ -0,0 +1,49 @@ +# $Id$ +# +# This file contains a sample ACE_Service_Config configuration +# file specifying the strategy factories utilized by an application +# using TAO. There are currently only two possible factories: +# Client_Strategy_Factory and Server_Strategy_Factory. These names +# must be used as the second argument to their corresponding line, +# because that's what the ORB uses to find the desired factory. +# +# Note that there are two unordinary characteristics of the way *this* +# file is set up: +# - both client and server strategies are specified in the same +# file, which would only make sense for co-located clients & servers +# - both of the factories are actually sourced out of libTAO.so +# (TAO.DLL on Win32), and they would normally be in a separate +# dll from the TAO ORB Core. +# +# The options which can be passed to the Resource Factory are: +# +# -ORBresources +# where can be 'global' to specify globally-held resources, +# or 'tss' to specify thread-specific resources. +# +# The options which can be passed to the Client are: +# +# +# The options which can be passed to the Server are: +# +# -ORBconcurrency +# where can be 'thread-per-connection' to specify +# use of the ACE_Threaded_Strategy concurrency strategy, +# or 'reactive' to specify use of the ACE_Reactive_Strategy +# concurrency strategy. +# +# -ORBthreadflags +# specifies the default thread flags to use, where is a +# logical OR'ing of the flags THR_DETACHED, THR_BOUND, THR_NEW_LWP, +# THR_SUSPENDED, or THR_DAEMON. Note that not every flag may be valid +# on every platform. +# +# -ORBdemuxstrategy +# where can be one of 'dynamic', 'linear', 'active', or 'user', +# and specifies the type of object lookup strategy used internally. +# -ORBtablesize +# specifies the size of the object table +# +dynamic Resource_Factory Service_Object * TAO:_make_TAO_Resource_Factory() "-ORBresources global" +dynamic Client_Strategy_Factory Service_Object * TAO:_make_TAO_Default_Client_Strategy_Factory() +dynamic Server_Strategy_Factory Service_Object * TAO:_make_TAO_Default_Server_Strategy_Factory() "-ORBconcurrency reactive -ORBdemuxstrategy dynamic -ORBtablesize 128" -- cgit v1.2.1