org.atmosphere.cpr
Class AtmosphereResourceImpl

java.lang.Object
  extended by org.atmosphere.cpr.AtmosphereResourceImpl
All Implemented Interfaces:
AtmosphereResource

public class AtmosphereResourceImpl
extends Object
implements AtmosphereResource

AtmosphereResource implementation for supporting AtmosphereRequest and AtmosphereResponse.

Author:
Jeanfrancois Arcand

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.atmosphere.cpr.AtmosphereResource
AtmosphereResource.TRANSPORT
 
Field Summary
protected  AsyncSupport asyncSupport
           
protected  Broadcaster broadcaster
           
static String METEOR
           
static String PRE_SUSPEND
           
protected  javax.servlet.http.HttpSession session
           
static String SKIP_BROADCASTER_CREATION
           
 
Constructor Summary
AtmosphereResourceImpl()
           
AtmosphereResourceImpl(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler)
          Deprecated. 
 
Method Summary
 void _destroy()
           
 Action action()
          Return the Action which represent the state of the response, e.g.
 AtmosphereResource addEventListener(AtmosphereResourceEventListener e)
          Add a AtmosphereResourceEventListener.
 AtmosphereResourceImpl atmosphereHandler(AtmosphereHandler atmosphereHandler)
           
 ConcurrentLinkedQueue<AtmosphereResourceEventListener> atmosphereResourceEventListener()
           
 void cancel()
           
 AtmosphereResourceImpl cloneState(AtmosphereResource r)
           
 void close()
          Close the underlying connection.
 void dirtyClose()
           
 AtmosphereResourceImpl disableSuspend(boolean disableSuspend)
           
 boolean disableSuspendEvent()
          Return true if AtmosphereResourceEventListener.onSuspend(AtmosphereResourceEvent) and AtmosphereResourceEventListener.onPreSuspend(AtmosphereResourceEvent) events are disabled.
 AtmosphereResourceImpl disableSuspendEvent(boolean disableSuspendEvent)
          Disable invocation of AtmosphereResourceEventListener.onSuspend(AtmosphereResourceEvent) and AtmosphereResourceEventListener.onPreSuspend(AtmosphereResourceEvent).
 boolean equals(Object o)
           
 boolean forceBinaryWrite()
          Return true when binary write is forced.
 AtmosphereResource forceBinaryWrite(boolean forceBinaryWrite)
          Force binary write and never write String value.
 boolean getAndSetInClosingPhase()
           
 AtmosphereConfig getAtmosphereConfig()
          Return the AtmosphereConfig.
 AtmosphereHandler getAtmosphereHandler()
          Return the associated AtmosphereHandler associated with this resource.
 AtmosphereResourceEventImpl getAtmosphereResourceEvent()
          Return the current AtmosphereResourceEvent.
 Broadcaster getBroadcaster()
          Return the current Broadcaster.
protected  Broadcaster getBroadcaster(boolean autoCreate)
           
 AtmosphereRequest getRequest()
          Return the underlying AtmosphereRequest request.
 AtmosphereRequest getRequest(boolean enforceScope)
           
 AtmosphereResponse getResponse()
          Return the AtmosphereResponse.
 AtmosphereResponse getResponse(boolean enforceScope)
           
 Serializer getSerializer()
          Get the Serializer or null if not defined.
 AtmosphereResource initialize(AtmosphereConfig config, Broadcaster broadcaster, AtmosphereRequest req, AtmosphereResponse response, AsyncSupport asyncSupport, AtmosphereHandler atmosphereHandler)
          Initialize an AtmosphereResource.
 boolean isCancelled()
          Return true if this object has been cancelled.
 boolean isInScope()
          Check if the AtmosphereRequest still is valid.
 boolean isResumed()
          Return true if this object has been resumed.
 boolean isSuspended()
          Return true if the AtmosphereResource.suspend() has been invoked.
 ConcurrentLinkedQueue<AtmosphereResourceEventListener> listeners()
           
 AtmosphereResource notifyListeners()
          Notify all AtmosphereResourceEventListeners.
 AtmosphereResource notifyListeners(AtmosphereResourceEvent event)
          Notify all AtmosphereResourceEventListener.
 void onThrowable(Throwable t)
          Notify AtmosphereResourceEventListener thah an unexpected exception occured.
protected  void register()
           
 AtmosphereResource removeEventListener(AtmosphereResourceEventListener e)
          Remove a AtmosphereResourceEventListener.
 AtmosphereResource removeEventListeners()
          Remove all AtmosphereResourceEventListeners.
 void reset()
          Completely reset the instance to its initial state.
 AtmosphereResource resume()
          Complete the AtmosphereResponse and finish/commit it.
 boolean resumeOnBroadcast()
          Return true if this AtmosphereResource is resumed after the first broadcast.
 AtmosphereResource resumeOnBroadcast(boolean resumeOnBroadcast)
          Set to true to resume the response after the first broadcast.
 javax.servlet.http.HttpSession session()
          Return the HttpSession if supported, null if not
 javax.servlet.http.HttpSession session(boolean create)
          Return the HttpSession if supported, and creates it if not already created.
 AtmosphereResourceImpl session(javax.servlet.http.HttpSession session)
           
 AtmosphereResourceImpl setBroadcaster(Broadcaster broadcaster)
          Set the current Broadcaster.
 void setIsInScope(boolean isInScope)
          Protect the object from being used after it got cancelled.
 AtmosphereResource setSerializer(Serializer s)
          Set the Serializer used to write broadcasted objects.
 AtmosphereResource suspend()
          Suspend the AtmosphereResponse indefinitely.
 AtmosphereResource suspend(long timeout)
          Suspend the AtmosphereResponse.
 AtmosphereResource suspend(long timeout, TimeUnit timeunit)
          Suspend the AtmosphereResponse.
 String toString()
           
 AtmosphereResource.TRANSPORT transport()
          Return the current AtmosphereResource.TRANSPORT.
 AtmosphereResourceImpl transport(AtmosphereResource.TRANSPORT transport)
          Manually set the TRANSPORT
 String uuid()
          Return the unique ID associated with this AtmosphereResource.
 WebSocket webSocket()
           
 AtmosphereResourceImpl webSocket(WebSocket webSocket)
           
 AtmosphereResource write(byte[] o)
          Write the bytes If AtmosphereResource.resumeOnBroadcast() is true, the underlying connection will be resumed (@link #resume());
 AtmosphereResource write(String s)
          Write the String.
 Object writeOnTimeout()
          Return the object that will be written when the resource times out.
 AtmosphereResource writeOnTimeout(Object o)
          Set a message that will be written when the resource times out.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PRE_SUSPEND

public static final String PRE_SUSPEND

SKIP_BROADCASTER_CREATION

public static final String SKIP_BROADCASTER_CREATION

METEOR

public static final String METEOR

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 an AtmosphereResource.

Specified by:
initialize in interface AtmosphereResource
Parameters:
config - The AtmosphereConfig
broadcaster - The Broadcaster.
req - The AtmosphereRequest
response - The AtmosphereResource
asyncSupport - The AsyncSupport
atmosphereHandler - The AtmosphereHandler
Returns:
this

register

protected void register()

getAtmosphereResourceEvent

public AtmosphereResourceEventImpl getAtmosphereResourceEvent()
Description copied from interface: AtmosphereResource
Return the current AtmosphereResourceEvent.

Specified by:
getAtmosphereResourceEvent in interface AtmosphereResource

getAtmosphereHandler

public AtmosphereHandler getAtmosphereHandler()
Description copied from interface: AtmosphereResource
Return the associated AtmosphereHandler associated with this resource.

Specified by:
getAtmosphereHandler in interface AtmosphereResource
Returns:
the associated AtmosphereHandler associated with this resource

writeOnTimeout

public AtmosphereResource writeOnTimeout(Object o)
Description copied from interface: AtmosphereResource
Set a message that will be written when the resource times out. Can be an Object or Callable.

Specified by:
writeOnTimeout in interface AtmosphereResource
Returns:
this

writeOnTimeout

public Object writeOnTimeout()
Description copied from interface: AtmosphereResource
Return the object that will be written when the resource times out.

Specified by:
writeOnTimeout in interface AtmosphereResource

uuid

public String uuid()
Description copied from interface: AtmosphereResource
Return the unique ID associated with this AtmosphereResource.

Specified by:
uuid in interface AtmosphereResource
Returns:
the unique ID associated with this AtmosphereResource

transport

public AtmosphereResource.TRANSPORT transport()
Description copied from interface: AtmosphereResource
Return the current AtmosphereResource.TRANSPORT. The transport value is retrieved using the HeaderConfig.X_ATMOSPHERE_TRANSPORT header value.

Specified by:
transport in interface AtmosphereResource

transport

public AtmosphereResourceImpl transport(AtmosphereResource.TRANSPORT transport)
Manually set the TRANSPORT

Parameters:
transport - set the TRANSPORT
Returns:

resumeOnBroadcast

public AtmosphereResource resumeOnBroadcast(boolean resumeOnBroadcast)
Description copied from interface: AtmosphereResource
Set to true to resume the response after the first broadcast. False by default.

Specified by:
resumeOnBroadcast in interface AtmosphereResource

isSuspended

public boolean isSuspended()
Description copied from interface: AtmosphereResource
Return true if the AtmosphereResource.suspend() has been invoked.

Specified by:
isSuspended in interface AtmosphereResource
Returns:
true if the AtmosphereResource.suspend() has been invoked

resumeOnBroadcast

public boolean resumeOnBroadcast()
Description copied from interface: AtmosphereResource
Return true if this AtmosphereResource is resumed after the first broadcast.

Specified by:
resumeOnBroadcast in interface AtmosphereResource
See Also:
AtmosphereResource.resumeOnBroadcast()

resume

public AtmosphereResource resume()
Description copied from interface: AtmosphereResource
Complete the AtmosphereResponse and finish/commit it. If the AtmosphereResponse is in the process of being resumed, invoking this method has no effect.

Specified by:
resume in interface AtmosphereResource

suspend

public AtmosphereResource suspend()
Description copied from interface: AtmosphereResource
Suspend the AtmosphereResponse indefinitely. Suspending a AtmosphereResponse will 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:
suspend in interface AtmosphereResource

suspend

public AtmosphereResource suspend(long timeout,
                                  TimeUnit timeunit)
Description copied from interface: AtmosphereResource
Suspend the AtmosphereResponse. Suspending a AtmosphereResponse will 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:
suspend in interface AtmosphereResource
Parameters:
timeout - The maximum amount of time a AtmosphereResponse can be suspended. When the timeout expires, the AtmosphereResponse will be automatically resumed and committed. Usage of any methods of a AtmosphereResponse that times out will throw an IllegalStateException.
timeunit - The time unit of the timeout value

suspend

public AtmosphereResource suspend(long timeout)
Description copied from interface: AtmosphereResource
Suspend the AtmosphereResponse. Suspending a AtmosphereResponse will 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:
suspend in interface AtmosphereResource
Parameters:
timeout - The maximum amount of time, in milliseconds, a AtmosphereResponse can be suspended. When the timeout expires, the AtmosphereResponse will be automatically resumed and committed. Usage of any methods of a AtmosphereResponse that times out will throw an IllegalStateException.

getRequest

public AtmosphereRequest getRequest(boolean enforceScope)

getResponse

public AtmosphereResponse getResponse(boolean enforceScope)

getRequest

public AtmosphereRequest getRequest()
Description copied from interface: AtmosphereResource
Return the underlying AtmosphereRequest request.

Specified by:
getRequest in interface AtmosphereResource
Returns:
AtmosphereRequest the underlying request.

getResponse

public AtmosphereResponse getResponse()
Description copied from interface: AtmosphereResource
Return the AtmosphereResponse.

Specified by:
getResponse in interface AtmosphereResource
Returns:
AtmosphereResponse the underlying response.

getBroadcaster

public Broadcaster getBroadcaster()
Description copied from interface: AtmosphereResource
Return the current Broadcaster.

Specified by:
getBroadcaster in interface AtmosphereResource
Returns:
the current Broadcaster

getBroadcaster

protected Broadcaster getBroadcaster(boolean autoCreate)

setBroadcaster

public AtmosphereResourceImpl setBroadcaster(Broadcaster broadcaster)
Description copied from interface: AtmosphereResource
Set the current Broadcaster. If null, a new Broadcaster will be created with Broadcaster.SCOPE.REQUEST if that resource hasn't been suspended yet.

Specified by:
setBroadcaster in interface AtmosphereResource
Returns:
this

getAtmosphereConfig

public AtmosphereConfig getAtmosphereConfig()
Description copied from interface: AtmosphereResource
Return the AtmosphereConfig.

Specified by:
getAtmosphereConfig in interface AtmosphereResource
Returns:
the AtmosphereConfig

action

public Action action()
Return the Action which 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 the AtmosphereRequest still is valid.

Returns:
true if the AtmosphereRequest still is valid

setSerializer

public AtmosphereResource setSerializer(Serializer s)
Set the Serializer used to write broadcasted objects.

Specified by:
setSerializer in interface AtmosphereResource
Parameters:
s -
Returns:
this

isResumed

public boolean isResumed()
Description copied from interface: AtmosphereResource
Return true if this object has been resumed.

Specified by:
isResumed in interface AtmosphereResource
Returns:
true if this object has been resumed

isCancelled

public boolean isCancelled()
Description copied from interface: AtmosphereResource
Return true if this object has been cancelled.

Specified by:
isCancelled in interface AtmosphereResource
Returns:
true if this object has been cancelled

write

public AtmosphereResource write(String s)
Description copied from interface: AtmosphereResource
Write the String. If AtmosphereResource.resumeOnBroadcast() is true, the underlying connection will be resumed (@link #resume());

Specified by:
write in interface AtmosphereResource
Returns:
this

write

public AtmosphereResource write(byte[] o)
Description copied from interface: AtmosphereResource
Write the bytes If AtmosphereResource.resumeOnBroadcast() is true, the underlying connection will be resumed (@link #resume());

Specified by:
write in interface AtmosphereResource
Returns:
this

getSerializer

public Serializer getSerializer()
Description copied from interface: AtmosphereResource
Get the Serializer or null if not defined.

Specified by:
getSerializer in interface AtmosphereResource
Returns:
the Serializer or null if not defined

addEventListener

public AtmosphereResource addEventListener(AtmosphereResourceEventListener e)
Add a AtmosphereResourceEventListener.

Specified by:
addEventListener in interface AtmosphereResource
Parameters:
e - an instance of AtmosphereResourceEventListener
Returns:
this

removeEventListener

public AtmosphereResource removeEventListener(AtmosphereResourceEventListener e)
Description copied from interface: AtmosphereResource
Remove a AtmosphereResourceEventListener.

Specified by:
removeEventListener in interface AtmosphereResource
Returns:
this

removeEventListeners

public AtmosphereResource removeEventListeners()
Description copied from interface: AtmosphereResource
Remove all AtmosphereResourceEventListeners.

Specified by:
removeEventListeners in interface AtmosphereResource
Returns:
this

notifyListeners

public AtmosphereResource notifyListeners()
Description copied from interface: AtmosphereResource
Notify all AtmosphereResourceEventListeners.

Specified by:
notifyListeners in interface AtmosphereResource
Returns:
this

notifyListeners

public AtmosphereResource notifyListeners(AtmosphereResourceEvent event)
Description copied from interface: AtmosphereResource
Notify all AtmosphereResourceEventListener.

Specified by:
notifyListeners in interface AtmosphereResource
Parameters:
event - an instance of AtmosphereResourceEvent
Returns:
this

onThrowable

public void onThrowable(Throwable t)
Notify AtmosphereResourceEventListener thah an unexpected exception occured.


atmosphereResourceEventListener

public ConcurrentLinkedQueue<AtmosphereResourceEventListener> atmosphereResourceEventListener()

atmosphereHandler

public AtmosphereResourceImpl atmosphereHandler(AtmosphereHandler atmosphereHandler)

cancel

public void cancel()
            throws IOException
Throws:
IOException

_destroy

public void _destroy()

toString

public String toString()
Overrides:
toString in class Object

disableSuspend

public AtmosphereResourceImpl disableSuspend(boolean disableSuspend)

session

public javax.servlet.http.HttpSession session(boolean create)
Description copied from interface: AtmosphereResource
Return the HttpSession if supported, and creates it if not already created.

Specified by:
session in interface AtmosphereResource
Returns:
the HttpSession if supported, and creates it if not already created

close

public void close()
           throws IOException
Description copied from interface: AtmosphereResource
Close the underlying connection. Invoking this method will close the underlying connection and resume the AtmosphereResource}.

Specified by:
close in interface AtmosphereResource
Throws:
IOException

dirtyClose

public void dirtyClose()

forceBinaryWrite

public AtmosphereResource forceBinaryWrite(boolean forceBinaryWrite)
Description copied from interface: AtmosphereResource
Force binary write and never write String value. return this

Specified by:
forceBinaryWrite in interface AtmosphereResource

forceBinaryWrite

public boolean forceBinaryWrite()
Description copied from interface: AtmosphereResource
Return true when binary write is forced.

Specified by:
forceBinaryWrite in interface AtmosphereResource
Returns:
true when binary write is forced.

session

public javax.servlet.http.HttpSession session()
Description copied from interface: AtmosphereResource
Return the HttpSession if supported, null if not

Specified by:
session in interface AtmosphereResource
Returns:
the HttpSession if supported, null if not

session

public AtmosphereResourceImpl session(javax.servlet.http.HttpSession session)

cloneState

public AtmosphereResourceImpl cloneState(AtmosphereResource r)

listeners

public ConcurrentLinkedQueue<AtmosphereResourceEventListener> listeners()

disableSuspendEvent

public AtmosphereResourceImpl disableSuspendEvent(boolean disableSuspendEvent)
Disable invocation of AtmosphereResourceEventListener.onSuspend(AtmosphereResourceEvent) and AtmosphereResourceEventListener.onPreSuspend(AtmosphereResourceEvent). You normally disable those events after the first onSuspend has been called so all transports behave the same way.
AtmosphereResourceEventListener marked with AllowInterceptor will not be affected by this property.

Parameters:
disableSuspendEvent -
Returns:
this

disableSuspendEvent

public boolean disableSuspendEvent()
Return true if AtmosphereResourceEventListener.onSuspend(AtmosphereResourceEvent) and AtmosphereResourceEventListener.onPreSuspend(AtmosphereResourceEvent) events are disabled.

Returns:
true if disabled

webSocket

public WebSocket webSocket()

webSocket

public AtmosphereResourceImpl webSocket(WebSocket webSocket)

equals

public boolean equals(Object o)
Overrides:
equals in class Object

getAndSetInClosingPhase

public boolean getAndSetInClosingPhase()


Copyright © 2014. All Rights Reserved.