Skip to content

Instantly share code, notes, and snippets.

@jklingsporn
jklingsporn / Mixed handler registration fails
Last active Sep 21, 2020
After both handlers have been registered and received a message the unregistration of the second handler fails
View Mixed handler registration fails
import com.hazelcast.core.Hazelcast;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.eventbus.MessageConsumer;
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
@jklingsporn
jklingsporn / run.sh
Created Dec 8, 2017
Expose public IP to JMX on EC2 instance
View run.sh
JMX_IP=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
exec java $JAVA_OPTS -Djava.rmi.server.hostname=$JMX_IP -jar app.jar $JAVA_ARGS
@jklingsporn
jklingsporn / build.sh
Created Dec 8, 2017
Expose public IP to JMX on EC2 instance
View build.sh
#!/bin/bash
set -e
now=$(date +"%Y-%m-%d_%H-%M-%S")
tag="./target/app-$now.zip"
mvn clean install
echo "web: ./run.sh" > target/Procfile
echo "JMX_IP=\$(curl http://169.254.169.254/latest/meta-data/public-ipv4)" > target/run.sh
echo "exec java \$JAVA_OPTS -Djava.rmi.server.hostname=\$JMX_IP -jar app.jar \$JAVA_ARGS" >> target/run.sh
chmod +x target/run.sh
zip -j ${tag} target/Procfile target/run.sh target/app.jar
@jklingsporn
jklingsporn / build.sh
Created Dec 8, 2017
Expose public IP to JMX on EC2 instance
View build.sh
#!/bin/bash
set -e
now=$(date +"%Y-%m-%d_%H-%M-%S")
tag="./target/app-$now.zip"
mvn clean install
echo "web: ./run.sh" > target/Procfile
echo "JMX_IP=\$(curl http://169.254.169.254/latest/meta-data/public-ipv4)" > target/run.sh
echo "exec java \$JAVA_OPTS -Djava.rmi.server.hostname=\$JMX_IP -jar app.jar \$JAVA_ARGS" >> target/run.sh
chmod +x target/run.sh
zip -j ${tag} target/Procfile target/run.sh target/app.jar
@jklingsporn
jklingsporn / CompletableFutureCollector2.java
Last active Apr 20, 2020
Converts a Stream<CompletableFuture<X>> to a CompletableFuture<List<X>> or a Stream<CompletableFuture<Void>> to a CompletableFuture<Void>
View CompletableFutureCollector2.java
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
public class CompletableFutureCollector2 {
private CompletableFutureCollector2(){
}
@jklingsporn
jklingsporn / CompletableFutureCollectorUsage.java
Created Nov 16, 2017
How to use CompletableFutureCollector
View CompletableFutureCollectorUsage.java
public static void main(String[] args) {
CompletableFuture<List<Integer>> collect = Stream.of(1,2,3).map(CompletableFuture::completedFuture).collect(CompletableFutureCollector.allOf());
}
@jklingsporn
jklingsporn / CompletableFutureSequence.java
Created Nov 16, 2017
Converts List<CompletableFuture<X>> to a CompletableFuture<List<X>>
View CompletableFutureSequence.java
static<T> CompletableFuture<List<T>> sequence(List<CompletableFuture<T>> com) {
return CompletableFuture.allOf(com.toArray(new CompletableFuture[com.size()]))
.thenApply(v -> com.stream()
.map(CompletableFuture::join)
.collect(toList())
);
}
@jklingsporn
jklingsporn / CompletableFutureCollector.java
Last active May 22, 2021
Converts a Stream<CompletableFuture<X>> to a CompletableFuture<List<X>>
View CompletableFutureCollector.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
View SomeJsonTest.java
public class SomeJsonTest {
public void getJsonFromRecord2(){
SomethingDao somethingDao = new SomethingDao();
CompletableFuture<JsonObject> jsonFuture = somethingDao.executeAsync(dslContext -> dslContext
.select(Tables.SOMETHING.SOMEID)
.select(Tables.SOMEOTHERTHING.SOMEVALUE)
.join(Tables.SOMEOTHERTHING)
.on(Tables.SOMETHING.SOMEID.eq(Tables.SOMEOTHERTHING.SOMEOTHERID))
.where(Tables.SOMETHING.SOMEID.eq(1))
View SomeJsonTest.java
public class SomeJsonTest {
public void getJsonFromRecord(){
SomethingDao somethingDao = new SomethingDao();
//setConfiguration/ setVertx left out
CompletableFuture<JsonObject> jsonFuture = somethingDao.executeAsync(dslContext -> dslContext
.selectFrom(somethingDao.getTable())
.where(Tables.SOMETHING.SOMEID.eq(1))
.fetchOne())
.thenApply(ISomething::toJson)