Results 1 to 6 of 6
  1. #1

    Need a Java Client Example

    Hello,

    Could someone point me to simple java client example code sample for use with HELLOWORLD adapte.
    ( I mean the java client for provided HELLOWORLD adapter. )
    ( I do see stock demo...but I am just beginer with LS techs ... so need to do a step clearly at a time -- starting with simple )
    My interest is to do "everything in java" only, hence the request.

    Please let me know if anything is availble on this.

    Appreciate your help.

    Regards,
    Digambar

  2. #2
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    538
    Hi Digambar,

    A Java client specific for HELLOWORLD adapter is not available. But please note that in <LS_HOME>/DOCS-SDKs/sdk_client_java_se/examples/ls_client you can find Test.java. This is a simple example program that explains LSClient basic concepts.
    The test can be invoked with "HOST PORT extended" parameters and opens a connection to Lightstreamer Server, subscribes a table, and displays the updates on the console. It requires that Lightstreamer Server is running with the DEMO Adapter Set installed.

    However, you could also adapt it, with few changes, to display the data from the HELLOWORLD adapter.

  3. #3
    Thanks GC.
    I am doing the same....Just thought that it may be already around and waiting to be asked.

  4. #4
    Hello,

    Need some help. I am trying a java client ( for HelloWorld adapter) and getting following error message:
    Exception in thread "main" com.lightstreamer.ls_client.PushUserException: Requested Data Adapter, HELLOWORLD, not found
    at com.lightstreamer.ls_client.PushServerTranslator.c heckAnswer(PushServerTranslator.java:741)
    at com.lightstreamer.ls_client.PushServerTranslator.d oControlRequest(PushServerTranslator.java:634)
    at com.lightstreamer.ls_client.PushServerTranslator.d oControlRequest(PushServerTranslator.java:615)
    at com.lightstreamer.ls_client.PushServerTranslator.c allTableRequest(PushServerTranslator.java:491)
    at com.lightstreamer.ls_client.PushServerProxy.reques tSubscr(PushServerProxy.java:302)
    at com.lightstreamer.ls_client.ServerManager.subscrTa ble(ServerManager.java:487)
    at com.lightstreamer.ls_client.LSClient.subscribeTabl e(LSClient.java:538)
    at Hello.playExtended(Hello.java:167)
    at Hello.main(Hello.java:140)
    -----
    browser client OK w/o issue.
    ------
    My Java client code :
    ====

    import java.util.ArrayList;
    import com.lightstreamer.ls_client.ConnectionInfo;
    import com.lightstreamer.ls_client.ExtendedConnectionList ener;
    import com.lightstreamer.ls_client.ExtendedTableInfo;
    import com.lightstreamer.ls_client.HandyTableListener;
    import com.lightstreamer.ls_client.LSClient;
    import com.lightstreamer.ls_client.PushConnException;
    import com.lightstreamer.ls_client.PushServerException;
    import com.lightstreamer.ls_client.PushUserException;
    import com.lightstreamer.ls_client.ExtendedTableInfo;
    import com.lightstreamer.ls_client.SimpleTableInfo;
    import com.lightstreamer.ls_client.SubscrException;
    import com.lightstreamer.ls_client.SubscribedTableKey;
    import com.lightstreamer.ls_client.SubscriptionConstraint s;
    import com.lightstreamer.ls_client.UpdateInfo;


    public class Hello {

    public static void main(String[] args) throws Exception {
    final String pushServerHost = args[0];
    final int pushServerPort = Integer.parseInt(args[1]);

    System.out.println("Main: Entry ");
    ArrayList<String> opts = new ArrayList<String>();
    for (int i = 2; i < args.length; i++) {
    opts.add(args[i]);
    }

    Thread.sleep(2000);

    final LSClient myClient = new LSClient();
    System.out.println("Main: myClient created...will setup connection ");
    myClient.openConnection(
    new ConnectionInfo() {
    {
    this.pushServerUrl = "http://" + pushServerHost + ":" + pushServerPort;
    this.adapter = "HELLOWORLD";
    // this.maxBandwidth = new Double(1.0);
    }
    },
    new ExtendedConnectionListener() {
    private long bytes = 0;
    public void onConnectionEstablished() {
    System.out.println("connection established");
    }
    public void onSessionStarted(boolean isPolling) {
    //never called
    }
    public void onSessionStarted(boolean isPolling, String controlLink) {
    String clAddendum = controlLink != null ? " to server " + controlLink : "";
    if (isPolling) {
    System.out.println("Session started in smart polling"+clAddendum);
    } else {
    System.out.println("Session started in streaming"+clAddendum);
    }
    }
    public void onNewBytes(long newBytes) {
    this.bytes += newBytes;
    }
    public void onDataError(PushServerException e) {
    System.out.println("data error");
    e.printStackTrace();
    }
    public void onActivityWarning(boolean warningOn) {
    if (warningOn) {
    System.out.println("connection stalled");
    } else {
    System.out.println("connection no longer stalled");
    }
    }
    public void onEnd(int cause) {
    System.out.println("connection forcibly closed");
    }
    public void onClose() {
    System.out.println("total bytes: " + bytes);
    }
    public void onFailure(PushServerException e) {
    System.out.println("server failure");
    e.printStackTrace();
    }
    public void onFailure(PushConnException e) {
    System.out.println("connection failure");
    e.printStackTrace();
    }
    }
    );
    System.out.println("Main: connection done ");
    Thread.sleep(5000);

    ArrayList<SubscribedTableKey> subscrRefs = new ArrayList<SubscribedTableKey>();

    System.out.println("Main: will call playSimple ");

    SubscribedTableKey tableRef = playExtended(myClient);
    subscrRefs.add(tableRef);


    SubscribedTableKey[] subscrKeys = subscrRefs.toArray(new SubscribedTableKey[0]);

    Thread.sleep(10000);
    myClient.changeSubscriptions(subscrKeys, new SubscriptionConstraints() {
    {
    maxFrequency = new Double(0.1);
    }
    });

    Thread.sleep(10000);
    myClient.unsubscribeTables(subscrKeys);

    Thread.sleep(5000);
    myClient.closeConnection();
    Thread.sleep(2000);
    System.exit(0);
    }



    private static SubscribedTableKey playExtended(final LSClient myClient)
    throws SubscrException, PushServerException, PushUserException,
    PushConnException {
    SubscribedTableKey tableRef = myClient.subscribeTable(
    new ExtendedTableInfo(
    new String[] { "greetings01", "greetings03", "greetings02" },
    "MERGE",
    new String[] { "message", "timestamp" },
    true) {
    {
    setDataAdapter("HELLOWORLD");
    }
    },
    new HandyTableListener() {
    private String notifyUpdate(UpdateInfo update) {
    return update.isSnapshot() ? "snapshot" : "update";
    }
    private String notifyValue(UpdateInfo update, String fldName) {
    String notify = " " + fldName + " = " + update.getNewValue(fldName);
    if (update.isValueChanged(fldName)) {
    notify += " (was " + update.getOldValue(fldName) + ")";
    }
    return notify;
    }
    public void onUpdate(int itemPos, String itemName, UpdateInfo update) {
    System.out.println(notifyUpdate(update) +
    " for " + itemName + ":" +
    notifyValue(update, "message") +
    notifyValue(update, "timestamp") );
    }
    public void onSnapshotEnd(int itemPos, String itemName) {
    System.out.println("end of snapshot for " + itemName);
    }
    public void onRawUpdatesLost(int itemPos, String itemName, int lostUpdates) {
    System.out.println(lostUpdates + " updates lost for " + itemName);
    }
    public void onUnsubscr(int itemPos, String itemName) {
    System.out.println("unsubscr " + itemName);
    }
    public void onUnsubscrAll() {
    System.out.println("unsubscr table");
    }
    },
    false
    );
    return tableRef;
    }

    }

  5. #5
    Administrator
    Join Date
    Feb 2012
    Location
    Milano
    Posts
    538
    Hi Digambar,

    Please note that if you have not changed the adapter.xml configuration file proposed in the tutorial the name of Adapter Set is HELLOWORLD and the name of Adapter has been non specified; ie. DEFAULT is assumed.

    So, it's correct specify the adapter set in your ConnectionInfo instance:



    but you need to remove the setDataAdapter call or alternatively call



    Hope that helps.

  6. #6
    Thanks GC,

    Removing setDataAdapter call did the trick.


    Regards,
    Digambar

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 06:16 PM.