com.pubnub.api
Class Pubnub

java.lang.Object
  extended by com.pubnub.api.Pubnub

public class Pubnub
extends java.lang.Object

Pubnub object facilitates querying channels for messages and listening on channels for presence/message events

Author:
Pubnub

Constructor Summary
Pubnub(java.lang.String publish_key, java.lang.String subscribe_key)
          Pubnub Constructor
Pubnub(java.lang.String publish_key, java.lang.String subscribe_key, boolean ssl)
           
Pubnub(java.lang.String publish_key, java.lang.String subscribe_key, java.lang.String secret_key)
           
Pubnub(java.lang.String publish_key, java.lang.String subscribe_key, java.lang.String secret_key, boolean ssl_on)
          Pubnub Constructor
Pubnub(java.lang.String publish_key, java.lang.String subscribe_key, java.lang.String secret_key, java.lang.String cipher_key, boolean ssl_on)
          Pubnub Constructor
 
Method Summary
 void detailedHistory(java.lang.String channel, boolean reverse, Callback callback)
          Read DetailedHistory for a channel.
 void detailedHistory(java.lang.String channel, int count, boolean reverse, Callback callback)
          Read DetailedHistory for a channel.
 void detailedHistory(java.lang.String channel, int count, Callback callback)
          Read DetailedHistory for a channel.
 void detailedHistory(java.lang.String channel, long start, boolean reverse, Callback callback)
          Read DetailedHistory for a channel.
 void detailedHistory(java.lang.String channel, long start, long end, boolean reverse, Callback callback)
          Read DetailedHistory for a channel.
 void detailedHistory(java.lang.String channel, long start, long end, Callback callback)
          Read DetailedHistory for a channel.
 void detailedHistory(java.lang.String channel, long start, long end, int count, boolean reverse, Callback callback)
          Read DetailedHistory for a channel.
 void disconnectAndResubscribe()
          Disconnect from all channels, and resubscribe
 void disconnectAndResubscribe(java.lang.String errorMessage)
          Disconnect from all channels, and resubscribe
 void disconnectAndResubscribeWithTimetoken(java.lang.String timetoken)
          Disconnect from all channels, and resubscribe
 void disconnectAndResubscribeWithTimetoken(java.lang.String timetoken, java.lang.String errorMessage)
          Disconnect from all channels, and resubscribe
 java.lang.String getAuthKey()
          This method return auth key.
 java.lang.String getCurrentlySubscribedChannelNames()
          This method returns all channel names currently subscribed to in form of a comma separated String
 java.lang.String[] getSubscribedChannelsArray()
          This method returns array of channel names, currently subscribed to
 void hereNow(java.lang.String channel, Callback callback)
          Read presence information from a channel
 void history(java.util.Hashtable args)
          Read history from a channel.
 void history(java.lang.String channel, int limit, Callback callback)
          Read history from a channel.
 boolean isResumeOnReconnect()
          This method returns the state of Resume on Reconnect setting
 void presence(java.lang.String channel, Callback callback)
          Listen for presence of subscribers on a channel
 void publish(java.util.Hashtable args)
          Send a message to a channel.
 void publish(java.util.Hashtable args, Callback callback)
          Send a message to a channel.
 void publish(java.lang.String channel, java.lang.Double message, Callback callback)
          Send a message to a channel.
 void publish(java.lang.String channel, java.lang.Integer message, Callback callback)
          Send a message to a channel.
 void publish(java.lang.String channel, org.json.JSONArray message, Callback callback)
          Send a message to a channel.
 void publish(java.lang.String channel, org.json.JSONObject message, Callback callback)
          Send a message to a channel.
 void publish(java.lang.String channel, java.lang.String message, Callback callback)
          Send a message to a channel.
 void setAuthKey(java.lang.String authKey)
          This method sets auth key.
 void setMaxRetries(int maxRetries)
          This methods sets maximum number of retries for subscribe.
 void setNonSubscribeTimeout(int timeout)
          This method set timeout value for non subscribe operations like publish, history, hereNow.
 void setOrigin(java.lang.String origin)
          Sets origin value, default is "pubsub"
 void setResumeOnReconnect(boolean resumeOnReconnect)
          If Resume on Reconnect is set to true, then Pubnub catches up on reconnection after disconnection.
 void setRetryInterval(int retryInterval)
          This method sets retry interval for subscribe.
 void setSubscribeTimeout(int timeout)
          This method sets timeout value for subscribe/presence.
 void setUUID(java.lang.String uuid)
          Sets value for UUID
 void setUUID(java.util.UUID uuid)
          Sets value for UUID
 void shutdown()
          This method when called stops Pubnub threads
 void subscribe(java.util.Hashtable args)
          Listen for a message on a channel.
 void subscribe(java.util.Hashtable args, Callback callback)
          Listen for a message on a channel.
 void subscribe(java.lang.String[] channelsArr, Callback callback)
          Listen for a message on a channel.
 void subscribe(java.lang.String[] channelsArr, Callback callback, java.lang.String timetoken)
          Listen for a message on a channel.
 void time(Callback callback)
          Read current time from PubNub Cloud.
 void unsetAuthKey()
          This method unsets auth key.
 void unsubscribe(java.util.Hashtable args)
          Unsubscribe/Disconnect from channel.
 void unsubscribe(java.lang.String channel)
          Unsubscribe/Disconnect from channel.
 void unsubscribe(java.lang.String[] channels)
          Unsubscribe from channels.
 void unsubscribeAll()
          Unsubscribe from all channel.
 void unsubscribePresence(java.lang.String channel)
          Unsubscribe from presence channel.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pubnub

public Pubnub(java.lang.String publish_key,
              java.lang.String subscribe_key,
              java.lang.String secret_key,
              java.lang.String cipher_key,
              boolean ssl_on)
Pubnub Constructor

Parameters:
publish_key - Publish Key
subscribe_key - Subscribe Key
secret_key - Secret Key
cipher_key - Cipher Key
ssl_on - SSL on ?

Pubnub

public Pubnub(java.lang.String publish_key,
              java.lang.String subscribe_key,
              java.lang.String secret_key,
              boolean ssl_on)
Pubnub Constructor

Parameters:
publish_key - Publish key
subscribe_key - Subscribe Key
secret_key - Secret Key
ssl_on - SSL on ?

Pubnub

public Pubnub(java.lang.String publish_key,
              java.lang.String subscribe_key)
Pubnub Constructor

Parameters:
publish_key - Publish Key
subscribe_key - Subscribe Key

Pubnub

public Pubnub(java.lang.String publish_key,
              java.lang.String subscribe_key,
              boolean ssl)
Parameters:
publish_key - Publish Key
subscribe_key - Subscribe Key
ssl -

Pubnub

public Pubnub(java.lang.String publish_key,
              java.lang.String subscribe_key,
              java.lang.String secret_key)
Parameters:
publish_key -
subscribe_key -
secret_key -
Method Detail

setUUID

public void setUUID(java.util.UUID uuid)
Sets value for UUID

Parameters:
uuid - UUID value for Pubnub client

setSubscribeTimeout

public void setSubscribeTimeout(int timeout)
This method sets timeout value for subscribe/presence. Default value is 310000 milliseconds i.e. 310 seconds

Parameters:
timeout - Timeout value in milliseconds for subscribe/presence

setNonSubscribeTimeout

public void setNonSubscribeTimeout(int timeout)
This method set timeout value for non subscribe operations like publish, history, hereNow. Default value is 15000 milliseconds i.e. 15 seconds.

Parameters:
timeout - Timeout value in milliseconds for Non subscribe operations like publish, history, hereNow

shutdown

public void shutdown()
This method when called stops Pubnub threads


isResumeOnReconnect

public boolean isResumeOnReconnect()
This method returns the state of Resume on Reconnect setting

Returns:
Current state of Resume On Reconnect Setting

setRetryInterval

public void setRetryInterval(int retryInterval)
This method sets retry interval for subscribe. Pubnub API will make maxRetries attempts to connect to pubnub servers. These attemtps will be made at an interval of retryInterval milliseconds.

Parameters:
retryInterval - Retry Interval in milliseconds

setMaxRetries

public void setMaxRetries(int maxRetries)
This methods sets maximum number of retries for subscribe. Pubnub API will make maxRetries attempts to connect to pubnub servers before timing out.

Parameters:
maxRetries - Max number of retries

getCurrentlySubscribedChannelNames

public java.lang.String getCurrentlySubscribedChannelNames()
This method returns all channel names currently subscribed to in form of a comma separated String

Returns:
Comma separated string with all channel names currently subscribed

setResumeOnReconnect

public void setResumeOnReconnect(boolean resumeOnReconnect)
If Resume on Reconnect is set to true, then Pubnub catches up on reconnection after disconnection. If false, then messages sent on the channel between disconnection and reconnection are not received.

Parameters:
resumeOnReconnect - True or False setting for Resume on Reconnect

setUUID

public void setUUID(java.lang.String uuid)
Sets value for UUID

Parameters:
uuid - UUID value for Pubnub client

publish

public void publish(java.lang.String channel,
                    org.json.JSONObject message,
                    Callback callback)
Send a message to a channel.

Parameters:
channel - Channel name
message - JSONObject to be published
callback - object of sub class of Callback class

publish

public void publish(java.lang.String channel,
                    org.json.JSONArray message,
                    Callback callback)
Send a message to a channel.

Parameters:
channel - Channel name
message - JSONOArray to be published
callback - object of sub class of Callback class

publish

public void publish(java.lang.String channel,
                    java.lang.String message,
                    Callback callback)
Send a message to a channel.

Parameters:
channel - Channel name
message - String to be published
callback - object of sub class of Callback class

publish

public void publish(java.lang.String channel,
                    java.lang.Integer message,
                    Callback callback)
Send a message to a channel.

Parameters:
channel - Channel name
message - Integer to be published
callback - object of sub class of Callback class

publish

public void publish(java.lang.String channel,
                    java.lang.Double message,
                    Callback callback)
Send a message to a channel.

Parameters:
channel - Channel name
message - Double to be published
callback - object of sub class of Callback class

publish

public void publish(java.util.Hashtable args,
                    Callback callback)
Send a message to a channel.

Parameters:
args - Hashtable containing channel name, message.
callback - object of sub class of Callback class

publish

public void publish(java.util.Hashtable args)
Send a message to a channel.

Parameters:
args - Hashtable containing channel name, message, callback

presence

public void presence(java.lang.String channel,
                     Callback callback)
              throws PubnubException
Listen for presence of subscribers on a channel

Parameters:
channel - Name of the channel on which to listen for join/leave i.e. presence events
callback - object of sub class of Callback class
Throws:
PubnubException - Throws PubnubException if Callback is null

hereNow

public void hereNow(java.lang.String channel,
                    Callback callback)
Read presence information from a channel

Parameters:
channel - Channel name
callback - object of sub class of Callback class

history

public void history(java.lang.String channel,
                    int limit,
                    Callback callback)
Read history from a channel.

Parameters:
channel - Channel Name
limit - Upper limit on number of messages in response

history

public void history(java.util.Hashtable args)
Read history from a channel.

Parameters:
args - Hashtable containing channel name, limit, Callback

detailedHistory

public void detailedHistory(java.lang.String channel,
                            long start,
                            long end,
                            int count,
                            boolean reverse,
                            Callback callback)
Read DetailedHistory for a channel.

Parameters:
channel - Channel name for which detailed history is required
start - Start time
end - End time
count - Upper limit on number of messages to be returned
reverse - True if messages need to be in reverse order
callback - Callback

detailedHistory

public void detailedHistory(java.lang.String channel,
                            long start,
                            boolean reverse,
                            Callback callback)
Read DetailedHistory for a channel.

Parameters:
channel - Channel name for which detailed history is required
start - Start time
reverse - True if messages need to be in reverse order
callback - Callback

detailedHistory

public void detailedHistory(java.lang.String channel,
                            long start,
                            long end,
                            Callback callback)
Read DetailedHistory for a channel.

Parameters:
channel - Channel name for which detailed history is required
start - Start time
end - End time
callback - Callback

detailedHistory

public void detailedHistory(java.lang.String channel,
                            long start,
                            long end,
                            boolean reverse,
                            Callback callback)
Read DetailedHistory for a channel.

Parameters:
channel - Channel name for which detailed history is required
start - Start time
end - End time
reverse - True if messages need to be in reverse order
callback - Callback

detailedHistory

public void detailedHistory(java.lang.String channel,
                            int count,
                            boolean reverse,
                            Callback callback)
Read DetailedHistory for a channel.

Parameters:
channel - Channel name for which detailed history is required
count - Upper limit on number of messages to be returned
reverse - True if messages need to be in reverse order
callback - Callback

detailedHistory

public void detailedHistory(java.lang.String channel,
                            boolean reverse,
                            Callback callback)
Read DetailedHistory for a channel.

Parameters:
channel - Channel name for which detailed history is required
reverse - True if messages need to be in reverse order
callback - Callback

detailedHistory

public void detailedHistory(java.lang.String channel,
                            int count,
                            Callback callback)
Read DetailedHistory for a channel.

Parameters:
channel - Channel name for which detailed history is required
callback - Callback

time

public void time(Callback callback)
Read current time from PubNub Cloud.

Parameters:
callback - Callback

unsubscribe

public void unsubscribe(java.lang.String[] channels)
Unsubscribe from channels.

Parameters:
channels - String[] array containing channel names as string.

unsubscribeAll

public void unsubscribeAll()
Unsubscribe from all channel.


unsubscribePresence

public void unsubscribePresence(java.lang.String channel)
Unsubscribe from presence channel.

Parameters:
channel - channel name as String.

unsubscribe

public void unsubscribe(java.lang.String channel)
Unsubscribe/Disconnect from channel.

Parameters:
channel - channel name as String.

unsubscribe

public void unsubscribe(java.util.Hashtable args)
Unsubscribe/Disconnect from channel.

Parameters:
args - Hashtable containing channel name.

subscribe

public void subscribe(java.util.Hashtable args,
                      Callback callback)
               throws PubnubException
Listen for a message on a channel.

Parameters:
args - Hashtable containing channel name
callback - Callback
Throws:
PubnubException - Throws PubnubException if Callback is null

subscribe

public void subscribe(java.util.Hashtable args)
               throws PubnubException
Listen for a message on a channel.

Parameters:
args - Hashtable containing channel name, callback
Throws:
PubnubException - Throws PubnubException if Callback is null

subscribe

public void subscribe(java.lang.String[] channelsArr,
                      Callback callback)
               throws PubnubException
Listen for a message on a channel.

Parameters:
channelsArr - Array of channel names (string) to listen on
callback - Callback
Throws:
PubnubException - Throws PubnubException if Callback is null

subscribe

public void subscribe(java.lang.String[] channelsArr,
                      Callback callback,
                      java.lang.String timetoken)
               throws PubnubException
Listen for a message on a channel.

Parameters:
channelsArr - Array of channel names (string) to listen on
callback - Callback
Throws:
PubnubException - Throws PubnubException if Callback is null

disconnectAndResubscribeWithTimetoken

public void disconnectAndResubscribeWithTimetoken(java.lang.String timetoken)
Disconnect from all channels, and resubscribe


disconnectAndResubscribeWithTimetoken

public void disconnectAndResubscribeWithTimetoken(java.lang.String timetoken,
                                                  java.lang.String errorMessage)
Disconnect from all channels, and resubscribe


disconnectAndResubscribe

public void disconnectAndResubscribe()
Disconnect from all channels, and resubscribe


disconnectAndResubscribe

public void disconnectAndResubscribe(java.lang.String errorMessage)
Disconnect from all channels, and resubscribe


getSubscribedChannelsArray

public java.lang.String[] getSubscribedChannelsArray()
This method returns array of channel names, currently subscribed to

Returns:
Array of channel names

setOrigin

public void setOrigin(java.lang.String origin)
Sets origin value, default is "pubsub"

Parameters:
origin - Origin value

getAuthKey

public java.lang.String getAuthKey()
This method return auth key. Return null if not set

Returns:
Auth Key. null if auth key not set

setAuthKey

public void setAuthKey(java.lang.String authKey)
This method sets auth key.

Parameters:
authKey - . 0 length string or null unsets auth key

unsetAuthKey

public void unsetAuthKey()
This method unsets auth key.