Package org.atmosphere.cpr
Interface AtmosphereResource
- All Known Implementing Classes:
AtmosphereResourceImpl
public interface AtmosphereResource
An
AtmosphereResource encapsulates the mechanism to suspend(), resume() and
broadcast (getBroadcaster()) messages among suspended resources. AtmosphereResources are passed to
an instance of AtmosphereHandler at runtime.- Author:
- Jeanfrancois Arcand
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionaddBroadcaster(Broadcaster broadcaster) Add/Associate aBroadcasterwith this resource.Return an unmodifiable list ofBroadcasters associated with this resourcevoidclose()Close the underlying connection.booleanReturn true when binary write is forced.forceBinaryWrite(boolean force) Force binary write and never write String value.Return theAtmosphereConfig.Return the associatedAtmosphereHandlerassociated with this resource.Return the currentAtmosphereResourceEvent.Return the first addedBroadcaster.Return the underlyingAtmosphereRequestrequest.Return theAtmosphereResponse.Get theSerializeror null if not defined.initialize(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler) Initialize anAtmosphereResource.booleanReturn true if this object has been cancelled.booleanReturn true if this object has been resumed.booleanReturn true if thesuspend()has been invoked.Notify allAtmosphereResourceEventListeners.Notify allAtmosphereResourceEventListener.removeBroadcaster(Broadcaster broadcaster) Remove aBroadcasterwith this resource.Remove aAtmosphereResourceEventListener.Remove allAtmosphereResourceEventListeners.Remove thisAtmosphereResourcefrom allBroadcasterresume()Complete theAtmosphereResponseand finish/commit it.booleanReturn true if this AtmosphereResource is resumed after the first broadcast.resumeOnBroadcast(boolean resumeOnBroadcast) Set to true to resume the response after the first broadcast.jakarta.servlet.http.HttpSessionsession()Return theHttpSessionif supported, null if notjakarta.servlet.http.HttpSessionsession(boolean create) Return theHttpSessionif supported, and creates it if not already created.setBroadcaster(Broadcaster broadcaster) Set the firstBroadcasterassociated with this resource.Set theSerializerto use whenwrite(java.lang.String)execute the operation.suspend()Suspend theAtmosphereResponseindefinitely.suspend(long timeout) Suspend theAtmosphereResponse.Suspend theAtmosphereResponse.Return the currentAtmosphereResource.TRANSPORT.uuid()Return the unique ID associated with this AtmosphereResource.write(byte[] s) Write the bytes IfresumeOnBroadcast()is true, the underlying connection will be resumed (@link #resume());Write the String.Return the object that will be written when the resource times out.Set a message that will be written when the resource times out.
-
Method Details
-
transport
AtmosphereResource.TRANSPORT transport()Return the currentAtmosphereResource.TRANSPORT. The transport value is retrieved using theHeaderConfig.X_ATMOSPHERE_TRANSPORTheader value. -
resumeOnBroadcast
Set to true to resume the response after the first broadcast. False by default.- Parameters:
resumeOnBroadcast- boolean
-
isSuspended
boolean isSuspended()Return true if thesuspend()has been invoked.- Returns:
- true if the
suspend()has been invoked
-
resumeOnBroadcast
boolean resumeOnBroadcast()Return true if this AtmosphereResource is resumed after the first broadcast.- See Also:
-
isResumed
boolean isResumed()Return true if this object has been resumed.- Returns:
- true if this object has been resumed
-
isCancelled
boolean isCancelled()Return true if this object has been cancelled.- Returns:
- true if this object has been cancelled
-
resume
AtmosphereResource resume()Complete theAtmosphereResponseand finish/commit it. If theAtmosphereResponseis in the process of being resumed, invoking this method has no effect. -
suspend
AtmosphereResource suspend()Suspend theAtmosphereResponseindefinitely. Suspending aAtmosphereResponsewill tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid committing a response. The Framework will output some HTML comments when suspending the response in order to make sure all browsers work well with suspended responses. -
suspend
Suspend theAtmosphereResponse. Suspending aAtmosphereResponsewill tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid committing response. Invoking this method when a request is being timed out (e.g.AtmosphereResourceEvent.isResumedOnTimeout()returns true) has no effect.- Parameters:
timeout- The maximum amount of time, in milliseconds, aAtmosphereResponsecan be suspended. When the timeout expires, theAtmosphereResponsewill be automatically resumed and committed. Usage of any methods of aAtmosphereResponsethat times out will throw anIllegalStateException.
-
suspend
Suspend theAtmosphereResponse. Suspending aAtmosphereResponsewill tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid committing response. Invoking this method when a request is being timed out (e.g.AtmosphereResourceEvent.isResumedOnTimeout()returns true) has no effect.- Parameters:
timeout- The maximum amount of time aAtmosphereResponsecan be suspended. When the timeout expires, theAtmosphereResponsewill be automatically resumed and committed. Usage of any methods of aAtmosphereResponsethat times out will throw anIllegalStateException.timeunit- The time unit of the timeout value
-
getRequest
AtmosphereRequest getRequest()Return the underlyingAtmosphereRequestrequest.- Returns:
AtmosphereRequestthe underlying request.
-
getResponse
AtmosphereResponse getResponse()Return theAtmosphereResponse.- Returns:
AtmosphereResponsethe underlying response.
-
getAtmosphereConfig
AtmosphereConfig getAtmosphereConfig()Return theAtmosphereConfig.- Returns:
- the
AtmosphereConfig
-
getBroadcaster
Broadcaster getBroadcaster()Return the first addedBroadcaster.- Returns:
- the current
Broadcaster
-
broadcasters
List<Broadcaster> broadcasters()Return an unmodifiable list ofBroadcasters associated with this resource- Returns:
- an unmodifiable list of
Broadcaster
-
removeFromAllBroadcasters
AtmosphereResource removeFromAllBroadcasters()Remove thisAtmosphereResourcefrom allBroadcaster- Returns:
- this
-
setBroadcaster
Set the firstBroadcasterassociated with this resource. ThisBroadcasterwill be returned whengetBroadcaster()is invoked.- Parameters:
broadcaster-- Returns:
- this
-
addBroadcaster
Add/Associate aBroadcasterwith this resource.- Parameters:
broadcaster-- Returns:
- this
-
removeBroadcaster
Remove aBroadcasterwith this resource.- Parameters:
broadcaster-- Returns:
- this
-
setSerializer
Set theSerializerto use whenwrite(java.lang.String)execute the operation. By default, theSerializeris null.- Parameters:
s- theSerializer- Returns:
- this
-
write
Write the String. IfresumeOnBroadcast()is true, the underlying connection will be resumed (@link #resume());- Parameters:
s-- Returns:
- this
-
write
Write the bytes IfresumeOnBroadcast()is true, the underlying connection will be resumed (@link #resume());- Parameters:
s-- Returns:
- this
-
getSerializer
Serializer getSerializer()Get theSerializeror null if not defined.- Returns:
- the
Serializeror null if not defined
-
getAtmosphereResourceEvent
AtmosphereResourceEvent getAtmosphereResourceEvent()Return the currentAtmosphereResourceEvent. -
getAtmosphereHandler
AtmosphereHandler getAtmosphereHandler()Return the associatedAtmosphereHandlerassociated with this resource.- Returns:
- the associated
AtmosphereHandlerassociated with this resource
-
writeOnTimeout
- Returns:
- this
-
writeOnTimeout
Object writeOnTimeout()Return the object that will be written when the resource times out. -
uuid
String uuid()Return the unique ID associated with this AtmosphereResource.- Returns:
- the unique ID associated with this AtmosphereResource
-
addEventListener
- Parameters:
e- an instance of AtmosphereResourceEventListener- Returns:
- this
-
removeEventListener
Remove aAtmosphereResourceEventListener.- Parameters:
e-- Returns:
- this
-
removeEventListeners
AtmosphereResource removeEventListeners()Remove allAtmosphereResourceEventListeners.- Returns:
- this
-
notifyListeners
Notify allAtmosphereResourceEventListener.- Parameters:
e- an instance of AtmosphereResourceEvent- Returns:
- this
-
notifyListeners
AtmosphereResource notifyListeners()Notify allAtmosphereResourceEventListeners.- Returns:
- this
-
session
jakarta.servlet.http.HttpSession session()Return theHttpSessionif supported, null if not- Returns:
- the
HttpSessionif supported, null if not
-
session
jakarta.servlet.http.HttpSession session(boolean create) Return theHttpSessionif supported, and creates it if not already created.- Returns:
- the
HttpSessionif supported, and creates it if not already created
-
close
Close the underlying connection. Invoking this method will close the underlying connection and resume theAtmosphereResource}.- Throws:
IOException
-
forceBinaryWrite
Force binary write and never write String value. return this -
forceBinaryWrite
boolean forceBinaryWrite()Return true when binary write is forced.- Returns:
- true when binary write is forced.
-
initialize
AtmosphereResource initialize(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler) Initialize anAtmosphereResource.- Parameters:
config- TheAtmosphereConfigbroadcaster- TheBroadcaster.req- TheAtmosphereRequestresponse- TheAtmosphereResourceasyncSupport- TheAsyncSupportatmosphereHandler- TheAtmosphereHandler- Returns:
- this
-