gemhost_java_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
gemhost_java_example [2020/05/12 18:33]
wikiadmin created
gemhost_java_example [2021/04/14 18:09] (current)
wikiadmin
Line 67: Line 67:
       @Override       @Override
       public void connectionStatusChanged(int connectionStatus, String comment) {       public void connectionStatusChanged(int connectionStatus, String comment) {
-         System.out.println ("Current Connection Status " + connectionStatus + " Status String \"" + comment + "\"");        +         System.out.println ("Current Connection Status " + connectionStatus + " Status String \"" + comment + "\"");    
 +         //note: see https://www.ergotech.com/wiki/doku.php?id=host_connection_status for connectionStatus values     
       }       }
     });     });
Line 197: Line 198:
 } }
 </code> </code>
 +
 +**Notifications**
 +
 +The example above demonstrates the most common notification - received events, reports and messages.  In most cases, receiving a notification of the message received and getting the values from the message is the easiest and most convenient approach.  However, it is possible to register to receive notifications for individual elements in a message.  In the element of the message the //"Publish"// checkbox must be checked.  For example, here we choose to Publish the "ECID".
 +
 +{{:pasted:20200513-184840.png}}
 +
 +
 +You can publish elements of any type.  Here a list is being published.
 +
 +{{:pasted:20200513-185052.png}}
 +
 +To receive notification of the published list, create a method to receive the notification
 +
 +<code java>
 +  public void ecidListUpdated ( ValueChangedEvent event ) {
 +    System.out.println("List updated " + event);
 +    [...]
 +  }
 +</code>
 +
 +Then create a connector that links from the //ECIDList// to the //ecidListUpdated// method.
 +
 +<code java>
 +      Connector connector = DataSourceContainer.getConnectorFor(this, "ecidListUpdated"); 
 +</code>
 +
 +The ECIDList is part of the ECIDListReply message. First get the ECIDListReply message and then the ECIDList data source and add the connector.
 +
 +<code java>
 +      ECIDListReply ecidListReply =  (ECIDListReply)host.getMessageBean("ECIDListReply");
 +      ecidListReply.getDataSource("ECIDList").addConnector(connector);
 +</code>
 +
 +Here's the full code:
 +
 +<code java>
 +    try {
 +      Connector connector = DataSourceContainer.getConnectorFor(this, "ecidListUpdated"); 
 +      ECIDListReply ecidListReply =  (ECIDListReply)host.getMessageBean("ECIDListReply");
 +      ecidListReply.getDataSource("ECIDList").addConnector(connector);
 +    } catch (Exception e1) {
 +      e1.printStackTrace();
 +    }
 +</code>
 +
 +Every time the ECIDListReply (S2F30) message is received, the ecidListUpdate method will be called.
 +
 +Normally, the notification would be called only once. However, here, the ECIDList is marked as "Repeat" which means that the ecidListUpdate will be called for each repeat of the list.
 +
 +The ECIDList is the last notification in the "Repeat" parsing, and so when that is received, the ECIDListReply message will have the current values from the list in the ECID, ECIDName, etc. variables.  These can then be retrieved with the "get" methods.  Filling out our notifier a little we may have something like this:
 +
 +<code java>
 +  public void ecidListUpdated ( ValueChangedEvent event ) {
 +    System.out.println("List updated " + event.getSource());
 +    try {
 +      ECIDListReply ecidListReply = (ECIDListReply)host.getMessageBean("ECIDListReply");
 +      System.out.println("ECID " + ecidListReply.getECID() + " Name " + ecidListReply.getECIDName() );
 +    } catch (Exception e) {
 +      e.printStackTrace();
 +    }
 +  }
 +</code>
 +
 +Be sure to read the section **Advanced Message Matching** in [[Message Matching]] concerning Repeat and Optional before using this approach, but when required it can be a powerful tool.
 +
 +**Characterization**
 +
 +An alternative to the above approach to listing ECIDs is to use the characterization capabilities of TransSECS.  
 +
 +Characterization provides a list of all CEIDs, Reports (RPTIDs) and VIDs (SVIDs and ECIDs) available on the tool.  Simply call the "characterize" method with the host controller.
 +
 +<code java>
 +Characterize.characterize(host);
 +</code>
 +
 +This will populate the GEM Host Model maintained by the host. This can be retrieved with the call:
 +
 +<code java>
 +host.getGemHostModel();
 +</code>
 +
 +
 +Check the GemHostModel JavaDocs for details of the model.
  
  • gemhost_java_example.1589326416.txt.gz
  • Last modified: 2020/05/12 18:33
  • by wikiadmin