Sunday, December 9, 2012

Dynamic region in ADF


Requirement : In the same region in UI different page has to be shown based on the link clicked.
Like Page has two links :
Employee Data
Department Data
- when user click on employee data , page with employee data opens up.
- when user click on Departmemnt data , page with department data opens up.


These two opens up in the same region.
ADF supports this with the help of dynamic region and bounded task flows.

Steps to achieve this :
1) Create two bounded task flows with fragments
Employee task flow  : Dynamic-employee-flow
Department task flow : dynamic-department-flow

I just use simple VO based on HR schema to achieve this.

2) Create one dashboard page like companydetails.jspx
- Split the page using panel splitter
- on the first half add two links one for employee details and other for department details.
- you can use images inside the links to give a visual look to the links

3) Drop any of the two task flow created on the second facet of panel splitter
- select dynamic region
- give name for the managed bean like : screenNameBB
- class name : hr.view.backing.screenSelectBean

This will be used to determine which task flow to display.
The bindings will be created like :
<taskFlow id="dynamicRegion1"
              taskFlowId="${backingBeanScope.screenNameBB.dynamicTaskFlowId}"
              activation="deferred"
              xmlns="http://xmlns.oracle.com/adf/controller/binding"/>

4) you will see that there is one method created in the bean class as :
public class screenSelectBean

public TaskFlowId getDynamicTaskFlowId()

This is a simple method that will be invoked at runtime to decide which task-flow to display.

5) We can achieve the dynamic navigation by setting up a managed property at session level on click of each link. For this I just created another managed bean(DisplayManager) which set the propert called displayUI based on click of link.

Like : private String displayUI="EMPLOYEE_DATA"; along with setters and getters. This is the property we will set on click of each link to decide which task flow to display.

6) The screenSelectBean is scoped at backing bean level and should refer this property.
So create a property in screenSelectBean  that can refer the class.
Code will look like :

      private DisplayManager _dispManager; - Reference to session propery for display
      String Employee_flow ="/WEB-INF/Dynamic-employee-flow.xml#Dynamic-employee-flow";
      String Dept_flow =    "/WEB-INF/dynamic-department-flow.xml#dynamic-department-flow";

     public TaskFlowId getDynamicTaskFlowId() {
     String toDisp = _dispManager.getDisplayUI();
     if (toDisp.equals("EMPLOYEE_DATA"))
         return TaskFlowId.parse(Employee_flow);
         else
         return TaskFlowId.parse(dept_flow);
     
      }

 You can have the values saved in Hashmap or Java enumeration to make the application more extensive.


7) Open adf-config , you will see that there is backing bean created with name : screenNameBB
Add another managed bean with scope as session for DisplayManager, Like :

 <managed-bean id="__7">
    <managed-bean-name id="__6">dispUI</managed-bean-name>
    <managed-bean-class id="__8">hr.view.DisplayManager</managed-bean-class>
    <managed-bean-scope id="__5">session</managed-bean-scope>
  </managed-bean>

Create property in screenNameBB to refer this bean for setting name of flow:like
  <managed-property id="__23">
      <property-name id="__25">dispManager</property-name>
      <property-class>hr.view.DisplayManager</property-class>
      <value id="__24">#{dispUI}</value>
    </managed-property>

The property name should match the setter in Bean . like bean should have setdispManager method defined.

8) One last step . Open the companydetails.jspx
Drop setPropertyListener on the link and set appropriate text to decide the correct task flow:

employee Link :

<af:setPropertyListener from="#{'EMPLOYEE_DATA'}" to="#{dispUI.displayUI}" type="action"/>

Department Link :
<af:setPropertyListener from="#{'DEPARTMENT_DATA'}" to="#{dispUI.displayUI}" type="action"/>


UI will look like this in Jdev :



When you run the UI you will see the links will open the different task flow at the same region Area.
We can further improve the performance by enabling partial submit for the link buttons.

Cheers !!

Sunday, September 9, 2012

Monitor Weblogic using WLST in java


Here is the code i used to monitor the weblogic server details written in java using WLST. At times the weblogic console doesnt respond or is very slow. The script helps getting the important data needed during issues and help monitoring the server.

Main parameters that we normally want to monitor :
- JVM Stats
- JMS stats
- JTA stats
- Thread Pool
- Deployed Application state

Here goes the java file , it fetches this data and writes to a text file.

Utility method to write the data to file
   public static void writeFile(StringBuffer data) {
     try {
       FileWriter outFile = new FileWriter("C:\\ServerStats\\serverinfo.txt");
       BufferedWriter out = new BufferedWriter(outFile);
       out.write(data.toString());
       out.close(); 
     }catch(Exception e){e.printStackTrace();}
  }

Main code to fetch server info :
The code is pretty simple and additional code for other parameters can be added easily. 

  
  StringBuffer data= new StringBuffer("Data");
            MBeanHome home = null;
           String url = "t3://serverurl:port";
           String username = "weblogic";
           String password = "welcome1";


            try {
                Environment env = new Environment();
                env.setProviderUrl(url);
                env.setSecurityPrincipal(username);
                env.setSecurityCredentials(password);
                Context ctx = env.getInitialContext();
                home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
            } catch (Exception e) {System.out.println("Exception caught: " + e);}

            
            try {
            
                data.append("DOMAIN NAME :  " +  home.getActiveDomain().getName() +"\n");
               
            } catch (Exception e) {System.out.println("Exception: " + e);}
           
           Set mbeanSet = home.getMBeansByType("ServerRuntime");
           data.append("Number of servers in the domain: " + mbeanSet.size() +"\n");
           
            
            Iterator mbeanIterator = mbeanSet.iterator();
            int cls=1;
            while(mbeanIterator.hasNext()) {
                ServerRuntimeMBean serverRuntime =  (ServerRuntimeMBean)mbeanIterator.next();
                
              if(cls==1)
              {
              try{
              ClusterRuntimeMBean clusterruntime = serverRuntime.getClusterRuntime();
              data.append("------------- CLUSTER INFORMATION---------------" + "\n");    
              data.append("1. Cluster Name :  "+clusterruntime.getName()+"\n");
              data.append("2. Cluster MulticastMessagesLostCount : "+clusterruntime.getMulticastMessagesLostCount()+"\n");
              data.append("3. Cluster Server Names  "+"\n"); 
                  for(int j=0;j<clusterruntime.getServerNames().length;j++) {
                    data.append(" Server :  "+(clusterruntime.getServerNames())[j] + "\n");
                  }
                  
              data.append("---------------------------------------------------------------------------- "+"\n");    
              }catch(Exception e){e.printStackTrace();}
              }  
              
              
              //if(cls==1)
              //{
              try{
                data.append("------------- WEB SERVER INFORMATION---------------" + "\n");  
              WebServerRuntimeMBean[] webserverruntime = serverRuntime.getWebServerRuntimes();
                
              for(int j=0;j<webserverruntime.length;j++) {
                data.append("1. Web server info : Web server Names  "+webserverruntime[j].getWebServerName()+"\n");
               
              }
                data.append("---------------------------------------------------------------------------- "+"\n");
              }catch(Exception e){e.printStackTrace();}
         
         
                   
            if(serverRuntime.getState().equals(ServerStates.RUNNING)){
              data.append("---------------------------------------------------------------------------- "+"\n");
              data.append(" INFO STARTS FOR SERVER "+serverRuntime.getName()+" ******"+"\n");
              data.append("---------------------------------------------------------------------------- "+"\n");
                     data.append("1. Server Name = " + serverRuntime.getName()+"\n");
                     data.append("2. Server ListenAddress = " +  serverRuntime.getListenAddress()+"\n");
                     data.append("3. Server ListenPort = " +  serverRuntime.getListenPort()+"\n");
                     data.append("4. Admin server Host = " +  serverRuntime.getAdminServerHost()+"\n");
                     data.append("5. Health state = " +  serverRuntime.getHealthState()+"\n");
                                    
                  data.append("---------------------------------------------------------------------------- "+"\n");
                  data.append(" JVM Parameters For SERVER "+serverRuntime.getName()+"\n");
                  data.append("---------------------------------------------------------------------------- "+"\n");
                  JVMRuntimeMBean jvmruntime = serverRuntime.getJVMRuntime();
                  data.append("1. JVM Current Heap size = " + jvmruntime.getHeapSizeCurrent()+"\n");
                  data.append("2. JVM  Heap free Current  = " + jvmruntime.getHeapFreeCurrent()+"\n");
                  data.append("3. JVM  Heap free Percent = " + jvmruntime.getHeapFreePercent()+"%"+"\n");
                  data.append("4. JVM  Heap size max = " + jvmruntime.getHeapSizeMax()+"\n");
                  data.append("5. JVM  JavaVersion = " + jvmruntime.getJavaVersion()+"\n");
                  data.append("6. JVM  JavaVendor = " + jvmruntime.getJavaVendor()+"\n");
              
                  try{
                    ExecuteQueueRuntimeMBean[] executeQueueRuntime =serverRuntime.getExecuteQueueRuntimes();
                    data.append("---------------------------------------------------------------------------- "+"\n");
                    data.append(" Execute Queue Runtime parameters "+"\n");
                    data.append("---------------------------------------------------------------------------- "+"\n");
                      for(int j =0;j<executeQueueRuntime.length;j++)
                      {
                        data.append("1. Execute Queue ThreadTotalCount =  "+executeQueueRuntime[j].getExecuteThreadTotalCount()+"\n");  
                        data.append("2. Execute Queue ThreadCurrentIdleCount =  "+executeQueueRuntime[j].getExecuteThreadCurrentIdleCount()+"\n");
                        data.append("3. Pending RequestCurrentCount =  "+executeQueueRuntime[j].getPendingRequestCurrentCount()+"\n");  
                        data.append("4. PendingRequestOldestTime =  "+executeQueueRuntime[j].getPendingRequestOldestTime()+"\n");  
                      }
                      
                  }catch(Exception e){e.printStackTrace();}
                  
                  
                  
                  data.append("---------------------------------------------------------------------------- "+"\n");                
                  data.append("  JTA STATS FOR SERVER "+serverRuntime.getName() +"\n");
                  data.append("---------------------------------------------------------------------------- "+"\n");
                  JTARuntimeMBean jtaruntime= serverRuntime.getJTARuntime();
                  
                   data.append( "1. Total Trx = " + jtaruntime.getActiveTransactionsTotalCount()+"\n");
                   data.append( "2. Total Abondened Trx = " + jtaruntime.getTransactionAbandonedTotalCount()+"\n");
                   data.append( "3. Total Commited Trx = " + jtaruntime.getTransactionCommittedTotalCount()+"\n");
                   
                                     
                  data.append("---------------------------------------------------------------------------- "+"\n");
                  data.append(" JMS Parameters FOR SERVER  "+serverRuntime.getName()+"\n");
                  data.append("---------------------------------------------------------------------------- "+"\n");
                  
                  JMSRuntimeMBean jmsruntime= serverRuntime.getJMSRuntime();
                  JMSServerRuntimeMBean[] jmsservers= jmsruntime.getJMSServers();
                  
                  for(int i=0;i<jmsservers.length;i++)
                  {
                     data.append( "1. JMS Server Name = "+jmsservers[i].getName()+"\n");
                     data.append( "2. MessagesHighCount = "+jmsservers[i].getMessagesHighCount()+"\n");
                     data.append( "3. MessagesPendingCount = "+jmsservers[i].getMessagesPendingCount()+"\n");
                     data.append( "3. DestinationsCurrentCount = "+jmsservers[i].getDestinationsCurrentCount()+"\n"); 
                    
                  }
                  data.append("4. JMS Health : " + jmsruntime.getHealthState()+"\n");

                  data.append("---------------------------------------------------------------------------- "+"\n");
         
                  data.append("---------------------------------------------------------------------------- "+"\n");
                  data.append(" Application Runtime Data FOR SERVER  "+serverRuntime.getName()+"\n");
                  data.append("---------------------------------------------------------------------------- "+"\n");
                  
                 ApplicationRuntimeMBean[] appruntime = serverRuntime.getApplicationRuntimes();
                 for(int j=0;j<appruntime.length;j++)
                 {
                   if(appruntime[j].isEAR())  
                   {
                    data.append("Application Name : " +appruntime[j].getApplicationName() +"\n");
                    data.append("Application Name : " +appruntime[j].getHealthState() +"\n");
                   }
                 }

                 // ThreadPoolRuntimeMBean tpoolruntime=serverRuntime.getThreadPoolRuntime();
                    data.append(" INFO ENDS FOR SERVER "+serverRuntime.getName() +"\n");
                  
                                                       
                }
              cls++;
            }//while ends
            
            writeFile(data);


-----------------------------------------------------------------------------------
You will find file : serverinfo.txt at C:\ServerStats.


Thanks !!