Package org.atmosphere.cpr
Interface AtmosphereResource
-
- All Known Implementing Classes:
AtmosphereResourceImpl
public interface AtmosphereResourceAnAtmosphereResourceencapsulates the mechanism tosuspend(),resume()and broadcast (getBroadcaster()) messages among suspended resources.AtmosphereResources are passed to an instance ofAtmosphereHandlerat runtime.- Author:
- Jeanfrancois Arcand
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classAtmosphereResource.TRANSPORT
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description AtmosphereResourceaddBroadcaster(Broadcaster broadcaster)Add/Associate aBroadcasterwith this resource.AtmosphereResourceaddEventListener(AtmosphereResourceEventListener e)java.util.List<Broadcaster>broadcasters()Return an unmodifiable list ofBroadcasters associated with this resourcevoidclose()Close the underlying connection.booleanforceBinaryWrite()Return true when binary write is forced.AtmosphereResourceforceBinaryWrite(boolean force)Force binary write and never write String value.AtmosphereConfiggetAtmosphereConfig()Return theAtmosphereConfig.AtmosphereHandlergetAtmosphereHandler()Return the associatedAtmosphereHandlerassociated with this resource.AtmosphereResourceEventgetAtmosphereResourceEvent()Return the currentAtmosphereResourceEvent.BroadcastergetBroadcaster()Return the first addedBroadcaster.AtmosphereRequestgetRequest()Return the underlyingAtmosphereRequestrequest.AtmosphereResponsegetResponse()Return theAtmosphereResponse.SerializergetSerializer()Get theSerializeror null if not defined.AtmosphereResourceinitialize(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler)Initialize anAtmosphereResource.booleanisCancelled()Return true if this object has been cancelled.booleanisResumed()Return true if this object has been resumed.booleanisSuspended()Return true if thesuspend()has been invoked.AtmosphereResourcenotifyListeners()Notify allAtmosphereResourceEventListeners.AtmosphereResourcenotifyListeners(AtmosphereResourceEvent e)Notify allAtmosphereResourceEventListener.AtmosphereResourceremoveBroadcaster(Broadcaster broadcaster)Remove aBroadcasterwith this resource.AtmosphereResourceremoveEventListener(AtmosphereResourceEventListener e)Remove aAtmosphereResourceEventListener.AtmosphereResourceremoveEventListeners()Remove allAtmosphereResourceEventListeners.AtmosphereResourceremoveFromAllBroadcasters()Remove thisAtmosphereResourcefrom allBroadcasterAtmosphereResourceresume()Complete theAtmosphereResponseand finish/commit it.booleanresumeOnBroadcast()Return true if this AtmosphereResource is resumed after the first broadcast.AtmosphereResourceresumeOnBroadcast(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.AtmosphereResourcesetBroadcaster(Broadcaster broadcaster)Set the firstBroadcasterassociated with this resource.AtmosphereResourcesetSerializer(Serializer s)Set theSerializerto use whenwrite(java.lang.String)execute the operation.AtmosphereResourcesuspend()Suspend theAtmosphereResponseindefinitely.AtmosphereResourcesuspend(long timeout)Suspend theAtmosphereResponse.AtmosphereResourcesuspend(long timeout, java.util.concurrent.TimeUnit timeunit)Suspend theAtmosphereResponse.AtmosphereResource.TRANSPORTtransport()Return the currentAtmosphereResource.TRANSPORT.java.lang.Stringuuid()Return the unique ID associated with this AtmosphereResource.AtmosphereResourcewrite(byte[] s)Write the bytes IfresumeOnBroadcast()is true, the underlying connection will be resumed (@link #resume());AtmosphereResourcewrite(java.lang.String s)Write the String.java.lang.ObjectwriteOnTimeout()Return the object that will be written when the resource times out.AtmosphereResourcewriteOnTimeout(java.lang.Object o)Set a message that will be written when the resource times out.
-
-
-
Method Detail
-
transport
AtmosphereResource.TRANSPORT transport()
Return the currentAtmosphereResource.TRANSPORT. The transport value is retrieved using theHeaderConfig.X_ATMOSPHERE_TRANSPORTheader value.
-
resumeOnBroadcast
AtmosphereResource resumeOnBroadcast(boolean 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:
resumeOnBroadcast()
-
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
AtmosphereResource suspend(long timeout)
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
AtmosphereResource suspend(long timeout, java.util.concurrent.TimeUnit timeunit)
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
java.util.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
AtmosphereResource setBroadcaster(Broadcaster broadcaster)
Set the firstBroadcasterassociated with this resource. ThisBroadcasterwill be returned whengetBroadcaster()is invoked.- Parameters:
broadcaster-- Returns:
- this
-
addBroadcaster
AtmosphereResource addBroadcaster(Broadcaster broadcaster)
Add/Associate aBroadcasterwith this resource.- Parameters:
broadcaster-- Returns:
- this
-
removeBroadcaster
AtmosphereResource removeBroadcaster(Broadcaster broadcaster)
Remove aBroadcasterwith this resource.- Parameters:
broadcaster-- Returns:
- this
-
setSerializer
AtmosphereResource setSerializer(Serializer s)
Set theSerializerto use whenwrite(java.lang.String)execute the operation. By default, theSerializeris null.- Parameters:
s- theSerializer- Returns:
- this
-
write
AtmosphereResource write(java.lang.String s)
Write the String. IfresumeOnBroadcast()is true, the underlying connection will be resumed (@link #resume());- Parameters:
s-- Returns:
- this
-
write
AtmosphereResource write(byte[] s)
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
AtmosphereResource writeOnTimeout(java.lang.Object o)
Set a message that will be written when the resource times out. Can be anObjectorCallable.- Returns:
- this
-
writeOnTimeout
java.lang.Object writeOnTimeout()
Return the object that will be written when the resource times out.
-
uuid
java.lang.String uuid()
Return the unique ID associated with this AtmosphereResource.- Returns:
- the unique ID associated with this AtmosphereResource
-
addEventListener
AtmosphereResource addEventListener(AtmosphereResourceEventListener e)
- Parameters:
e- an instance of AtmosphereResourceEventListener- Returns:
- this
-
removeEventListener
AtmosphereResource removeEventListener(AtmosphereResourceEventListener e)
Remove aAtmosphereResourceEventListener.- Parameters:
e-- Returns:
- this
-
removeEventListeners
AtmosphereResource removeEventListeners()
Remove allAtmosphereResourceEventListeners.- Returns:
- this
-
notifyListeners
AtmosphereResource notifyListeners(AtmosphereResourceEvent e)
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
void close() throws java.io.IOExceptionClose the underlying connection. Invoking this method will close the underlying connection and resume theAtmosphereResource}.- Throws:
java.io.IOException
-
forceBinaryWrite
AtmosphereResource forceBinaryWrite(boolean force)
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
-
-