Package org.atmosphere.cpr
Class AtmosphereResourceImpl
- java.lang.Object
-
- org.atmosphere.cpr.AtmosphereResourceImpl
-
- All Implemented Interfaces:
AtmosphereResource
public class AtmosphereResourceImpl extends java.lang.Object implements AtmosphereResource
- Author:
- Jeanfrancois Arcand
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.atmosphere.cpr.AtmosphereResource
AtmosphereResource.TRANSPORT
-
-
Field Summary
Fields Modifier and Type Field Description protected AsyncSupportasyncSupportprotected Broadcasterbroadcasterprotected java.util.List<Broadcaster>broadcastersstatic java.lang.StringMETEORstatic java.lang.StringPRE_SUSPENDprotected javax.servlet.http.HttpSessionsessionstatic java.lang.StringSKIP_BROADCASTER_CREATION
-
Constructor Summary
Constructors Constructor Description AtmosphereResourceImpl()AtmosphereResourceImpl(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void_destroy()Actionaction()Return theActionwhich represent the state of the response, e.g.AtmosphereResourceaddBroadcaster(Broadcaster broadcaster)Add/Associate aBroadcasterwith this resource.AtmosphereResourceaddEventListener(AtmosphereResourceEventListener e)AtmosphereResourceImplatmosphereHandler(AtmosphereHandler atmosphereHandler)java.util.concurrent.ConcurrentLinkedQueue<AtmosphereResourceEventListener>atmosphereResourceEventListener()java.util.List<Broadcaster>broadcasters()Return an unmodifiable list ofBroadcasters associated with this resourcevoidcancel()AtmosphereResourceImplcloneState(AtmosphereResource r)voidclose()Close the underlying connection.voiddirtyClose()AtmosphereResourceImpldisableSuspend(boolean disableSuspend)booleandisableSuspendEvent()Return true ifAtmosphereResourceEventListener.onSuspend(AtmosphereResourceEvent)andAtmosphereResourceEventListener.onPreSuspend(AtmosphereResourceEvent)events are disabled.AtmosphereResourceImpldisableSuspendEvent(boolean disableSuspendEvent)booleanequals(java.lang.Object o)booleanforceBinaryWrite()Return true when binary write is forced.AtmosphereResourceforceBinaryWrite(boolean forceBinaryWrite)Force binary write and never write String value.booleangetAndSetInClosingPhase()booleangetAndSetPendingClose()AtmosphereConfiggetAtmosphereConfig()Return theAtmosphereConfig.AtmosphereHandlergetAtmosphereHandler()Return the associatedAtmosphereHandlerassociated with this resource.AtmosphereResourceEventImplgetAtmosphereResourceEvent()Return the currentAtmosphereResourceEvent.BroadcastergetBroadcaster()Return the first addedBroadcaster.protected BroadcastergetBroadcaster(boolean autoCreate)AtmosphereRequestgetRequest()Return the underlyingAtmosphereRequestrequest.AtmosphereRequestgetRequest(boolean enforceScope)AtmosphereResponsegetResponse()Return theAtmosphereResponse.AtmosphereResponsegetResponse(boolean enforceScope)SerializergetSerializer()Get theSerializeror null if not defined.inthashCode()AtmosphereResourceinitialize(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler)Initialize anAtmosphereResource.booleanisCancelled()Return true if this object has been cancelled.booleanisInScope()Check if theAtmosphereRequeststill is valid.booleanisPendingClose()booleanisResumed()Return true if this object has been resumed.booleanisSuspended()Return true if theAtmosphereResource.suspend()has been invoked.java.util.concurrent.ConcurrentLinkedQueue<AtmosphereResourceEventListener>listeners()AtmosphereResourcenotifyListeners()Notify allAtmosphereResourceEventListeners.AtmosphereResourcenotifyListeners(AtmosphereResourceEvent event)Notify allAtmosphereResourceEventListener.voidonThrowable(java.lang.Throwable t)NotifyAtmosphereResourceEventListenerthah an unexpected exception occured.protected voidregister()AtmosphereResourceremoveBroadcaster(Broadcaster broadcaster)Remove aBroadcasterwith this resource.AtmosphereResourceremoveEventListener(AtmosphereResourceEventListener e)Remove aAtmosphereResourceEventListener.AtmosphereResourceremoveEventListeners()Remove allAtmosphereResourceEventListeners.AtmosphereResourceremoveFromAllBroadcasters()Remove thisAtmosphereResourcefrom allBroadcastervoidreset()Completely reset the instance to its initial state.AtmosphereResourceresume()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.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.AtmosphereResourceImplsession(javax.servlet.http.HttpSession session)AtmosphereResourcesetBroadcaster(Broadcaster broadcaster)Set the firstBroadcasterassociated with this resource.voidsetIsInScope(boolean isInScope)Protect the object from being used after it got cancelled.AtmosphereResourcesetSerializer(Serializer s)Set theSerializerused to write broadcasted objects.protected voidsetUUID(java.lang.String uuid)AtmosphereResourcesuspend()Suspend theAtmosphereResponseindefinitely.AtmosphereResourcesuspend(long timeout)Suspend theAtmosphereResponse.AtmosphereResourcesuspend(long timeout, java.util.concurrent.TimeUnit timeunit)Suspend theAtmosphereResponse.java.lang.StringtoString()AtmosphereResource.TRANSPORTtransport()Return the currentAtmosphereResource.TRANSPORT.AtmosphereResourceImpltransport(AtmosphereResource.TRANSPORT transport)Manually set theAtmosphereResource.TRANSPORTprotected AtmosphereResourceuniqueBroadcaster(Broadcaster newB)java.lang.Stringuuid()Return the unique ID associated with this AtmosphereResource.WebSocketwebSocket()AtmosphereResourceImplwebSocket(WebSocket webSocket)AtmosphereResourcewrite(byte[] o)Write the bytes IfAtmosphereResource.resumeOnBroadcast()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.
-
-
-
Field Detail
-
PRE_SUSPEND
public static final java.lang.String PRE_SUSPEND
-
SKIP_BROADCASTER_CREATION
public static final java.lang.String SKIP_BROADCASTER_CREATION
-
METEOR
public static final java.lang.String METEOR
-
broadcasters
protected final java.util.List<Broadcaster> broadcasters
-
broadcaster
protected Broadcaster broadcaster
-
asyncSupport
protected AsyncSupport asyncSupport
-
session
protected javax.servlet.http.HttpSession session
-
-
Constructor Detail
-
AtmosphereResourceImpl
public AtmosphereResourceImpl()
-
AtmosphereResourceImpl
@Deprecated public AtmosphereResourceImpl(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler)
Deprecated.
-
-
Method Detail
-
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
protected void setUUID(java.lang.String uuid)
-
register
protected void register()
-
getAtmosphereResourceEvent
public AtmosphereResourceEventImpl getAtmosphereResourceEvent()
Description copied from interface:AtmosphereResourceReturn the currentAtmosphereResourceEvent.- Specified by:
getAtmosphereResourceEventin interfaceAtmosphereResource
-
getAtmosphereHandler
public AtmosphereHandler getAtmosphereHandler()
Description copied from interface:AtmosphereResourceReturn the associatedAtmosphereHandlerassociated with this resource.- Specified by:
getAtmosphereHandlerin interfaceAtmosphereResource- Returns:
- the associated
AtmosphereHandlerassociated with this resource
-
writeOnTimeout
public AtmosphereResource writeOnTimeout(java.lang.Object o)
Description copied from interface:AtmosphereResourceSet a message that will be written when the resource times out. Can be anObjectorCallable.- Specified by:
writeOnTimeoutin interfaceAtmosphereResource- Returns:
- this
-
writeOnTimeout
public java.lang.Object writeOnTimeout()
Description copied from interface:AtmosphereResourceReturn the object that will be written when the resource times out.- Specified by:
writeOnTimeoutin interfaceAtmosphereResource
-
uuid
public java.lang.String 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
public AtmosphereResource.TRANSPORT 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
public AtmosphereResourceImpl transport(AtmosphereResource.TRANSPORT transport)
Manually set theAtmosphereResource.TRANSPORT- Parameters:
transport- set theAtmosphereResource.TRANSPORT- Returns:
-
resumeOnBroadcast
public AtmosphereResource resumeOnBroadcast(boolean resumeOnBroadcast)
Description copied from interface:AtmosphereResourceSet to true to resume the response after the first broadcast. False by default.- Specified by:
resumeOnBroadcastin interfaceAtmosphereResource
-
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:
AtmosphereResource.resumeOnBroadcast()
-
resume
public AtmosphereResource 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
public AtmosphereResource 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
public AtmosphereResource suspend(long timeout, java.util.concurrent.TimeUnit timeunit)
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
public AtmosphereResource suspend(long timeout)
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
public AtmosphereRequest getRequest(boolean enforceScope)
-
getResponse
public AtmosphereResponse getResponse(boolean enforceScope)
-
getRequest
public AtmosphereRequest getRequest()
Description copied from interface:AtmosphereResourceReturn the underlyingAtmosphereRequestrequest.- Specified by:
getRequestin interfaceAtmosphereResource- Returns:
AtmosphereRequestthe underlying request.
-
getResponse
public AtmosphereResponse getResponse()
Description copied from interface:AtmosphereResourceReturn theAtmosphereResponse.- Specified by:
getResponsein interfaceAtmosphereResource- Returns:
AtmosphereResponsethe underlying response.
-
getBroadcaster
public Broadcaster getBroadcaster()
Description copied from interface:AtmosphereResourceReturn the first addedBroadcaster.- Specified by:
getBroadcasterin interfaceAtmosphereResource- Returns:
- the current
Broadcaster
-
broadcasters
public java.util.List<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
protected Broadcaster getBroadcaster(boolean autoCreate)
-
setBroadcaster
public AtmosphereResource setBroadcaster(Broadcaster broadcaster)
Description copied from interface:AtmosphereResourceSet the firstBroadcasterassociated with this resource. ThisBroadcasterwill be returned whenAtmosphereResource.getBroadcaster()is invoked.- Specified by:
setBroadcasterin interfaceAtmosphereResource- Returns:
- this
-
addBroadcaster
public AtmosphereResource addBroadcaster(Broadcaster broadcaster)
Description copied from interface:AtmosphereResourceAdd/Associate aBroadcasterwith this resource.- Specified by:
addBroadcasterin interfaceAtmosphereResource- Returns:
- this
-
removeBroadcaster
public AtmosphereResource removeBroadcaster(Broadcaster broadcaster)
Description copied from interface:AtmosphereResourceRemove aBroadcasterwith this resource.- Specified by:
removeBroadcasterin interfaceAtmosphereResource- Returns:
- this
-
uniqueBroadcaster
protected AtmosphereResource uniqueBroadcaster(Broadcaster newB)
-
getAtmosphereConfig
public AtmosphereConfig getAtmosphereConfig()
Description copied from interface:AtmosphereResourceReturn theAtmosphereConfig.- Specified by:
getAtmosphereConfigin interfaceAtmosphereResource- Returns:
- the
AtmosphereConfig
-
action
public Action 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.- Parameters:
isInScope-
-
isInScope
public boolean isInScope()
Check if theAtmosphereRequeststill is valid.- Returns:
- true if the
AtmosphereRequeststill is valid
-
setSerializer
public AtmosphereResource setSerializer(Serializer s)
Set theSerializerused to write broadcasted objects.- Specified by:
setSerializerin interfaceAtmosphereResource- Parameters:
s-- 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
public AtmosphereResource write(java.lang.String s)
Description copied from interface:AtmosphereResourceWrite the String. IfAtmosphereResource.resumeOnBroadcast()is true, the underlying connection will be resumed (@link #resume());- Specified by:
writein interfaceAtmosphereResource- Returns:
- this
-
write
public AtmosphereResource write(byte[] o)
Description copied from interface:AtmosphereResourceWrite the bytes IfAtmosphereResource.resumeOnBroadcast()is true, the underlying connection will be resumed (@link #resume());- Specified by:
writein interfaceAtmosphereResource- Returns:
- this
-
getSerializer
public Serializer getSerializer()
Description copied from interface:AtmosphereResourceGet theSerializeror null if not defined.- Specified by:
getSerializerin interfaceAtmosphereResource- Returns:
- the
Serializeror null if not defined
-
addEventListener
public AtmosphereResource addEventListener(AtmosphereResourceEventListener e)
- Specified by:
addEventListenerin interfaceAtmosphereResource- Parameters:
e- an instance of AtmosphereResourceEventListener- Returns:
- this
-
removeEventListener
public AtmosphereResource removeEventListener(AtmosphereResourceEventListener e)
Description copied from interface:AtmosphereResourceRemove aAtmosphereResourceEventListener.- Specified by:
removeEventListenerin interfaceAtmosphereResource- Returns:
- this
-
removeEventListeners
public AtmosphereResource removeEventListeners()
Description copied from interface:AtmosphereResourceRemove allAtmosphereResourceEventListeners.- Specified by:
removeEventListenersin interfaceAtmosphereResource- Returns:
- this
-
notifyListeners
public AtmosphereResource notifyListeners()
Description copied from interface:AtmosphereResourceNotify allAtmosphereResourceEventListeners.- Specified by:
notifyListenersin interfaceAtmosphereResource- Returns:
- this
-
notifyListeners
public AtmosphereResource notifyListeners(AtmosphereResourceEvent event)
Description copied from interface:AtmosphereResourceNotify allAtmosphereResourceEventListener.- Specified by:
notifyListenersin interfaceAtmosphereResource- Parameters:
event- an instance of AtmosphereResourceEvent- Returns:
- this
-
removeFromAllBroadcasters
public AtmosphereResource removeFromAllBroadcasters()
Description copied from interface:AtmosphereResourceRemove thisAtmosphereResourcefrom allBroadcaster- Specified by:
removeFromAllBroadcastersin interfaceAtmosphereResource- Returns:
- this
-
onThrowable
public void onThrowable(java.lang.Throwable t)
NotifyAtmosphereResourceEventListenerthah an unexpected exception occured.
-
atmosphereResourceEventListener
public java.util.concurrent.ConcurrentLinkedQueue<AtmosphereResourceEventListener> atmosphereResourceEventListener()
-
atmosphereHandler
public AtmosphereResourceImpl atmosphereHandler(AtmosphereHandler atmosphereHandler)
-
cancel
public void cancel() throws java.io.IOException- Throws:
java.io.IOException
-
_destroy
public void _destroy()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
disableSuspend
public AtmosphereResourceImpl disableSuspend(boolean 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
public void close() throws java.io.IOExceptionDescription copied from interface:AtmosphereResourceClose the underlying connection. Invoking this method will close the underlying connection and resume theAtmosphereResource}.- Specified by:
closein interfaceAtmosphereResource- Throws:
java.io.IOException
-
dirtyClose
public void dirtyClose()
-
forceBinaryWrite
public AtmosphereResource forceBinaryWrite(boolean 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
public AtmosphereResourceImpl session(javax.servlet.http.HttpSession session)
-
cloneState
public AtmosphereResourceImpl cloneState(AtmosphereResource r)
-
listeners
public java.util.concurrent.ConcurrentLinkedQueue<AtmosphereResourceEventListener> listeners()
-
disableSuspendEvent
public AtmosphereResourceImpl disableSuspendEvent(boolean 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
public WebSocket webSocket()
-
webSocket
public AtmosphereResourceImpl webSocket(WebSocket webSocket)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getAndSetInClosingPhase
public boolean getAndSetInClosingPhase()
-
isPendingClose
public boolean isPendingClose()
- Returns:
-
getAndSetPendingClose
public boolean getAndSetPendingClose()
-
-