Please Wait

Loading..

Java SDK 1.0.0

Create amazing realtime applications easily with Yalgaar Java SDK

Java SDK

1 Connect To Yalgaar

Requirement:

Desktop machine running on windows or Linux with JDK 1.7 or higher installed.

Create instance of Yalgaar client with context of application.

YalgaarClient objYalgaarClient = new YalgaarClient(context);

To connect to a Yalgaar client, use following method, it must have valid Client Key.

connect(String Clientkey, boolean IsSecure, ConnectionCallback callback);
connect(String Clientkey, boolean IsSecure, String UUID, ConnectionCallback callback);
connect(String Clientkey, boolean IsSecure, String AESSecretKey, AESType type,ConnectionCallback callback);
connect(String Clientkey, boolean IsSecure, String AESSecretKey, AESType type, String UUID, ConnectionCallback callback);

Parameter:

  • Clientkey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: String
  • IsSecure
    • Description: Specified connection is establish with SSL or not.
    • DataType: boolean
  • AESSecretKey
    • Description: Secret key use for encrypt/decrypt message.
    • DataType: String
  • AESType
    • Description: Type of AES algorithm use for encrypt/decrypt message. Supports AES_128, AES_192, AES_256
    • DataType: AESType
  • UUID
    • Description: Any unique user name for user to enable presence feature for client.
    • DataType: String
  • ConnectionCallback
    • Description: There are three types of callbacks.
      • connectSuccessfullyCallback: called when successfully connected to server.
      • connectionErrorCallback: called when system error occurred during connection.
      • connectionDisconnectCallback: called when connection disconnect with server.
    • DataType: ConnectionCallback


2 Publish Message

To publish message, use following method.

publish(String Channel, String Message, PublishMessageCallback PublishCallback);

Parameter:

  • Channel
    • Description: Channels name on which message will be published. Channel name is CASE SENSITIVE.
    • DataType: String
  • Message
    • Description: Data to be send.
    • DataType: String
  • PublishMessageCallback
    • Publish Callback or null. There are two types of callbacks.
      • successCallback: called on successfully send message.
      • errorCallback: called on error occurred during publish message.
    • DataType: PublishMessageCallback


3 Subscribe Message

To subscribe message, use following method.

subscribe(String Channel, SubscribeCallback subscriptionCallback, PresenceCallback presenceCallback);
subscribe(ArrayList Channels, SubscribeCallback subscriptionCallback, PresenceCallback presenceCallback);

Parameter:

  • Channel(s)
    • Description: Single channel name or arraylist of channels name on which message will be published. Channel name is CASE SENSITIVE.
    • DataType: String (for multiple channels use arrayList).
  • SubscribeCallback
    • Description: Subscription Callback or null. There are three types of subscription callbacks: successSubCallback, messageRecieveSubCallback, and errorSubCallback.
      • successSubCallback: called on successfully subscription of channel(s).
      • messageRecieveSubCallback: called on any data arrived in channel(s).Data will be available in form of string.
      • errorSubCallback: called on system error occurred during subscription.
    • DataType: SubscribeCallback
  • PresenceCallback
    • Description: Presence Callback or null. Use for get presence information from Yalgaar server. Its work when you create Yalgaar client with UUID.
    • presenceMessageReceiveCallback: called on any presence message arrive from server.
    • DataType: PresenceCallback


4 Unsubscribe Message

To unsubscribe message, use following method.

unSubscribe(String Channel, UnSubscribeCallback unSubscribeCallback);
unSubscribe(String ChannelList, UnSubscribeCallback unSubscribeCallback);
  • Channel(s)
    • Description: Single channel name or arraylist of channels to be unsubscribe. Channel name is CASE SENSITIVE.
    • DataType: String or arrayList for multiple channels.
  • UnSubscribeCallback
    • Description: Unsubscription Callback or null. There are two types of subscription callbacks. successUnSubscribeCallback, and errorUnSubCallback.
      • successUnSubscribeCallback: called on successfully unsubscribe channel.
      • errorUnSubCallback: called on system error occurred during unsubscribe.
    • DataType: UnSubscribeCallback


5 Get User List

To get list of all user subscribe with specified channel name, use following method.

getUUIDList(String Channel, DataCallback callback);

Parameter:

  • Channel
    • Description: Name of valid channel name. Channel name is CASE SENSITIVE.
    • DataType: String
  • DataCallback
    • Description: Data Callback or null. Call on response from server. Returns empty arraylist if no matching channel name found.
    • DataType: DataCallback


6 Get Channel List

To get list of all channels subscribed by specified user, use following method.

getChannelList(String UUID, DataCallback callback);

Parameter:

  • UUID
    • Description: Valid UUID. UUID is CASE SENSITIVE.
    • DataType: String
  • DataCallback
    • Description: Data Callback or null. Call on response from server. Returns empty arraylist if no matching UUID found.
    • DataType: DataCallback


7 History Message

To get message history from specified channel name, use following method.

getHistory(String Channel, int MessageCount, HistoryCallback callback);

Parameter:

  • Channel
    • Description: Name of valid channel name. Channel name is CASE SENSITIVE.
    • DataType: String
  • MessageCount
    • Description: How many messages that you want to fetch. Maximum 100 messages allow at a time.
    • DataType: int
  • HistoryCallback
    • Description: HistoryCallback or null. Call on response from server. Returns empty arraylist if no matching channel name found.
    • HistoryMessage: Contains two methods.
      • getMessage(): returns String message.
      • GetTimeStamp() : returns message time in milliseconds.
    • DataType: HistoryCallback


8 Disconnect

To disconnect connection with YalgaarClient, use following method.

disConnect();


You can publish/subscribe message like so :

Include Yalgaar Java SDK(yalgaar_java.jar) in your code

import java.util.ArrayList;
import com.sls.yalgaar_api.Context;
import com.sls.yalgaar_api.YalgaarClient;
import com.sls.yalgaar_api.exception.ArgumentException;
import com.sls.yalgaar_api.exception.ConnectFailureException;
import com.sls.yalgaar_api.interfaces.ConnectionCallback;
import com.sls.yalgaar_api.interfaces.PublishMessageCallback;
import com.sls.yalgaar_api.interfaces.SubscribeCallback;
public class YalgaarExample {
	public static void main(String[] args) {
		try
        {
            Context context = new Context();
            final YalgaarClient objYalgaarClient = new YalgaarClient(context);   
            
            final PublishMessageCallback publishMessageCallback = new PublishMessageCallback() 
            {
                @Override
                public void successCallback() {
                    System.out.println("Publish successfully !!!");
                }
                @Override
                public void errorCallback(String string) {
                    System.out.println("Error: "+ string);
                }
            };
            
            final SubscribeCallback objSubscribeCallback= new SubscribeCallback()
            {
                @Override
                public void successSubCallback(ArrayList<String> al, String string) {
                    System.out.println("Subscribe successfully !!!");	
                    try {
						objYalgaarClient.publish("YourChannel", "This is Yalgaar Java SDK Example", publishMessageCallback);
					} catch (ArgumentException | ConnectFailureException e) {
						e.printStackTrace();
					}
                }
                @Override
                public void messageReceiveSubCallback(ArrayList<String> al, String message) {
                    System.out.println("Subscribe : " + message);
                }
                @Override
                public void errorSubCallback(String string) {
                    System.out.println("Error: "+ string);
                }
            };
            
            ConnectionCallback objConnectionCallback = new ConnectionCallback() 
            {
                @Override
                public void connectSuccessfullyCallback(String message) {
                    System.out.println("Connect Successfully !!!");
                    try {
						objYalgaarClient.subscribe("YourChannel", objSubscribeCallback, null);
					} catch (ArgumentException | ConnectFailureException e) {
						e.printStackTrace();
					}
                }
                @Override
                public void connectionDisconnectCallback(String message) {
                        System.out.println("connectionDisconnectCallback: "+ message);
                }
                @Override
                public void connectionErrorCallback(String string) {
                    System.out.println("Error: "+ string);
                }
            };
		
            objYalgaarClient.connect("YourClientKey", false, objConnectionCallback);
            
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
	}
}