Streaming Set Up for Shared Custom Java Adapters

Streaming Set Up for Shared Custom Java Adapters

book

Article ID: KB0070227

calendar_today

Updated On:

Products Versions
TIBCO Streaming 10, 11, and later

Description

What is the best setup to share a set of Streaming custom Java adapters?

Issue/Introduction

Use the Wizard to create the Adapter, then move to a Maven JAR project and add pom.xml settings.

Resolution

Custom Java Operators may be shared in two supported ways:
A. using an EventFlow fragment project each user loads into their Studio workspace and uses through a pom.xml dependency.
B. using a Maven Java project the user's EventFlow (EF) or Live Datamart (LDM) project uses through a pom.xml dependency.

A. As an EventFlow Fragment Project

In an EventFlow fragment project, use the New > StreamBase Java Adapter wizard to create the adapter .java and BeanInfo.java files and edit normally to add functionality. Then in the user EF or LDM project, add the dependency to the pom.xml in the <dependencies> section (example):
<dependencies>
  <dependency>
    <groupId>com.example</groupId>
    <artifactId>myadapters</artifactId>
    <type>ep-eventflow-fragment</type>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>
</dependencies>

Since the project supplying the custom java adapters is present in the workspace, use from the Palette-view "Adapters, Java Operators" dialog, typechecking, and setting element StreamBase Properties all work as expected without additional configuration. Note that if the EventFlow fragment implementing the custom Java adapters is closed or removed from the workspace then Studio will use the Maven Repository build of the supplying project, but lacks access to the custom adapter properties for configuration. HOCON configuration in the adapter project is available from an EventFlow fragment in the workspace or from the Maven Repository. This is useful when the custom Java adapter requires additional AdapterGroup (com.tibco.ep.streambase.configuration.adapter) configuration. Care must be taken to make sure shared projects which supply HOCON have their HOCON "name" and "version" properties set uniquely from HOCON which may be present in the dependent projects. If two HOCON files are found across all projects and their dependencies with the same "name" and "version" then this is a conflict which will prevent the node from being installed. 

B. As a Maven Java Project

In an EventFlow fragment project, use the New > StreamBase Java Adapter wizard to create the adapter .java and BeanInfo.java files and edit normally to add functionality.

Then create a new Maven Project. Add an appropriate package (e.g. com.mycompany.org.sb.utilities). Copy the .java and BeanInfo.java files for each custom adapter from the EventFlow fragment project into the Java package. The "package" statement will be updated automatically in Eclipse.

Edit the Maven project pom.xml to make sure the packaging is "jar", e.g. "<packaging>jar</packaging>".

Add to the pom.xml the dependencies for Streaming Java Adapters:
<dependencies>
   <dependency>
     <groupId>com.tibco.ep.sb</groupId>
     <artifactId>client-core</artifactId>
     <version>11.1.0</version>
   </dependency>
   <dependency>
     <groupId>com.tibco.ep.sb</groupId>
     <artifactId>server</artifactId>
     <version>11.1.0</version>
   </dependency>
 </dependencies>

Add to the pom.xml the build MANIFEST.MF settings (example, replace InputAdapter with the name of your class):
<build>
   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-jar-plugin</artifactId>
       <version>3.2.0</version>
       <configuration>
         <archive>
           <manifestSections>
             <manifestSection>
               <name>com/example/myadapters/InputAdapter.class</name>
               <manifestEntries>
                 <StreamBase-Adapter>True</StreamBase-Adapter>
               </manifestEntries>
             </manifestSection>
             <manifestSection>
               <name>com/example/myadapters/OutputAdapter.class</name>
               <manifestEntries>
                 <StreamBase-Adapter>True</StreamBase-Adapter>
               </manifestEntries>
             </manifestSection>
           </manifestSections>
         </archive>
       </configuration>
     </plugin>
   </plugins>
 </build>

Additional <manifestSection> sections are needed for each class to be presented as a Streaming Adapter.

On the Java project perform: Run As > Maven build…, with targets "clean install". This places the adapter jar into the local Maven Repository. This allows your Streaming custom Java adapter to be deployed the same way as any of the product built-in Java adapters.

Finally, in the user EventFlow or Live Datamart project, add the dependency to the pom.xml in the <dependencies> section (example):
<dependencies>
  <dependency>
    <groupId>com.example</groupId>
    <artifactId>myadapters</artifactId>
    <type>jar</type>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>
</dependencies>

Optionally, the full set of build settings available for a Streaming Operator are:
<manifestEntries>
  <StreamBase-Adapter>True</StreamBase-Adapter>
  <Display-Name>My Input Adapter</Display-Name>
  <Short-Display-Name>MyInput</Short-Display-Name>
  <Canvas-Icon>/com/example/myadapters/MyInput-48x48.png</Canvas-Icon>
  <Large-Icon>/com/example/myadapters/MyInput-32x32.png</Large-Icon>
  <Small-Icon>/com/example/myadapters/MyInput-16x16.png</Small-Icon>
</manifestEntries>

Be aware that when shared as a jar file dependency, the depending EventFlow fragment project will not have access to any HOCON defined within the jar file. Any additional HOCON configuration needed by the adapters must be re-created in the depending project. It is possible to inspect the files within a jar file dependency in Studio by finding and expanding the jar in the depending project's "Maven Dependencies" folder. Files cannot be copied directly from this view, but text files (.conf, .xml, etc.) may be opened in an editor and the text contents may be copied and pasted into a new file for use.

Troubleshooting

If in Studio the custom Java adapter does not typecheck, the class is not found, or the StreamBase Properties view does not populate fully, doublecheck the EventFlow project's pom.xml dependency and that the jar is at the expected location in the local Maven Repository (e.g. C:\Users\Me\.m2\repository, or where specified in the .m2/settings.xml file if it exists). 

Use the right-click action on the EventFlow project: Maven > Update Project, with "Force Update of Snapshots/Releases" enabled.

Monitor build actions using the Eclipse "Progress" view to ensure all build and typechecking actions have completed before trying to correct an error.