org.atmosphere.cpr
Interface AtmosphereResource<E,F>

All Known Implementing Classes:
AtmosphereResourceImpl

public interface AtmosphereResource<E,F>

A AtmosphereResource encapsulates the mechanism to suspend(), resume() and broadcast (getBroadcaster()) messages among suspended response. AtmosphereResource are passed at runtime to an instance of AtmosphereHandler.

Author:
Jeanfrancois Arcand

Method Summary
 AtmosphereServlet.AtmosphereConfig getAtmosphereConfig()
          Return the AtmosphereServlet.AtmosphereConfig
 AtmosphereResourceEvent getAtmosphereResourceEvent()
          Return the current AtmosphereResourceEvent.
 Broadcaster getBroadcaster()
          Return the current Broadcaster
 E getRequest()
          Return the underlying Request.
 F getResponse()
          Return the underlying Response.
 Serializer getSerializer()
          Get the Serializer or null if not defined.
 void resume()
          Complete the HttpServletResponse and finish/commit it.
 void setBroadcaster(Broadcaster broadcaster)
          Set the current Broadcaster
 void setSerializer(Serializer s)
          Set the Serializer to use when write(java.io.OutputStream, java.lang.Object) execute the operation.
 void suspend()
          Suspend the HttpServletResponse indefinitely.
 void suspend(long timeout)
          Suspend the HttpServletResponse.
 void suspend(long timeout, boolean flushComment)
          Suspend the HttpServletResponse.
 void write(OutputStream os, Object o)
          Write the Object using the OutputStream by invoking the current Serializer.
 

Method Detail

resume

void resume()
Complete the HttpServletResponse and finish/commit it. If the HttpServletResponse is in the process of being resumed, invoking that method has no effect.


suspend

void suspend()
Suspend the HttpServletResponse indefinitely. Suspending a HttpServletResponse will tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid commiting response.

The Framework will output some HTML comments when suspending the response in order to make sure all Browser works well with suspended response.


suspend

void suspend(long timeout)
Suspend the HttpServletResponse. Suspending a HttpServletResponse will tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid commiting response. Invoking this method when a request is being timed out, e.g. AtmosphereResourceEvent.isResumedOnTimeout() return true, has no effect.

The Framework will output some HTML comments when suspending the response in order to make sure all Browser works well with suspended response. By default, the ServletResponse.getWriter() will be used. You can change that behavior by setting a request attribute named org.atmosphere.useStream to so the framework will use ServletResponse.getOutputStream()

Parameters:
timeout - The maximum amount of time, in milliseconds, a HttpServletResponse can be suspended. When the timeout expires (because nothing has been written or because the resume() , the HttpServletResponse will be automatically resumed and commited. Usage of any methods of a HttpServletResponse that times out will throw an IllegalStateException.

suspend

void suspend(long timeout,
             boolean flushComment)
Suspend the HttpServletResponse. Suspending a HttpServletResponse will tell the underlying container to avoid recycling objects associated with the current instance, and also to avoid commiting response. Invoking this method when a request is being timed out, e.g. AtmosphereResourceEvent.isResumedOnTimeout() return true, has no effect.

The Framework will output some HTML comments when suspending the response in order to make sure all Browser works well with suspended response. By default, the ServletResponse.getWriter() will be used. You can change that behavior by setting a request attribute named org.atmosphere.useStream to so the framework will use ServletResponse.getOutputStream()

Parameters:
timeout - The maximum amount of time, in milliseconds, a HttpServletResponse can be suspended. When the timeout expires (because nothing has been written or because the resume() , the HttpServletResponse will be automatically resumed and commited. Usage of any methods of a HttpServletResponse that times out will throw an IllegalStateException.
flushComment - By default, Atmosphere will output some comments to make WebKit based browser working. Set it to false if you want to remove it.

getRequest

E getRequest()
Return the underlying Request.

Returns:
E the underlying Request.

getResponse

F getResponse()
Return the underlying Response.

Returns:
F the underlying Response.

getAtmosphereConfig

AtmosphereServlet.AtmosphereConfig getAtmosphereConfig()
Return the AtmosphereServlet.AtmosphereConfig

Returns:
the AtmosphereServlet.AtmosphereConfig

getBroadcaster

Broadcaster getBroadcaster()
Return the current Broadcaster

Returns:
the current Broadcaster

setBroadcaster

void setBroadcaster(Broadcaster broadcaster)
Set the current Broadcaster

Parameters:
broadcaster -

setSerializer

void setSerializer(Serializer s)
Set the Serializer to use when write(java.io.OutputStream, java.lang.Object) execute the operation. By default, the Serializer is null.

Parameters:
s - the Serializer

write

void write(OutputStream os,
           Object o)
           throws IOException
Write the Object using the OutputStream by invoking the current Serializer. If Serializer is null, the Object will be directly written using the {

Parameters:
os - OutputStream
o - Object
Throws:
IOException

getSerializer

Serializer getSerializer()
Get the Serializer or null if not defined.

Returns:
the Serializer or null if not defined.

getAtmosphereResourceEvent

AtmosphereResourceEvent getAtmosphereResourceEvent()
Return the current AtmosphereResourceEvent.



Copyright © 2011. All Rights Reserved.