squash perl 5.12 warning
[bioperl-db.git] / scripts / corba / caching_corba_server.pl
blobc5687d0478babd18591d520b27c00528a12c6eaa
1 #!/usr/local/lib/perl
3 use Bio::CorbaServer::BioEnv;
4 use Bio::CorbaClient::SeqDB;
5 use Bio::DB::CacheServer::SeqDB;
6 use Bio::DB::BioSQL::DBAdaptor;
9 use CORBA::ORBit idl => [ 'biocorba.idl' ];
10 use Getopt::Long;
12 my $host = "localhost";
13 my $sqlname = "bioperlcache";
14 my $dbuser = "root";
15 my $dbpass = undef;
16 my $format = 'fasta';
17 my $dbname = undef;
19 &GetOptions( 'host:s' => \$host,
20 'sqldb:s' => \$sqlname,
21 'dbuser:s' => \$dbuser,
22 'dbpass:s' => \$dbpass,
23 'format:s' => \$format,
24 'dbname:s' => \$dbname,
25 'iorfile:s' => \$iorfile
28 if( !defined $dbname) {
29 die "Must specify the dbname to cache\n";
33 # build the ORB
35 my $orb = CORBA::ORB_init("orbit-local-orb");
36 my $root_poa = $orb->resolve_initial_references("RootPOA");
38 # get the corba object of our remote server
40 open(F,"$iorfile") || die "Could not open $iorfile";
41 $ior = <F>;
42 chomp $ior;
43 close(F);
45 my $remote = $orb->string_to_object($ior);
46 my $corba_ref = $remote->get_SeqDB_by_name($dbname);
48 if( !defined $corba_ref ) {
49 die "No remote database for $dbname";
52 # bind the corba object as Bioperl Client
54 my $read = Bio::CorbaClient::SeqDB->new( -corbaref => $corba_ref);
57 # connect to our local database. This will throw on inability to connect
59 $dbadaptor = Bio::DB::BioSQL::DBAdaptor->new( -host => $host,
60 -dbname => $sqlname,
61 -user => $dbuser,
62 -pass => $dbpass
66 # build a caching server
68 my $cache = Bio::DB::CacheServer::SeqDB->new( -read_db => $read,
69 -write_dbadaptor => $dbadaptor,
70 -dbname => $dbname);
73 # bind cache to a servant object
75 my $servant = Bio::CorbaServer::BioEnv->new('-poa' => $root_poa,
76 '-no_destroy' => 1);
79 $servant->add_SeqDB($dbname,"unknown-version",$cache);
81 # Read to rock and roll
83 # this registers this object as a live object with the ORB
84 my $id = $root_poa->activate_object ($servant);
87 # we need to get the IOR of this object. The way to do this is to
88 # to get a client of the object (temp) and then get the IOR of the
89 # client
90 $temp = $root_poa->id_to_reference ($id);
91 my $ior = $orb->object_to_string ($temp);
93 # write out the IOR. This is what we give to a different machine
94 $out_file = "cache.ior";
95 open (OUT, ">$out_file") || die "Cannot open file for ior: $!";
96 print OUT "$ior";
97 close OUT;
99 # tell everyone we are ready for it
100 print STDERR "Activating the ORB. IOR written to $out_file\n";
102 # and off we go. Woo Hoo!
103 $root_poa->_get_the_POAManager->activate;
104 $orb->run;