org.mule.module.pubnub
Class PubNubCloudConnector

java.lang.Object
  extended by org.mule.module.pubnub.PubNubCloudConnector

@Connector(namespacePrefix="pubnub")
public class PubNubCloudConnector
extends Object

PubNub is an Internet-Wide Messaging Service for Real-time Web and Mobile apps and games. PubNub is a massively scalable Real-time Bidirectional Messaging Service in the Cloud.

This connector supports version 3 of the PubNub REST API.

PubNub is a freemium service where users get 5,000 messages per day for free but then have reasonable pricing plans for higher volume usage. For more information go to PubNub: http://pubnub.com


Field Summary
static int MESSAGE_LIMIT
           
 
Constructor Summary
PubNubCloudConnector()
          Creates a new PubNub connector with no state.
PubNubCloudConnector(String publishKey, String subscribeKey, String secretKey)
          Creates a new PubHub connector with required state.
PubNubCloudConnector(String publishKey, String subscribeKey, String secretKey, boolean ssl)
          Creates a new PubHub connector with required state.
 
Method Summary
 org.codehaus.jackson.node.ObjectNode createMessage()
          Creates a new Json Object message.
protected  String getBaseUrl()
           
 String getPublishKey()
           
 String getSecretKey()
           
 String getSubscribeKey()
           
 org.codehaus.jackson.JsonNode history(String channel, int limit)
          Load history from a channel.
 void init()
           
 boolean isSsl()
           
 org.codehaus.jackson.JsonNode publish(String channel, org.codehaus.jackson.JsonNode jsonMessage)
          Send a json message to a channel.
 org.codehaus.jackson.JsonNode publish(String channel, String jsonMessage)
          Send a json message to a channel.
 org.codehaus.jackson.JsonNode request(String channel, long timeout)
          Makes a blocking request to receive a message on a channel.
 double serverTime()
          Get the Timestamp from PubNub Cloud.
 void setPublishKey(String publishKey)
           
 void setSecretKey(String secretKey)
           
 void setSsl(boolean ssl)
           
 void setSubscribeKey(String subscribeKey)
           
 void subscribe(String channel, MessageListener listener)
          Register a message listener for a channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_LIMIT

public static final int MESSAGE_LIMIT
See Also:
Constant Field Values
Constructor Detail

PubNubCloudConnector

public PubNubCloudConnector()
Creates a new PubNub connector with no state. If this constructor is used, then you must also call #config(String, String, String, boolean)


PubNubCloudConnector

public PubNubCloudConnector(String publishKey,
                            String subscribeKey,
                            String secretKey,
                            boolean ssl)
Creates a new PubHub connector with required state. The keys required to create the connector are available from your account on the PubNub website: http://www.pubnub.com/account. SSL can be used by setting the SSL flag.

Parameters:
publishKey - Your publish key that allows you to send data to the PubNub cloud
subscribeKey - Your subscribe key that allows you to send data to the PubNub cloud
secretKey - The secret key given to you when you created the account
ssl - Whether to use SSL or not when communicating with the PubNub cloud

PubNubCloudConnector

public PubNubCloudConnector(String publishKey,
                            String subscribeKey,
                            String secretKey)
Creates a new PubHub connector with required state. The keys required to create the connector are available from your account on the PubNub website: http://www.pubnub.com/account.

Parameters:
publishKey - Your publish key that allows you to send data to the PubNub cloud
subscribeKey - Your subscribe key that allows you to send data to the PubNub cloud
secretKey - The secret key given to you when you created the account
Method Detail

getPublishKey

public String getPublishKey()

setPublishKey

public void setPublishKey(String publishKey)

getSubscribeKey

public String getSubscribeKey()

setSubscribeKey

public void setSubscribeKey(String subscribeKey)

getSecretKey

public String getSecretKey()

setSecretKey

public void setSecretKey(String secretKey)

isSsl

public boolean isSsl()

setSsl

public void setSsl(boolean ssl)

init

@PostConstruct
public void init()

getBaseUrl

protected String getBaseUrl()

publish

public org.codehaus.jackson.JsonNode publish(String channel,
                                             org.codehaus.jackson.JsonNode jsonMessage)
Send a json message to a channel.

Parameters:
channel - to publish to
jsonMessage - the message to publish
Returns:
the response from the server

publish

@Operation
public org.codehaus.jackson.JsonNode publish(String channel,
                                                       @Parameter(optional=true,defaultValue="#[payload]")
                                                       String jsonMessage)
Send a json message to a channel. <pubnub:publish channel="mychannel" jsonMessage="world"/>

Parameters:
channel - name to publish the message to
jsonMessage - the message to publish
Returns:
boolean false on fail.

subscribe

public void subscribe(String channel,
                      MessageListener listener)
Register a message listener for a channel. This is a blocking subscribe which also means that only one subscription can be made per connector.

Listen for a message on a channel.

Parameters:
channel - name to listen on
listener - the message callback to invoke when a message is received. there will be one invocation per message and the invocation on the message listener is guaranteed never to be null.

request

@Operation
public org.codehaus.jackson.JsonNode request(String channel,
                                                       @Parameter(optional=true,defaultValue="5000")
                                                       long timeout)
Makes a blocking request to receive a message on a channel. <pubnub:request channel="mychannel"/>

Parameters:
channel - name to read from
timeout - how long to wait for a message. The value is expressed in milliseconds. specify for
Returns:
zero or more messages depending on what was in the queue

history

@Operation
public org.codehaus.jackson.JsonNode history(String channel,
                                                       int limit)
Load history from a channel. <pubnub:history channel="mychannel" limit="20"/>

Parameters:
channel - name.
limit - history count response.
Returns:
JsonNode of history.

serverTime

@Operation
public double serverTime()
Get the Timestamp from PubNub Cloud. <pubnub:server-time/>

Returns:
double timestamp.

createMessage

public org.codehaus.jackson.node.ObjectNode createMessage()
Creates a new Json Object message. The ObjectNode can be used like a Map to write key/value pairs. Objects can be text, numeric, binary or complex objects

Returns:
a newly created ObjectNode instance.


Copyright © 2011. All Rights Reserved.