本文整理汇总了Java中io.vertx.ext.web.handler.sockjs.BridgeEventType类的典型用法代码示例。如果您正苦于以下问题:Java BridgeEventType类的具体用法?Java BridgeEventType怎么用?Java BridgeEventType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BridgeEventType类属于io.vertx.ext.web.handler.sockjs包,在下文中一共展示了BridgeEventType类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: eventBusHandler
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
private SockJSHandler eventBusHandler() {
SockJSHandlerOptions options = new SockJSHandlerOptions().setHeartbeatInterval(2000);
BridgeOptions boptions = new BridgeOptions()
.addOutboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.UPDATE_ORDERBOOK+":[A-Z]+-[A-Z]+"))
.addOutboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.UPDATE_INDICATORS+":[A-Z]+-[A-Z]+"))
.addOutboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.ORDERBOOK_READY+":[A-Z]+-[A-Z]+"))
.addInboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.GET_ORDERBOOK+":[A-Z]+-[A-Z]+"))
.addInboundPermitted(new PermittedOptions().setAddressRegex("getMovingAverage:[A-Z]+-[A-Z]+"))
.addInboundPermitted(new PermittedOptions().setAddressRegex(MessageDefinitions.REDEPLOYBITTREXVERTICLES));
return SockJSHandler.create(vertx, options).bridge(boptions, event -> {
if (event.type() == BridgeEventType.SOCKET_CREATED) {
System.out.println("A socket was created!");
} else if (event.type() == BridgeEventType.SOCKET_CLOSED){
System.out.println("A socket was closed!");
} else if (event.type() == BridgeEventType.UNREGISTER || event.type() == BridgeEventType.REGISTER){
System.out.println(event.getRawMessage().encode());
}
event.complete(true);
});
}
示例2: eventBusHandler
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
private SockJSHandler eventBusHandler() {
BridgeOptions options = new BridgeOptions().addOutboundPermitted(new PermittedOptions().setAddressRegex(".*"));
return SockJSHandler.create(vertx).bridge(options, event -> {
if (event.type() == BridgeEventType.SOCKET_CREATED) {
logger.info("A socket was created");
}
event.complete(true);
});
}
示例3: handle
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
@Override
public boolean handle(BridgeEvent event) throws EventBridgeChainException {
boolean isHandle = Boolean.FALSE;
if(BridgeEventType.SOCKET_CLOSED == event.type()) {
Vertx vertx = VertxHolder.getVertx();
isHandle = Boolean.TRUE;
SockJSSocket sockJSSocket = event.socket();
// notify user offline
String address = "topic/chat/offline";
String userId = sockJSSocket.headers().get(WebSocketSessionHolder.USER_KEY);
WebSocketSessionHolder.remove(userId);
RedisSockjsClient.PUBLISH(address,
new JsonObject()
.put("userId", userId));
// vertx.eventBus().publish(address,
// new JsonObject()
// .put("userId", userId));
}
return isHandle;
}
示例4: handle
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
@Override
public boolean handle(BridgeEvent event) throws EventBridgeChainException {
boolean isHandle = Boolean.FALSE;
if(BridgeEventType.PUBLISH == event.type()) {
Vertx vertx = VertxHolder.getVertx();
SockJSSocket sockJSSocket = event.socket();
Map<String, Object> rawMessage = event.getRawMessage().getMap();
String senderId = sockJSSocket.headers().get(WebSocketSessionHolder.USER_KEY);
String address = (String) rawMessage.get("address");
String msg = (String) rawMessage.get("body");
RedisSockjsClient.PUBLISH(address,
new JsonObject()
.put("message", msg)
.put("sender", senderId));
// vertx.eventBus().publish(address,
// new JsonObject()
// .put("message", msg)
// .put("sender", senderId));
isHandle = Boolean.TRUE;
}
return isHandle;
}
示例5: socketJSRegister
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
private SockJSHandler socketJSRegister() {
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
//[appName].[address]
options.addOutboundPermitted(new PermittedOptions().setAddressRegex(appConfig.getAppName() + "..*"));
sockJSHandler.bridge(options, event -> {
if (event.type() == BridgeEventType.SOCKET_CREATED) {
}
event.complete(true);
});
return sockJSHandler;
}
示例6: createFromController
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
static Map<BridgeEventType, Method> createFromController(Class<?> controller) {
Map<BridgeEventType, Method> map = new EnumMap<>(BridgeEventType.class);
for (Method method : controller.getMethods()) {
createFromMethod(map, method);
}
return map;
}
示例7: createFromAnnotation
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
private static void createFromAnnotation(Map<BridgeEventType, Method> map, Method method, Annotation annot) {
BridgeEventType type = types.get(annot.annotationType());
if (type != null && map.get(type) != null) {
throw new IllegalArgumentException("You cannot register many methods on the same BridgeEvent.Type");
} else if (type != null ){
map.put(type, method);
}
}
示例8: eventBusHandler
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
private SockJSHandler eventBusHandler() {
BridgeOptions options = new BridgeOptions()
.addOutboundPermitted(new PermittedOptions().setAddressRegex("auction\\.[0-9]+"));
return SockJSHandler.create(vertx).bridge(options, event -> {
if (event.type() == BridgeEventType.SOCKET_CREATED) {
logger.info("A socket was created");
}
event.complete(true);
});
}
示例9: handle
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
@Override
public boolean handle(BridgeEvent event) throws EventBridgeChainException {
boolean isHandle = Boolean.FALSE;
if(BridgeEventType.SEND == event.type()) {
Vertx vertx = VertxHolder.getVertx();
SockJSSocket sockJSSocket = event.socket();
Map<String, Object> rawMessage = event.getRawMessage().getMap();
String replyAddress = (String) rawMessage.get("replyAddress");
String address = (String) rawMessage.get("address");
if("vertx.basicauthmanager.login".equals(address)) {
@SuppressWarnings("unchecked")
Map<String, String> credential = (Map<String, String>) rawMessage.get("body");
String userId = credential.get("username");
//String password = credential.get("password");
if(userId == null || "".equals(userId)) {
logger.warn("Connection rejected");
sockJSSocket.close();
throw new EventBridgeChainException(true, "No user attached");
}
else {
boolean exists = WebSocketSessionHolder.exists(userId);
if(exists) {
throw new EventBridgeChainException(true, "User already registered");
}
sockJSSocket.headers().set(WebSocketSessionHolder.USER_KEY, userId);
requestLogService.logWebSocketConnection(sockJSSocket);
WebSocketSessionHolder.add(userId, sockJSSocket);
System.out.println(vertx);
System.out.println(vertx.eventBus());
System.out.println(userId);
RedisSockjsClient.PUBLISH("topic/chat/user",
new JsonObject()
.put("userId", userId));
// publish there is a new user coming
// vertx.eventBus().publish("topic/chat/user",
// new JsonObject()
// .put("userId", userId));
// get all online and send back to
JsonObject json = new JsonObject()
.put("type", "login") // optional
.put("address", replyAddress)
.put("body",
new JsonObject()
.put("result", true)
.put("list", WebSocketSessionHolder.getUsers()));
String data = json.toString();
sockJSSocket.write(Buffer.buffer(data));
isHandle = Boolean.TRUE;
}
}
}
return isHandle;
}
示例10: start
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
@Override
public void start() throws Exception{
if( VertxHolder.getVertx() == null ) VertxHolder.setVertx(vertx);
logger.info("Pub/Sub SockJs Server started on port {}", serverPort);
Router router = Router.router(vertx);
SockJSHandler socketHandler = SockJSHandler.create(vertx)
.bridge(new BridgeOptions()
.addOutboundPermitted(new PermittedOptions().setAddressRegex("^topic/.*"))
// use to set client ping timeout -> will result closing connection if no ping sent
/*.setPingTimeout(60000)*/,
new Handler<BridgeEvent>() {
@Override
public void handle(BridgeEvent event) {
boolean isResult = true;
String message = "Oops!";
System.out.println(event.type());
EventBridgeChainResponse processInChain = eventBridgeChain.processInChain(event);
if(processInChain.isProcesssed()) {
if(processInChain.getException() != null) {
isResult = false;
logger.error(processInChain.getException().getMessage(),
processInChain.getException());
message = processInChain.getException().getMessage();
}
}
if(isResult) {
if(event.type().equals(BridgeEventType.REGISTER)){
System.out.println(event.getRawMessage());
RedisSockjsClient.REGISTER(event);
}
event.complete(isResult);
}
else {
event.fail(new Exception(message));
}
}
});
router.route("/sockjs/*").handler(
socketHandler
);
/*
* subscribe published message
*/
vertx.deployVerticle(new MessageSubscribeVerticle(), new DeploymentOptions().setWorker(true).setMultiThreaded(true));
vertx.deployVerticle(new MessageSubscribeVerticle(), new DeploymentOptions().setWorker(true).setMultiThreaded(true));
vertx.deployVerticle(new MessageSubscribeVerticle(), new DeploymentOptions().setWorker(true).setMultiThreaded(true));
HttpServer server = vertx.createHttpServer().requestHandler(router::accept);
server.listen(serverPort);
}
示例11: createFromMethod
import io.vertx.ext.web.handler.sockjs.BridgeEventType; //导入依赖的package包/类
private static void createFromMethod(Map<BridgeEventType, Method> map, Method method) {
for (Annotation annot : method.getDeclaredAnnotations()) {
createFromAnnotation(map, method, annot);
}
}