public class CometDClient extends Object
Below is an example on how to listen for messages on the notifications channel:
// Creates a CometDClient that will connect to the CometD Server at the specified URL. CometDClient cometDClient = new CometDClient(cometDEndpointUrl); // Starts the cometDClient and performs the initial handshake with the CometD server cometDClient.start(); // Subscribes to the notifications channel cometDClient.subscribe("/ddf/notifications/**")); // Retrieves messages on all subscribed channels (in this example, receives messages on // on the notifications channel). Listmessages = cometDClient.getAllMessages(); // Shutdown the cometD Client and un-subscribes from all channels cometDClient.shutdown();
Constructor and Description |
---|
CometDClient(String url)
Creates a CometD client without authentication.
|
CometDClient(String url,
String realm,
String username,
String password)
Creates a CometD client with authentication.
|
Modifier and Type | Method and Description |
---|---|
void |
cancelAllDownloads()
Cancels all resource downloads.
|
void |
cancelDownload(String downloadId)
Cancels a resource download.
|
List<String> |
getAllMessages()
Gets the list of messages received on all channels.
|
List<String> |
getAllMessagesInAscOrder()
Gets the list of messages received on all channels in time ascending order, i.e., from oldest
to most recent.
|
String |
getClientId()
Gets the CometD client ID.
|
Set<String> |
getDownloadIds() |
List<String> |
getMessages(String channel)
Gets the list of messages received on a given channel.
|
List<String> |
getMessagesInAscOrder(String channel)
Gets the list of messages received on a given channel in time ascending order, i.e., from
oldest to most recent.
|
void |
publish(String channel,
Map<String,Object> message)
Publishes a message
|
void |
searchByMetacardId(String responseChannel,
String source,
String metacardId)
Publishes a search message for a specific metacard ID.
|
Optional<String> |
searchMessages(String searchCriterion)
Gets the first message that matches the search criterion
|
void |
shutdown()
Shuts down the client.
|
void |
start()
Starts the client.
|
void |
subscribe(String channel)
Subscribes to a channel.
|
void |
unsubscribe(String channel)
Un-subscribes from a channel.
|
void |
unsubscribeFromAllChannels()
Un-subscribes from all channels.
|
public CometDClient(String url) throws Exception
url
- CometD endpointException
- thrown if client setup failspublic CometDClient(String url, String realm, String username, String password) throws Exception
url
- CometD endpointrealm
- security realmusername
- user namepassword
- passwordException
- thrown if client setup failspublic void start() throws Exception
Exception
- thrown if the client fails to startpublic void publish(String channel, Map<String,Object> message)
channel
- channel to publish message tomessage
- message to publishpublic void subscribe(String channel)
channel
- channel namepublic Optional<String> searchMessages(String searchCriterion)
searchCriterion
- a string that will be searched for in the messagespublic List<String> getMessages(String channel)
channel
- channel namepublic List<String> getMessagesInAscOrder(String channel)
channel
- channel namepublic String getClientId()
public List<String> getAllMessages()
public List<String> getAllMessagesInAscOrder()
public void searchByMetacardId(String responseChannel, String source, String metacardId)
responseChannel
- ID of the channel where the response should be sentsource
- source to querymetacardId
- ID of the metacard to retrievepublic void cancelDownload(String downloadId)
downloadId
- ID of the download to cancelpublic void cancelAllDownloads()
public void unsubscribe(String channel)
channel
- channel namepublic void unsubscribeFromAllChannels()
public void shutdown() throws Exception
Exception
- thrown if the shutdown failsThis work is licensed under a Creative Commons Attribution 4.0 International License.