: eval 'exec perl -S `echo $0 | sed "s/.*\///" ` ${1+"$@"}' if 0; @a=@ARGV; @flags=grep(/^-/,@a); @other=(); @other = grep(!/^-/,@a); @words = split /\./, "$a[0]"; #print "words = @words\n"; #print "scalar(\@words)=",scalar(@words),"\n"; #print "scalar(\@other)=",scalar(@other),"\n"; #print "\$words[1]=$words[1]\n"; #print "\$words[1] !~ m/^get/ is ",$words[1] !~ m/^get/,"\n"; if ( scalar(@words) != 2 or $words[1] !~ m/^get/ or $words[0] !~ m/^[A-Z]/ or grep( /^-h(elp)?$/,@flags) or scalar(@other) != 1) { $scriptName = $0; $scriptName =~ s%^.*/%%; print <<"END"; Usage: $scriptName [-h -help] RemoteClass.getThing PRINT out a code to call a remote method asynchonously, with a timeout. END exit;} $rN="\n"; $rN="\n" if ( ! -d "/var" ); $Class = "$words[0]"; $instance = lc "$Class"; $Get = "$words[1]"; $Get =~ s/get//; print <<"END"; /** Get $Get from a $Class asynchronously, with a timeout for RMI failure. This is more robust than calling $Class.get$Get() directly and possibly hanging. \@param $instance the $Class to get state from. \@param timeoutMillis Wait this many milliseconds before returning state, or a null if unavailable. \@return $Get or a null if timed out. \@exception RemoteException If thrown by $Class. */ public static $Get get$Get($Class $instance, long timeoutMillis) throws java.rmi.RemoteException { Get${Get}Thread thread = new Get${Get}Thread($instance); thread.start(); try { thread.join(timeoutMillis); } catch (InterruptedException e) {Thread.currentThread().interrupt();} if (thread.remoteException != null) throw thread.remoteException; if (thread.isAlive()) {thread.interrupt();} return thread.result; } private static class Get${Get}Thread extends Thread { private $Class _$instance = null; public java.rmi.RemoteException remoteException = null; public $Get result = null; public Get${Get}Thread($Class $instance) {_$instance = $instance;} public void run() { try { result = _$instance.get$Get(); } catch (java.rmi.RemoteException e) {remoteException = e;} } } END