Exemple #1
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  try
   {
     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    if (parse_args (argc, argv) != 0)
      return 1;

   CORBA::Object_var rootObj = orb->resolve_initial_references("NameService");

     CosNaming::NamingContext_var rootNC =
       CosNaming::NamingContext::_narrow(rootObj.in());

     // Get reference to Root POA.
     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");

     PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

     // Activate POA manager
     PortableServer::POAManager_var mgr = poa->the_POAManager();

     mgr->activate();

     // Create an object
     PortableServer::Servant_var<Messenger_i> messenger_servant =
       new Messenger_i(orb.in());

     Messenger_var messenger = messenger_servant->_this();

     CosNaming::Name name;
     name.length (1);
     name[0].id = CORBA::string_dup("MessengerService");

     rootNC->rebind(name, messenger.in());

     CORBA::String_var str = orb->object_to_string (messenger.in());
     std::ofstream iorFile (ACE_TEXT_ALWAYS_CHAR(ior_output_file));
     iorFile << str.in () << std::endl;
     iorFile.close ();
     std::cout << "IOR written to file " << ior_output_file << std::endl;

     // Accept requests
     orb->run();
   }
  catch(const CORBA::Exception& ex)
  {
    std::cerr << "MessengerServer::Caught exception: " << ex << std::endl;
    return 1;
  }

 return 0;
}
Exemple #2
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) {
  try {
    if (argc <= 1) {
      std::cerr << "Error: Must specify the name of an IOR file." << std::endl;
      return 1;
    }
    ACE_TString ior = ACE_TEXT("file://");
    ior += argv[1];

    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    CORBA::Object_var obj = orb->string_to_object(ior.c_str());

    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Unable to get a Messenger reference." << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup("Hello!");
    messenger->send_message("TAO User", "TAO Test", message.inout());
    std::cout << "message was sent" << std::endl;
    std::cout << "Reply was : " << message.in() << std::endl;

    return 0;
  } catch(const CORBA::Exception& ex) {
    std::cerr << "Client main() Caught Exception: " << ex << std::endl;
  }
  return 1;
}
Exemple #3
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    //Get reference to Root POA
    CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
    PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );

    // Activate POA Manager
    PortableServer::POAManager_var mgr = poa->the_POAManager();
    mgr->activate();


    // Find the Naming Service
    obj = orb->resolve_initial_references("NameService");
    CosNaming::NamingContext_var root =
      CosNaming::NamingContext::_narrow(obj.in());
    if (CORBA::is_nil(root.in())) {
      std::cerr << "Nil Naming Context reference" << std::endl;
      return 1;
    }

    // Bind the example Naming Context, if necessary
    CosNaming::Name name;
    name.length( 1 );
    name[0].id = CORBA::string_dup("example");
    try {
      obj = root->resolve(name);
    }
    catch(const CosNaming::NamingContext::NotFound&) {
      CosNaming::NamingContext_var dummy = root->bind_new_context(name);
    }

    // Bind the Messenger object
    name.length(2);
    name[1].id = CORBA::string_dup("Messenger");

    // Create an object
    PortableServer::Servant_var<Messenger_i> servant = new Messenger_i;
    PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
    obj = poa->id_to_reference(oid.in());
    Messenger_var messenger = Messenger::_narrow(obj.in());
    root->rebind(name, messenger.in());

    std::cout << "Messenger object bound in Naming Service" << std::endl;

    // Accept requests
    orb->run();
    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "server: Caught a CORBA::Exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
    try
    {
        // Initialize orb
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

        CORBA::Object_var rootObj =
            orb->resolve_initial_references("NameService");

        CosNaming::NamingContext_var rootContext =
            CosNaming::NamingContext::_narrow(rootObj.in());

        CosNaming::Name name;
        name.length (1);
        name[0].id = CORBA::string_dup ("MessengerService");

        CORBA::Object_var messengerObj = rootContext->resolve(name);

        if (CORBA::is_nil(messengerObj.in())) {
            std::cerr << "Nil Messenger reference" << std::endl;
            return 1;
        }

        // Narrow
        Messenger_var messenger = Messenger::_narrow(messengerObj.in());
        if (CORBA::is_nil(messenger.in ())) {
            std::cerr << "Argument is not a Messenger reference" << std::endl;
            return 1;
        }

        CORBA::String_var message = CORBA::string_dup(
                                        "We are experiencing network problems.");
        messenger->send_message ("*****@*****.**",
                                 "urgent",
                                 message.inout());

        message = CORBA::string_dup("Where can I get TAO?");
        messenger->send_message ("*****@*****.**",
                                 "OCI's Distribution of TAO",
                                 message.inout());

        message = CORBA::string_dup(
                      "Please contact [email protected] regarding your request.");
        messenger->send_message ("*****@*****.**",
                                 "OCI's Distribution of TAO",
                                 message.inout());

    }
    catch(const CORBA::Exception& ex) {
        std::cerr << "Caught a CORBA exception: " << ex << std::endl;
        return 1;
    }

    std::cout << "MessengerClient: success" << std::endl;
    return 0;
}
Exemple #5
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    // Find the Naming Service
    CORBA::Object_var naming_obj = orb->resolve_initial_references("NameService");
    CosNaming::NamingContextExt_var root =
      CosNaming::NamingContextExt::_narrow(naming_obj.in());
    if (CORBA::is_nil(root.in())) {
      std::cerr << "Nil Naming Context reference" << std::endl;
      return 1;
    }

    // Resolve the Messenger object
    CosNaming::Name name;
    name.length( 2 );
    name[0].id = CORBA::string_dup( "example" );
    name[1].id = CORBA::string_dup( "Messenger" );
    CORBA::Object_var obj = CORBA::Object::_nil();
    while (CORBA::is_nil(obj.in())) {
      try {
        obj = root->resolve_str("example/Messenger");
      } catch (const CosNaming::NamingContext::NotFound&) {
        // Sleep for a second and try again
        ACE_OS::sleep(1);
      }
    }

    // Narrow the Messenger object reference
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup("Hello!");

    // Send a message
    messenger->send_message("TAO User", "TAO Test", message.inout());

    std::cout << "Message was sent" << std::endl;

    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Caught a CORBA exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemple #6
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{

  // Detection of closed on read currently not working certain platforms.
#if defined (sun) || defined (AIX) || defined (__FreeBSD_version)
  return 2;
#endif

  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    // Destringify ior
    CORBA::Object_var obj = orb->string_to_object( ior );
    if (CORBA::is_nil(obj.in())) {
      std::cerr << "Nil Messenger reference" << std::endl;
      return 1;
    }

    // Narrow
    Messenger_var messenger = Messenger::_narrow( obj.in() );
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Argument is not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup( "Hello!" );

    messenger->send_message( "TAO User", "Test 1", message.inout() );

    // Force server to abort to verify it will be brought
    // back up when send_message() is called.
    messenger->abort(2);
    ACE_OS::sleep(seconds_between_requests);

    ACE_DEBUG ((LM_INFO,
                "(%P|%t) - Sending another message after abort of server\n"));

    messenger->send_message( "TAO User", "Test 2", message.inout() );

    std::cout << "messages were sent" << std::endl;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Client main() Caught CORBA::Exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemple #7
0
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
  try {
    // Initialize the ORB
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    if (parse_args (argc, argv) != 0)
      return 1;

    // Create a smart proxy factory.  It will register itself with the
    // smart proxy factory adapter so it can be used to create
    // Messenger proxies.  It must be created on the heap, but is
    // otherwise unused here.
    new Smart_Messenger_Proxy_Factory(orb.in());

    // Convert the contents of the Messenger.ior file to an object reference.
    CORBA::Object_var obj = orb->string_to_object(ior);
    if (CORBA::is_nil(obj.in())) {
      std::cerr << "Nil Messenger reference" << std::endl;
      return 1;
    }

    // Narrow the object reference to a Messenger object reference.
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Not a Messenger object reference" << std::endl;
      return 1;
    }

    // Create a message and send it to the Messenger.
    CORBA::String_var message = CORBA::string_dup("Hello!");
    messenger->send_message ("TAO User", "TAO Test", message.inout());
    std::cout << "Message was sent" << std::endl;

    // Release resources.
    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Caught a CORBA exception: " << ex << std::endl;
    return 1;
  }
  catch(...) {
    std::cerr << "Caught an unknown exception type" << std::endl;
    return 1;
  }

  return 0;
}
Exemple #8
0
void
ClientInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info)
{
  // Find the Naming Service
  CORBA::Object_var naming_obj =
    info->resolve_initial_references("NameService");
  CosNaming::NamingContext_var root =
    CosNaming::NamingContext::_narrow(naming_obj.in());
  if( CORBA::is_nil(root.in())) {
    std::cerr << "Nil Naming Context reference" << std::endl;
    ACE_ASSERT(false);
  }

  // Resolve the Messenger object
  CosNaming::Name name;
  name.length( 1 );
  name[0].id = CORBA::string_dup( "Messenger" );
  CORBA::Object_var obj = CORBA::Object::_nil();
  while ( CORBA::is_nil( obj.in() ) ) {
    try {
      obj = root->resolve( name );
    } catch (const CosNaming::NamingContext::NotFound&) {
      // Sleep for a second and try again
      ACE_OS::sleep(1);
    }
   }

  Messenger_var messenger = Messenger::_narrow( obj.in() );
  if( CORBA::is_nil( messenger.in() ) ) {
    std::cerr << "Not a Messenger reference" << std::endl;
    ACE_ASSERT(false);
  }

  // allocate slot
  slot_ = info->allocate_slot_id();

  // get PICurrent
  CORBA::Object_var current_obj = info->resolve_initial_references("PICurrent");

  current_ =
    PortableInterceptor::Current::_narrow(current_obj.in());

  // Create and register the request interceptors.
  PortableInterceptor::ClientRequestInterceptor_var ci =
      new ClientInterceptor(messenger, current_.in(), slot_);
  info->add_client_request_interceptor (ci.in());
}
Exemple #9
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    if (parse_args (argc, argv) != 0)
      return 1;

    // Get reference to Root POA.
    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

    // Activate POA manager
    PortableServer::POAManager_var mgr = poa->the_POAManager();
    mgr->activate();

    // Create an object
    PortableServer::Servant_var<Messenger_i> messenger_servant =
      new Messenger_i;

    // Write its stringified reference to a file
    PortableServer::ObjectId_var oid = poa->activate_object(messenger_servant.in());
    obj = poa->id_to_reference(oid.in());
    Messenger_var messenger = Messenger::_narrow(obj.in());
    CORBA::String_var str = orb->object_to_string(messenger.in());
    std::ofstream fout(ACE_TEXT_ALWAYS_CHAR(ior_output_file));
    fout << str.in() << std::endl;
    fout.close();
    std::cout << "IOR written to file " << ACE_TEXT_ALWAYS_CHAR(ior_output_file) << std::endl;

    // Accept requests
    orb->run();
    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "CORBA::Exception " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemple #10
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    // Find the Naming Service  & the Message Server name in it
    CORBA::Object_var obj = orb->string_to_object(ior_input_file);

    // Narrow
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup("Hello!");
    messenger->send_message( "TAO User", "TAO Test", message.inout());

    std::cout << "Message was sent" << std::endl;

    std::cout << "Now try the same thing with the simple name." << std::endl;
    obj = orb->resolve_initial_references("NameService");
    CosNaming::NamingContextExt_var root =
      CosNaming::NamingContextExt::_narrow(obj.in());
    obj = root->resolve_str("Simple/Messenger");
    messenger = Messenger::_narrow(obj.in());
    messenger->send_message( "ACE User", "TAO Test", message.inout());

    std::cout << "Message was sent" << std::endl;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Caught a CORBA::Exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemple #11
0
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
  try
  {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    if (parse_args (argc, argv) != 0)
      return 1;

    CORBA::Object_var obj = orb->string_to_object( ior );
    if (CORBA::is_nil(obj.in())) {
      std::cerr << "Nil Messenger reference" << std::endl;
      return 1;
    }

    // Narrow
    Messenger_var messenger = Messenger::_narrow( obj.in() );
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Argument is not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup(
      "Where can I get TAO?");
    for (int i=0; i<3; i++) {
      messenger->send_message ("*****@*****.**",
                               "OCI's Distribution of TAO",
                               message.inout());
    }
  }
  catch(const CORBA::Exception& ex)
  {
    std::cerr << "Caught exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Exemple #12
0
int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
  try {
    // Initialize the ORB.
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args (argc, argv) != 0)
        return 1;

    // Read and destringify the Messenger object's IOR.
    CORBA::Object_var obj = orb->string_to_object( ior );
    if( CORBA::is_nil( obj.in() ) ) {
      std::cerr << "Could not get Messenger IOR." << std::endl;
      return 1;
    }

    // Narrow the IOR to a Messenger object reference.
    Messenger_var messenger = Messenger::_narrow( obj.in() );
    if( CORBA::is_nil( messenger.in() ) ) {
      std::cerr << "IOR was not a Messenger object reference." << std::endl;
      return 1;
    }

    // Send a message the the Messenger object.
    CORBA::String_var msg = CORBA::string_dup( "Hello!" );
    messenger->send_message( "TAO User", "TAO Test", msg.inout() );

    // Print the Messenger's reply.
    std::cout << "Reply: " << msg.in() << std::endl;

    return 0;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "CORBA exception: " << ex << std::endl;
  }

  return 1;
}
Exemple #13
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
  {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    CORBA::Object_var obj =
      orb->string_to_object (ior);

    // Narrow the Messenger object reference
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil(messenger.in())) {
      ACE_ERROR((LM_ERROR, " ERROR: Client cannot get a Messenger reference\n"));
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup("Hello!");

    // Send a message
    messenger->send_message("user", "TAO Test", message.inout());

    ACE_DEBUG((LM_DEBUG, "CLIENT: Message was sent\n"));

    orb->destroy();
  }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return 1;
    }

  return 0;
}
Exemple #14
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  try {
    // Initialize the ORB
    CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

    if (parse_args (argc, argv) != 0)
        return 1;

    // Converts the contents of the file to an object reference
    CORBA::Object_var obj = orb->string_to_object (ior);
    if (CORBA::is_nil (obj.in())) {
      std::cerr << "Nill Messenger reference" << std::endl;
      return 1;
    }

    // Narrow the object reference to a Messenger object reference
    Messenger_var messenger = Messenger::_narrow(obj.in());
    if (CORBA::is_nil (messenger.in())) {
      std::cerr << "Not a Messenger object reference" << std::endl;
      return 1;
    }

    // Create a message and send it to the Messenger
    CORBA::String_var message = CORBA::string_dup("Hello!");
    messenger->send_message ("TAO User", "TAO Test", message.inout());

    orb->destroy();
    std::cout << "Message was sent" << std::endl;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Client Caught a CORBA exception: " << ex << std::endl;
    return 1;
  }
  std::cout << "Message was sent" << std::endl;
  return 0;
}
Exemple #15
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      ClientInitializer* temp_initializer = new ClientInitializer;

      PortableInterceptor::ORBInitializer_var orb_initializer =
        temp_initializer;

      PortableInterceptor::register_orb_initializer (orb_initializer.in ());

      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Client ORB");

      // Now that the ORB is initialized (and subsequently the
      // PICurrent), we can set the slot data on the PICurrent for our
      // interceptor initializer.
      temp_initializer->set_slot_data ();

      CORBA::Object_var naming_obj =
        orb->resolve_initial_references( "NameService" );
      CosNaming::NamingContext_var root =
        CosNaming::NamingContext::_narrow( naming_obj.in() );
      if ( CORBA::is_nil(root.in() ) ) {
        std::cerr << "Couldn't find Naming Service." << std::endl;
        return 1;
      }

      // get Messenger
      CosNaming::Name name;
      name.length(1);
      name[0].id = CORBA::string_dup( "Messenger" );

      CORBA::Object_var obj = CORBA::Object::_nil();
      while ( CORBA::is_nil( obj.in() ) ) {
        try {
          obj = root->resolve( name );
        } catch (const CosNaming::NamingContext::NotFound&) {
          // Sleep for a second and try again
          ACE_OS::sleep(1);
        }
      }

      Messenger_var messenger = Messenger::_narrow( obj.in() );
      if( CORBA::is_nil( messenger.in() ) ) {
        std::cerr << "Not a Messenger reference" << std::endl;
        return 1;
      }

      CORBA::String_var message = CORBA::string_dup( "Hello!" );
      messenger->send_message( "TAO User", "TAO Test", message.inout() );

    }

  catch(const CORBA::Exception& ex)
    {
      std::cerr << "Caught CORBA exception: " << ex << std::endl;
      return 1;
    }

  return 0;
}
Exemple #16
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      PortableInterceptor::ORBInitializer_var orb_initializer =
        new ClientInitializer;

      PortableInterceptor::register_orb_initializer (orb_initializer.in ());

      // Initialize orb
      CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

      if (parse_args (argc, argv) != 0)
        return 1;

      // Destringify ior
      CORBA::Object_var obj = orb->string_to_object( ior );
      if( CORBA::is_nil( obj.in() ) ) {
        std::cerr << "Nil Messenger reference" << std::endl;
        return 1;
      }

      // Narrow
      Messenger_var messenger = Messenger::_narrow( obj.in() );
      if( CORBA::is_nil( messenger.in() ) ) {
        std::cerr << "Argument is not a Messenger reference" << std::endl;
        return 1;
      }

      // Obtain a reference to the CodecFactory.
      CORBA::Object_var obj2 =
      orb->resolve_initial_references ("CodecFactory");

      IOP::CodecFactory_var codec_factory;

      if(CORBA::is_nil(obj2.in()))
        {
          std::cerr <<  "Error: codec_factory" << std::endl;
          ACE_OS::exit(1);
        }
      else
        {
          codec_factory = IOP::CodecFactory::_narrow (obj2.in ());
          std::cout << "got codec factory" << std::endl;
        }

      // Set up a structure that contains information necessary to
      // create a GIOP 1.2 CDR encapsulation Codec.
      IOP::Encoding encoding;
      encoding.format = IOP::ENCODING_CDR_ENCAPS;
      encoding.major_version = 1;
      encoding.minor_version = 2;

      // Obtain the CDR encapsulation Codec.
      IOP::Codec_var codec =
        codec_factory->create_codec (encoding);

      CORBA::Long uid = 64321;

      CORBA::Any uid_as_any;

      uid_as_any <<= uid;
      CORBA::OctetSeq client_uid = *codec->encode (uid_as_any);
      messenger->send_message( client_uid );
    }

  catch(const CORBA::Exception& ex)
    {
      std::cerr << "Exception in MessengerClient: " << ex << std::endl;
      return 1;
    }

  std::cout << "message was sent" << std::endl;
  return 0;
}
Exemple #17
0
int TestClient::svc()
{
  // Every invocation of svc increates the thread count
  instance_++;
  int threadNum = instance_;
  size_t vec_size = iors_.size();

  ACE_DEBUG((LM_DEBUG, "* Client Thread started (%d.%d.%d.%d)\n",
             threadNum, iterations_, vec_size, requestCount_));

  int     i           = 0;
  size_t  objIter     = 0;
  int     requestIter = 0;

  ACE_TString currentIOR;

  ACE_OS::srand(static_cast<u_int> (ACE_OS::time()));

  try
  {
    int holdingCount    = 0;
    int noProfileCount  = 0;

    // For each iteration
    for (i = 1; i <= iterations_; i++)
    {
      // For each object reference read from file
      for (objIter = 1; objIter <= vec_size; objIter++)
      {
        requestIter = -1;
        // Get a imr_test_var
        currentIOR = iors_[objIter - 1];
        CORBA::Object_var obj = orb_->string_to_object(currentIOR.c_str());
        if (CORBA::is_nil(obj.in()) == false)
        {
          requestIter = 0;
          Messenger_var test = Messenger::_narrow(obj.in());

          if (CORBA::is_nil(test.in()) == false)
          {
            // Calculate the number of requests
            int newReqCount (randomRequests_ == false ? requestCount_ :
            (int)((((double)ACE_OS::rand() / (double)RAND_MAX) * (double)(requestCount_ - 1)) + .5) + 1);
            // For each request
            for (requestIter = 1; requestIter <= newReqCount;  requestIter++)
            {
              try
              {
                ::CORBA::Long instance = test->send_message(threadNum, i, objIter, requestIter);
                ACE_UNUSED_ARG (instance);
              }
              catch (const CORBA::SystemException& ex)
              {
                // If these exceptions are expected record the number of instances, otherwise rethrow
                if (expectHolding_ == true && ex.minor() == TAO_POA_HOLDING)
                {
                   ACE_ERROR((LM_ERROR, "Caught expected holding exception with (%d.%d.%d)\n",
                     threadNum, objIter, requestIter));
                  holdingCount++;
                }
                else
                {
                  throw;
                }
                if (expectNoProfile_ == true
                  && ex.minor() == TAO_INVOCATION_SEND_REQUEST_MINOR_CODE)
                {
                   ACE_ERROR((LM_ERROR, "Caught expected holding exception with (%d.%d.%d)\n",
                     threadNum, objIter, requestIter));
                  noProfileCount++;
                }
                else
                {
                  throw;
                }
              } // catch
            } // for request
            // We are done with our non-nil narrowed obj ref
            if (shutdownOrb_ == true) test->shutdownOrb();
          } // if narrow
        } // if obj
      } // for obj
    } // for iter
    // Report expected exceptions
    if (holdingCount > 0)
    {
      ACE_DEBUG((LM_DEBUG,"Client thread %d received %d holding error(s).\n",
                 threadNum, holdingCount));
    }

    if (noProfileCount > 0)
    {
      ACE_DEBUG((LM_DEBUG,"Client thread %d received %d no profile error(s).\n",
                 threadNum, noProfileCount));
    }

    return 0;
  } // try
  catch (const CORBA::Exception& ex)
  {
    ACE_ERROR((LM_ERROR,"CORBA client error with (%d.%d.%d.%d):%s\n",
               threadNum, i, objIter, requestIter, currentIOR.c_str()));
    ex._tao_print_exception ("");
  }
  return 1;
}
Exemple #18
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  // Detection of closed on read currently not working certain platforms.
#if defined (sun) || defined (AIX) || defined (__FreeBSD_version)
  return 2;
#endif

  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    if (parse_args (argc, argv) != 0)
      return 1;

    // Destringify ior
    CORBA::Object_var obj = orb->string_to_object( ior );
    if (CORBA::is_nil(obj.in())) {
      std::cerr << "Nil Messenger reference" << std::endl;
      return 1;
    }

    // Narrow
    Messenger_var messenger = Messenger::_narrow( obj.in() );
    if (CORBA::is_nil(messenger.in())) {
      std::cerr << "Argument is not a Messenger reference" << std::endl;
      return 1;
    }

    CORBA::String_var message = CORBA::string_dup( "Hello!" );

    int try_count = 0;
    int succeeded = 0;
    for (; try_count < number_of_tries; ++try_count)
    {
      ACE_DEBUG ((LM_INFO,
                  "(%P|%t) - Sending message <%d> to server\n", try_count));

      try {
        messenger->send_message( "TAO User", "Test 1", message.inout() );

        ACE_DEBUG ((LM_INFO,
            "(%P|%t) - Successfully received response for message <%d> to server\n", try_count));
        ++succeeded;

        // Force server to abort to verify it will be brought
        // back up when send_message() is called.
        messenger->abort(2);
        ACE_OS::sleep(seconds_between_requests);
      }
      catch (const CORBA::Exception&)
      {
        // Swallow
      }
    }

    if (succeeded == number_of_succeed)
    {
      ACE_DEBUG ((LM_INFO,
            "(%P|%t) - <%d> Messages where send to the server, <%d> succeeded\n", try_count, succeeded));
    }
    else
    {
      ACE_ERROR ((LM_INFO,
            "(%P|%t) - ERROR: <%d> Messages where send to the server, <%d> succeeded, should be <%d>\n", try_count, succeeded, number_of_succeed));
    }

    orb->destroy ();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Client main() Caught CORBA::Exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}