Java Code Examples for io.vertx.core.shareddata.SharedData#getLocalMap()
The following examples show how to use
io.vertx.core.shareddata.SharedData#getLocalMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSLocalHandler.java From vert.x-microservice with Apache License 2.0 | 6 votes |
@Override public void findRouteSocketInRegistryAndRemove(ServerWebSocket serverSocket) { final SharedData sharedData = this.vertx.sharedData(); final String binaryHandlerID = serverSocket.binaryHandlerID(); final String textHandlerID = serverSocket.textHandlerID(); final LocalMap<String, byte[]> wsRegistry = sharedData.getLocalMap(WS_REGISTRY); final WSEndpointHolder holder = getWSEndpointHolderFromSharedData(wsRegistry); if (holder != null) { final List<WSEndpoint> all = holder.getAll(); final Optional<WSEndpoint> first = all.parallelStream().filter(e -> e.getBinaryHandlerId().equals(binaryHandlerID) && e.getTextHandlerId().equals(textHandlerID)).findFirst(); first.ifPresent(endpoint -> { holder.remove(endpoint); wsRegistry.replace(WS_ENDPOINT_HOLDER, serialize(holder)); log("OK REMOVE: " + serverSocket.binaryHandlerID()); }); } }
Example 2
Source File: WSLocalHandler.java From vert.x-microservice with Apache License 2.0 | 6 votes |
@Override public void replyToAllWS(Message<byte[]> message) { try { log("Reply to all: " + this); final WSMessageWrapper wrapper = (WSMessageWrapper) Serializer.deserialize(message.body()); final String stringResult = TypeTool.trySerializeToString(wrapper.getBody()); final byte[] payload = stringResult != null ? stringResult.getBytes() : Serializer.serialize(wrapper.getBody()); final SharedData sharedData = this.vertx.sharedData(); final LocalMap<String, byte[]> wsRegistry = sharedData.getLocalMap(WS_REGISTRY); final byte[] holderPayload = wsRegistry.get(WS_ENDPOINT_HOLDER); if (holderPayload != null) { final WSEndpointHolder holder = (WSEndpointHolder) deserialize(holderPayload); final List<WSEndpoint> all = holder.getAll(); all.parallelStream(). filter(endP -> endP.getUrl().equals(wrapper.getEndpoint().getUrl())). forEach( endpoint -> replyToEndpoint(stringResult, payload, endpoint) ); } } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } }
Example 3
Source File: LocalMapValueParamInjector.java From nubes with Apache License 2.0 | 5 votes |
@Override public Object resolve(RoutingContext context, LocalMapValue annotation, String paramName, Class<?> resultClass) { SharedData sd = context.vertx().sharedData(); String mapName = annotation.mapName(); String key = annotation.key(); if ("".equals(key)) { key = paramName; } io.vertx.core.shareddata.LocalMap<Object, Object> map = sd.getLocalMap(mapName); return map.get(key); }
Example 4
Source File: LocalMapParamInjector.java From nubes with Apache License 2.0 | 5 votes |
@Override public Object resolve(RoutingContext context, VertxLocalMap annotation, String paramName, Class<?> resultClass) { SharedData sd = context.vertx().sharedData(); String mapName = annotation.value(); if ("".equals(mapName)) { mapName = paramName; } return sd.getLocalMap(mapName); }
Example 5
Source File: WSLocalHandler.java From vert.x-microservice with Apache License 2.0 | 3 votes |
private void createEndpointDefinitionAndRegister(ServerWebSocket serverSocket) { final SharedData sharedData = this.vertx.sharedData(); final LocalMap<String, byte[]> wsRegistry = sharedData.getLocalMap(WS_REGISTRY); final WSEndpointHolder holder = getWSEndpointHolderFromSharedData(wsRegistry); final String path = serverSocket.path(); final WSEndpoint endpoint = new WSEndpoint(serverSocket.binaryHandlerID(), serverSocket.textHandlerID(), path); replaceOrAddEndpoint(wsRegistry, holder, endpoint); sendToWSService(serverSocket, path, endpoint); }