Class ConnectionManagerSupport
- java.lang.Object
- org.springframework.web.socket.client.ConnectionManagerSupport
- All Implemented Interfaces:
Lifecycle,Phased,SmartLifecycle
- Direct Known Subclasses:
AnnotatedEndpointConnectionManager,EndpointConnectionManager,WebSocketConnectionManager
public abstract class ConnectionManagerSupport extends Object implements SmartLifecycle
A base class for WebSocket connection managers. Provides a declarative style of connecting to a WebSocket server given a URI to connect to. The connection occurs when the Spring ApplicationContext is refreshed, if theautoStartupproperty is set totrue, or if set tofalse, thestart()and #stop methods can be invoked manually.- Since:
- 4.0
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Constructor Description ConnectionManagerSupport(String uriTemplate, Object... uriVariables)
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidcloseConnection()intgetPhase()Return the phase in which this endpoint connection factory will be auto-connected and stopped.protected URIgetUri()booleanisAutoStartup()Return the value for the 'autoStartup' property.protected abstract booleanisConnected()booleanisRunning()Return whether this ConnectionManager has been started.protected abstract voidopenConnection()voidsetAutoStartup(boolean autoStartup)Set whether to auto-connect to the remote endpoint after this connection manager has been initialized and the Spring context has been refreshed.voidsetPhase(int phase)Specify the phase in which a connection should be established to the remote endpoint and subsequently closed.voidstart()Start the WebSocket connection.protected voidstartInternal()voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.voidstop(Runnable callback)Indicates that a Lifecycle component must stop if it is currently running.protected voidstopInternal()
Constructor Detail
ConnectionManagerSupport
public ConnectionManagerSupport(String uriTemplate, Object... uriVariables)
Method Detail
setAutoStartup
public void setAutoStartup(boolean autoStartup)
Set whether to auto-connect to the remote endpoint after this connection manager has been initialized and the Spring context has been refreshed.Default is "false".
isAutoStartup
public boolean isAutoStartup()
Return the value for the 'autoStartup' property. If "true", this endpoint connection manager will connect to the remote endpoint upon a ContextRefreshedEvent.- Specified by:
isAutoStartupin interfaceSmartLifecycle- See Also:
Lifecycle.start(),Phased.getPhase(),LifecycleProcessor.onRefresh(),ConfigurableApplicationContext.refresh()
setPhase
public void setPhase(int phase)
Specify the phase in which a connection should be established to the remote endpoint and subsequently closed. The startup order proceeds from lowest to highest, and the shutdown order is the reverse of that. By default this value is Integer.MAX_VALUE meaning that this endpoint connection factory connects as late as possible and is closed as soon as possible.
getPhase
public int getPhase()
Return the phase in which this endpoint connection factory will be auto-connected and stopped.
start
public final void start()
Start the WebSocket connection. If already connected, the method has no impact.- Specified by:
startin interfaceLifecycle- See Also:
SmartLifecycle.isAutoStartup()
startInternal
protected void startInternal()
stop
public final void stop()
Description copied from interface:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecyclebeans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.Should not throw an exception if the component is not running (not started yet).
In the case of a container, this will propagate the stop signal to all components that apply.
- Specified by:
stopin interfaceLifecycle- See Also:
SmartLifecycle.stop(Runnable),DisposableBean.destroy()
stop
public final void stop(Runnable callback)
Description copied from interface:SmartLifecycleIndicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the
LifecycleProcessorto support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecyclecomponent does indeed stop.The
LifecycleProcessorwill call only this variant of thestopmethod; i.e.Lifecycle.stop()will not be called forSmartLifecycleimplementations unless explicitly delegated to within the implementation of this method.- Specified by:
stopin interfaceSmartLifecycle- See Also:
Lifecycle.stop(),Phased.getPhase()
stopInternal
protected void stopInternal() throws Exception
- Throws:
Exception
isRunning
public boolean isRunning()
Return whether this ConnectionManager has been started.
openConnection
protected abstract void openConnection()
closeConnection
protected abstract void closeConnection() throws Exception
- Throws:
Exception
isConnected
protected abstract boolean isConnected()