Package org.atmosphere.cpr
Class AtmosphereResourceImpl
java.lang.Object
org.atmosphere.cpr.AtmosphereResourceImpl
- All Implemented Interfaces:
AtmosphereResource
- Author:
- Jeanfrancois Arcand
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.atmosphere.cpr.AtmosphereResource
AtmosphereResource.TRANSPORT -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AsyncSupport<AtmosphereResourceImpl> protected Broadcasterprotected final List<Broadcaster> static final Stringstatic final Stringprotected javax.servlet.http.HttpSessionstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionAtmosphereResourceImpl(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport<AtmosphereResourceImpl> asyncSupport, AtmosphereHandler atmosphereHandler) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid_destroy()action()Return theActionwhich represent the state of the response, e.g.addBroadcaster(Broadcaster broadcaster) Add/Associate aBroadcasterwith this resource.atmosphereHandler(AtmosphereHandler atmosphereHandler) Return an unmodifiable list ofBroadcasters associated with this resourcevoidcancel()voidclose()Close the underlying connection.voiddisableSuspend(boolean disableSuspend) booleanReturn true ifAtmosphereResourceEventListener.onSuspend(AtmosphereResourceEvent)andAtmosphereResourceEventListener.onPreSuspend(AtmosphereResourceEvent)events are disabled.disableSuspendEvent(boolean disableSuspendEvent) booleanbooleanReturn true when binary write is forced.forceBinaryWrite(boolean forceBinaryWrite) Force binary write and never write String value.booleanbooleanReturn theAtmosphereConfig.Return the associatedAtmosphereHandlerassociated with this resource.Return the currentAtmosphereResourceEvent.Return the first addedBroadcaster.protected BroadcastergetBroadcaster(boolean autoCreate) Return the underlyingAtmosphereRequestrequest.getRequest(boolean enforceScope) Return theAtmosphereResponse.getResponse(boolean enforceScope) Get theSerializeror null if not defined.inthashCode()initialize(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler) Initialize anAtmosphereResource.booleanReturn true if this object has been cancelled.booleanCheck if theAtmosphereRequeststill is valid.booleanbooleanReturn true if this object has been resumed.booleanReturn true if theAtmosphereResource.suspend()has been invoked.Notify allAtmosphereResourceEventListeners.Notify allAtmosphereResourceEventListener.voidNotifyAtmosphereResourceEventListenerthah an unexpected exception occured.protected voidregister()removeBroadcaster(Broadcaster broadcaster) Remove aBroadcasterwith this resource.Remove aAtmosphereResourceEventListener.Remove allAtmosphereResourceEventListeners.Remove thisAtmosphereResourcefrom allBroadcastervoidreset()Completely reset the instance to its initial state.resume()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.javax.servlet.http.HttpSessionsession()Return theHttpSessionif supported, null if notjavax.servlet.http.HttpSessionsession(boolean create) Return theHttpSessionif supported, and creates it if not already created.session(javax.servlet.http.HttpSession session) setBroadcaster(Broadcaster broadcaster) Set the firstBroadcasterassociated with this resource.voidsetIsInScope(boolean isInScope) Protect the object from being used after it got cancelled.Set theSerializerused to write broadcasted objects.protected voidsuspend()Suspend theAtmosphereResponseindefinitely.suspend(long timeout) Suspend theAtmosphereResponse.Suspend theAtmosphereResponse.toString()Return the currentAtmosphereResource.TRANSPORT.transport(AtmosphereResource.TRANSPORT transport) Manually set theAtmosphereResource.TRANSPORTprotected AtmosphereResourceuniqueBroadcaster(Broadcaster newB) uuid()Return the unique ID associated with this AtmosphereResource.write(byte[] o) Write the bytes IfAtmosphereResource.resumeOnBroadcast()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.
-
Field Details
-
PRE_SUSPEND
-
SKIP_BROADCASTER_CREATION
-
METEOR
-
broadcasters
-
broadcaster
-
asyncSupport
-
session
protected javax.servlet.http.HttpSession session
-
-
Constructor Details
-
AtmosphereResourceImpl
public AtmosphereResourceImpl() -
AtmosphereResourceImpl
@Deprecated public AtmosphereResourceImpl(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport<AtmosphereResourceImpl> asyncSupport, AtmosphereHandler atmosphereHandler) Deprecated.
-
-
Method Details
-
initialize
public AtmosphereResource initialize(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler) Initialize anAtmosphereResource.- Specified by:
initializein interfaceAtmosphereResource- Parameters:
config- TheAtmosphereConfigbroadcaster- TheBroadcaster.req- TheAtmosphereRequestresponse- TheAtmosphereResourceasyncSupport- TheAsyncSupportatmosphereHandler- TheAtmosphereHandler- Returns:
- this
-
setUUID
-
register
protected void register() -
getAtmosphereResourceEvent
Description copied from interface:AtmosphereResourceReturn the currentAtmosphereResourceEvent.- Specified by:
getAtmosphereResourceEventin interfaceAtmosphereResource
-
getAtmosphereHandler
Description copied from interface:AtmosphereResourceReturn the associatedAtmosphereHandlerassociated with this resource.- Specified by:
getAtmosphereHandlerin interfaceAtmosphereResource- Returns:
- the associated
AtmosphereHandlerassociated with this resource
-
writeOnTimeout
Description copied from interface:AtmosphereResource- Specified by:
writeOnTimeoutin interfaceAtmosphereResource- Returns:
- this
-
writeOnTimeout
Description copied from interface:AtmosphereResourceReturn the object that will be written when the resource times out.- Specified by:
writeOnTimeoutin interfaceAtmosphereResource
-
uuid
Description copied from interface:AtmosphereResourceReturn the unique ID associated with this AtmosphereResource.- Specified by:
uuidin interfaceAtmosphereResource- Returns:
- the unique ID associated with this AtmosphereResource
-
transport
Description copied from interface:AtmosphereResourceReturn the currentAtmosphereResource.TRANSPORT. The transport value is retrieved using theHeaderConfig.X_ATMOSPHERE_TRANSPORTheader value.- Specified by:
transportin interfaceAtmosphereResource
-
transport
Manually set theAtmosphereResource.TRANSPORT- Parameters:
transport- set theAtmosphereResource.TRANSPORT
-
resumeOnBroadcast
Description copied from interface:AtmosphereResourceSet to true to resume the response after the first broadcast. False by default.- Specified by:
resumeOnBroadcastin interfaceAtmosphereResource- Parameters:
resumeOnBroadcast- boolean
-
isSuspended
public boolean isSuspended()Description copied from interface:AtmosphereResourceReturn true if theAtmosphereResource.suspend()has been invoked.- Specified by:
isSuspendedin interfaceAtmosphereResource- Returns:
- true if the
AtmosphereResource.suspend()has been invoked
-
resumeOnBroadcast
public boolean resumeOnBroadcast()Description copied from interface:AtmosphereResourceReturn true if this AtmosphereResource is resumed after the first broadcast.- Specified by:
resumeOnBroadcastin interfaceAtmosphereResource- See Also:
-
resume
Description copied from interface:AtmosphereResourceComplete theAtmosphereResponseand finish/commit it. If theAtmosphereResponseis in the process of being resumed, invoking this method has no effect.- Specified by:
resumein interfaceAtmosphereResource
-
suspend
Description copied from interface:AtmosphereResourceSuspend 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.- Specified by:
suspendin interfaceAtmosphereResource
-
suspend
Description copied from interface:AtmosphereResourceSuspend 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.- Specified by:
suspendin interfaceAtmosphereResource- 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
-
suspend
Description copied from interface:AtmosphereResourceSuspend 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.- Specified by:
suspendin interfaceAtmosphereResource- 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.
-
getRequest
-
getResponse
-
getRequest
Description copied from interface:AtmosphereResourceReturn the underlyingAtmosphereRequestrequest.- Specified by:
getRequestin interfaceAtmosphereResource- Returns:
AtmosphereRequestthe underlying request.
-
getResponse
Description copied from interface:AtmosphereResourceReturn theAtmosphereResponse.- Specified by:
getResponsein interfaceAtmosphereResource- Returns:
AtmosphereResponsethe underlying response.
-
getBroadcaster
Description copied from interface:AtmosphereResourceReturn the first addedBroadcaster.- Specified by:
getBroadcasterin interfaceAtmosphereResource- Returns:
- the current
Broadcaster
-
broadcasters
Description copied from interface:AtmosphereResourceReturn an unmodifiable list ofBroadcasters associated with this resource- Specified by:
broadcastersin interfaceAtmosphereResource- Returns:
- an unmodifiable list of
Broadcaster
-
getBroadcaster
-
setBroadcaster
Description copied from interface:AtmosphereResourceSet the firstBroadcasterassociated with this resource. ThisBroadcasterwill be returned whenAtmosphereResource.getBroadcaster()is invoked.- Specified by:
setBroadcasterin interfaceAtmosphereResource- Parameters:
broadcaster-- Returns:
- this
-
addBroadcaster
Description copied from interface:AtmosphereResourceAdd/Associate aBroadcasterwith this resource.- Specified by:
addBroadcasterin interfaceAtmosphereResource- Parameters:
broadcaster-- Returns:
- this
-
removeBroadcaster
Description copied from interface:AtmosphereResourceRemove aBroadcasterwith this resource.- Specified by:
removeBroadcasterin interfaceAtmosphereResource- Parameters:
broadcaster-- Returns:
- this
-
uniqueBroadcaster
-
getAtmosphereConfig
Description copied from interface:AtmosphereResourceReturn theAtmosphereConfig.- Specified by:
getAtmosphereConfigin interfaceAtmosphereResource- Returns:
- the
AtmosphereConfig
-
action
Return theActionwhich represent the state of the response, e.g. suspended, resumed or timed out.- Returns:
- the
Action
-
reset
public void reset()Completely reset the instance to its initial state. -
setIsInScope
public void setIsInScope(boolean isInScope) Protect the object from being used after it got cancelled. -
isInScope
public boolean isInScope()Check if theAtmosphereRequeststill is valid.- Returns:
- true if the
AtmosphereRequeststill is valid
-
setSerializer
Set theSerializerused to write broadcasted objects.- Specified by:
setSerializerin interfaceAtmosphereResource- Parameters:
s- theSerializer- Returns:
- this
-
isResumed
public boolean isResumed()Description copied from interface:AtmosphereResourceReturn true if this object has been resumed.- Specified by:
isResumedin interfaceAtmosphereResource- Returns:
- true if this object has been resumed
-
isCancelled
public boolean isCancelled()Description copied from interface:AtmosphereResourceReturn true if this object has been cancelled.- Specified by:
isCancelledin interfaceAtmosphereResource- Returns:
- true if this object has been cancelled
-
write
Description copied from interface:AtmosphereResourceWrite the String. IfAtmosphereResource.resumeOnBroadcast()is true, the underlying connection will be resumed (@link #resume());- Specified by:
writein interfaceAtmosphereResource- Parameters:
s-- Returns:
- this
-
write
Description copied from interface:AtmosphereResourceWrite the bytes IfAtmosphereResource.resumeOnBroadcast()is true, the underlying connection will be resumed (@link #resume());- Specified by:
writein interfaceAtmosphereResource- Parameters:
o-- Returns:
- this
-
getSerializer
Description copied from interface:AtmosphereResourceGet theSerializeror null if not defined.- Specified by:
getSerializerin interfaceAtmosphereResource- Returns:
- the
Serializeror null if not defined
-
addEventListener
- Specified by:
addEventListenerin interfaceAtmosphereResource- Parameters:
e- an instance of AtmosphereResourceEventListener- Returns:
- this
-
removeEventListener
Description copied from interface:AtmosphereResourceRemove aAtmosphereResourceEventListener.- Specified by:
removeEventListenerin interfaceAtmosphereResource- Parameters:
e-- Returns:
- this
-
removeEventListeners
Description copied from interface:AtmosphereResourceRemove allAtmosphereResourceEventListeners.- Specified by:
removeEventListenersin interfaceAtmosphereResource- Returns:
- this
-
notifyListeners
Description copied from interface:AtmosphereResourceNotify allAtmosphereResourceEventListeners.- Specified by:
notifyListenersin interfaceAtmosphereResource- Returns:
- this
-
notifyListeners
Description copied from interface:AtmosphereResourceNotify allAtmosphereResourceEventListener.- Specified by:
notifyListenersin interfaceAtmosphereResource- Parameters:
event- an instance of AtmosphereResourceEvent- Returns:
- this
-
removeFromAllBroadcasters
Description copied from interface:AtmosphereResourceRemove thisAtmosphereResourcefrom allBroadcaster- Specified by:
removeFromAllBroadcastersin interfaceAtmosphereResource- Returns:
- this
-
onThrowable
NotifyAtmosphereResourceEventListenerthah an unexpected exception occured. -
atmosphereResourceEventListener
-
atmosphereHandler
-
cancel
- Throws:
IOException
-
_destroy
public void _destroy() -
toString
-
disableSuspend
-
session
public javax.servlet.http.HttpSession session(boolean create) Description copied from interface:AtmosphereResourceReturn theHttpSessionif supported, and creates it if not already created.- Specified by:
sessionin interfaceAtmosphereResource- Returns:
- the
HttpSessionif supported, and creates it if not already created
-
close
Description copied from interface:AtmosphereResourceClose the underlying connection. Invoking this method will close the underlying connection and resume theAtmosphereResource}.- Specified by:
closein interfaceAtmosphereResource- Throws:
IOException
-
dirtyClose
public void dirtyClose() -
forceBinaryWrite
Description copied from interface:AtmosphereResourceForce binary write and never write String value. return this- Specified by:
forceBinaryWritein interfaceAtmosphereResource
-
forceBinaryWrite
public boolean forceBinaryWrite()Description copied from interface:AtmosphereResourceReturn true when binary write is forced.- Specified by:
forceBinaryWritein interfaceAtmosphereResource- Returns:
- true when binary write is forced.
-
session
public javax.servlet.http.HttpSession session()Description copied from interface:AtmosphereResourceReturn theHttpSessionif supported, null if not- Specified by:
sessionin interfaceAtmosphereResource- Returns:
- the
HttpSessionif supported, null if not
-
session
-
cloneState
-
listeners
-
disableSuspendEvent
Disable invocation ofAtmosphereResourceEventListener.onSuspend(AtmosphereResourceEvent)andAtmosphereResourceEventListener.onPreSuspend(AtmosphereResourceEvent). You normally disable those events after the first onSuspend has been called so all transports behave the same way.
AtmosphereResourceEventListenermarked withAllowInterceptorwill not be affected by this property.- Parameters:
disableSuspendEvent-- Returns:
- this
-
disableSuspendEvent
public boolean disableSuspendEvent()Return true ifAtmosphereResourceEventListener.onSuspend(AtmosphereResourceEvent)andAtmosphereResourceEventListener.onPreSuspend(AtmosphereResourceEvent)events are disabled.- Returns:
- true if disabled
-
webSocket
-
webSocket
-
equals
-
hashCode
public int hashCode() -
getAndSetInClosingPhase
public boolean getAndSetInClosingPhase() -
isPendingClose
public boolean isPendingClose()- Returns:
-
getAndSetPendingClose
public boolean getAndSetPendingClose()
-