• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BridgeEventType类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
    });
}
 
开发者ID:AlxGDev,项目名称:BittrexGatherer,代码行数:21,代码来源:BittrexVerticle.java


示例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);
	});
}
 
开发者ID:simonemasoni,项目名称:vertx_spring,代码行数:10,代码来源:RestVerticle.java


示例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;
	}
 
开发者ID:unlogicaldev,项目名称:slime,代码行数:30,代码来源:OfflineChainHandler.java


示例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;
	}
 
开发者ID:unlogicaldev,项目名称:slime,代码行数:29,代码来源:ChatMessageChainHandler.java


示例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;

}
 
开发者ID:quebic-source,项目名称:puppy-io,代码行数:14,代码来源:ServerVerticle.java


示例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;
}
 
开发者ID:aesteve,项目名称:nubes,代码行数:8,代码来源:BridgeEventFactory.java


示例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);
  }
}
 
开发者ID:aesteve,项目名称:nubes,代码行数:9,代码来源:BridgeEventFactory.java


示例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);
    });
}
 
开发者ID:mwarc,项目名称:realtime-auctions-vertx3-example,代码行数:11,代码来源:SockJSBridgeVerticle.java


示例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;
	}
 
开发者ID:unlogicaldev,项目名称:slime,代码行数:71,代码来源:LoginChainHandler.java


示例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);

}
 
开发者ID:unlogicaldev,项目名称:slime,代码行数:69,代码来源:PubSubSockJsServer.java


示例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);
  }
}
 
开发者ID:aesteve,项目名称:nubes,代码行数:6,代码来源:BridgeEventFactory.java



注:本文中的io.vertx.ext.web.handler.sockjs.BridgeEventType类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SchemaConfigured类代码示例发布时间:2022-05-22
下一篇:
Java Track类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap