Database Reference
In-Depth Information
"iPad Cover" -> 7.49
)
Using the list of names and map of product name to price, we will create a function that
will randomly pick a product and name from these sources, generating a specified number
of product events:
/** Generate a number of random product events */
def generateProductEvents(n: Int) = {
(1 to n).map { i =>
val (product, price) =
products(random.nextInt(products.size))
val user = random.shuffle(names).head
(user, product, price)
}
}
Finally, we will create a network socket and set our producer to listen on this socket. As
soon as a connection is made (which will come from our consumer streaming applica-
tion), the producer will start generating random events at a random rate between 0 and 5
per second:
// create a network producer
val listener = new ServerSocket(9999)
println("Listening on port: 9999")
while (true) {
val socket = listener.accept()
new Thread() {
override def run = {
println("Got client connected from: " +
socket.getInetAddress)
val out = new
PrintWriter(socket.getOutputStream(), true)
while (true) {
Thread.sleep(1000)
val num = random.nextInt(MaxEvents)
val productEvents = generateProductEvents(num)
Search WWH ::




Custom Search