IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#TechXchangePresenter
 View Only
Expand all | Collapse all

How to calculate FileAge?

  • 1.  How to calculate FileAge?

    Posted Wed May 19, 2010 10:12 PM

    Hi All,

    I would like to know whether there is any service which calculates the fileage.

    For eg: It lists out all the files in a folder and checks the fileage. It must say 15 mins old. Then I will process those files.

    If anyone has a code for this, Please help

    Thanks,
    David


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 2.  RE: How to calculate FileAge?

    Posted Thu May 20, 2010 06:08 AM

    Have you given up on the file polling port?


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 3.  RE: How to calculate FileAge?

    Posted Thu May 20, 2010 12:04 PM

    Hi reamon,

    For now, Yes. I have tried the filepolling part but the files which they are writing are very big files…it is picking up half files even before it is closed by the source; even though i have mentioned 3 mins as fileage it is not working as expected.

    So, I wanted to try this second approach where I will move all the files from one folder to another whose fileage is greater than 15 mins.

    Do u know any builtin services or any utility?

    thanks,
    David


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: How to calculate FileAge?

    Posted Thu May 20, 2010 04:13 PM

    [COLOR=#000000][FONT=arial]Below code will help you to get the last modified date of the file…from there you can calculate the current time and do required validation.

    Hope this helps


    import java.util.Date;
    import java.util.;
    import java.io.File;
    import java.io.
    ;

    IDataCursor idcPipeline = pipeline.getCursor();

    File f = new File( “c:\excelTest.java” );
    Date date=new Date(f.lastModified());

    idcPipeline.insertAfter(“lastModifiedDate”, date);
    idcPipeline.destroy();


    Output Type: Object Variable: lastModifiedDate


    [/FONT][/COLOR]


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 5.  RE: How to calculate FileAge?

    Posted Fri May 21, 2010 07:08 AM

    This can be acheived by the following java code -


    Input: Directory Name
    Output: Number of files suitable for processing
    Names of files suitable for processing
    Imports: import java.util.;
    import java.io.
    ;

    IDataCursor idcPipeline = pipeline.getCursor();
    //read the directory name from Pipeline
    if (!idcPipeline.first(“directory”))
    throw new ServiceException(“Directory is null!”);
    String strDirectoryName = (String)idcPipeline.getValue();
    //create handle to Directory and check existence and access
    File directoryHandle = new File(strDirectoryName);
    if(!(directoryHandle.canRead())) {
    throw new ServiceException(strDirectoryName + " Directory does not have Read Permission!“);
    }
    if(!directoryHandle.exists() || !directoryHandle.isDirectory()) {
    throw new ServiceException(strDirectoryName + " does not exist or is not a directory!”);
    }

    //get all elements in the directory
    File arrDirectoryElementList;
    arrDirectoryElementList = directoryHandle.listFiles();
    int iDirectoryElementCount = arrDirectoryElementList.length;

    //retrieve all the Files from the elements list
    int iDirectoryFileCount = 0;
    Vector filesVector = new Vector();
    Vector fileModificationTimeVector = new Vector();
    for (int i=0; i<iDirectoryElementCount; i++){
    if(arrDirectoryElementList[i].isFile()) {
    iDirectoryFileCount++;
    filesVector.addElement(arrDirectoryElementList[i]);
    //retrieve last modified time for the file - long value as milliseconds since the epoch
    fileModificationTimeVector.addElement(new Long(arrDirectoryElementList[i].lastModified()));
    }
    }

    if (iDirectoryFileCount < 1) {
    //No files to list
    IDataUtil.put(idcPipeline, “numFiles”, “0”);
    IDataUtil.put(idcPipeline, “fileList”, new String[0]);
    return;
    }

    //check file suitability for processing based on modified time
    Vector suitableFilesVector = new Vector();
    int iSuitableFileCount = 0;
    Calendar calendar = Calendar.getInstance();
    Long currentTime = calendar.getTimeInMillis();

    for(int j=0; j<filesVector.size(); j++) {
    Long fileModificationDate = (Long)fileModificationTimeVector.elementAt(j);
    //elapsed time after creation (in ms)
    Long timeDiff = currentTime - fileModificationDate;
    //elapsed time after creation (in mins)
    timeDiff = timeDiff/60000;
    //if elapsed time is more than 15 mins, consider it suitable for processing
    if(timeDiff >= 15) {
    iSuitableFileCount++;
    suitableFilesVector.addElement((File)filesVector.elementAt(j));
    }
    }
    if (iSuitableFileCount < 1) {
    //No suitable files
    IDataUtil.put(idcPipeline, “numFiles”, “0”);
    IDataUtil.put(idcPipeline, “fileList”, new String[0]);
    return;
    }

    String arrSuitableFilesList = new String[iSuitableFileCount];
    for(int k=0; k<iSuitableFileCount; k++) {
    File file = (File)suitableFilesVector.elementAt(k);
    arrSuitableFilesList[k] = file.getName();
    }
    IDataUtil.put(idcPipeline, “numFiles”, String.valueOf(iSuitableFileCount));
    IDataUtil.put(idcPipeline, “fileList”, arrSuitableFilesList);
    idcPipeline.destroy();


    You may need to modify as per specific requirements like filetype, etc.

    HTH


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 6.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 05:45 PM

    Hi all,

    Thanks for all your help. I have found a code and modified it where it picks up files > 15 mins and gives the filenames.

    But I am still searching for filePolling option in UNIX. Also, Does anyone know whether there is an option in UNIX to lock the files?

    I read in wikipedia…where in UNIX we have an option to lock files as in Windows. Your help is much appreciated.

    Thanks,
    David


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 7.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 05:47 PM

    The built-in facility is…the file polling port. If 3 minutes is insufficient, increase the time.

    When the age has been met, the file polling port will move the file to a working directory.

    You’re trying to reinvent the wheel on this one. The file polling port will work. You just need to configure it properly for your scenario.

    I personally would do a full-court press and tell the source system that they must do a rename after writing the file.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 8.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 05:52 PM

    I don’t see how this differs, in terms of polling, from the file polling port.


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 9.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 05:55 PM

    Hi reamon,

    I’ll try again and will let you know if I find the same issue.

    Thanks,
    David


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 10.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 06:05 PM

    Hi reamon,

    I tried it again but it is polling the second file also.

    My configuration.

    Monitoring directory: /xxxxx/xxxx/xxx
    Working, Completion, error, filenamefilter, Content type …unspecified.
    Fileage 120 seconds
    lock file extension .lock
    file polling interval 15 seconds
    log only…No
    Directories are NFS…No
    cleanup…not specified
    max no. of threads…1

    Now, I have written a file on the working directory and exactly after 1 min I have written second file.

    After 2 mins…the first file disappeared and after 5-10 seconds the second file disappeared too.

    Is there anything I am missing in the filepolling configuration.

    Thanks,
    David


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 11.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 06:06 PM

    Hi reamon,

    I tried it again but it is polling the second file also.

    My configuration.

    Monitoring directory: /xxxxx/xxxx/xxx
    Working, Completion, error, filenamefilter, Content type …unspecified.
    Fileage 120 seconds
    lock file extension .lock
    file polling interval 15 seconds
    log only…No
    Directories are NFS…No
    cleanup…not specified
    max no. of threads…1

    Now, I have written a file on the working directory and exactly after 1 min I have written second file.

    After 2 mins…the first file disappeared and after 5-10 seconds the second file disappeared too.

    Is there anything I am missing in the filepolling configuration.

    Thanks,
    David


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 12.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 09:24 PM

    How are the 2 files being written? If with file copy, it may be that the file modification timestamp is not being updated. Thus the polling thinks the file age is good to be picked up.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 13.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 09:55 PM

    Hi Reamon,

    I am writing the files using a util service which writes file to a certain path.

    Thanks,
    David


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 14.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 10:48 PM

    Have you or can you check that the file mod time is as expected? I’d be surprised if the file polling port is picking up the file before it is of age. Is the directory being polled on the same machine as IS? Is the process that is writing the file on the same machine too? Perhaps there is a time mismatch between the IS host and another machine.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 15.  RE: How to calculate FileAge?

    Posted Mon May 24, 2010 11:34 PM

    Hi Reamon,

    To my knowledge, They are both on the same box. The Util service which I am using to write a file is on webMethods IS.

    Also, When I am using a java service which lists out files >15 mins. When I am running this service, It is working perfect. Whereas the filepolling is not working as expected. Both are on webMethods IS.

    Thanks,


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 16.  RE: How to calculate FileAge?

    Posted Tue May 25, 2010 12:26 AM

    Sounds like a case for wM tech support. Something is not right.


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 17.  RE: How to calculate FileAge?

    Posted Tue May 25, 2010 04:03 PM

    Yes. You may be right. I’ll try to find if i get any valuable information. If not, I will raise a ticket to Software AG.

    Thanks,
    David.


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services