Search This Blog

ExecutorService - Java - Parallel execution

ExecutorService - Java - Parallel execution    


import java.util.concurrent.ExecutorService;

import java.util.concurrent.Executors;




                  ExecutorService executor = Executors.newFixedThreadPool(2);
                     
                        Runnable worker1 = new accumulator();
                        executor.execute(worker1);
                     

                        Runnable worker2 = new claim();
                        executor.execute(worker2);
                 

                        executor.shutdown();
             
                        // Wait until all threads are finish
                        while (!executor.isTerminated()) {
                         
                        }




    public class accumulator implements Runnable {
                    @Override
                    public void run() {
                        try {
                         
                        } catch(Exception e){
                            e.printStackTrace();
                        }
                    }
    }
   
   
    public  class claim implements Runnable {
                    @Override
                    public void run() {
                        try {
                     
                        } catch(Exception e){
                            e.printStackTrace();
                        }
                       
                    }
    }


XREF Usage in SOA ( Select - xref:lookupXRef , Add - Update - xref:populateXRefRow )

XRef Usage:

( Select,Add and Update)


Xref Table Name : CLR

Name : "InterfaceName" , "LastRunDate"

Select Xref :


Syntax :


xref:lookupXRef(xrefLocation as string, xrefReferenceColumnName as string,
xrefReferenceValue as string, xrefColumnName as string, needAnException as
boolean) as string
Example :

xref:lookupXRef("CLR.xref","InterfaceName","CLR022","LastRunDate",true())


Add - xref:populateXRefRow :



xref:populateXRefRow(xrefLocation as string, xrefReferenceColumnName as string,
 xrefReferenceValue as string, xrefColumnName as string, xrefValue as string, mode
 as string) as string
Parameters

  • xrefLocation: The cross reference table URI.
  • xrefReferenceColumnName: The name of the reference column.
  • xrefReferenceValue: The value corresponding to the reference column name.
  • xrefColumnName: The name of the column to be populated.
  • xrefValue: The value to be populated in the column.
  • modeThe mode in which the xref:populateXRefRow function populates the column. You can specify any of the following values: ADDLINK, or UPDATE
Example :

xref:populateXRefRow("CLR.xref","InterfaceName","CLR022","LastRunDate",xp20:format-dateTime(xp20:current-dateTime(),'[Y0001]-[M01]-[D01] [H01]:[m01]:[s01].[f001]'),"ADD")


Update :


xref:populateXRefRow("CLR.xref","InterfaceName","CLR022","LastRunDate",xp20:format-dateTime(xp20:current-dateTime(),'[Y0001]-[M01]-[D01] [H01]:[m01]:[s01].[f001]'),"UPDATE")

Common Used code for Dev

DVM Syntax:

dvm:lookupValue("DVM Location ","Key","ValueName","Value","")

Example :
dvm:lookupValue("oramds:/apps/Hello/dvm/wave3/xyz.dvm","Key","compName","Value","")

Count Line for large file in Java: ( Fast Execution )

    /**
     * @param filePath
     * @return
     * @throws FileNotFoundException
     * @throws IOException
     */
    public int countLineNumbers(String filePath) throws FileNotFoundException,
                                                        IOException {

        LineNumberReader lnr =
            new LineNumberReader(new FileReader(new File(filePath)));
        lnr.skip(Long.MAX_VALUE);
        int lineCount = lnr.getLineNumber() + 1;
        lnr.close();
        return lineCount;
    }

Move File and Copy File logic in Java:



    public void moveWorkingFile(String sourceFile, String destinationPath) {
            try {
                File afile = new File(sourceFile);
                afile.renameTo(new File(destinationPath));
            } catch (Exception e) {
                 throw ex;
            }
        }
         
       
     import oracle.j2ee.ws.common.util.FileUtils;
  
    public void copyWorkingFile(String sourceFile,
                                    String destinationPath) throws Exception {
            try {
                FileUtils.copyFile(new File(sourceFile),
                                   new File(destinationPath));
            } catch (Exception ex) {
                             throw ex;
            }
        }

 

StringTokenizer :

 private HashMap<String, String>  propertiesMap = new HashMap<String, String>();

strProps ( userName=xyz | password = abc | url = http)

    private void loadCommonProperties(String strProps) throws Exception {

          String strTempProps = "";
            try {
                StringTokenizer tok = new StringTokenizer(strProps, "|");
                while (tok.hasMoreTokens()) {
                  strTempProps = tok.nextToken();
                    if (strTempProps.contains("=")) {
                        String[] strKeyVal = strTempProps.split("=");
                        if( strKeyVal.length < 2 ){
                            propertiesMap.put(strKeyVal[0], " ");
                                }else{
                        propertiesMap.put(strKeyVal[0], strKeyVal[1]);
                                }
                    }
                }
           } catch (Exception ex) {
                       throw ex;
            }
         
        }


Value get from Map

propertiesMap.get("userName");



Creating Connection in Java code from Data Source JNDI Name:


private Connection getJdbcConnection(String jdbcParams) throws SQLException,
                                                                   NamingException,
                                                                   ClassNotFoundException {
        try {
            String[] strParam = jdbcParams.split(",");

            String serverUrl = strParam[0];
            String jndi = strParam[1];
            Properties prop = new Properties();
            prop.put(Context.INITIAL_CONTEXT_FACTORY,
                     "weblogic.jndi.WLInitialContextFactory");
            prop.put(Context.PROVIDER_URL, serverUrl);

            InitialContext ctx = new InitialContext(prop);

            DataSource dataSource = (DataSource)ctx.lookup(jndi);
           Connection objConn = dataSource.getConnection();
  }catch(Exception ex){
  throw ex;
  }
  return objConn;

  }



Java code to Convert Unix File format to DOS File Format

Note : Below logic only works in Unix Flavor platform.

    public static String convertUnixToDosFile(String sourceFile,String targetFile) {

        try {

            Runtime.getRuntime().exec("unix2dos " + sourceFile + " " +   targetFile);

        } catch (IOException e) {

            e.printStackTrace();

        }
        return "true";
    }


SingleTon Property very important if code deployed in Cluster Env


SingleTon Property very important if code deployed in Cluster Env



 <reference name="CopyMoveFileOperation"   ui:wsdlLocation="CopyMoveFileOperation.wsdl">
    <interface.wsdl interface="http://xmlns.oracle.com/pcbpel/adapter/file/CopyMoveFileOperation#wsdl.interface(CopyFile_ptt)"/>
    <binding.jca config="CopyMoveFileOperation_file.jca">
       <property name="singleton">true</property>
    </binding.jca>
  </reference>

IHelperBean Class - Predefined SOA Class to set JCA properties in Spring Component

IHelperBean Class - Predefined SOA Class to set JCA properties in Spring Component 


    Most of the Business logic are not simple to achieve in SOA ( BPEL ) or BPM, to make process more faster and simple to maintain Spring approach  can be use. Calling SOA adapter in Spring also simple.

Question ???    

How to set JCA properties in Run Time with out hard coding properties in .JCA  and I know how to use in BPEL , But how to set in Spring ????


IHelper Bean  ( Note don't change any name for IHelper Bean)

Import Statement :
import oracle.soa.platform.component.spring.beans.IHeaderHelperBean;


 private IHeaderHelperBean headerHelper;


Getters and Setters 


    public void setHeaderHelper(IHeaderHelperBean headerHelper) {
        this.headerHelper = headerHelper;
    }

    public IHeaderHelperBean getHeaderHelper() {
        return headerHelper;

    }


Code Logic :


      headerHelper.setHeaderProperty("jca.file.FileName", "TmpBPCL.txt");
      headerHelper.setHeaderProperty("jca.file.Directory", filePath);



Spring.xml

<beans>
  <bean class="com.bcbsri.spring.mapUtil.ClaimProcessor"
        id="CLM030837IpEditsFileBean">
    <property name="headerHelper" ref="headerHelperBean"/>
  </bean>
</beans>



How to read GB file or more than 10 MB file using File Adapter - SOA - BPEL

How to read GB file or more than 10 MB file using File Adapter - SOA - BPEL


Most of the time in SOA suite have a suitation to handle more than 10 MB of data to read. But SOA file adapter limitation only 10MB beyond that adapter will fail to read input data. Solution to read GB input file also using Chunk Read logic .



Create normal file adapter using - Sync Read option and modify the .jca file completely

.JCA File :

Chunk Size I defined 100 record / chunk

<adapter-config name="ReadFileChunk" adapter="File Adapter" wsdlLocation="ReadFileChunk.wsdl" xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">

  <connection-factory location="eis/FileAdapter"/>
  <endpoint-interaction portType="SynchReadFile_ptt" operation="synchReadFile">
    <interaction-spec className="oracle.tip.adapter.file.outbound.ChunkedInteractionSpec">
      <property name="DeleteFile" value="true"/>
      <property name="PhysicalDirectory" value="D:\Out"/>
      <property name="FileName" value="Krishna.txt."/>
      <property name="ChunkSize" value="100"/>
     </interaction-spec>
  </endpoint-interaction>
</adapter-config>



BPEL Implementation :


Declare default value before while loop logic


 LineNumber=  "1"
 ColumnNumber= "1"
 IsEOF = "false"


<while name="While_ChunkLoop"
               condition="bpws:getVariableData('VarChunkJcaProperties','/ns7:ChunkFileAdapterProp/ns7:IsEOF') ='false'">
          <sequence name="SeqChunkLogic">
            <invoke name="Invoke_ReadFileFromWorkingDir"
                    inputVariable="ReadFile_InputVariable"
                    outputVariable="ReadFile_OutputVariable"
                    partnerLink="ReadFileChunk" portType="ns8:SynchReadFile_ptt"
                    operation="synchReadFile" bpelx:invokeAsDetail="no">
              <bpelx:inputProperty name="jca.file.FileName"
                                   variable="VarChunkJcaProperties"
                                   query="/ns7:ChunkFileAdapterProp/ns7:file"/>
              <bpelx:inputProperty name="jca.file.Directory"
                                   variable="VarChunkJcaProperties"
                                   query="/ns7:ChunkFileAdapterProp/ns7:dir"/>
              <bpelx:inputProperty name="jca.file.LineNumber"
                                   variable="VarChunkJcaProperties"
                                   query="/ns7:ChunkFileAdapterProp/ns7:LineNumber"/>
              <bpelx:inputProperty name="jca.file.ColumnNumber"
                                   variable="VarChunkJcaProperties"
                                   query="/ns7:ChunkFileAdapterProp/ns7:ColumnNumber"/>
              <bpelx:inputProperty name="jca.file.IsEOF"
                                   variable="VarChunkJcaProperties"
                                   query="/ns7:ChunkFileAdapterProp/ns7:IsEOF"/>
              <bpelx:outputProperty name="jca.file.LineNumber"
                                    variable="VarChunkJcaProperties"
                                    query="/ns7:ChunkFileAdapterProp/ns7:LineNumber"/>
              <bpelx:outputProperty name="jca.file.ColumnNumber"
                                    variable="VarChunkJcaProperties"
                                    query="/ns7:ChunkFileAdapterProp/ns7:ColumnNumber"/>
              <bpelx:outputProperty name="jca.file.IsEOF"
                                    variable="VarChunkJcaProperties"
                                    query="/ns7:ChunkFileAdapterProp/ns7:IsEOF"/>
              <bpelx:outputProperty name="jca.file.IsMessageRejected"
                                    variable="VarChunkJcaProperties"
                                    query="/ns7:ChunkFileAdapterProp/ns7:returnIsMessageRejected"/>
              <bpelx:outputProperty name="jca.file.RejectionReason"
                                    variable="VarChunkJcaProperties"
                                    query="/ns7:ChunkFileAdapterProp/ns7:returnRejectionReason"/>
              <bpelx:outputProperty name="jca.file.NoDataFound"
                                    variable="VarChunkJcaProperties"
                                    query="/ns7:ChunkFileAdapterProp/ns7:returnNoDataFound"/>
            </invoke>

        </while>



Spring Logic IHelper Bean :

             chunkSize = 1000;
             lineNumber = "1";
             columnNumber = "1";
             currentLineCount = 1;
       
            while (currentLineCount <= totalLineCount - 1) {
                currentLineCount = currentLineCount + chunkSize;
             
             
                               headerHelper.setHeaderProperty("jca.file.FileName",propertiesMap.get("IN_DENT_FILENM"));
                headerHelper.setHeaderProperty("jca.file.Directory", filePath);
                headerHelper.setHeaderProperty("jca.file.LineNumber",  lineNumber);
                headerHelper.setHeaderProperty("jca.file.ColumnNumber", columnNumber);
         
                 lineNumber = Integer.toString(Integer.parseInt(lineNumber) + chunkSize);
            }
            

normalize-space() - Be Clear where to use in SOA

normalize-space() - Be Clear where to use in SOA


normalize-space() - Performs remove unwanted spaces in a string . We know that but how it works internally.

Example : "      Hai       User             Weclome     you            "

Input String contains spaces in the front , last and middle also. I want to remove spaces in front,middle and last.

Note : normalize space will remove extra spaces in between words also and put only one character space.

normalize-space("      Hai       User             Weclome     you            ") ;


Ouput :    "Hai User Welcome you"


If you are looking for front and last to remove spaces use 

oraext:right-trim(oreaxt:left-trim("      Hai       User             Weclome     you            "));


Output : "Hai       User             Weclome     you"


xp20:format-dateTime - SOA- Custom format Date Time

xp20:format-dateTime - SOA- Custom format Date Time


Middleware  intreacts with mostly external system - Each system need some custom Date and Time format structure. Most of the time developers not remember Syntax .

Y001 - year
M01 - month
D01 - date
H01 - hour
m01 - minutes
s01   -  seconds
f001 - millsec

Use Ready Made functions:


xp20:format-dateTime(xp20:current-dateTime(),'[Y0001][M01][D01]_[H01][m01][s01]')


Including MillSeconds :

xp20:format-dateTime(xp20:current-dateTime(),'[M01]/[D01]/[Y0001] [H01]:[m01]:[s01].[f001]')

Universal Time format with T :


xp20:format-dateTime(xp20:current-dateTime(),"[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001]")

New Line Character in BPEL - SOA

New Line Character in BPEL - SOA :


My Requirement to create new line between two words.

Example :



Input    :  Krishna Moorthi
Output :  Krishna
              Moorthi

create BPEL variable varNewLine  and assign Values as "&#13;&#10;"

Now use "Krishna"+ $varNewLine  + "Moorthi".

:-) :-)

File / FTP Adapter SOA - COPY / MOVE / DELETE Operation

File Adapter Move / Copy Operation :


File Adapter or FTP Adapter in 11g won't direct support in GUI mode.

In Some scenarios we need to perform move or copy   from one folder to another folder. Following code will support

FileMove.jca

MOVE Operation 
=================================================================
<adapter-config name="FileMove" adapter="File Adapter"
                wsdlLocation="FileMovet.wsdl"
                xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
    <connection-factory location="eis/FileAdapter"/>
    <endpoint-interaction portType="FileMove_ptt" operation="FileMove">
        <interaction-spec className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec">
            <property name="SourcePhysicalDirectory" value="D:\Krishna"/>
            <property name="SourceFileName" value="HelloWorld.txt"/>
            <property name="TargetPhysicalDirectory" value="D:\Moorthi"/>
            <property name="TargetFileName" value="HelloWorldNew.txt"/>
            <property name="Type" value="MOVE"/>
        </interaction-spec>

    </endpoint-interaction>
</adapter-config>
=================================================================

COPY Operation 
=================================================================
<adapter-config name="FileMove" adapter="File Adapter"
                wsdlLocation="FileMovet.wsdl"
                xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
    <connection-factory location="eis/FileAdapter"/>
    <endpoint-interaction portType="FileMove_ptt" operation="FileMove">
        <interaction-spec className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec">
            <property name="SourcePhysicalDirectory" value="D:\Krishna"/>
            <property name="SourceFileName" value="HelloWorld.txt"/>
            <property name="TargetPhysicalDirectory" value="D:\Moorthi"/>
            <property name="TargetFileName" value="HelloWorldNew.txt"/>
            <property name="Type" value="COPY"/>
        </interaction-spec>

    </endpoint-interaction>
</adapter-config>
=================================================================


DELETE Operation 
=================================================================
<adapter-config name="FileMove" adapter="File Adapter"
                wsdlLocation="FileMovet.wsdl"
                xmlns="http://platform.integration.oracle/blocks/adapter/fw/metadata">
    <connection-factory location="eis/FileAdapter"/>
    <endpoint-interaction portType="FileMove_ptt" operation="FileMove">
        <interaction-spec className="oracle.tip.adapter.file.outbound.FileIoInteractionSpec">
            <property name="TargetPhysicalDirectory" value="D:\Moorthi"/>
            <property name="TargetFileName" value="HelloWorldNew.txt"/>
            <property name="Type" value="DELETE"/>
        </interaction-spec>

    </endpoint-interaction>
</adapter-config>
=================================================================


Invoke Change in BPEL :


 <invoke name="Invoke1" inputVariable="Invoke1_FileMove_InputVariable"
                outputVariable="Invoke1_FileMove_OutputVariable"
                partnerLink="FileAdptMoveTest" portType="ns1:FileMove_ptt"
                operation="FileMove" bpelx:invokeAsDetail="no">
<bpelx:inputProperty name="jca.file.SourceDirectory" variable="sourceDirectory"/>
<bpelx:inputProperty name="jca.file.SourceFileName" variable="sourceFileName"/>
<bpelx:inputProperty name="jca.file.TargetDirectory" variable="targetDirectory"/>
<bpelx:inputProperty name="jca.file.TargetFileName" variable="targetFileName"/>
</invoke>