Results 1 to 2 of 2
- 09-26-2012, 12:25 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 9
- Rep Power
- 0
Pipe-and-Filter Architecture for txt file.
Hi everyone,
I hope you are all fine and live happy and safely. I have been long time to post here in the forum, sorry for that. I feel that there is a nice and variety developers community here. I really appreciate and willing to share with you some of my experience and knowledge. By the way, my English is second language, so if you misunderstand me please let me know.
Currently, I am working in designing and implementing a Filter-and-Pipe architecture for Word document. I stuck with implementing the pipe class. My classes looks like;
Filter class
Pipe class
Class A extends Filter implements Runnable
Class B extends Filter implements Runnable
Class C extends Filter implements Runnable
Class D extends Filter implements Runnable
Class A: read a txt file line by line and SEND it to Class B.
Class B: read the line coming from A, processing it and SEND it to Class C.
Class C: read the line coming from B, processing it and SEND it to Class D.
Class D: read the line coming from C, processing it and print it out.
each of these classes should run in its own thread. Each Filter should wait if there is no data ready. once it ready, should the sender notify the receiver.
I have implement the classes and stuck with the pipe. I don't know how to send the processed line to the next Filter.
Here are what I have done;
Java Code:public class Filter { Pipe _dataINPipe; Pipe _dataOUTPipe; public String getData(){ return _dataINPipe.dataOUT(); } public void sendData( String tempData){ _dataOUTPipe.dataIN(tempData); } } class Pipe{ Queue<String> _inData = new LinkedList<String>(); public void dataIN (String in){ _inData.add(in); } public String dataOUT (){ return _inData.poll(); } }
Java Code:Pipe p1 = new Pipe(); Pipe p2 = new Pipe(); Pipe p3 = new Pipe(); Pipe p4 = new Pipe(); //// A a1 = new A(null,p1) null refer to inPipe, and p1 refer to outPipe A a1 = new A(null,p1); B b1 = new B(p1,p2); C c1 = new C(p2,p3); D d1 = new D(p3,null); Thread th1 = new Thread( a1 ); Thread th2 = new Thread( b1 ); Thread th3 = new Thread( c1 ); Thread th4 = new Thread( d1 ); th1.start() th2.start(); th3.start(); th4.start();
For example, the txt file has 10 line. Class D will stop after line 4 because the Class C takes time to process line 3 and can not pass data to the queue for class D.
I hope you understand the issue. I need your help if you have any idea.
- 09-26-2012, 06:23 PM #2
Re: Pipe-and-Filter Architecture for txt file.
Also posted at Pipe-and-Filter Architecture for txt file. - Dev Shed
If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
Passing arguments to jar file with a pipe
By clover in forum New To JavaReplies: 7Last Post: 06-27-2011, 05:36 PM -
File Extension Filter
By heartysnowy in forum New To JavaReplies: 9Last Post: 10-09-2010, 02:33 PM -
Broken pipe exception while feeding a console's inputstream from a non-finished file
By Andy09 in forum Advanced JavaReplies: 1Last Post: 09-10-2009, 02:58 PM -
Hi please help with a file filter!
By xbox_nutter in forum New To JavaReplies: 4Last Post: 03-23-2009, 01:09 PM -
How to filter files in file upload using html contorl
By deivaganesh in forum Advanced JavaReplies: 0Last Post: 01-29-2008, 07:31 AM
Bookmarks