question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add option to remove a added route from HttpServerRoutes

See original GitHub issue

At the moment it’s not possible to remove a previously added route from HttpServerRoutes

Motivation

I’m currently working on an “Webflux light” for OSGI. Because of the dynamic nature of OSGI (Components are dynamic added/removed) I need a way to remove a previous added route when the component that added the route is removed.

While the OSGI side is pretty easy to implement, the problem is that there is no way currently to remove a previous added route …

Desired solution

Extend HttpServerRoutes to a remove option. Remove option should be overloaded to be able to remove by:

(Examples, not thread safe)

  • Predicate instance
  public HttpServerRoutes remove(Predicate<? super HttpServerRequest> condition) {
      for(HttpRouteHandler h: handlers){
          if(h.condition.equals(condition)){
              handlers.remove(h);
          }
      }
      return this;
  }
  • Handler instance
  public HttpServerRoutes remove(BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler) {
      for(HttpRouteHandler h: handlers){
          if(h.handler.equals(handler)){
              handlers.remove(h);
          }
      }
      return this;
  }
  • Path
 public HttpServerRoutes remove(String path) {
     for(HttpRouteHandler h: handlers){
         if(h.path != null && h.path.equals(path)){
             handlers.remove(h);
         }
     }
     return this;
 }

Considered alternatives

Extend HttpServerRoutes and add a new variant for each method that uses a publisher as a argument

  public interface HttpServerRoute {

      Predicate<? super HttpServerRequest> condition();

      BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler()

  }

public void route(Publisher<HttpServerRoute> publisher) {
  publisher.subscribe(new Subscriber<HttpServerRoute>() {
  
	  private final List<HttpRouteHandler> publisherHandlers = new CopyOnWriteArrayList<>();
  
	  @Override
	  public void onSubscribe(Subscription subscription) {
		  subscription.request(Integer.MAX_VALUE);
	  }
  
	  @Override
	  public void onNext(HttpServerRoute httpServerRoute) {
		  publisherHandlers.add(addRoute(httpServerRoute.condition(), httpServerRoute.handler()));
	  }
  
	  @Override
	  public void onError(Throwable t) {
  
		  // TODO: Remove all handlers added ??????
  
	  }
  
	  @Override
	  public void onComplete() {
  
		  // Remove all handler added by the publisher
		  initialOrderHandlers.removeAll(publisherHandlers);
		  handlers.removeAll(publisherHandlers);
	  }
  });
}

or

Extend HttpServerRoutes and add a new variant for each method that returns a Subscription or similar.

  public Subscription publishRoute(Predicate<? super HttpServerRequest> condition,
                                BiFunction<? super HttpServerRequest, ? super HttpServerResponse, ? extends Publisher<Void>> handler) {
      Objects.requireNonNull(condition, "condition");
      Objects.requireNonNull(handler, "handler");

      if (condition instanceof HttpPredicate) {
          HttpRouteHandler httpRouteHandler = new HttpRouteHandler(condition,
                  handler,
                  (HttpPredicate) condition, ((HttpPredicate) condition).uri);

          handlers.add(httpRouteHandler);
          initialOrderHandlers.add(httpRouteHandler);
          return new Subscription() {
              @Override
              public void request(long n) {

              }

              @Override
              public void cancel() {
                  handlers.remove(httpRouteHandler);
              }
          };

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
roggenbrotcommented, Jul 20, 2021

I’m currently on vacation. I will update the issue asap

1reaction
roggenbrotcommented, Jun 15, 2021

I’m willing to provide a pull request if this is something you would consider to add

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Add or Remove Static Route on Windows - Action1
In this article, we will look at what a 'static route' is and why it should be added at all. We will use...
Read more >
reactor-netty/HttpServerRoutes.java at main - GitHub
Listens for HTTP DELETE on the passed path to be used as a routing condition. ... <p>Additional regex matching is available, e.g. "/test/{param}"....
Read more >
HttpServerRoutes (reactor-netty 1.1.0)
Listens for HTTP DELETE on the passed path to be used as a routing condition. default HttpServerRoutes · directory(String uri, Path directory). Listens...
Read more >
How do I delete a route from Linux routing table - Server Fault
The net-tools way to delete these routes would be to use route del on it. ... Please note that this applies to routes...
Read more >
How to check, add and delete routes in linux
To check the routing table · Adding route · Deleting route · A quick way to add default route · A quick way...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found