本文整理汇总了Java中io.vertx.ext.web.handler.sockjs.PermittedOptions类的典型用法代码示例。如果您正苦于以下问题:Java PermittedOptions类的具体用法?Java PermittedOptions怎么用?Java PermittedOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PermittedOptions类属于io.vertx.ext.web.handler.sockjs包,在下文中一共展示了PermittedOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: eventBusHandler
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的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: loadPlugins
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
@Override
protected void loadPlugins() {
super.loadPlugins();
plugins.add(new Plugin() {
@Override
public Single<Void> preRoute() {
AppGlobals globals = AppGlobals.get();
SockJSHandler sockJSHandler = SockJSHandler.create(globals.getVertx());
BridgeOptions bridgeOptions = new BridgeOptions()
.addInboundPermitted(new PermittedOptions().setAddress("app.markdown"))
.addOutboundPermitted(new PermittedOptions().setAddress("page.saved"));
sockJSHandler.bridge(bridgeOptions);
globals.getRouter().route("/eventbus/*").handler(sockJSHandler);
return super.preRoute();
}
});
}
示例3: eventBusBridgeOptions
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
private static BridgeOptions eventBusBridgeOptions() {
BridgeOptions options = new BridgeOptions();
options.setInboundPermitted(ImmutableList.of(
new PermittedOptions().setAddress(BrowserEvents.userPositionTracking),
new PermittedOptions().setAddress(BrowserEvents.replayUserPositions)
));
options.setOutboundPermitted(ImmutableList.of(
new PermittedOptions().setAddress(BrowserEvents.userPositionTracking),
new PermittedOptions().setAddress(BrowserEvents.replayUserPositions)
));
return options;
}
示例4: initWebSocket
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
private void initWebSocket() {
Router router = Router.router(vertx);
SockJSHandlerOptions options = new SockJSHandlerOptions()
.setHeartbeatInterval(1000 * 60);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);
PermittedOptions inboundPermitted = new PermittedOptions().setAddressRegex("server/.*");
PermittedOptions outboundPermitted = new PermittedOptions().setAddressRegex("client/.*");
BridgeOptions ops = new BridgeOptions()
.addInboundPermitted(inboundPermitted)
.addOutboundPermitted(outboundPermitted);
sockJSHandler.bridge(ops);
router.route("/eb/*").handler(sockJSHandler);
mainRouter.mountSubRouter("/ws", router);
}
示例5: createSockJSServer
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
private void createSockJSServer(final ConfigurationContext context) throws InitializationException {
final int port = context.getProperty(PORT).asInteger();
final String ContextPath = context.getProperty(CONTEXT_PATH).getValue();
Router router = Router.router(vertx);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
if (context.getProperty(INBOUND_ADDRESS_REGEX).isSet()) {
options.addInboundPermitted(new PermittedOptions().setAddressRegex(context.getProperty(INBOUND_ADDRESS_REGEX).getValue()));
}
if (context.getProperty(OUTBOUND_ADDRESS_REGEX).isSet()) {
options.addOutboundPermitted(new PermittedOptions().setAddressRegex(context.getProperty(OUTBOUND_ADDRESS_REGEX).getValue()));
}
sockJSHandler.bridge(options);
router.route(ContextPath).handler(sockJSHandler);
httpServer = vertx.createHttpServer().requestHandler(router::accept).listen(port);
}
示例6: serviceAndSockJS
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
public void serviceAndSockJS(Vertx vertx) {
SomeDatabaseService service = new SomeDatabaseServiceImpl();
ProxyHelper.registerService(SomeDatabaseService.class, vertx, service,
"database-service-address");
Router router = Router.router(vertx);
// Allow events for the designated addresses in/out of the event bus bridge
BridgeOptions opts = new BridgeOptions()
.addInboundPermitted(new PermittedOptions()
.setAddress("database-service-address"))
.addOutboundPermitted(new PermittedOptions()
.setAddress("database-service-address"));
// Create the event bus bridge and add it to the router.
SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts);
router.route("/eventbus/*").handler(ebHandler);
vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}
示例7: eventBusHandler
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
private SockJSHandler eventBusHandler() {
SockJSHandler handler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
// open access
PermittedOptions permitted = new PermittedOptions();
options.addOutboundPermitted(permitted);
handler.bridge(options);
return handler;
}
示例8: addOutboundPermitted
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
private void addOutboundPermitted(BridgeOptions bridgeOptions, JsonObject outbound) {
PermittedOptions permittedOptions=new PermittedOptions();
permittedOptions.setAddress(outbound.getString(ADDRESS));
String authority=outbound.getString(REQUIRED_AUTHORITY, EMPTY_CSRF_SECRET);
if(!authority.isEmpty())
permittedOptions.setRequiredAuthority(authority);
bridgeOptions.addOutboundPermitted(permittedOptions);
}
示例9: addInboundPermitted
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
private void addInboundPermitted(BridgeOptions bridgeOptions, JsonObject inbound) {
PermittedOptions permittedOptions=new PermittedOptions();
permittedOptions.setAddress(inbound.getString(ADDRESS));
String authority=inbound.getString(REQUIRED_AUTHORITY, EMPTY_CSRF_SECRET);
if(!authority.isEmpty())
permittedOptions.setRequiredAuthority(authority);
bridgeOptions.addInboundPermitted(permittedOptions);
}
示例10: configure
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
@Override
public SockJSHandler configure(VertxContext vertxContext, ServerConfiguration<JsonObject, JsonObject[]> config) {
BridgeOptions bridgeOptions=new BridgeOptions();
bridgeOptions.addOutboundPermitted(new PermittedOptions().setAddress(VertxBusContext.DEFAULT_SOCKJS_ADDRESS));
SockJSHandler sockJSHandler = SockJSHandler.create(vertxContext.vertx());
sockJSHandler.bridge(bridgeOptions, event -> event.complete(true));
sockJSHandler.socketHandler(event -> event.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW_ALL));
return sockJSHandler;
}
示例11: eventBusHandler
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的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);
});
}
示例12: start
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
@Start
public void start() {
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
PermittedOptions chatPermission = new PermittedOptions().setAddress("chat");
PermittedOptions outboundPermitted1 = new PermittedOptions().setAddress("chat");
options.addInboundPermitted(chatPermission);
options.addOutboundPermitted(outboundPermitted1);
sockJSHandler.bridge(options);
Route route = router.route("/eventbus/*");
routes.add(route);
route.handler(sockJSHandler);
}
示例13: start
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
@Override
public void start() throws Exception {
// Vert.x Web router
Router router = Router.router(vertx);
// Routes definition
router.get().path("/temp/:sensorId").handler(this::handlerGetTemp);
router.put().path("/led").handler(this::handlerPutLed);
// Setting Bridge permissions
BridgeOptions options = new BridgeOptions()
.addInboundPermitted(new PermittedOptions().setAddress("sensor-temp"))
// all outbound messages are permitted
.addOutboundPermitted(new PermittedOptions());
router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options));
// Serve static Files from webroot dir
router.route().handler(StaticHandler.create());
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8000, event -> {
log.info("HTTP Server started on port 8000");
});
}
示例14: start
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
@Override
public void start() throws Exception {
super.start();
Router router = Router.router(vertx);
// create Dropwizard metrics service
MetricsService service = MetricsService.create(vertx);
// event bus bridge
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions()
.addOutboundPermitted(new PermittedOptions().setAddress("microservice.monitor.metrics"))
.addOutboundPermitted(new PermittedOptions().setAddress("events.log"));
sockJSHandler.bridge(options);
router.route("/eventbus/*").handler(sockJSHandler);
// discovery endpoint
ServiceDiscoveryRestEndpoint.create(router, discovery);
// static content
router.route("/*").handler(StaticHandler.create());
int port = config().getInteger("monitor.http.port", 9100);
String host = config().getString("monitor.http.host", "0.0.0.0");
int metricsInterval = config().getInteger("monitor.metrics.interval", 5000);
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(port, host);
// send metrics message to the event bus
vertx.setPeriodic(metricsInterval, t -> {
JsonObject metrics = service.getMetricsSnapshot(vertx);
vertx.eventBus().publish("microservice.monitor.metrics", metrics);
});
}
示例15: start
import io.vertx.ext.web.handler.sockjs.PermittedOptions; //导入依赖的package包/类
@Override
public void start() {
// Initialize the router and a webserver with HTTP-compression
Router router = Router.router(vertx);
PermittedOptions freewayOK = new PermittedOptions().setAddress(Client.freeway);
PermittedOptions myDtoOK = new PermittedOptions().setAddress(Client.addressPojo);
BridgeOptions firewall = new BridgeOptions().addInboundPermitted(freewayOK).addOutboundPermitted(freewayOK)
.addInboundPermitted(myDtoOK).addOutboundPermitted(myDtoOK);
router.route("/chatEventbus/*").handler(SockJSHandler.create(vertx).bridge(firewall
// If you want to know the sender, add it as header:
// , be -> {
// if (be.type() == BridgeEventType.RECEIVE || be.type() ==
// BridgeEventType.PUBLISH) {
// JsonObject headers = be.getRawMessage().getJsonObject("headers");
// if (headers == null) {
// headers = new JsonObject();
// be.getRawMessage().put("headers", headers); }
// headers.put("sender", be.socket().writeHandlerID()); }
// be.complete(true); }
));
// to broadcast: vertx.eventBus().publish(Client.freeway,"Bla");
// to receive: vertx.eventBus().consumer(Client.freeway, m -> ... );
// broadcasting to everyone is done automaticly by .publish()
// extra: pojo example
Pojofy.eventbus(Client.addressPojo, Dto.class, this::serviceDoSomething);
AllExamplesServer.start(Client.class, router);
}