LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Java node - begginer

    Employee
    Posted 02-11-2014 07:11

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dialpemo

    Hiya,

    I am trying to achieve 2 things using the java node one is to output a plain text eg "run" and the other thing I am trying to achieve is to output the result of an external input. I have try to follow the java example but I haven't had much luck, hope you can help.

    Yours,

    Alejandro


  • 2.  RE: Java node - begginer

    Employee
    Posted 02-11-2014 10:54

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    Have you tried to follow through the example that is talked through in the Java Node Getting Started guide?
    The Java Node Getting Started Guide comes with the LAE installation in the docs directory.

    That's probably the best place to start.

    If you've tried this and are still running into issues, perhaps you can post the node as you have it currently and someone might be able to offer more help.

    Regards,
    Tim.


  • 3.  RE: Java node - begginer

    Employee
    Posted 02-12-2014 09:53

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dialpemo

    I have now gone back, and manage to create a simple output from within the script however I am still not sure if what I did is correct as I can write either monitor or monitor 1 at the following line "private void writeRecord(int monitor1) throws NodeFailedException" and still get the right output, I was wondering if I could have some advice of why is this the case, and if is necessary to write "write" to create each record output, an how can I adjust it so that I can have more than just one column in the output, I try to use some of the other code from the example nodes but I was unsuccessful. Please Help.

    Please see attachment for my brg
    Attachments:
    output_from_java.brp
    output_from_java.brg


  • 4.  RE: Java node - begginer

    Employee
    Posted 02-12-2014 17:03

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    The general process is to setup the output metadata for each of the outputs you are writing to in the "setup" method.
    This involves:
    For each output
    1. Construct a new metadata object, using:
      output(<outputIndex>).newMetadata();
      e.g.
      RecordMetadata metadata = output(0).newMetadata();
    2. Setup the metadata for that output, by adding all of the fields that you want on the output, using:
      metadata.add(new SimpleFieldMetadata("<FieldName", <FieldClass>);
      e.g.
      metadata.add(new SimpleFieldMetadata("MyNewField", java.lang.String.class); 
      metadata.add(new SimpleFieldMetadata("My Integer Field", java.lang.Integer.class);
      Where <FieldClass> is the Class of the field
      1. For a "string" field, this is java.lang.String.class, for a "double" field, tihs is java.lang.Double.class (or just double.class), etc.
      2. For time, date, and datetime fields (which don't have direct corresponding java classes, use com.lavastorm.lang.Time.class, com.lavastorm.lang.Date.class, and com.lavastorm.lang.TimeStamp.class.
      3. For "unicode" types, this is com.lavastorm.lang.UnicodeString.class
    3. ​Assign the metadata to the output, using:
      output(<outputIndex>.metadata(<metadataObject>);
      - e.g.
      output(0).metadata(metadata);
    Then, open all of the outputs, using:
    openOutputs();
    Once this is done, within the processAll method, where you are processing input data (or doing whatever other processing is required), you can write to each of these outputs.
    In order to write to these outputs, you must:
    1. Get a new Record object from the output, using:
      Record <recordObject> = output(<outputIndex>).metadata().newRecord();
      e.g.
       Record rec = output(0).metadata().newRecord();
    2. Set all of the values for the different fields, using:
      <recordObject>.field(<fieldIndex>, <fieldValue>);
      e.g.
      rec.field(0, "My String Field");
      rec.field(1, 123);
    3. Write the output record, using:
      write(<outputIndex>, record);
      e.g.
      write(0, rec);

    So in summary, if you wanted two fields on the node's first output - one string field called "MyNewField", one integer field called "My Integer Field", you'd set up using:
    RecordMetadata rmd = output(0).newMetadata();
    rmd.add(new SimpleFieldMetadata("MyNewField", java.lang.String.class);
    rmd.add(new SimpleFieldMetadata("My Integer Field", int.class);
    output(0).metadata(rmd);
    openOutputs();
    Then to write the values "fred" and 123 to to an output record, you would use:
    Record rec = output(0).metadata().newRecord();
    rec.field(0, "fred");
    rec.field(1, 123);
    write(0, rec);

    This is talked through pretty well with examples in the Java Node Getting Started Guide and via the API, but if you have more questions, feel free to post here.

    Hope this helps,

    Tim.


  • 5.  RE: Java node - begginer

    Employee
    Posted 02-13-2014 08:21

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: dialpemo

    Thank you Tim it work perfeclty


  • 6.  RE: Java node - begginer

    Employee
    Posted 01-08-2015 07:23

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ghostwriter

    its the first example on that forum, that gives some real world examples. please continue with such explanations.