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
import java.io.InputStreamReader; | |
import java.io.Reader; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import javax.script.Invocable; | |
import javax.script.ScriptEngine; | |
import javax.script.ScriptEngineManager; |
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
public interface RouteDSL { | |
RouteDSL param(String paramName, Handler<RoutingContext> checker) | |
default<T> RouteDSL param(String paramName, Function<String, T> checker) { | |
return param(paramName, ctx -> { | |
String p = ctx.request().getParam(name); | |
try { | |
ctx.put(paramName, checker.apply(p)); | |
ctx.next(); |
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
// It's weird it doesn't work ootb since Handler<T> is a functional java interface | |
// I must have missed something | |
fun <T> asHandler(handler: (T) -> Unit): Handler<T> = | |
Handler { event -> handler(event) } |
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
public class InterceptorExample extends AbstractVerticle { | |
public final static String API_PATH = "/api/v1/"; | |
public final static String STATIC_FILES = "/static/"; | |
// ... | |
private Router router; | |
@Override | |
public void start(Future<Void> future) { |
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
// Let's imagin you have such a service | |
class TodoMongoService { | |
void fetchById(String todoId, Handler<AsyncResult<Todo>> handler) { | |
mongo.find(id) { res -> | |
if(res.succeeded) { | |
handler.handle(Future.suceededFuture(res.result)) | |
} else { | |
handler.handle(Future.failedFuture(res.cause)) | |
} | |
} |
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
java.lang.IllegalStateException: Uh oh! Event loop context executing with wrong thread! Expected null got Thread[Test worker,5,main] | |
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$3(ContextImpl.java:343) | |
at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:240) | |
at io.vertx.core.http.impl.ConnectionManager$ConnQueue.http1xConnected(ConnectionManager.java:422) | |
at io.vertx.core.http.impl.ConnectionManager$ConnQueue.lambda$internalConnect$159(ConnectionManager.java:384) | |
at io.vertx.core.http.impl.ConnectionManager$ConnQueue$1.lambda$connect$157(ConnectionManager.java:282) | |
at io.vertx.core.net.impl.AsyncResolveBindConnectHelper.addListener(AsyncResolveBindConnectHelper.java:43) | |
at io.vertx.core.http.impl.ConnectionManager$ConnQueue$1.connect(ConnectionManager.java:280) | |
at io.vertx.core.http.impl.ConnectionManager$ConnQueue.internalConnect(ConnectionManager.java:395) | |
at io.vertx.core.http.impl.ConnectionManager$ConnQueue.createNewConnection(ConnectionManager.java:226) |
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
List<Handler<RoutingContext>> handlers = /* ... */; | |
handlers.forEach(router.route("/a/b/")::handler); // KO : "You're attaching a handler to a route more than once" | |
handlers.forEach(handler -> router.route("/a/b").handler(handler)); // works |
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
package main | |
import ( | |
"golang.org/x/tour/wc"; | |
"strings"; | |
) | |
func WordCount(s string) map[string]int { | |
count := make(map[string]int) | |
words := strings.Fields(s) |
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
package main | |
import "golang.org/x/tour/pic" | |
func mult(x, y int) uint8 { | |
return uint8( x * y ) | |
} | |
func mid(x, y int) uint8 { | |
return uint8( (x + y) / 2 ) |
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
package com.github.vertx.node.example; | |
import io.vertx.core.AbstractVerticle; | |
import io.vertx.core.Vertx; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.concurrent.TimeUnit; |
NewerOlder