Top Description Fields Constructors Methods
org.springframework.web.socket.client

public abstract Class ConnectionManagerSupport

extends Object
implements SmartLifecycle
Class Inheritance
All Implemented Interfaces
org.springframework.context.SmartLifecycle, org.springframework.context.Phased, org.springframework.context.Lifecycle
Known Direct Subclasses
org.springframework.web.socket.client.WebSocketConnectionManager, org.springframework.web.socket.client.standard.AnnotatedEndpointConnectionManager, org.springframework.web.socket.client.standard.EndpointConnectionManager
Imports
java.net.URI, org.apache.commons.logging.Log, .LogFactory, org.springframework.context.SmartLifecycle, org.springframework.web.util.UriComponentsBuilder

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.
Author
Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
private boolean
private final Object
protected final Log
private int
private volatile boolean
private final URI

Constructor Summary

AccessConstructor and Description
public
ConnectionManagerSupport(String uriTemplate, Object... uriVariables)

Constructor with a URI template and variables.

public
ConnectionManagerSupport(URI
the url to connect to
uri
)

Constructor with a prepared URI.

Method Summary

Modifier and TypeMethod and Description
protected abstract void
closeConnection()

Subclasses implement this to close the connection.

public int
getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Return the phase in which this endpoint connection factory will be auto-connected and stopped.

protected URI
public boolean
isAutoStartup()

Overrides default org.springframework.context.SmartLifecycle.isAutoStartup.

Return the value for the 'autoStartup' property.

public abstract boolean
isConnected()

Whether the connection is open/true or closed/false.

public boolean
isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Return whether this ConnectionManager has been started.

protected abstract void
openConnection()

Subclasses implement this to actually establish the connection.

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.

public void
setPhase(int phase)

Specify the phase in which a connection should be established to the remote endpoint and subsequently closed.

public final void
start()

Implements org.springframework.context.Lifecycle.start.

Start the WebSocket connection.

protected void
public final void
stop()

Implements org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.

public final void
stop(Runnable callback)

Overrides default org.springframework.context.SmartLifecycle.stop.

Indicates that a Lifecycle component must stop if it is currently running.

protected void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoStartupback to summary
private boolean autoStartup
lifecycleMonitorback to summary
private final Object lifecycleMonitor
loggerback to summary
protected final Log logger
phaseback to summary
private int phase
runningback to summary
private volatile boolean running
uriback to summary
private final URI uri

Constructor Detail

ConnectionManagerSupportback to summary
public ConnectionManagerSupport(String uriTemplate, Object... uriVariables)

Constructor with a URI template and variables.

ConnectionManagerSupportback to summary
public ConnectionManagerSupport(URI uri)

Constructor with a prepared URI.

Parameters
uri:URI

the url to connect to

Since
6.0.5

Method Detail

closeConnectionback to summary
protected abstract void closeConnection() throws Exception

Subclasses implement this to close the connection.

getPhaseback to summary
public int getPhase()

Overrides default org.springframework.context.SmartLifecycle.getPhase.

Return the phase in which this endpoint connection factory will be auto-connected and stopped.

Annotations
@Override
getUriback to summary
protected URI getUri()
isAutoStartupback to summary
public boolean isAutoStartup()

Overrides default org.springframework.context.SmartLifecycle.isAutoStartup.

Return the value for the 'autoStartup' property. If "true", this endpoint connection manager will connect to the remote endpoint upon a ContextRefreshedEvent.

Annotations
@Override
isConnectedback to summary
public abstract boolean isConnected()

Whether the connection is open/true or closed/false.

isRunningback to summary
public boolean isRunning()

Implements org.springframework.context.Lifecycle.isRunning.

Return whether this ConnectionManager has been started.

Returns:boolean

Doc from org.springframework.context.Lifecycle.isRunning.

whether the component is currently running

Annotations
@Override
openConnectionback to summary
protected abstract void openConnection()

Subclasses implement this to actually establish the connection.

setAutoStartupback to summary
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".

setPhaseback to summary
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.

startback to summary
public final void start()

Implements org.springframework.context.Lifecycle.start.

Start the WebSocket connection. If already connected, the method has no impact.

Annotations
@Override
startInternalback to summary
protected void startInternal()
stopback to summary
public final void stop()

Implements org.springframework.context.Lifecycle.stop.

Doc from org.springframework.context.Lifecycle.stop.

Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementing SmartLifecycle and its stop(Runnable) variant when asynchronous stop behavior is necessary.

Note that this stop notification is not guaranteed to come before destruction: On regular shutdown, Lifecycle beans 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.

Annotations
@Override
stopback to summary
public final void stop(Runnable callback)

Overrides default org.springframework.context.SmartLifecycle.stop.

Doc from org.springframework.context.SmartLifecycle.stop.

Indicates that a Lifecycle component must stop if it is currently running.

The provided callback is used by the LifecycleProcessor to support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after the SmartLifecycle component does indeed stop.

The LifecycleProcessor will call only this variant of the stop method; i.e. Lifecycle#stop() will not be called for SmartLifecycle implementations unless explicitly delegated to within the implementation of this method.

The default implementation delegates to stop() and immediately triggers the given callback in the calling thread. Note that there is no synchronization between the two, so custom implementations may at least want to put the same steps within their common lifecycle monitor (if any).

Annotations
@Override
stopInternalback to summary
protected void stopInternal() throws Exception