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
- public void run()
- {
- try
- {
- System.out.println("YOU ARE IN DESKTOPSHMTRANSLATOR RUN()");
- this.listen();
- }
- catch(Exception e)
- {
- System.out.println("RUN EXCEPTION");
- }
- }
- public void listen() throws Exception
- {
- System.out.println("YOU ARE IN DESKTOPSHMTRANSLATOR LISTEN()");
- String remoteCommand = "cattail";
- String remoteDir = "/infra/sbt-support/supportTools/hsqldb/ics/tmp/";
- String remoteFile = "alarmNotification.log.orig";
- String server = "server";
- String userName = "username";
- String password = "password";
- StringBuffer rcmd = new StringBuffer();
- rcmd.append(remoteCommand);
- rcmd.append(" ");
- rcmd.append(remoteDir);
- rcmd.append(remoteFile);
- System.out.println("RCMD IS: " + rcmd);
- IgnoreHostKeyVerification hostKey = new IgnoreHostKeyVerification();
- SshClient ssh = new SshClient();
- ssh.connect(server, 22, hostKey);
- //Authenticate
- PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
- passwordAuthenticationClient.setUsername(userName);
- passwordAuthenticationClient.setPassword(password);
- int result = ssh.authenticate(passwordAuthenticationClient);
- if(result != AuthenticationProtocolState.COMPLETE){
- System.out.println("Login to " + server + ":" + " " + userName + "/" + password + " failed");
- }
- SessionChannelClient sshChannel = new SessionChannelClient();
- sshChannel = ssh.openSessionChannel();
- sshChannel.executeCommand(rcmd.toString());
- BufferedReader reader = new BufferedReader(new InputStreamReader(sshChannel.getInputStream()));
- System.out.println("READER IS: " + reader.readLine());
- String currentLine;
- Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
- System.out.println("PRIOTIRY IS: " + Thread.currentThread().getPriority());
- while((currentLine = reader.readLine()) != null)
- {
- System.out.println("YOU ARE IN LISTEN");
- }
- sshChannel.close();
- ssh.disconnect();
- }//listen
Thanks very much for your help!!!