|
Here is the code that is trying to use the executor plugin's submit and get method. For some reason I am getting following error:
import trials.* new BootStrap().init() def bookService = new BookService() bookService.getAbstractBooks() Exception thrown java.lang.NullPointerException: Cannot invoke method submit() on null object at trials.BookService.getAbstractBooks(BookService.groovy:9) at trials.BookService$getAbstractBooks.call(Unknown Source) at ConsoleScript0.run(ConsoleScript0:5) ---------------- // I had not imported the Callable as it was not mentioned in the document at github // but then compiler complained about missing Callable so, I included the java package // Not sure if this is the reason for the error. package trials import java.util.concurrent.Callable class BookService { def executorService def getAbstractBooks() { log.info "in abstractBooks" def future = executorService.submit({ getAuthors() } as Callable) return future.get() } def getAuthors() { log.info "in getAuthors" def authorMap = [:] def books = Book.findAll() books.each {book -> authorMap[book] = book.author.name println "authorMap[$book]: ${authorMap[book]}" } log.info "out of getAuthors" return authorMap } } |
|
On 14/11/2012 23:54, rkgrails wrote:
> def bookService = new BookService() If you "new" your service object directly then it won't get its dependencies injected. Instead you need to fetch the bookService bean from the Spring context - if you're in a grails console it should be accessible as ctx.bookService. Also you don't need to do new BootStrap().init() as that should have happened already as part of the console startup process. Ian -- Ian Roberts | Department of Computer Science [hidden email] | University of Sheffield, UK --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
This post was updated on .
Ian,
Thanks for the helpful response! For some reason I do have to use new BootStrap().init() or it won't work. I am using it to load the data in the database. Using ctx works as it removes the exception that I was getting earlier and the method gets called alright. The data gets printed inside the method but then it returns null from the service - any idea what is wrong? Here is the new output: groovy> import trials.* groovy> new BootStrap().init() groovy> def books = Book.findAll() groovy> def bookService = ctx.bookService groovy> print bookService.getAbstractBooks() authorMap[(Falling Star)]: Bill Conner authorMap[(Blue Moon)]: Bill Conner authorMap[(Mars Alive)]: Bill Conner authorMap[(Old Woman)]: Warren Levin authorMap[(Old Shoe)]: Warren Levin authorMap[(Very Old Woman)]: Warren Levin authorMap[(Young Woman)]: Warren Levin authorMap[(Shades of Grey)]: Cindy Mark authorMap[(Autumn in Yellow)]: Cindy Mark authorMap[(Deep Black)]: Cindy Mark authorMap[(Fat Cat)]: Todd Dander authorMap[(Big Dog)]: Todd Dander authorMap[(Pink Gerbil)]: Todd Dander authorMap[(Running Hamster)]: Todd Dander authorMap[(Crazy Horse)]: Todd Dander authorMap[(Dust Storm)]: Lucy Sparks authorMap[(Marble Storm)]: Lucy Sparks authorMap[(Diamond Storm)]: Lucy Sparks authorMap[(Windmill Falling)]: Richard Corsin authorMap[(Flag on a Breeze)]: Richard Corsin authorMap[(Nine Leaves)]: Richard Corsin authorMap[(Moon Nuts)]: Richard Corsin authorMap[(Cedar Plank)]: Richard Corsin authorMap[(Horn and Drum)]: Anna Heart authorMap[(Bayou Billy)]: Anna Heart authorMap[(Roughing It)]: Anna Heart authorMap[(Laser Focus)]: Anna Heart authorMap[(Watching the Moon)]: Leslie Derby authorMap[(Moonrise Over Shame)]: Leslie Derby authorMap[(Feral Harness)]: Leslie Derby authorMap[(Granite Doll)]: Leslie Derby authorMap[(Vodka Sunrise)]: Leslie Derby authorMap[(Bull and China)]: Clint Fallow authorMap[(Tip the Boat)]: Clint Fallow authorMap[(Calm Raft)]: Clint Fallow authorMap[(River Surge)]: Clint Fallow authorMap[(Still in Yellow)]: Lucy Peters authorMap[(Rags on Fire)]: Lucy Peters authorMap[(Spin the Moon)]: Lucy Peters authorMap[(Field of Fey)]: Lucy Peters authorMap[(Sunflower Vengence)]: Lucy Peters null --rakesh
|
|
On 16/11/2012 01:50, rkgrails wrote:
> groovy> print bookService.getAbstractBooks() > > authorMap[(Falling Star)]: Bill Conner [snip] > authorMap[(Sunflower Vengence)]: Lucy Peters > > *null* That is correct, the "null" is the return value of the final "print" statement. If you just said groovy> bookService.getAbstractBooks() then you would see the list of books as the return value. Ian -- Ian Roberts | Department of Computer Science [hidden email] | University of Sheffield, UK --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Ian,
The prints that you see on the screen is from within the method that is called by the service. Once service gets the value, it tries to print that and that is what is printing as null. This is the code for the service: def getAbstractBooks() {
log.info "in abstractBooks"
// def future = callAsync getAuthors
def future = executorService.submit({
getAuthors()
} as Callable)
def absBooks = future.get()
log.info "out of abstractBooks"
return absBooks
}--rakesh
|
| Powered by Nabble | Edit this page |
