org.glassfish.jersey.media.sse
Class EventChannel

java.lang.Object
  extended by org.glassfish.jersey.media.sse.EventChannel

public class EventChannel
extends java.lang.Object

Outgoing event message queue. When returned from resource method, underlying connection is kept open and application is able to write messages. One instance of this class corresponds with exactly one HTTP connection.

Author:
Pavel Bucek (pavel.bucek at oracle.com)

Field Summary
static java.lang.String SERVER_SENT_EVENTS
          String representation of Server sent events media type.
static MediaType SERVER_SENT_EVENTS_TYPE
          Server sent events media type.
 
Constructor Summary
EventChannel()
          Default constructor.
EventChannel(java.lang.Long interval, java.util.concurrent.TimeUnit timeUnit)
          Create EventChannel with specified type and polling interval.
 
Method Summary
 void close()
          Close underlying outgoing connection
 boolean isClosed()
          Get information about EventChannel state.
 void write(java.lang.Object data, java.lang.Class<?> dataType)
          Send a message with given parameters.
 void write(java.lang.String eventName, java.lang.Object data, java.lang.Class<?> dataType)
          Send a message with given parameters.
 void write(java.lang.String eventName, java.lang.String eventId, java.lang.Object data, java.lang.Class<?> dataType)
          Send a message with given parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVER_SENT_EVENTS

public static final java.lang.String SERVER_SENT_EVENTS
String representation of Server sent events media type. (""text/event-stream"").

See Also:
Constant Field Values

SERVER_SENT_EVENTS_TYPE

public static final MediaType SERVER_SENT_EVENTS_TYPE
Server sent events media type.

Constructor Detail

EventChannel

public EventChannel()
Default constructor.


EventChannel

public EventChannel(java.lang.Long interval,
                    java.util.concurrent.TimeUnit timeUnit)
Create EventChannel with specified type and polling interval. Polling interval is used when retrieving data - basically it specifies how often will be connection checked if it is closed from the client side.

Parameters:
interval - polling interval. Default value is 5.
timeUnit - polling interval TimeUnit. Default value is TimeUnit.SECONDS.
Method Detail

write

public void write(java.lang.String eventName,
                  java.lang.String eventId,
                  java.lang.Object data,
                  java.lang.Class<?> dataType)
           throws java.lang.IllegalStateException,
                  java.lang.IllegalArgumentException
Send a message with given parameters.

Parameters:
eventName - event name.
eventId - event id.
dataType - Class which will be used for MessageBodyWriter lookup. MUST NOT be null.
data - actual data. MUST NOT be null.
Throws:
java.lang.IllegalStateException - when trying to write message to closed EventChannel.
java.lang.IllegalArgumentException - when dataType or data is null.

write

public void write(java.lang.String eventName,
                  java.lang.Object data,
                  java.lang.Class<?> dataType)
           throws java.lang.IllegalStateException,
                  java.lang.IllegalArgumentException
Send a message with given parameters.

Parameters:
eventName - event name.
dataType - Class which will be used for MessageBodyWriter lookup. MUST NOT be null.
data - actual data. MUST NOT be null.
Throws:
java.lang.IllegalStateException - when trying to write message to closed EventChannel.
java.lang.IllegalArgumentException - when dataType or data is null.

write

public void write(java.lang.Object data,
                  java.lang.Class<?> dataType)
           throws java.lang.IllegalStateException,
                  java.lang.IllegalArgumentException
Send a message with given parameters.

Parameters:
dataType - Class which will be used for MessageBodyWriter lookup. MUST NOT be null.
data - actual data. MUST NOT be null.
Throws:
java.lang.IllegalStateException - when trying to write message to closed EventChannel.
java.lang.IllegalArgumentException - when dataType or data is null.

isClosed

public boolean isClosed()
Get information about EventChannel state.

Returns:
true when EventChannel is closed, otherwise false.

close

public void close()
Close underlying outgoing connection



Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.