Tuesday, March 8, 2011

Building an S4 Application

Having gathered some knowledge about 'how to run an S4 app' in my previous post, its time we move up to building applications of our own. Before we kick off this task, a precise note on the structure of a basic S4 application is required.

Structure of an S4 application 



 To start, create a similar directory structure in your s4image directory's example folder. Assuming your application name 'appName', we would  take up each segment of the app one by one.
.java files

The most elementary S4 application also requires 2 java classes :
1. Bean class :This class declares variables that represent the event of its type. In your application, you can start with a Login bean having two string variables 'id' and 'pwd' and their getter and setter methods.

2. Receiver class for the Bean :It is significant to point out the action to be taken when an event is fired. For each distinct event, represented by a bean class, there has to be a receiver class that describes how to process the event it is meant for, in its processEvent() function.

public void processEvent(Login data) {
//handle the Login object
}
public String getId() {
return this.getClass().getName();
}

appName_conf.xml

Precisely, this xml defines a set of beans and the stream and the keys for each receiver classes, on which they would operate. Each bean is allocated an id of your choice and the class it represents.
In this example the xml could be as :

<bean id="loginDataCatcher" class="io.s4.example.appName.LoginReceiverPE">
    <property name="keys">
      <list>
        <value>LoginData *</value>
      </list>
    </property> 

</bean>

assembly.xml

This xml is common to all the applications and you only need to replace the 'fileset include' with appName.xml which is indicating the resource directory as follows :

<fileSet>
      <directory>${project.basedir}/src/main/resources</directory>
      <outputDirectory />
      <includes>
    <include>appName_conf.xml</include>
      </includes>
 </fileSet>

pom.xml

Here you only need to replace  <artifactId></artifactId> and <name></name> tag values with appName

<modelVersion>4.0.0</modelVersion>
<groupId>io.s4.examples</groupId>
<artifactId>appName</artifactId>
<packaging>jar</packaging>
<version>0.0.0.1</version>
<name>appName</name>

Once you are done with these files, you can create an input (.txt) file and in case of any doubt you can download the sample application. Though commands for 'Running an S4 app' have been listed in my previous post, here's an apprise listing :
  •     cd /path _to_s4image_dir/examples/appName
  •     mvn assembly:assembly install
 will create a target folder in appName
  •     cd /path _to_s4image_dir/core/target/s4_apps/
  •     tar xzf /path _to_s4image_dir/examples/appName/target/appName-*.tar.gz
  •     cd /path _to_s4image_dir/core/target/bin
  •     ./s4_start.sh &
  •     head -10 /path _input_file_location/xyz.txt | \       ./generate_load.sh -x -r 2 -u/path _to_s4image_dir/core/target/s4_apps/appName/lib/appName-0.0.0.1.jar -
Hope this helped you somehow ! Any suggestions would be highly appreciated.  


1 comment:

  1. Hi jayati,

    are you working in S4?
    I need some help.

    Thanks,
    sara-

    ReplyDelete