Java Code Examples for io.vertx.core.http.ServerWebSocket#binaryHandlerID()

The following examples show how to use io.vertx.core.http.ServerWebSocket#binaryHandlerID() . 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 vote down vote up
@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: WSClusterHandler.java    From vert.x-microservice with Apache License 2.0 5 votes vote down vote up
@Override
public void findRouteSocketInRegistryAndRemove(ServerWebSocket serverSocket) {
    final String binaryHandlerID = serverSocket.binaryHandlerID();
    final String textHandlerID = serverSocket.textHandlerID();
    this.vertx.sharedData().<String, WSEndpointHolder>getClusterWideMap(WS_REGISTRY, onSuccess(registryMap -> registryMap.get(WS_ENDPOINT_HOLDER, wsEndpointHolder -> {
        retrieveEndpointHolderAndRemove(serverSocket, binaryHandlerID, textHandlerID, registryMap, wsEndpointHolder);

    }))
    );
}
 
Example 3
Source File: WSClusterHandler.java    From vert.x-microservice with Apache License 2.0 5 votes vote down vote up
private void updateWSEndpointHolder(ServerWebSocket serverSocket, AsyncMap<String, WSEndpointHolder> registryMap, AsyncResult<WSEndpointHolder> wsEndpointHolder) {
    log("add entry: " + Thread.currentThread());
    final String binaryHandlerId = serverSocket.binaryHandlerID();
    final String textHandlerId = serverSocket.textHandlerID();
    final String path = serverSocket.path();
    final EventBus eventBus = vertx.eventBus();
    final WSEndpoint endpoint = new WSEndpoint(binaryHandlerId, textHandlerId, path);
    final WSEndpointHolder result = wsEndpointHolder.result();
    if (result != null) {
        addDefinitionToRegistry(serverSocket, eventBus, path, endpoint, registryMap, result);
    } else {
        createEntryAndAddDefinition(serverSocket, eventBus, path, endpoint, registryMap);
    }
}
 
Example 4
Source File: WSLocalHandler.java    From vert.x-microservice with Apache License 2.0 3 votes vote down vote up
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);


}