Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 26th, 2012, 04:37 AM
saziz94 saziz94 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 1 saziz94 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 53 sec
Reputation Power: 0
Homework - Pipe-and-Filter Architecture for txt file.

Hi everyone,

I hope you are all fine and live happy and safely. This is the first time to post here in the forum, and 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;
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;
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Homework - Pipe-and-Filter Architecture for txt file.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap