Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Norm

Thread: Pipe-and-Filter Architecture for txt file.

  1. #1
    saziz94 is offline Member
    Join Date
    Jul 2009
    Posts
    9
    Rep Power
    0

    Default 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();  
        }  
      
    }
    The main class create all objects;
    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();
    When I run the project, I notice that the Class D run and stop before it gets all data to print it out. This is because of the class D check if the queue is empty. If True, it will stop processing and stop the thread.

    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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Pipe-and-Filter Architecture for txt file.

    DarrylBurke likes this.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Passing arguments to jar file with a pipe
    By clover in forum New To Java
    Replies: 7
    Last Post: 06-27-2011, 04:36 PM
  2. File Extension Filter
    By heartysnowy in forum New To Java
    Replies: 9
    Last Post: 10-09-2010, 01:33 PM
  3. Replies: 1
    Last Post: 09-10-2009, 01:58 PM
  4. Hi please help with a file filter!
    By xbox_nutter in forum New To Java
    Replies: 4
    Last Post: 03-23-2009, 12:09 PM
  5. How to filter files in file upload using html contorl
    By deivaganesh in forum Advanced Java
    Replies: 0
    Last Post: 01-29-2008, 06:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •