8 Replies - 1609 Views - Last Post: 01 July 2011 - 03:43 PM Rate Topic: -----

#1 rahuldagr81  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-July 11

Directory watcher false event throw

Posted 01 July 2011 - 10:18 AM

Hi,

I am having a problem with directory watcher, environment is :

Windows 2003

Coldfusion 8.0.1



Current scenario :

My directory watcher is watching a shared folder (A) on network, and copies files from that folder to a different share folder ( B ) on network (Both shared folder are in different boxes)



Problem :

Sometime my onAdd fires at odd times and it starts copying all the files available on A folder to B. And when I check logs, that time no files were added in A folder.

Problem is onAdd event fires any time and I dont know why its happening.

Please Help.



Some more info:

I am not moving files from A to B, just copying, so old files remains in same folder, there are around 3000-4000 files as of now in A folder, and every day 10-12 files gets copy in A.

This post has been edited by rahuldagr81: 01 July 2011 - 10:19 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Directory watcher false event throw

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: Directory watcher false event throw

Posted 01 July 2011 - 10:31 AM

Hi rahuldagr81 and welcome to DIC!

What would you like us to do to help? You've posted nothing we can look at except a generic description of a problem you're having. No code means no specific suggestions for a fix. What have you tried to fix this? Presumably you wrote the code that's firing...what have you tried to troubleshoot your problem.

Have you looked elsewhere on the web? I did and came up with this link about the common pitfalls associated with DW code.

Anyway, if you did write this malfunctioning piece of code, feel free to post it here so we might actually be able to render specific suggestions.

Good luck!
Was This Post Helpful? 0
  • +
  • -

#3 rahuldagr81  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-July 11

Re: Directory watcher false event throw

Posted 01 July 2011 - 10:46 AM

This is code and problem I explained above.
Please help me.


	<cffunction name="onAdd" output="no">
		<cfargument name="CFEvent" type="struct" required="yes">
		<cfset data = CFEvent.data>
		<cfset holdInfo = GetFileinfo("#data.filename#")>
		<cflog application="No" file="vortex" text="ACTION: #data.type#; FILE: #data.filename#; PATH: #holdInfo.Parent# ">

		<cfset copy_path = 'Server1\folder1'>


		<cfinvoke component="FileProcess" method="Copy" returnvariable="Variables.Result">
			<cfinvokeargument name="SrceDirNme" value="#holdInfo.Parent#">
			<cfinvokeargument name="SrceFleNme" value="#holdInfo.Name#">
			<cfinvokeargument name="TrgtDirNme" value="#copy_path#">
			<cfinvokeargument name="TrgtFleNme" value="#holdInfo.Name#">
		</cfinvoke>
		
		<cfreturn>
	</cffunction>






View PostCraig328, on 01 July 2011 - 10:31 AM, said:

Hi rahuldagr81 and welcome to DIC!

What would you like us to do to help? You've posted nothing we can look at except a generic description of a problem you're having. No code means no specific suggestions for a fix. What have you tried to fix this? Presumably you wrote the code that's firing...what have you tried to troubleshoot your problem.

Have you looked elsewhere on the web? I did and came up with this link about the common pitfalls associated with DW code.

Anyway, if you did write this malfunctioning piece of code, feel free to post it here so we might actually be able to render specific suggestions.

Good luck!

Was This Post Helpful? 0
  • +
  • -

#4 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: Directory watcher false event throw

Posted 01 July 2011 - 10:54 AM

I don't think that the problem is the code at all, but the fact that you are trying to monitor a network based directory. My first question to you is how are you connecting to the shared directory? If you are not using a mapped network drive then that could be your problem right there. When you monitor a directory at something like //servername/scans for example you may run into issues where the server isn't maintaining a constant connection to the shared network drive and therefore it is screwing ColdFusion up.

The alternative method is to map a network drive. If you aren't sure if you are using a mapped network drive then look at the path you are watching. If it is a drive based path, z:/scans, then you have a mapped drive. If you don't have it setup that way and don't have the powers to do so or don't know how then give you sysadmin a call and ask if he can set that up for you.

If you do have a mapped network drive then I would suggest testing this on another CF server and testing the same code and directory watcher configuration on a local directory located on the server.
Was This Post Helpful? 1
  • +
  • -

#5 rahuldagr81  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-July 11

Re: Directory watcher false event throw

Posted 01 July 2011 - 11:00 AM

Hi xheartonfire43x,
Thanks for quick reply, and you may be right as I am NOT using mapped network, I am using full server path.
I will give it a try with mapped network drive.
your suggestion makes sense, but can you please let me know why using //servername/scans may be a problem.

Thanks



View Postxheartonfire43x, on 01 July 2011 - 10:54 AM, said:

I don't think that the problem is the code at all, but the fact that you are trying to monitor a network based directory. My first question to you is how are you connecting to the shared directory? If you are not using a mapped network drive then that could be your problem right there. When you monitor a directory at something like //servername/scans for example you may run into issues where the server isn't maintaining a constant connection to the shared network drive and therefore it is screwing ColdFusion up.

The alternative method is to map a network drive. If you aren't sure if you are using a mapped network drive then look at the path you are watching. If it is a drive based path, z:/scans, then you have a mapped drive. If you don't have it setup that way and don't have the powers to do so or don't know how then give you sysadmin a call and ask if he can set that up for you.

If you do have a mapped network drive then I would suggest testing this on another CF server and testing the same code and directory watcher configuration on a local directory located on the server.

Was This Post Helpful? 0
  • +
  • -

#6 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: Directory watcher false event throw

Posted 01 July 2011 - 12:00 PM

As far as what I think about the server path I have a strong theory about it.

I will refer to the CF Server as ServerA and the server that you share is on as ServerB.

When you connect to a server through //serverb/directory you are essentially doing the same as a <cfinvoke /> command. It is designed to do the following:

  • Connect to the server
  • Open the directory
  • Perform necessary actions
  • Close the connection


It is not designed for a maintained connection to the server. So eventually the connection to the server times out when ServerA goes into an idle process. A little bit of time passes and suddenly ServerB has a new file on it so ColdFusion connects to the share, which in turn takes ServerA out of the idle process. Since this is a new connection CF is now like "Whoa, all these files are new! Okay well imma go do some copyin' now."

When you setup a mapped share you are doing something similar to the createObject() function which is designed to maintain an open connection. This process follows this method:

  • Connect to the server
  • Open the directory
  • Perform necessary actions
  • Store the connection in memory so that I can keep using it


I am slightly more sure of the first part of this explanation than this part.

Reminder this is only a theory, so don't go to your sysadmin and say "Well xheartonfire43x said that this is what happens so do it this way!" In my past experience with sysadmins that is a sure way to NOT get stuff done.
Was This Post Helpful? 1
  • +
  • -

#7 rahuldagr81  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-July 11

Re: Directory watcher false event throw

Posted 01 July 2011 - 12:30 PM

Hi xheartonfire43x
Thanks for nice and useful explanation.
I just have 1 more question

Quote

Since this is a new connection CF is now like "Whoa, all these files are new! Okay well imma go do some copyin' now."


In my case, this doesn't happen every time, sometime it happens sometime its not. once in month it happens so.






View Postxheartonfire43x, on 01 July 2011 - 12:00 PM, said:

As far as what I think about the server path I have a strong theory about it.

I will refer to the CF Server as ServerA and the server that you share is on as ServerB.

When you connect to a server through //serverb/directory you are essentially doing the same as a <cfinvoke /> command. It is designed to do the following:

  • Connect to the server
  • Open the directory
  • Perform necessary actions
  • Close the connection


It is not designed for a maintained connection to the server. So eventually the connection to the server times out when ServerA goes into an idle process. A little bit of time passes and suddenly ServerB has a new file on it so ColdFusion connects to the share, which in turn takes ServerA out of the idle process. Since this is a new connection CF is now like "Whoa, all these files are new! Okay well imma go do some copyin' now."

When you setup a mapped share you are doing something similar to the createObject() function which is designed to maintain an open connection. This process follows this method:

  • Connect to the server
  • Open the directory
  • Perform necessary actions
  • Store the connection in memory so that I can keep using it


I am slightly more sure of the first part of this explanation than this part.

Reminder this is only a theory, so don't go to your sysadmin and say "Well xheartonfire43x said that this is what happens so do it this way!" In my past experience with sysadmins that is a sure way to NOT get stuff done.

Was This Post Helpful? 0
  • +
  • -

#8 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: Directory watcher false event throw

Posted 01 July 2011 - 12:45 PM

I'm not really sure why that is. I am going to assume that it is the way the directory watcher works.

What I am betting happens is that ColdFusion isn't actually running a "watcher" but a scheduled task that runs once a minute or so that checks the directory. It scans through the directory and checks all of the timestamps against a stored list of timestamps. If there is a change in the stamp then it says "Hey, here's a new file" and passes it onto your code. I can't remember for sure, but I think I remember windows always having weird things happen when Java tries to read file's time stamps.

In looking at Railo's source code I can verify that the directory watcher there checks the file's last modified date. I can't say for sure, but I assume that Adobe ColdFusion runs similarly. I highly doubt that it would be running some sort of in file delta to check changes within an actual file.

If I am correct that Java (reminder that ColdFusion is just a servlet that compiles down to Java) has issues with Windows time stamps, then that is why you would be having inconsistent problems.
Was This Post Helpful? 1
  • +
  • -

#9 rahuldagr81  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-July 11

Re: Directory watcher false event throw

Posted 01 July 2011 - 03:43 PM

Yes makes sense.
Thanks xheartonfire43x, for your quick and useful response.
Thanks alot.




View Postxheartonfire43x, on 01 July 2011 - 12:45 PM, said:

I'm not really sure why that is. I am going to assume that it is the way the directory watcher works.

What I am betting happens is that ColdFusion isn't actually running a "watcher" but a scheduled task that runs once a minute or so that checks the directory. It scans through the directory and checks all of the timestamps against a stored list of timestamps. If there is a change in the stamp then it says "Hey, here's a new file" and passes it onto your code. I can't remember for sure, but I think I remember windows always having weird things happen when Java tries to read file's time stamps.

In looking at Railo's source code I can verify that the directory watcher there checks the file's last modified date. I can't say for sure, but I assume that Adobe ColdFusion runs similarly. I highly doubt that it would be running some sort of in file delta to check changes within an actual file.

If I am correct that Java (reminder that ColdFusion is just a servlet that compiles down to Java) has issues with Windows time stamps, then that is why you would be having inconsistent problems.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1