28 Replies - 571 Views - Last Post: 13 February 2012 - 12:19 PM
#1
Refresh remote folder
Posted 07 February 2012 - 05:40 AM
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?
Replies To: Refresh remote folder
#2
Re: Refresh remote folder
Posted 07 February 2012 - 06:19 AM
Quote
On which box is your code running - the Windows or Linux?
#3
Re: Refresh remote folder
Posted 07 February 2012 - 11:52 PM
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?
#4
Re: Refresh remote folder
Posted 08 February 2012 - 03:06 AM
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.
#5
Re: Refresh remote folder
Posted 08 February 2012 - 06:35 AM
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
#6
Re: Refresh remote folder
Posted 08 February 2012 - 07:01 AM
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();
}
#7
Re: Refresh remote folder
Posted 08 February 2012 - 08:06 AM
aset.add(new PrinterName("HP LaserJet 6MP PS", null));
#8
Re: Refresh remote folder
Posted 08 February 2012 - 11:34 PM
#9
Re: Refresh remote folder
Posted 09 February 2012 - 03:14 AM
#10
Re: Refresh remote folder
Posted 09 February 2012 - 03:39 AM
Quote
If your using Java 7, try WatchService. I may just try this out myself!
source
Quote
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
#11
Re: Refresh remote folder
Posted 09 February 2012 - 08:13 AM
I have downloaded java 7 and am playing around with WatchDir class right now :-)
#12
Re: Refresh remote folder
Posted 09 February 2012 - 08:24 AM
Quote
Ah.
Quote
Good luck with that.
#13
Re: Refresh remote folder
Posted 10 February 2012 - 02:31 AM
blackcompe, on 09 February 2012 - 08:24 AM, said:
Quote
Ah.
Quote
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
#14
Re: Refresh remote folder
Posted 10 February 2012 - 03:03 AM
Quote
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?
#15
Re: Refresh remote folder
Posted 10 February 2012 - 05:03 AM
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
|
|

New Topic/Question
Reply



MultiQuote




|