Package org.atmosphere.cpr
Class AtmosphereSession
java.lang.Object
org.atmosphere.cpr.AtmosphereSession
An AtmosphereSession allow an application to keep track of the AtmosphereResource associated with a remote client.
For example, with the long-polling transport, a new
AtmosphereResource will be created every time a
reconnect occurs. If an application has a reference to the AtmosphereResource, the object will become
out of scope, or unusable, after the reconnection. To fix this problem, you can use this class to track and invoke
tryAcquire() ()} or acquire()} in order to get the AtmosphereResource.
AtmosphereResource are tracked using the list of associated Broadcaster, e.g you must make sure the AtmosphereResource
has called Broadcaster.addAtmosphereResource(AtmosphereResource) once if you want this class to work.- Author:
- Jeanfrancois Arcand
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BroadcasterListenerAdapterprotected final Semaphoreprotected final org.slf4j.Loggerprotected Broadcaster[]protected final AtomicReference<AtmosphereResource> protected final booleanprotected String -
Constructor Summary
ConstructorsConstructorDescriptionAtmosphereSession(AtmosphereResource resource) Track the currentAtmosphereResourcewith all createdBroadcasterAtmosphereSession(AtmosphereResource r, Broadcaster... broadcasters) -
Method Summary
Modifier and TypeMethodDescriptionacquire()Retrieve theAtmosphereResourceassociated with this session.voidclose()Retrieve theAtmosphereResourceassociated with this session.tryAcquire(int timeInSecond) Retrieve theAtmosphereResourceassociated with this session.uuid()
-
Field Details
-
logger
protected final org.slf4j.Logger logger -
resource
-
uuid
-
latch
-
broadcasterListener
-
usesLongPolling
protected final boolean usesLongPolling
-
-
Constructor Details
-
AtmosphereSession
-
AtmosphereSession
Track the currentAtmosphereResourcewith all createdBroadcaster- Parameters:
resource- anAtmosphereResource
-
-
Method Details
-
acquire
Retrieve theAtmosphereResourceassociated with this session. If there is noAtmosphereResourceassociated, return null.- Returns:
- an
AtmosphereResource
-
tryAcquire
Retrieve theAtmosphereResourceassociated with this session. If there is noAtmosphereResourceassociated, wait until theAtmosphereResourceis retrieved. This method will wait 60 seconds and then return.- Returns:
- an
AtmosphereResource - Throws:
InterruptedException
-
tryAcquire
Retrieve theAtmosphereResourceassociated with this session. If there is noAtmosphereResourceassociated, wait until theAtmosphereResourceis retrieved.If the resource uses long polling as its transport, this method treats the resource as a single use connection and will make subsequent callers wait until the client reconnects and the
broadcasterListener'sBroadcasterListenerAdapter.onAddAtmosphereResource(org.atmosphere.cpr.Broadcaster, org.atmosphere.cpr.AtmosphereResource)method gets called again.WARNING: Use this method with long polling only if you intend to broadcast to the returned resource. If no broadcast is made, the client won't have to reconnect, the resource won't get re-added, and any subsequent calls will have to wait until the timeout is reached.
- Parameters:
timeInSecond- The timeToWait before continuing the execution- Returns:
- an
AtmosphereResourceornullif the resource was not set and it didn't get set during the timeout - Throws:
InterruptedException
-
close
public void close() -
uuid
-