Hi there,
I have a ruby script as follows:
class MyScript
# Import the interface required by the Script snap.
include com.snaplogic.scripting.language.ScriptHook
attr_reader :log, :input, :output, :error
def initialize(log, input, output, error)
@log = log
@input = input
@output = output
@error = error
end
# The "execute()" method is called once when the pipeline is started
# and allowed to process its inputs or just send data to its outputs.
def execute()
while input.hasNext() do
begin
# Read the next document, wrap it in a map and write out the wrapper
doc = input.next()
wrapper = {
"original" => doc
}
log.info("Executed Ruby script")
output.write(doc, wrapper)
rescue => e
log.error("Bad Rublet " + e.message)
errWrapper = {
"errMsg" => e.message
}
error.write(errWrapper)
end
end
end
end
The Script Snap will look for a ScriptHook object in the “hook”
variable. The snap will then call the hook’s “execute” method.
$hook = MyScript.new($log, $input, $output, $error)
===================================
When I trying to execute it, I am getting this error:
com.snaplogic.api.ExecutionException: (NoMethodError) undefined method hasNext' for nil:NilClass at com.snaplogic.snaps.script.CommonExecute.execute(CommonExecute.java:148) at com.snaplogic.cc.snap.common.SnapRunnableImpl.executeSnap(SnapRunnableImpl.java:791) at com.snaplogic.cc.snap.common.SnapRunnableImpl.execute(SnapRunnableImpl.java:541) at com.snaplogic.cc.snap.common.SnapRunnableImpl.doRun(SnapRunnableImpl.java:857) at com.snaplogic.cc.snap.common.SnapRunnableImpl.access$000(SnapRunnableImpl.java:117) at com.snaplogic.cc.snap.common.SnapRunnableImpl$1.run(SnapRunnableImpl.java:384) at com.snaplogic.cc.snap.common.SnapRunnableImpl$1.run(SnapRunnableImpl.java:380) at java.base/java.security.AccessController.doPrivileged(Native Method) at java.base/javax.security.auth.Subject.doAs(Subject.java:423) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657) at com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:379) at com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:117) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: org.jruby.exceptions.NoMethodError: (NoMethodError) undefined method
hasNext’ for nil:NilClass
at RUBY.execute(:16)
================
Any help pls?
=====================
In order words, can you give me a JRuby example for Java 11 where an interface is implemented and also the object initialized properly? thnaks.