Class Router

java.lang.Object
com.predic8.membrane.core.Router
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle
Direct Known Subclasses:
HttpRouter

public class Router extends Object implements org.springframework.context.Lifecycle, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.BeanNameAware
Description

Membrane API Gateway's main object.

The router is a Spring Lifecycle object: It is automatically started and stopped according to the Lifecycle of the Spring Context containing it. In Membrane's standard setup (standalone or in a J2EE web app), Membrane itself controls the creation of the Spring Context and its Lifecycle.

In this case, the router is hot deployable: It can monitor proxies.xml, the Spring configuration file, for changes and reinitialize the Spring Context, when a change is detected. Note that, during the Spring Context restart, the router object itself along with almost all other Membrane objects (interceptors, etc.) will be recreated.

Topic
1. Membrane Service Proxy
  • Field Details

    • hotDeployingContexts

      protected static final HashSet<org.springframework.context.ApplicationContext> hotDeployingContexts
      In case more than one starts within the same app context, we track them here, so they start only one HotDeploymentThread.
    • ruleManager

      protected RuleManager ruleManager
    • exchangeStore

      protected ExchangeStore exchangeStore
    • transport

      protected Transport transport
    • resolverMap

      protected ResolverMap resolverMap
    • dnsCache

      protected DNSCache dnsCache
    • backgroundInitializator

      protected ExecutorService backgroundInitializator
    • hdt

      protected HotDeploymentThread hdt
    • uriFactory

      protected URIFactory uriFactory
    • statistics

      protected Statistics statistics
    • jmxRouterName

      protected String jmxRouterName
  • Constructor Details

    • Router

      public Router()
  • Method Details

    • getRules

      public Collection<Rule> getRules()
    • setRules

      public void setRules(Collection<Rule> proxies)
    • init

      public static Router init(String configFileName) throws MalformedURLException
      Throws:
      MalformedURLException
    • init

      public static Router init(String resource, ClassLoader classLoader)
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • getRuleManager

      public RuleManager getRuleManager()
    • setRuleManager

      public void setRuleManager(RuleManager ruleManager)
    • getExchangeStore

      public ExchangeStore getExchangeStore()
    • setExchangeStore

      public void setExchangeStore(ExchangeStore exchangeStore)
      Default
      create a LimitedMemoryExchangeStore limited to the size of 1 MB.
      Description
      Spring Bean ID of an ExchangeStore. The exchange store will be used by this router's components (AdminConsoleInterceptor, ExchangeStoreInterceptor, etc.) by default, if no other exchange store is explicitly set to be used by them.
    • getTransport

      public Transport getTransport()
    • setTransport

      public void setTransport(Transport transport)
    • getHttpClientConfig

      public HttpClientConfiguration getHttpClientConfig()
    • setHttpClientConfig

      public void setHttpClientConfig(HttpClientConfiguration httpClientConfig)
    • getDnsCache

      public DNSCache getDnsCache()
    • getResolverMap

      public ResolverMap getResolverMap()
    • shutdown

      public void shutdown() throws IOException
      Closes all ports (if any were opened) and waits for running exchanges to complete.

      When running as an embedded servlet, this has no effect.

      Throws:
      IOException
    • shutdownNoWait

      @Deprecated public void shutdownNoWait() throws IOException
      Deprecated.
      Simply invokes shutdown(). "Not waiting" is not supported anymore, as open connections can now be forcibly closed after a timeout. See HttpTransport.setForceSocketCloseOnHotDeployAfter(int).
      Closes all ports (if any were opened), but does not wait for running exchanges to complete.
      Throws:
      IOException
    • getBackgroundInitializator

      public ExecutorService getBackgroundInitializator()
    • getParentProxy

      public Rule getParentProxy(Interceptor interceptor)
    • add

      public void add(Rule rule) throws IOException
      Throws:
      IOException
    • init

      public void init() throws Exception
      Throws:
      Exception
    • start

      public void start()
      Specified by:
      start in interface org.springframework.context.Lifecycle
    • tryReinitialization

      public void tryReinitialization()
    • stop

      public void stop()
      Specified by:
      stop in interface org.springframework.context.Lifecycle
    • stopAll

      public void stopAll()
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface org.springframework.context.Lifecycle
    • setHotDeploy

      public void setHotDeploy(boolean hotDeploy)
      Parameters:
      hotDeploy - If true the hot deploy feature is activated
      Default
      true
      Description

      Whether changes to the router's configuration file should automatically trigger a restart.

      Monitoring the router's configuration file proxies.xml is only possible, if the router is created by a Spring Application Context which supports monitoring.

    • isHotDeploy

      public boolean isHotDeploy()
    • getRetryInitInterval

      public int getRetryInitInterval()
    • setRetryInitInterval

      public void setRetryInitInterval(int retryInitInterval)
      Default
      5 minutes
      Description
      number of milliseconds after which reinitialization of <soapProxy>s should be attempted periodically
    • getBaseLocation

      public String getBaseLocation()
    • setBaseLocation

      public void setBaseLocation(String baseLocation)
    • getBeanFactory

      public org.springframework.context.ApplicationContext getBeanFactory()
    • isRetryInit

      public boolean isRetryInit()
    • setRetryInit

      public void setRetryInit(boolean retryInit)
      Default
      false
      Explanation

      Whether the router should continue startup, if initialization of a rule (proxy, serviceProxy or soapProxy) failed (for example, when a WSDL a component depends on could not be downloaded).

      If false, the router will exit with code -1 just after startup, when the initialization of a rule failed.

      If true, the router will continue startup, and all rules which could not be initialized will be inactive (=not Rule.isActive()).

      Inactive rules

      Inactive rules will simply be ignored for routing decissions for incoming requests. This means that requests for inactive rules might be routed using different routes or result in a "400 Bad Request" when no active route could be matched to the request.

      Once rules become active due to reinitialization, they are considered in future routing decissions.

      Reinitialization

      Inactive rules may be reinitialized and, if reinitialization succeeds, become active.

      By default, reinitialization is attempted at regular intervals using a timer (see setRetryInitInterval(int)).

      Additionally, using the AdminConsoleInterceptor, an admin may trigger reinitialization of inactive rules at any time.

    • getUriFactory

      public URIFactory getUriFactory()
    • setUriFactory

      public void setUriFactory(URIFactory uriFactory)
    • isProduction

      public boolean isProduction()
    • setProduction

      public void setProduction(boolean production)
      Default
      false
      Explanation

      By default the error messages Membrane sends back to an HTTP client provide information to help the caller find the problem. The caller might even get sensitive information. In production the error messages should not reveal to much details. With this option you can put Membrane in production mode and reduce the amount of information in error messages.

    • getStatistics

      public Statistics getStatistics()
    • setJmx

      public void setJmx(String name)
    • getJmx

      public String getJmx()
    • setBeanName

      public void setBeanName(String s)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • getId

      public String getId()
    • waitFor

      public void waitFor() throws InterruptedException
      waits until the router has shut down
      Throws:
      InterruptedException
    • getTimerManager

      public TimerManager getTimerManager()
    • getKubernetesClientFactory

      public KubernetesClientFactory getKubernetesClientFactory()
    • getHttpClientFactory

      public HttpClientFactory getHttpClientFactory()