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)
          Constructor for Pubnub Class
Pubnub(java.lang.String publish_key, java.lang.String subscribe_key, java.lang.String secret_key)
          Constructor for Pubnub Class
Pubnub(java.lang.String publish_key, java.lang.String subscribe_key, java.lang.String secret_key, boolean ssl_on)
          Constructor for Pubnub Class
Pubnub(java.lang.String publish_key, java.lang.String subscribe_key, java.lang.String secret_key, java.lang.String cipher_key, boolean ssl_on)
          Constructor for Pubnub Class
 
Method Summary
 org.json.JSONArray detailedHistory(java.lang.String channel, boolean reverse)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, boolean reverse, int requestTimeout)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, int count, boolean reverse)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, int count, boolean reverse, int requestTimeout)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, long start, boolean reverse)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, long start, boolean reverse, int requestTimeout)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, long start, long end)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, long start, long end, boolean reverse)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, long start, long end, boolean reverse, int requestTimeout)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, long start, long end, int requestTime)
           
 org.json.JSONArray detailedHistory(java.lang.String channel, long start, long end, int count, java.lang.Boolean reverse)
          Read DetailedHistory for a channel.
 org.json.JSONArray detailedHistory(java.lang.String channel, long start, long end, int count, java.lang.Boolean reverse, int requestTimeout)
          Read DetailedHistory for a channel.
 int getConnectionTimeout()
          Returns the timeout value for TCP connections made by api
 int getFastWebRequestTimeout()
          Returns timeout value in milliseconds for api's publish, history, here_now, detailedHistory, uuid, time
 int getNetworkCheckRetriesCount()
          Returns No of times attempt will be made to check network availability
 int getWebRequestCallbackInterval()
          Returns Time interval in milliseconds for which the API's like Presence and Subscribe will block
 int getWebRequestRetryInterval()
          Returns time interval in milliseconds between each attempt for network connectivity check
 org.json.JSONArray here_now(java.lang.String channel)
          Read presence information from a channel
 org.json.JSONArray here_now(java.lang.String channel, int requestTimeout)
          Read presence information from a channel
 org.json.JSONArray history(java.lang.String channel, int limit)
          Read history from a channel.
 org.json.JSONArray history(java.lang.String channel, int limit, int requestTimeout)
          Read history from a channel.
 void presence(java.lang.String channel, Callback callback)
          Listen for presence of subscribers on a channel
 org.json.JSONArray publish(java.lang.String channel, org.json.JSONObject message)
          Send a message to a channel.
 org.json.JSONArray publish(java.lang.String channel, org.json.JSONObject message, int requestTimeout)
          Send a message to a channel.
 java.lang.String sessionUUID()
           
 void setConnectionTimeout(int timeout)
          Sets the timeout value for TCP connections made by API to Pubnub Servers
 void setFastWebRequestTimeout(int timeout)
          Sets timeout values for publish, history, detailedHistory, time, here_now
 void setNetworkCheckRetriesCount(int count)
          Sets number of retries to be made for network availability check
 void setWebRequestCallbackInterval(int interval)
          Sets wait time for Presence/Subscribe API
 void setWebRequestRetryInterval(int interval)
          Sets time interval between consecutive network availability checks
 void subscribe(java.lang.String channel, Callback callback)
          Listen for a message on a channel.
 double time()
          Read current time from PubNub Cloud.
 void unsubscribe(java.util.HashMap<java.lang.String,java.lang.Object> args)
          Unsubscribe/Disconnect from channel.
static java.lang.String uuid()
          Get 32 digit UUID generation at client side.
 
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)
Constructor for Pubnub Class

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

Pubnub

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

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

Pubnub

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

Parameters:
publish_key - Publish Key
subscribe_key - Subscribe Key

Pubnub

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

Parameters:
publish_key - Publish Key
subscribe_key - Subscribe Key
secret_key - Secret Key
Method Detail

setWebRequestCallbackInterval

public void setWebRequestCallbackInterval(int interval)
Sets wait time for Presence/Subscribe API

Parameters:
interval - Time interval in milliseconds for which the API's like Presence and Subscribe will block

setNetworkCheckRetriesCount

public void setNetworkCheckRetriesCount(int count)
Sets number of retries to be made for network availability check

Parameters:
count - No of times attempt will be made to check network availability

setWebRequestRetryInterval

public void setWebRequestRetryInterval(int interval)
Sets time interval between consecutive network availability checks

Parameters:
interval - Time interval in milliseconds between each attempt for network connectivity check

setFastWebRequestTimeout

public void setFastWebRequestTimeout(int timeout)
Sets timeout values for publish, history, detailedHistory, time, here_now

Parameters:
timeout - timeout value in milliseconds for api's publish, history, here_now, detailedHistory, time

setConnectionTimeout

public void setConnectionTimeout(int timeout)
Sets the timeout value for TCP connections made by API to Pubnub Servers

Parameters:
timeout - timeout value in milliseconds for tcp connection attempt.

getWebRequestCallbackInterval

public int getWebRequestCallbackInterval()
Returns Time interval in milliseconds for which the API's like Presence and Subscribe will block

Returns:
Time interval in milliseconds for which the API's like Presence and Subscribe will block

getNetworkCheckRetriesCount

public int getNetworkCheckRetriesCount()
Returns No of times attempt will be made to check network availability

Returns:
No of times attempt will be made to check network availability

getWebRequestRetryInterval

public int getWebRequestRetryInterval()
Returns time interval in milliseconds between each attempt for network connectivity check

Returns:
Time interval in milliseconds between each attempt for network connectivity check

getFastWebRequestTimeout

public int getFastWebRequestTimeout()
Returns timeout value in milliseconds for api's publish, history, here_now, detailedHistory, uuid, time

Returns:
timeout value in milliseconds for api's publish, history, here_now, detailedHistory, uuid, time

getConnectionTimeout

public int getConnectionTimeout()
Returns the timeout value for TCP connections made by api

Returns:
the timeout value for TCP connections made by api

sessionUUID

public java.lang.String sessionUUID()

publish

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

Parameters:
channel - Channel name
message - JSONObject to be published
Returns:
JSONArray of response

publish

public org.json.JSONArray publish(java.lang.String channel,
                                  org.json.JSONObject message,
                                  int requestTimeout)
Send a message to a channel.

Parameters:
channel - Channel name
message - JSONObject of message to be published
requestTimeout - timeout value in milliseconds for this request
Returns:
JSONArray of response

subscribe

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

Parameters:
channel - Channel name for subscribing
callback - Callback
Throws:
PubnubException - Throws PubnubException if Callback is null

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 - Callback
Throws:
PubnubException - Throws PubnubException if Callback is null

here_now

public org.json.JSONArray here_now(java.lang.String channel)
Read presence information from a channel

Parameters:
channel -
Returns:
JSONArray of uuid's currently subscribing to a channel

here_now

public org.json.JSONArray here_now(java.lang.String channel,
                                   int requestTimeout)
Read presence information from a channel

Parameters:
channel - Channel name
requestTimeout - timeout in milliseconds for this request
Returns:
Array of uuid's currently subscribing to a channel

history

public org.json.JSONArray history(java.lang.String channel,
                                  int limit,
                                  int requestTimeout)
Read history from a channel.

Parameters:
channel - Channel Name
limit - Upper limit on number of messages in response
requestTimeout - timeout in milliseconds for this request
Returns:
JSONArray of message history on a channel.

history

public org.json.JSONArray history(java.lang.String channel,
                                  int limit)
Read history from a channel.

Parameters:
channel - Channel Name
limit - Upper limit on number of messages in response.
Returns:
JSONArray of message history on a channel.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          long start,
                                          long end,
                                          int count,
                                          java.lang.Boolean reverse,
                                          int requestTimeout)
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
requestTimeout - Timeout value in milliseconds for this request
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          long start,
                                          long end,
                                          int count,
                                          java.lang.Boolean reverse)
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
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          long start,
                                          boolean reverse)
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
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          long start,
                                          boolean reverse,
                                          int requestTimeout)
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
requestTimeout - Timeout value in milliseconds for this request
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          long start,
                                          long end)
Read DetailedHistory for a channel.

Parameters:
channel - Channel name for which detailed history is required
start - Start time
end - End time
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          long start,
                                          long end,
                                          int requestTime)

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          long start,
                                          long end,
                                          boolean reverse)
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
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          long start,
                                          long end,
                                          boolean reverse,
                                          int requestTimeout)
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
requestTimeout - Timeout value in milliseconds for this request
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          int count,
                                          boolean reverse)
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
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          int count,
                                          boolean reverse,
                                          int requestTimeout)
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
requestTimeout - Timeout value in milliseconds for this request
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          boolean reverse)
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
Returns:
JSONArray of detailed history.

detailedHistory

public org.json.JSONArray detailedHistory(java.lang.String channel,
                                          boolean reverse,
                                          int requestTimeout)
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
requestTimeout - Timeout value in milliseconds for this request
Returns:
JSONArray of detailed history.

time

public double time()
Read current time from PubNub Cloud.

Returns:
current timestamp.

uuid

public static java.lang.String uuid()
Get 32 digit UUID generation at client side.

Returns:
uuid.

unsubscribe

public void unsubscribe(java.util.HashMap<java.lang.String,java.lang.Object> args)
Unsubscribe/Disconnect from channel.

Parameters:
args - HashMap of containing channel name.