473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to wait on a file to populate?

112 100+
Hi,
I need help writing code to wait for a file to populate on another machine.
I am doing a cattail on a log file on another machine, and when the file gets written to, then I need to perform some action in my java code, but I need the code to wait till something on the log file does get populated.
Right now, my code seems to fly by the section that has the cattail command and I need for it to stop and wait.

I have tried creating a thread and giving the thread the max priority, but i still can not get the method to wait for my cattail.

The code below shows the class and methods involved that i have written that doesnt work:

Expand|Select|Wrap|Line Numbers
  1. public void run()
  2.     {
  3.         try
  4.         {
  5.             System.out.println("YOU ARE IN DESKTOPSHMTRANSLATOR RUN()");
  6.             this.listen();
  7.         }
  8.         catch(Exception e)
  9.         {
  10.             System.out.println("RUN EXCEPTION");
  11.         }
  12.     }
  13.  
  14.     public void listen() throws Exception
  15.     {
  16.         System.out.println("YOU ARE IN DESKTOPSHMTRANSLATOR LISTEN()");
  17.  
  18.         String remoteCommand = "cattail";
  19.         String remoteDir = "/infra/sbt-support/supportTools/hsqldb/ics/tmp/";
  20.         String remoteFile = "alarmNotification.log.orig";
  21.  
  22.         String server = "server";
  23.         String userName = "username";
  24.         String password = "password";
  25.  
  26.  
  27.         StringBuffer rcmd = new StringBuffer();
  28.         rcmd.append(remoteCommand);
  29.         rcmd.append(" ");
  30.         rcmd.append(remoteDir);
  31.         rcmd.append(remoteFile);
  32.  
  33.         System.out.println("RCMD IS: " + rcmd);
  34.  
  35.  
  36.         IgnoreHostKeyVerification hostKey = new IgnoreHostKeyVerification();
  37.         SshClient ssh = new SshClient();
  38.         ssh.connect(server, 22, hostKey);
  39.         //Authenticate
  40.         PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
  41.         passwordAuthenticationClient.setUsername(userName);
  42.         passwordAuthenticationClient.setPassword(password);
  43.         int result = ssh.authenticate(passwordAuthenticationClient);
  44.         if(result != AuthenticationProtocolState.COMPLETE){
  45.                 System.out.println("Login to " + server + ":" + " " + userName + "/" + password + " failed");
  46.         }
  47.  
  48.         SessionChannelClient sshChannel = new SessionChannelClient();
  49.         sshChannel = ssh.openSessionChannel();
  50.         sshChannel.executeCommand(rcmd.toString());
  51.         BufferedReader reader = new BufferedReader(new InputStreamReader(sshChannel.getInputStream()));
  52.         System.out.println("READER IS: " + reader.readLine());
  53.  
  54.         String currentLine;
  55.  
  56.         Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
  57.         System.out.println("PRIOTIRY IS: " + Thread.currentThread().getPriority());
  58.         while((currentLine = reader.readLine()) != null)
  59.         {
  60.             System.out.println("YOU ARE IN LISTEN");
  61.         }
  62.  
  63.         sshChannel.close();
  64.         ssh.disconnect();
  65.  
  66.     }//listen
  67.  
  68.  

Thanks very much for your help!!!
Feb 14 '11 #1
3 3355
Dheeraj Joshi
1,123 Expert 1GB
Why can't you implements lock on the files?
Check this link.
Check this link too.

Regards
Dheeraj Joshi
Feb 15 '11 #2
ndedhia1
112 100+
When and how do i use the filelock? By the time i get to the line
Expand|Select|Wrap|Line Numbers
  1. System.out.println("READER IS: " + reader.readLine());
  2.  
the value is null, which means that my while loop will never be true.

thanks again for the help!!
Feb 15 '11 #3
ndedhia1
112 100+
Hi Dheeraj,
Thanks for your help. I was using the wrong cattail command and once i fixed that, i got it to work.

thanks
Feb 16 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Sharon | last post by:
I have successfully loaded a DataSet object with a XML schema (XSD). Now I wish to populate the tables that was created in the DataSet. I have an XML file/string that contain all the needed data...
5
by: Phil Kelly | last post by:
Hi I need to write the contents of a structure to a binary file - there is one string and 2 integers, but I can't seem to figure out how to write the data correctly. If I am simply writing...
2
by: pat | last post by:
Given: Dim r As String = WS.getInfo("arg1", "arg2", "arg3") Dim dsTest As New DataSet Dim srTest As New System.IO.StringReader(r) dsTest.ReadXml(srTest) This is how I currently populate a...
5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
0
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
5
by: John | last post by:
Hi I have a typical front end/back end access app. Additionally a vb.net app accesses the backend mdb file every few minutes and runs insert and update queries on some table. The data to be...
2
by: mattcushing | last post by:
I have three dropdowns, one is populated, the other two I'm just putting in values myself (facility, year, month). I have a gridview running a stored procedure that is waiting for values from the...
12
by: webinfinite | last post by:
I am starting a new thread for this topic since previous problem has been solved. I have code like this: #include <stdio.h> int main(){
10
by: Paul E Collins | last post by:
I want to fill an ImageList with bitmaps for a ListView from another thread, because it's a time-consuming process. I expect the ListViewItems' images to "load" one by one, as in a Web browser. ...
0
by: naivewisdom | last post by:
For a lengthy program which would be in no way helpful to discribe, I need to populate a three dementional array from a file and overwrite the file with the modefied arraylist later. The three...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.