Monday, October 15, 2012

Active Data Service (ADS)


Active Data Service :

As name imply active data service is used to show the latest data on UI.
The main example is stock market where the value of the share is always changing therefore provide this type of feasibility oracle has introduced a mechanize which is called Active Data Service.

 But before going to jump into the details about Active Data Service i would like to put some light on why do we really need active data service and how it is work in real scenario.

All the real time application now days are based on client server architecture. So there is two things
1-Request
2-Response

Always request is initiated by client for to performing  operation on server and server will response as soon as possible .as long as the response come there is no any communication left  between server and client.
Following picture depicts the relation ship between server and client .

So this is all about the server and client relation and about Hyper text transfer protocol .Let come on actual topic .
To be honest the Active Data Service is huge and also it is bit complex.That is reason why i thought  to start with simple.Since oracle has given one component that support the Active Data Service without doing any thing.By the way oracle also has give other component that support the Active Data Service but that require configuration and coding to make them work.

So for understanding the Active data service it is good to first understand about af:poll component which is based on the Active data Service however you can direct start  learning  the Active data service without knowing the af:poll  components.

af:poll document is at following location

1-http://jdevadf.oracle.com/adf-richclient-demo/docs/tagdoc/af_poll.html

af:poll will run automatically and run at certain period of time or  it will run periodically.

The server and client communication can happens following three type which are following

1-Push  as know as HTTP stream 
2-Poll 
3-Long poll

So af:poll is based on poll communication.Where client always should request to server after some period of time.
For one request server will response so there is no any more communication left  and client need to initiate  again new request.
In my next post i will go more depth in about above maintained approach.

Here it is clear that af:poll is based on the Poll approach.

For understanding the af:poll i have implemented following way

1-First i have created a page where i have inserted  af:table and af:poll component.

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1">
      <af:form id="f1">
        <af:table var="row" value="#{pollApplication.tableValue}"
                  rowBandingInterval="0" id="t1"
                  binding="#{pollApplication.richTable}">
          <af:column sortable="false" headerText="ColumnHearder" id="c2">
            <af:outputText value="#{row.columnValue}" id="ot1"/>
          </af:column>
          <af:column sortable="false" headerText="TimeStamp" id="c1">
            <af:outputText value="#{row.timeStamp}" id="ot2"/>
          </af:column>
        </af:table><af:poll id="p1" pollListener="#{pollApplication.pollListenerMethod}"/>
      
      </af:form>
    </af:document>
  </f:view>
</jsp:root>

And i am passing the table data using table through backing bean and also i attached poll event with backing bean
2-Passing value through backing bean
    private List<TableData> tableValue;
    private RichTable richTable;

    public void setTableValue(List<TableData> tableValue) {
        this.tableValue = tableValue;
    }

    public List<TableData> getTableValue() {
        if (tableValue == null) {
            tableValue = new ArrayList<TableData>();
            for (int i = 0; i < 4; i++) {
                TableData tableData = new TableData();
                tableData.setColumnValue(i + "Column" +
                                         System.currentTimeMillis());
                tableData.setTimeStamp(System.currentTimeMillis());
                tableValue.add(tableData);
            }
        }
        return tableValue;
    }

    public void pollListenerMethod(PollEvent pollEvent) {
        AdfFacesContext.getCurrentInstance().addPartialTarget(richTable);
    }

    public void setRichTable(RichTable richTable) {
        this.richTable = richTable;
    }

    public RichTable getRichTable() {
        return richTable;
    }

Here in backing bean i have refreshing whole adf table again and again in the pollListenerMethod method which automatically trigger after every five seconds
Although user has option to increase/decrease  interval value as their need by the way default interval is 5000 mill second.

This sample example which is based on af:poll and af:poll is based on active data service .In Poll client will call server periodically based on what interval is given .

Above code is example how Poll is working.Here client will call the server at some period of time.
Nevertheless in my up coming post i  would like to put more information on active data service.


Source code is present at following link
1-https://docs.google.com/open?id=0B8cP4jZuxLlXRTRyVnVYeTdSWW8



Disadvantage :
1-It is always call server which extra over head on server.
2-This approach is just for understanding about af:poll.If you executing binding again regardless if there is any change or not  then it is  not suitable .
3-Refereshing the whole pages or whole table obviously not correct.

PS:
1-For using af:poll does  not require any extra coding since Adf servlet which is added  by default in web.xml will take care.no extra code .
2-Through client side java script it will call server periodically .

No comments:

Post a Comment