in reply to Using Perl to Publishing to Message Queues
It is increasingly the case that vendors favour Java first followed by C as the preferred method of delivering an API. This tends to exclude Perl development until someone writes the XS and delivers it as a CPAN module. Fortunately the Inline modules provide a suitable compromise in that you can have 'native language' code inside your Perl app.
The following code uses Inline::Java to import an external Java class from a vendor API and use it in a small program. The code starts by introducing Inline::Java to the first class in AUTOSTUDY mode. This gives us a place to start while allowing us to use any class that we care to instantiate. From this point on, the coding is Perl coding in a Java style i.e. with lots of exception handling!
#! /usr/bin/perl use strict; use warnings; use Data::Dumper; use Inline ( Java => 'STUDY', STUDY => ['com.verity.search.VSearch'], AUTOSTUDY => 1, ); use Inline::Java qw(caught) ; eval { my $search = new com::verity::search::VSearch(); $search->setServerSpec('localhost:9900'); $search->setK2UserName('user'); $search->setK2Password('password'); my $ticket = $search->k2Login();; my $colls = $search->collectionsInfo(); my $collCount = $colls->count(); foreach (0..$collCount-1) { my $coll = $colls->at($_); print "Collection: ".$coll->getAlias."\n"; } $search->addCollection ('verity_doccoll'); $search->setQueryText('*'); my $result = $search->getResult(); print "Docs Found: ", $result->{docsFound}; }; if ($@) { if (caught("java.lang.Exception")) { my $msg; $msg = ($@->getMessage()); print "Exception $msg\n"; # prints ouch! } else { # It wasn't a Java exception after all... die $@ ; } }
Execution is slow when the code is run for the first time. Information relating to the classes is compiled and stored for later use. Subsequent execution uses this stored information. The JVM also takes a period of time to initiate which adds to startup time. Architecting your apps to do a lot of work or stay in memory between transactions will minimise this startup overhead. See the POD for details on using as a CGI for example.
Bye!
|
|---|