com.crankuptheamps.client
Class MessageStream
java.lang.Object
com.crankuptheamps.client.MessageStream
- All Implemented Interfaces:
- ConnectionStateListener, MessageHandler, Closeable, Iterable<Message>, Iterator<Message>
public class MessageStream
- extends Object
- implements Iterator<Message>, Iterable<Message>, MessageHandler, ConnectionStateListener, Closeable
MessageStream provides an iteration abstraction over the results of an AMPS command such
as a subscribe, a SOW query, or SOW delete. MessageStream is produced when calling Client.execute() and
continues iterating over the results until the connection is closed, or the iterator is explicitly closed, or when the SOW query is ended.
You can use a MessageStream as you would other Iterators, for example, using a for loop (Java 1.7):
MessageStream stream = client.execute(new Command("sow").setTopic("/orders"));
for(Message message : stream)
{
...
}
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MessageStream
protected MessageStream(Client client_)
setSubscription
protected void setSubscription(CommandId commandId_)
setSOWOnly
protected void setSOWOnly()
setStatsOnly
protected void setStatsOnly()
setRunning
protected void setRunning()
connectionStateChanged
public void connectionStateChanged(int newState_)
- Description copied from interface:
ConnectionStateListener
- Called on an implementation of this interface when
the connection state changes.
- Specified by:
connectionStateChanged
in interface ConnectionStateListener
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interface Iterator<Message>
next
public Message next()
- Specified by:
next
in interface Iterator<Message>
invoke
public void invoke(Message message)
- Description copied from interface:
MessageHandler
- Method for the AMPS client to call when a message is received.
The AMPS client reuses the same message object in successive calls to
the message handler, resetting the contents of the object for each call.
Should you need to use the data in the message outside of the call to
the message handler, you must copy the message object or copy data out
of the message object.
- Specified by:
invoke
in interface MessageHandler
remove
public void remove()
- Specified by:
remove
in interface Iterator<Message>
iterator
public Iterator<Message> iterator()
- Specified by:
iterator
in interface Iterable<Message>
isConnected
public boolean isConnected()
- Returns:
- true if the connection to AMPS is still active, or false if a disconnect is detected.
close
public void close()
- Closes this MessageStream, unsubscribing from AMPS if applicable.
- Specified by:
close
in interface Closeable