Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LuceneActor extends DefaultActor{
- // shortened version
- protected void act() {
- loop() {
- react { command ->
- try {
- def result = null
- log.debug("LuceneActor received: $command")
- switch (command.type) {
- case CommandType.ADD_TO_INDEX: addToIndex(command); break
- case CommandType.REMOVE_FROM_INDEX: removeFromIndex(command); break
- case CommandType.UPDATE_INDEX: removeFromIndex(command); addToIndex(command); break
- case CommandType.SEARCH: result = search(command); break;
- }
- result = result ?: 'finished'
- log.debug("reply & finish")
- reply result
- }
- catch (Exception e) {
- log.debug("Failed to act on command:", e)
- }
- }
- }
- }
- // -----------------------------------------
- // calling code in a Grails service:
- static LuceneActor lucene
- static {
- lucene = new LuceneActor()
- lucene.start()
- }
- void doStuff(){
- def cmd = new IndexCommand(indexable: indexable, repository: database, type: CommandType.ADD_TO_INDEX)
- lucene.sendAndWait(cmd)
- }
- // -----------------------------------------
- // result:
- /*
- java.lang.IllegalStateException: The actor cannot accept messages at this point.
- at groovyx.gpars.actor.Actor.createActorMessage(Actor.java:288)
- at groovyx.gpars.actor.AbstractLoopingActor.send(AbstractLoopingActor.java:241)
- at groovyx.gpars.actor.impl.MessageStream.sendAndWait(MessageStream.java:115)
- at vs.lucene.LuceneService.addToIndex(LuceneService.groovy:40)
- */
Advertisement
Add Comment
Please, Sign In to add comment