Created
January 24, 2011 10:59
-
-
Save timyates/793075 to your computer and use it in GitHub Desktop.
Playing around with HawtDispatch examples in Groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab( 'org.fusesource.hawtdispatch:hawtdispatch:1.1' ) | |
import org.fusesource.hawtdispatch.* | |
import static org.fusesource.hawtdispatch.Dispatch.* | |
import java.util.concurrent.Semaphore | |
done = new Semaphore( 1 - ( 1000 * 1000 ) ) | |
queue = createQueue() | |
source = createSource EventAggregators.INTEGER_ADD, queue | |
source.setEventHandler { | |
count = source.data | |
println "got: $count" | |
done.release count | |
} | |
source.resume() | |
// Produce 1,000,000 concurrent merge events | |
(0..<1000).each { i -> | |
globalQueue.execute { | |
(0..<1000).each { j -> | |
source.merge 1 | |
} | |
} | |
} | |
// Wait for all the event to arrive. | |
done.acquire() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example code taken from http://hawtdispatch.fusesource.org/index.html#Custom_Dispatch_Source