Refresh remote folder

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 571 Views - Last Post: 13 February 2012 - 12:19 PM Rate Topic: -----

Topic Sponsor:

#1 gyron  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-January 07

Refresh remote folder

Posted 07 February 2012 - 05:40 AM

I have an electronic document signature device that is connected to a windows machine while my point-of-sale system runs on Linux. The ESD device signs documents that i save into a folder that is on the windows machine. This signed document is converted into PDF format and is saved into another location. Both these locations i have them mounted on Linux using smbmount.
Now, the challenge i have is that i want my program to detect a new document being added, then work on it (i use iText for this). For listening, I tried to use JNotify for this but found out that when this document is added remotely, the event is not triggered for my code to work on it. How do i make my system detect and/or refresh this mounted location?

Is This A Good Question/Topic? 0
  • +

Replies To: Refresh remote folder

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1413
  • View blog
  • Posts: 6,037
  • Joined: 20-September 08

Re: Refresh remote folder

Posted 07 February 2012 - 06:19 AM

I'm a little confused

Quote

the event is not triggered for my code to work on it.


On which box is your code running - the Windows or Linux?
Was This Post Helpful? 0
  • +
  • -

#3 gyron  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-January 07

Re: Refresh remote folder

Posted 07 February 2012 - 11:52 PM

The listening code runs on a linux box and it listens to events that 'take place' on a windows machine. The windows location being listened to is mounted on linux using smbmount

sudo smbmount //[windows box IP]/Spool /mnt/ESD/ -o username=gyron



This results in me having a location /mnt/ESD/Fiscal_invoices into which the windows machine saves documents. I'm listening to this location like this:

int mask = JNotify.FILE_CREATED  | 
                   JNotify.FILE_DELETED  | 
                   JNotify.FILE_MODIFIED | 
                   JNotify.FILE_RENAMED;
try {
			int watchID = JNotify.addWatch(signed_invoices_location, mask, false, this);
			System.out.println("monitoring started: " + watchID);
		} catch (JNotifyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}



now, the variable 'signed_invoices_location'=/mnt/ESD/Fiscal_invoices and my class implements JNotifyListener. When the windows machine adds a file (signed .pdf document), my code does not detect this event! How do i resolve this?
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1413
  • View blog
  • Posts: 6,037
  • Joined: 20-September 08

Re: Refresh remote folder

Posted 08 February 2012 - 03:06 AM

I can give you only a general hint in this case as i haven't used JNotify. There are basically two ways to listen for file system events

a. polling the target filesystem
b. receiving and processing kernel events

Since JNotify ships with native libraries, it looks like its default mode could be b. This is normally the superior methodology as it is less resource intensive and more direct. In your case though, since you're not watching a native filesystem, b. might not work.

So you need to try to 'turn down' the functionality to use methodology a. I'd be surprised if JNotify doesn't support polling but sadly i was unable to find any javadoc for this software.
Was This Post Helpful? 0
  • +
  • -

#5 gyron  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-January 07

Re: Refresh remote folder

Posted 08 February 2012 - 06:35 AM

I have thought of an 'easier' workaround: Put the listening piece of code on the windows box. It's not exactly as clean as i prefer my systems to be (would rather have one 'big' system as opposed to having disparate pieces of code to maintain). In windows, is there the linux equivalent of addressing a specific printer from the command line? Currently, this is how i do it in linux:

 
Runtime rn =Runtime.getRuntime();
            try {
                    Process proc=rn.exec("lp -d "+ WideInvoicePrinter + " /home/pos/wide_invoice");
                    Process proc1=rn.exec("rm -Rf /home/pos/wide_invoice");
            } catch (IOException e) {
                    e.printStackTrace();
            }



so in this case, i am using the linux lp command to print to the printer called WideInvoicePrinter. Is there an equivalent windows command that i can use to achieve the above?

OR how can i change the following code to point to a specific printer and not just the one marked as default?

FileInputStream textStream;
            try {
                    textStream = new FileInputStream("/home/pos/wide_invoice");

                    PrintService defService = PrintServiceLookup.lookupDefaultPrintService();
                    
                    DocFlavor myFormat = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
                    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                    aset.add(MediaSizeName.ISO_A4);

                    DocPrintJob job = defService.createPrintJob();
                    Doc myDoc = new SimpleDoc(textStream, myFormat, null);
                    try {
                            job.print(myDoc, aset);
                    } catch (PrintException pe) {
                            pe.printStackTrace();
                    }
            

            } catch (FileNotFoundException e) {
                    e.printStackTrace();
            } 


This post has been edited by g00se: 08 February 2012 - 07:01 AM
Reason for edit:: Corrected code tags

Was This Post Helpful? 0
  • +
  • -

#6 gyron  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-January 07

Re: Refresh remote folder

Posted 08 February 2012 - 07:01 AM

I have thought of an 'easier' workaround: Put the listening piece of code on the windows box. It's not exactly as clean as i prefer my systems to be (would rather have one 'big' system as opposed to having disparate pieces of code to maintain). In windows, is there the linux equivalent of addressing a specific printer from the command line? Currently, this is how i do it in linux:

	Runtime rn =Runtime.getRuntime();
	            try {
	                    Process proc=rn.exec("lp -d "+ WideInvoicePrinter + " /home/pos/wide_invoice");
	                    Process proc1=rn.exec("rm -Rf /home/pos/wide_invoice");
	            } catch (IOException e) {
	                    e.printStackTrace();
	            }



so in this case, i am using the linux lp command to print to the printer called WideInvoicePrinter. Is there an equivalent windows command that i can use to achieve the above?

OR how can i change the following code to point to a specific printer and not just the one marked as default?

FileInputStream textStream;
try {
textStream = new FileInputStream("/home/pos/wide_invoice");

PrintService defService = PrintServiceLookup.lookupDefaultPrintService();

DocFlavor myFormat = DocFlavor.INPUT_STREAM.TEXT_PLAIN_UTF_8;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);

DocPrintJob job = defService.createPrintJob();
Doc myDoc = new SimpleDoc(textStream, myFormat, null);
try {
job.print(myDoc, aset);
} catch (PrintException pe) {
pe.printStackTrace();
}


} catch (FileNotFoundException e) {
e.printStackTrace();
}


Was This Post Helpful? 0
  • +
  • -

#7 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1413
  • View blog
  • Posts: 6,037
  • Joined: 20-September 08

Re: Refresh remote folder

Posted 08 February 2012 - 08:06 AM

Try something like

aset.add(new PrinterName("HP LaserJet 6MP PS", null));

Was This Post Helpful? 1
  • +
  • -

#8 gyron  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-January 07

Re: Refresh remote folder

Posted 08 February 2012 - 11:34 PM

Thank you so much g00se, you have been so helpful
Was This Post Helpful? 0
  • +
  • -

#9 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1413
  • View blog
  • Posts: 6,037
  • Joined: 20-September 08

Re: Refresh remote folder

Posted 09 February 2012 - 03:14 AM

No problem. What POS software are you using btw?
Was This Post Helpful? 0
  • +
  • -

#10 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 719
  • View blog
  • Posts: 1,692
  • Joined: 05-May 05

Re: Refresh remote folder

Posted 09 February 2012 - 03:39 AM

Quote

Now, the challenge i have is that i want my program to detect a new document being added, then work on it


If your using Java 7, try WatchService. I may just try this out myself!

source

Quote

I have thought of an 'easier' workaround: Put the listening piece of code on the windows box.


I would've took that route initially if it was available, unless uptime is a factor (perhaps your communicating with several remote systems). Also, what's wrong with polling the mount for modification times?

This post has been edited by blackcompe: 09 February 2012 - 03:40 AM

Was This Post Helpful? 0
  • +
  • -

#11 gyron  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-January 07

Re: Refresh remote folder

Posted 09 February 2012 - 08:13 AM

I'm using a POS that they forked out of the Mercator project. Now the Zimbabwe revenues guys have come up with this idea of installing ESD machines on all POS systems and i have devices from MAT Technologies. My POS runs on Linux (Debian) boxes and these guys dont have any linux software for their devices. So i have had to have a windows box where the device is connected and my tills sending invoices there.

I have downloaded java 7 and am playing around with WatchDir class right now :-)
Was This Post Helpful? 0
  • +
  • -

#12 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 719
  • View blog
  • Posts: 1,692
  • Joined: 05-May 05

Re: Refresh remote folder

Posted 09 February 2012 - 08:24 AM

Quote

My POS runs on Linux (Debian) boxes and these guys dont have any linux software for their devices. So i have had to have a windows box where the device is connected and my tills sending invoices there.


Ah.

Quote

I have downloaded java 7 and am playing around with WatchDir class right now :-)


Good luck with that.
Was This Post Helpful? 0
  • +
  • -

#13 gyron  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-January 07

Re: Refresh remote folder

Posted 10 February 2012 - 02:31 AM

View Postblackcompe, on 09 February 2012 - 08:24 AM, said:

Quote

My POS runs on Linux (Debian) boxes and these guys dont have any linux software for their devices. So i have had to have a windows box where the device is connected and my tills sending invoices there.


Ah.





Quote

I have downloaded java 7 and am playing around with WatchDir class right now :-)


Good luck with that.


These guys' ESD devices take a .txt document, scan through it and record the total invoice value and the total tax, then they convert the document to .pdf document that has a signature appended to it. The software uses a Microsoft Access database (unbelievable) to save the settings (i.e. tax rates, invoice tags etc). At one time i was tempted to design my own driver for the devices. I bought a whole lot of them worth US$36 000 (a tidy amount, this is Africa, remember?). Does anyone know where i can get ESD devices that run on Linux?


I'm experimenting with this class and it seems to do exactly what JNotify does, with the same limitations of not 'seeing' events that originate from a remote location. My intention is to eventually get rid of the Windows box i have in my setup (am a Linux fan big time). I observed that when a new document is added by the windows machine, that event is not detected by the Linux box on which the location is mounted using samba. Any workaround besides putting the code on the windows box?

This post has been edited by gyron: 10 February 2012 - 02:33 AM

Was This Post Helpful? 0
  • +
  • -

#14 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1413
  • View blog
  • Posts: 6,037
  • Joined: 20-September 08

Re: Refresh remote folder

Posted 10 February 2012 - 03:03 AM

Quote

I observed that when a new document is added by the windows machine, that event is not detected by the Linux box on which the location is mounted using samba.


You must use the polling methodology on the Linux box to do that successfully. Is that what's happening?

What make and model number are the ESD devices?
Was This Post Helpful? 0
  • +
  • -

#15 gyron  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-January 07

Re: Refresh remote folder

Posted 10 February 2012 - 05:03 AM

The ESDs were made by Microelec electronics and the product name is ESD No 2 SUE. The product code is ESDNo2G/DZW/SUE

The manufactures must be these guys here: http://www.mat.com.g...and-definitions

This post has been edited by gyron: 10 February 2012 - 05:10 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2