me van a tener que seguir soportando
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
public class Main {
public static void main(String args[]) {
EventBus eventBus = new EventBus();
eventBus.chanel("/sistema/session/parametros").on(t -> System.out.println(t));
eventBus.chanel("/sistema/session/parametros").fire(new RegistraParametro("mi parametrito"));
}
}
public class RegistraParametro {
private String string;
public RegistraParametro(String string) {
this.string = string;
}
@Override
public String toString() {
return "RegistraParametro [string=" + string + "]";
}
}
import java.util.function.Function;
public interface Callbak { void apply(Object obj); }
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.function.Consumer;
import java.util.function.Function;
public class Chanel {
private List<Callbak> events = new ArrayList<>();
public void fire(Object event) {
events.forEach(p -> p.apply(event));
}
public void on(Callbak event) {
events.add(event);
}
}
import java.util.HashMap;
public class EventBus {
private HashMap<String, Chanel> chanels = new HashMap<>();
public Chanel chanel(String string) {
return chanels.computeIfAbsent(string, p -> new Chanel());
}
}
package testingasync;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import static org.junit.Assert.*;
public class asyn_gretting_should_Test {
private static interface Callback<T> {
void call(T t);
}
private static class AssynGreating {
public void sayHi(String name, Callback<String> callback) {
new Thread(() -> callback.call("hi " + name)).start();
}
}
@Test
public void say_hi() throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
StringBuilder stringBuilder = new StringBuilder();
new AssynGreating().sayHi("luis", (name) -> {
stringBuilder.append(name);
countDownLatch.countDown();
});
countDownLatch.await(1, TimeUnit.SECONDS);
assertEquals("hi luis", stringBuilder.toString());
}
}