This file contains hidden or 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
class EventBus(internal: JEventBus) { | |
trait Sendable[T] { | |
def send(address: String, message: T)(handler: Message[T] => Unit) | |
def publish(address: String, message: T) | |
} | |
object Sendable { | |
def instance[T](jSend: ((String, T, Handler[JMessage[T]]) => JEventBus), jPublish: (String, T) => JEventBus): Sendable[T] = new Sendable[T] { | |
def publish(address: String, t: T) = { | |
jPublish(address, t) | |
} |
This file contains hidden or 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
package com.mycompany.myproject; | |
/* | |
* Copyright 2013 Red Hat, Inc. | |
* | |
* Red Hat licenses this file to you under the Apache License, version 2.0 (the "License"); you may | |
* not use this file except in compliance with the License. You may obtain a copy of the License at: | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* |
This file contains hidden or 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
[19:20:14] <purplefox> Narigo: ok found the problem | |
[19:20:24] <purplefox> Narigo: the problem is you're playing with threads in your verticle | |
[19:20:38] <purplefox> Narigo: you're using a fork join | |
[19:20:49] <purplefox> Narigo: and calling deployVerticle on the result of that | |
[19:20:56] <purplefox> Narigo: which is not the vert.x thread | |
[19:21:16] <purplefox> Narigo: so vert.x doesn't know what verticle you're in | |
[19:21:28] <purplefox> Narigo: basically - don't use other threads in verticles | |
[19:21:38] <purplefox> Narigo: you're also opening yourself up to race conditions | |
[19:22:15] <purplefox> Narigo: I'll add some better exceptions in vert.x so you'll get a better message next time you do this | |
[19:22:37] <purplefox> Narigo: "deploVerticle called from a non Vert.x thread. You are a very naughty boy!!" |
This file contains hidden or 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
// Set the project name to the string 'My Project' | |
name := "SBTProject" | |
// The := method used in Name and Version is one of two fundamental methods. | |
// The other method is <<= | |
// All other initialization methods are implemented in terms of these. | |
version := "1.0" | |
scalaVersion := "2.10.1" |
This file contains hidden or 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
trait MessageHelpers { | |
type Validated[T] = Either[List[String], T] | |
type Decoder[T] = Message[JsonObject] => Validated[T] | |
def validatedMap[X, Y](v: Validated[X], f: X => Y): Validated[Y] = v match { | |
case Left(errors) => Left(errors) | |
case Right(x) => Right(f(x)) | |
} | |
private def missingField[T](field: String): T => Validated[T] = { maybe => |
This file contains hidden or 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
eventBus.replaceData("address", "read-action", "replace-action", { | |
"id" : 15 | |
}, | |
// action on replace computation | |
function (readData) { | |
var replacedData = readData; | |
replacedData.nickname = replacedData.nickname.toLowerCase(); | |
return replacedData; | |
}, | |
// action on success |
This file contains hidden or 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
package reactivemongotest | |
import scala.concurrent.Await | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.Future | |
import scala.concurrent.duration.DurationInt | |
import org.junit.Test | |
import reactivemongo.api.MongoConnection | |
import reactivemongo.bson.BSONDocument | |
import reactivemongo.bson.BSONInteger |
This file contains hidden or 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
package reactivemongotest | |
import scala.concurrent.Await | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.Future | |
import scala.concurrent.duration.DurationInt | |
import org.junit.Test | |
import reactivemongo.api.MongoConnection | |
import reactivemongo.bson.BSONDocument | |
import reactivemongo.bson.BSONInteger |
This file contains hidden or 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
package tests; | |
import org.vertx.java.core.Handler; | |
import org.vertx.java.core.http.HttpServerRequest; | |
import org.vertx.java.core.http.RouteMatcher; | |
import org.vertx.java.deploy.Verticle; | |
public class HttpClientExample extends Verticle { | |
public void start() { |
This file contains hidden or 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
package com.campudus.scalasnippets | |
import actors.Actor._ | |
import java.util.concurrent.atomic.AtomicInteger | |
import scala.annotation.tailrec | |
object SomeAsyncTests { | |
def asyncFunction(i: Int)(doWhenDone: => Unit) = actor { | |
println("doing stuff " + i) |