Hello arunhorne

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!


In reply to Re: Using Perl to Publishing to Message Queues by inman
in thread Using Perl to Publishing to Message Queues by arunhorne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.