Class 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
- 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 Summary
FieldsModifier and TypeFieldDescriptionprotected ExecutorServiceprotected DNSCacheprotected ExchangeStoreprotected HotDeploymentThreadprotected static final HashSet<org.springframework.context.ApplicationContext>In case more than onestarts within the same app context, we track them here, so they start only one HotDeploymentThread. protected Stringprotected ResolverMapprotected RuleManagerprotected Statisticsprotected Transportprotected URIFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidorg.springframework.context.ApplicationContextgetId()getJmx()getParentProxy(Interceptor interceptor) intgetRules()voidinit()static Routerstatic Routerinit(String resource, ClassLoader classLoader) booleanbooleanbooleanbooleanvoidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetBaseLocation(String baseLocation) voidvoidsetExchangeStore(ExchangeStore exchangeStore) voidsetHotDeploy(boolean hotDeploy) voidsetHttpClientConfig(HttpClientConfiguration httpClientConfig) voidvoidsetProduction(boolean production) voidsetRetryInit(boolean retryInit) voidsetRetryInitInterval(int retryInitInterval) voidsetRuleManager(RuleManager ruleManager) voidsetRules(Collection<Rule> proxies) voidsetTransport(Transport transport) voidsetUriFactory(URIFactory uriFactory) voidshutdown()Closes all ports (if any were opened) and waits for running exchanges to complete.voidDeprecated.voidstart()voidstop()voidstopAll()voidvoidwaitFor()waits until the router has shut down
-
Field Details
-
hotDeployingContexts
In case more than onestarts within the same app context, we track them here, so they start only one HotDeploymentThread. -
ruleManager
-
exchangeStore
-
transport
-
resolverMap
-
dnsCache
-
backgroundInitializator
-
hdt
-
uriFactory
-
statistics
-
jmxRouterName
-
-
Constructor Details
-
Router
public Router()
-
-
Method Details
-
getRules
-
setRules
-
init
- Throws:
MalformedURLException
-
init
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
getRuleManager
-
setRuleManager
-
getExchangeStore
-
setExchangeStore
- Default
- create a
LimitedMemoryExchangeStorelimited 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
-
setTransport
-
getHttpClientConfig
-
setHttpClientConfig
-
getDnsCache
-
getResolverMap
-
shutdown
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.Simply invokesshutdown(). "Not waiting" is not supported anymore, as open connections can now be forcibly closed after a timeout. SeeHttpTransport.setForceSocketCloseOnHotDeployAfter(int).Closes all ports (if any were opened), but does not wait for running exchanges to complete.- Throws:
IOException
-
getBackgroundInitializator
-
getParentProxy
-
add
- Throws:
IOException
-
init
- Throws:
Exception
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
tryReinitialization
public void tryReinitialization() -
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
stopAll
public void stopAll() -
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.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
-
setBaseLocation
-
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
-
setUriFactory
-
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
-
setJmx
-
getJmx
-
setBeanName
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
getId
-
waitFor
waits until the router has shut down- Throws:
InterruptedException
-
getTimerManager
-
getKubernetesClientFactory
-
getHttpClientFactory
-
shutdown().