Class ConnectionManagerSupport
java.lang.Object
org.springframework.web.socket.client.ConnectionManagerSupport
- All Implemented Interfaces:
org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle
- Direct Known Subclasses:
AnnotatedEndpointConnectionManager,EndpointConnectionManager,WebSocketConnectionManager
public abstract class ConnectionManagerSupport
extends Object
implements org.springframework.context.SmartLifecycle
Base class for a connection manager that automates the process of connecting
to a WebSocket server with the Spring ApplicationContext lifecycle. Connects
to a WebSocket server on
start() and disconnects on stop().
If setAutoStartup(boolean) is set to true this will be done
automatically when the Spring ApplicationContext is refreshed.- Since:
- 4.0
- Author:
- Rossen Stoyanchev
-
Field Summary
FieldsFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionConnectionManagerSupport(String uriTemplate, Object... uriVariables) Constructor with a URI template and variables.Constructor with a preparedURI. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidSubclasses implement this to close the connection.intgetPhase()Return the phase in which this endpoint connection factory will be auto-connected and stopped.protected URIgetUri()booleanReturn the value for the 'autoStartup' property.abstract booleanWhether the connection is open/trueor closed/false.booleanReturn whether this ConnectionManager has been started.protected abstract voidSubclasses implement this to actually establish the connection.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.final voidstart()Start the WebSocket connection.protected voidfinal voidstop()final voidprotected void
-
Field Details
-
logger
-
-
Constructor Details
-
ConnectionManagerSupport
Constructor with a URI template and variables. -
ConnectionManagerSupport
Constructor with a preparedURI.- Parameters:
uri- the url to connect to- Since:
- 6.0.5
-
-
Method Details
-
getUri
-
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 interfaceorg.springframework.context.SmartLifecycle
-
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.- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
start
public final void start()Start the WebSocket connection. If already connected, the method has no impact.- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
startInternal
protected void startInternal() -
stop
public final void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
stop
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
stopInternal
- Throws:
Exception
-
isRunning
public boolean isRunning()Return whether this ConnectionManager has been started.- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
isConnected
public abstract boolean isConnected()Whether the connection is open/trueor closed/false. -
openConnection
protected abstract void openConnection()Subclasses implement this to actually establish the connection. -
closeConnection
Subclasses implement this to close the connection.- Throws:
Exception
-