summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/ImplRepo_Service/ImplRepo_i.cpp
blob: fa7d151b89a857ab6b1b2d7791e8ce16bfdb212d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
/* -*- C++ -*- */
// $Id$

#include "ImplRepo_i.h"
#include "ace/Get_Opt.h"
#include "ace/Read_Buffer.h"
#include "ace/Process.h"
#include "tao/IIOP_Profile.h"

ACE_RCSID(ImplRepo_Service, ImplRepo_i, "$Id$")

ImplRepo_i::ImplRepo_i (void)
  : forwarder_impl_ (0),
    activator_ (0),
    ior_output_file_ (0),
    server_key_ (0),
    debug_level_ (1)
{
}

// Starts up the server associated with the object pointer and returns
// an updated pointer.

CORBA::Object_ptr
ImplRepo_i::activate_object (CORBA::Object_ptr obj,
                             CORBA::Environment &TAO_IN_ENV)
{
  Implementation_Repository::INET_Addr *new_addr;
  IIOP_Object *new_iiop_obj = 0;

  if (this->debug_level_ >= 1) 
    ACE_DEBUG ((LM_DEBUG,
                "Activating Object: %s\n",
                this->orb_manager_.orb ()->object_to_string (obj)));

  TAO_TRY
    {
      // @@ Where to get the poa name from?
      new_addr = this->activate_server (0, TAO_TRY_ENV);
      TAO_CHECK_ENV;

      IIOP_Object *iiop_obj = ACE_dynamic_cast (IIOP_Object *,
                                                obj->_stubobj ());
      TAO_IIOP_Profile *iiop_pfile =
                ACE_dynamic_cast (TAO_IIOP_Profile *,
                                  iiop_obj->profile_in_use ());

      TAO_IIOP_Profile *new_pfile;
      // @@ Would new_addr->host_ be different from object_addr()?
      // if so I wil add another ctor  frde
      ACE_NEW_RETURN (new_pfile,
                      TAO_IIOP_Profile (new_addr->host_,
                                        new_addr->port_,
                                        iiop_pfile->object_key ()),
                      0);
                                   
      // over write and possibly change the value set from
      // that set by new_addr!
      new_pfile->object_addr (&iiop_pfile->object_addr ());

      // create new obj, pfile will be copied!
      new_iiop_obj = new IIOP_Object (iiop_obj->type_id, new_pfile);

      delete new_pfile;

      if (new_iiop_obj == 0)
        return 0;
    }
  TAO_CATCHANY
    {
      TAO_RETHROW_RETURN (0);
    }
  TAO_ENDTRY;

  return new CORBA_Object (new_iiop_obj,
                           obj->_servant ());
}

// Starts the server <server> if it is not already started

Implementation_Repository::INET_Addr *
ImplRepo_i::activate_server (const char *server,
                             CORBA::Environment &TAO_IN_ENV)
{
  int start = 0;
  char *ping_ior;
  Implementation_Repository::INET_Addr *address =
    new Implementation_Repository::INET_Addr;
  address->port_ = 0;
  address->host_ = CORBA::string_dup ("");

  if (this->debug_level_ >= 1)
    ACE_DEBUG ((LM_DEBUG,
                "Activating Server: %s\n",
                server));

  // Find out if it is already running
  if (this->repository_.get_ping_ior (server, ping_ior) != 0)
    {
      // If we had problems getting the ping_ior, probably meant that
      // there is no <server> registered
      ACE_ERROR ((LM_ERROR,
                  "Error: Cannot find ping IOR for server <%s>\n",
                  server));
      TAO_THROW_RETURN (Implementation_Repository::Not_Found (),
                        address);
    }

  // if length is 0, then none is running yet.
  if (ACE_OS::strlen (ping_ior) != 0)
    {
      TAO_TRY
        {
          CORBA::Object_var object =
            this->orb_manager_.orb ()->string_to_object (ping_ior,
                                                         TAO_TRY_ENV);
          TAO_CHECK_ENV;

          Ping_Object_var ping_object = Ping_Object::_narrow (object.in (),
                                                              TAO_TRY_ENV);
          TAO_CHECK_ENV;

          if (CORBA::is_nil (ping_object.in ()))
            {
              ACE_ERROR ((LM_ERROR,
                          "Error: Invalid Ping Object ior: <%s>\n",
                          ping_ior));
              TAO_THROW_RETURN (Implementation_Repository::Not_Found (),
                                address);
            }

          ping_object->ping (TAO_TRY_ENV);
          TAO_CHECK_ENV;
        }
      TAO_CATCHANY
        {
          start = 1;
        }
      TAO_ENDTRY;
    }
  else
    start = 1;

  // Start it up...
  if (start == 1)
    {
      // Start it up
      char *cl;

      int status = this->repository_.get_comm_line (server,
                                                    cl);

      if (status == 0)
        {
          if (this->debug_level_ >= 1)
            ACE_DEBUG ((LM_DEBUG,
                        "Starting %s\n",
                        server));
          ACE_Process_Options proc_opts;

          proc_opts.command_line (cl);

          ACE_Process proc;

          if (proc.spawn (proc_opts) == -1)
            {
              ACE_ERROR ((LM_ERROR,
                          "Error: Cannot activate server <%s> using <%s>\n",
                          server,
                          cl));
              delete [] cl;
              TAO_THROW_RETURN (Implementation_Repository::Cannot_Activate (CORBA::string_dup ("N/A")),
                                address);
            }

          delete [] cl;
        }
      else
        {
          ACE_ERROR ((LM_ERROR,
                      "Error: Cannot find commandline for server <%s>\n",
                      server));
          TAO_THROW_RETURN (Implementation_Repository::Not_Found (),
                            address);
        }

      // @@ Here is where we need to wait for the response so we can
      // find out where (host/port) the server started
      ACE_OS::sleep (3);
    }

  char *host;
  u_short port;

  this->repository_.get_hostport (server, host, port);

  address->host_ = CORBA::string_dup (host);
  address->port_ = port;

  return address;
}

// Adds an entry to the Repository about this <server>

void
ImplRepo_i::register_server (const char *server,
                             const Implementation_Repository::Process_Options &options,
                             CORBA::Environment &TAO_IN_ENV)
{
  Repository::Record rec;
  rec.comm_line = CORBA::string_dup (options.command_line_);
  rec.env = CORBA::string_dup (options.environment_);
  rec.wdir = CORBA::string_dup (options.working_directory_);
  rec.host = "";
  rec.port = 0;
  rec.ping_ior = "";

  int status = this->repository_.add (server, rec);

  if (status == 1)
    {
      ACE_ERROR ((LM_ERROR,
                  "Error: Server %s Already Registered!\n",
                  server));
      TAO_THROW (Implementation_Repository::Already_Registered ());
    }
  else
    {
      if (this->debug_level_ >= 1)
        ACE_DEBUG ((LM_DEBUG,
                    "register_server: Server %s Successfully Registered\n",
                    server));
      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Server: %s\n"
                              "Command Line: %s\n"
                              "Environment: %s\n"
                              "Working Directory: %s\n\n",
                              rec.comm_line,
                              rec.env,
                              rec.wdir));
    }
}

// Updates the entry in the Repository about this <server> or adds it
// if necessary.

void
ImplRepo_i::reregister_server (const char *server,
                               const Implementation_Repository::Process_Options &options,
                               CORBA::Environment &TAO_IN_ENV)
{
  ACE_UNUSED_ARG (TAO_IN_ENV);
  Repository::Record rec;
  // @@ Darrell, please make sure to use the ACE_ALLOCATOR and
  // ACE_ALLOCATOR_RETURN macros for all of these string_dup() calls
  // in your code.
  rec.comm_line = CORBA::string_dup (options.command_line_);
  rec.env = CORBA::string_dup (options.environment_);
  rec.wdir = CORBA::string_dup (options.working_directory_);
  rec.host = "";
  rec.port = 0;
  rec.ping_ior = "";

  this->repository_.update (server, rec);

  if (this->debug_level_ >= 1)
    ACE_DEBUG ((LM_DEBUG,
                "Server %s Successfully Registered\n",
                server));
  if (this->debug_level_ >= 2)
    ACE_DEBUG ((LM_DEBUG, "Server: %s\n"
                          "Command Line: %s\n"
                          "Environment: %s\n"
                          "Working Directory: %s\n\n",
                          rec.comm_line,
                          rec.env,
                          rec.wdir));
}

// Remove the server entry from the Repository

void
ImplRepo_i::remove_server (const char *server,
                           CORBA::Environment &TAO_IN_ENV)
{
  if (this->repository_.remove (server) == 0)
    {
      if (this->debug_level_ >= 1)
        ACE_DEBUG ((LM_DEBUG,
                    "Successfully Removed Server\n"));
    }
  else
    {
      ACE_ERROR ((LM_ERROR,
                  "Error: Trying to remove unknown server <%s>\n",
                  server));
      TAO_THROW (Implementation_Repository::Not_Found ());
    }
}

// Register the current location of the server

Implementation_Repository::INET_Addr *
ImplRepo_i::server_is_running (const char *server,
                               const Implementation_Repository::INET_Addr &addr,
                               CORBA::Object_ptr ping,
                               CORBA::Environment &TAO_IN_ENV)
{
  Implementation_Repository::INET_Addr *new_addr =
    new Implementation_Repository::INET_Addr;

  if (this->debug_level_ >= 1)
    ACE_DEBUG ((LM_DEBUG,
                "Server <%s> is running\n",
                server));

  // Update the record in the repository
  Repository::Record rec;
  if (this->repository_.resolve (server, rec) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  "Error: Unknown Server <%s>\n",
                  server));
      TAO_THROW_RETURN (Implementation_Repository::Not_Found (),
                        new_addr);
    }

  // Delete the stuff that we will update
  delete [] rec.ping_ior;
  delete [] rec.host;

  rec.host = ACE::strnew (addr.host_.in ());
  rec.port = addr.port_;
  rec.ping_ior = ACE::strnew (this->orb_manager_.orb ()->object_to_string (ping,
                                                                           TAO_IN_ENV));
  this->repository_.update (server, rec);

  if (this->repository_.update (server, rec) == 0)
    {
      if (this->debug_level_ >= 1)
        ACE_DEBUG ((LM_DEBUG,
                    "Successful server_is_running () of <%s>\n",
                    server));
    }
  else
    {
      ACE_ERROR ((LM_ERROR,
                 "Error: While updating Repository while server_is_running () %s\n",
                 server));
      // @@ Return here?
    }

  if (this->debug_level_ >= 2)
    ACE_DEBUG ((LM_DEBUG,
                "The old host/port was: %Lu:%hu\n",
                rec.host,
                rec.port));

  ACE_INET_Addr my_addr = TAO_ORB_Core_instance ()->orb_params ()->addr ();

  // @@ We are assuming that we are on the same machine right now
  new_addr->host_ = CORBA::string_dup (my_addr.get_host_name ());
  new_addr->port_ = my_addr.get_port_number ();

  if (this->debug_level_ >= 2)
    ACE_DEBUG ((LM_DEBUG,
                "The new host/port is: %Lu:%hu\n",
                new_addr->host_.inout (),
                new_addr->port_));

  return new_addr;
}

// Remove the state information for the current server

void
ImplRepo_i::server_is_shutting_down (const char *server,
                                     CORBA::Environment &TAO_IN_ENV)
{
  ACE_UNUSED_ARG (TAO_IN_ENV);
  Repository::Record rec;

  if (this->repository_.resolve (server, rec) == 0)
    {
      rec.host = "";
      rec.port = 0;
      rec.ping_ior = "";

      if (this->repository_.update (server, rec) == 0)
        {
          if (this->debug_level_ >= 1)
            ACE_DEBUG ((LM_DEBUG,
                        "Successful server_is_shutting_down () of <%s>\n",
                        server));
        }
      else
        {
          ACE_ERROR ((LM_ERROR,
                     "Error: While updating Repository while shutting down <%s>\n",
                     server));
        }
    }
  else
    {
      ACE_ERROR ((LM_ERROR,
                  "Error: Unknown Server <%s>\n",
                  server));
      TAO_THROW (Implementation_Repository::Not_Found ());
    }
}

// Reads the Server factory ior from a file

int
ImplRepo_i::read_ior (char *filename)
{
  // Open the file for reading.
  ACE_HANDLE f_handle_ = ACE_OS::open (filename, 0);

  if (f_handle_ == ACE_INVALID_HANDLE)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Error: Unable to open %s for writing: %p\n",
                       filename),
                      -1);
  ACE_Read_Buffer ior_buffer (f_handle_);
  this->server_key_ = ior_buffer.read ();

  if (this->server_key_ == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Error: Unable to allocate memory to read ior: %p\n"),
                      -1);

  ACE_OS::close (f_handle_);
  return 0;
}

int
ImplRepo_i::parse_args (void)
{
  ACE_Get_Opt get_opts (this->argc_, this->argv_, "d:f:o:");
  int c;

  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'd':  // debug flag.
        this->debug_level_ = ACE_OS::atoi (get_opts.optarg);
        break;
      case 'o':  // output the IOR to a file.
        this->ior_output_file_ = ACE_OS::fopen (get_opts.optarg, "w");
        if (this->ior_output_file_ == 0)
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Error: Unable to open %s for writing: %p\n",
                             get_opts.optarg), -1);
        break;
      case 'f': // read the IOR from the file.
        this->server_input_file_ = ACE::strnew (get_opts.optarg);
        break;
      case '?':  // display help for use of the server.
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Usage:  %s"
                           " [-d] <debug_level>"
                           " [-f] <server_ior_file>"
                           " [-o] <ior_output_file>"
                           "\n",
                           argv_ [0]),
                          1);
      }

  // Indicates successful parsing of command line.
  return 0;
}

int
ImplRepo_i::init (int argc, char **argv, CORBA::Environment &TAO_IN_ENV)
{
  TAO_TRY
    {
      // Call the init of <TAO_ORB_Manager> to initialize the ORB and
      // create a child POA under the root POA.
      if (this->orb_manager_.init_child_poa (argc,
                                             argv,
                                             "ir_poa",
                                             TAO_TRY_ENV) == -1)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Error: With %p\n",
                           "init_child_poa"),
                          -1);
      TAO_CHECK_ENV;

      this->argc_ = argc;
      this->argv_ = argv;

      int retval = this->parse_args ();

      if (retval != 0)
        return retval;

      ACE_NEW_RETURN (this->forwarder_impl_,
                      IR_Forwarder (this->orb_manager_.orb (),
                                    this->orb_manager_.child_poa (),
                                    this),
                      -1);

      CORBA::String_var str  =
        this->orb_manager_.activate (this->forwarder_impl_);
      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG,
                    "The server IOR is: <%s>\n",
                    str.in ()));

      if (this->ior_output_file_)
        {
          ACE_OS::fprintf (this->ior_output_file_,
                           "%s",
                           str.in ());
          ACE_OS::fclose (this->ior_output_file_);
        }

      CORBA::String_var ir_var  =
        this->orb_manager_.activate_under_child_poa ("implrepo",
                                                     this,
                                                     TAO_TRY_ENV);
      TAO_CHECK_ENV;

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG,
                    "The IR IOR is: <%s>\n",
                    ir_var.in ()));

      FILE *ir_file = ACE_OS::fopen ("implrepo.ior", "w");
      ACE_OS::fprintf (ir_file, "%s", ir_var.in ());
      ACE_OS::fclose (ir_file);

      ACE_NEW_RETURN (this->activator_,
                      IR_Adapter_Activator(this->forwarder_impl_),
                      -1);

      PortableServer::AdapterActivator_var activator =
        this->activator_->_this (TAO_TRY_ENV);
      TAO_CHECK_ENV;

      // Register the TAO_Adapter_Activator reference to be the RootPOA's
      // Adapter Activator.

      this->orb_manager_.root_poa ()->the_activator (activator.in (),
                                                     TAO_TRY_ENV);
      TAO_CHECK_ENV;
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Server_i::init");
      TAO_RETHROW_RETURN (-1);
    }
  TAO_ENDTRY;
  return 0;
}

int
ImplRepo_i::run (CORBA::Environment& env)
{
  if (this->orb_manager_.run (env) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Error: In IR_Server_i::run"),
                      -1);
  return 0;
}

CORBA::String
ImplRepo_i::get_forward_host (const char *server)
{
  char *host;
  u_short port;

  if (this->repository_.get_hostport (server, host, port) != 0)
    return 0;

  return host;
}

CORBA::UShort
ImplRepo_i::get_forward_port (const char *server)
{
  char *host;
  u_short port;

  if (this->repository_.get_hostport (server, host, port) != 0)
    return 0;

  delete host;
  return port;
}

ImplRepo_i::~ImplRepo_i (void)
{
  if (this->forwarder_impl_ != 0)
    delete this->forwarder_impl_;

  if (this->activator_ != 0)
    delete this->activator_;
}

IR_Adapter_Activator::IR_Adapter_Activator (IR_Forwarder *servant)
  : servant_ (servant)
{
  // Nothing
}

CORBA::Boolean
IR_Adapter_Activator::unknown_adapter (PortableServer::POA_ptr parent,
                                       const char *name,
                                       CORBA_Environment &env)
{
  CORBA::PolicyList policies (4);
  policies.length (4);

  // ID Assignment Policy
  policies[0] =
    parent->create_id_assignment_policy (PortableServer::USER_ID, env);
  if (env.exception () != 0)
    {
      env.print_exception ("PortableServer::POA::create_id_assignment_policy");
      return 0;
    }

  // Lifespan Policy
  policies[1] =
    parent->create_lifespan_policy (PortableServer::PERSISTENT, env);
  if (env.exception () != 0)
    {
      env.print_exception ("PortableServer::POA::create_lifespan_policy");
      return 0;
    }

  // Request Processing Policy
  policies[2] =
    parent->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT, env);
  if (env.exception () != 0)
    {
      env.print_exception ("PortableServer::POA::create_request_processing_policy");
      return 0;
    }

  // @@ Darrell, can you please make all this code work correctly with
  // native C++ exceptions?!

  // Id Uniqueness Policy
  policies[3] =
    parent->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID, env);
  if (env.exception () != 0)
    {
      env.print_exception ("PortableServer::POA::create_id_uniqueness_policy");
      return 0;
    }

  PortableServer::POA_var child = parent->create_POA (name,
                                                      PortableServer::POAManager::_nil (),
                                                      policies,
                                                      env);
  if (env.exception () != 0)
    return 0;

  for (CORBA::ULong i = 0;
       i < policies.length () && env.exception () == 0;
       ++i)
    {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy (env);
    }

  if (env.exception () != 0)
    {
      env.print_exception ("unknown_adapter::policy->destroy");
      return 0;
    }

  PortableServer::AdapterActivator_var activator = this->_this (env);
  if (env.exception () != 0)
    {
      child->destroy (0, 0, env);
      return 0;
    }

  child->the_activator (activator.in (), env);

  if (env.exception () != 0)
    {
      env.print_exception ("unknown_adapter, the_activator");
      child->destroy (0, 0, env);
      return 0;
    }

  child->set_servant (this->servant_, env);

  if (env.exception () != 0)
    {
      env.print_exception ("unknown_adapter, set_servant");
      child->destroy (0, 0, env);
      return 0;
    }

  // Finally everything is fine
  return 1;
}

// Constructor
IR_Forwarder::IR_Forwarder (CORBA::ORB_ptr orb_ptr,
                            PortableServer::POA_ptr poa_ptr,
                            ImplRepo_i *ir_impl)
  : ir_impl_ (ir_impl),
    orb_var_ (CORBA::ORB::_duplicate (orb_ptr)),
    poa_var_ (PortableServer::POA::_duplicate (poa_ptr))
{
}

CORBA::RepositoryId
IR_Forwarder::_primary_interface (const PortableServer::ObjectId & /* oid */,
                                  PortableServer::POA_ptr /* poa */,
                                  CORBA::Environment &)
{
  return 0;
}

void
IR_Forwarder::invoke (CORBA::ServerRequest_ptr /* request */,
                      CORBA::Environment &TAO_IN_ENV)
{
  // Get the POA Current object reference
  CORBA::Object_var obj = this->orb_var_->resolve_initial_references ("POACurrent");

  TAO_ORB_Core *orb_core = TAO_ORB_Core_instance ();
  TAO_POA_Current *poa_current = orb_core->poa_current ();

  if (TAO_IN_ENV.exception () != 0)
    {
      TAO_IN_ENV.print_exception ("PortableServer::Current::_narrow");
      return;
    }

  // The servant determines the key associated with the database entry
  // represented by self
  PortableServer::ObjectId_var oid = poa_current->get_object_id (TAO_IN_ENV);
  if (TAO_IN_ENV.exception () != 0)
    return;

  // Now convert the id into a string
  CORBA::String_var key = PortableServer::ObjectId_to_string (oid.in ());

  PortableServer::POA_ptr poa = poa_current->get_POA (TAO_IN_ENV);
  if (TAO_IN_ENV.exception () != 0)
    return;

  // Now FORWARD!!!

  Implementation_Repository::INET_Addr *new_addr = 0;

  TAO_TRY
    {
      new_addr = this->ir_impl_->activate_server (poa->the_name (),
                                                  TAO_TRY_ENV);
      TAO_CHECK_ENV;
    }
  TAO_CATCHANY
    {
      TAO_RETHROW;
    }
  TAO_ENDTRY;

  CORBA_Object_ptr forward_object =
    this->orb_var_->key_to_object (poa_current->object_key (),
                                   0,
                                   TAO_IN_ENV);

  IIOP_Object *iiop_obj = ACE_dynamic_cast (IIOP_Object *,
                                            forward_object->_stubobj ());

  TAO_IIOP_Profile *iiop_pfile =
            ACE_dynamic_cast (TAO_IIOP_Profile *,
                              iiop_obj->profile_in_use ());

  iiop_pfile->port (new_addr->port_);
  iiop_pfile->host (new_addr->host_);

//  if (TAO_debug_level > 0)
//    ACE_DEBUG ((LM_DEBUG,
//                "The forward_to is <%s>\n",
//                this->orb_var_->object_to_string (forward_object, TAO_IN_ENV)));

  if (!CORBA::is_nil (forward_object))
    TAO_IN_ENV.exception (new PortableServer::ForwardRequest (forward_object));
  else
    ACE_ERROR ((LM_ERROR,
                "Error: Forward_to reference is nil.\n"));
}