Commit a0f0ceca authored by yazan.halloul's avatar yazan.halloul

build encapsulation system class "TextProcessingSystem" and Main class

parent 54a96b52
import TextProcessing.TextProcessingSystem;
public class Main {
public static void main(String[] args) {
TextProcessingSystem textProcessingSystem = new TextProcessingSystem(3);
textProcessingSystem.decryption(
"C:\\Users\\dell\\Desktop\\input Encryption Text.txt",
"C:\\Users\\dell\\Desktop\\Decryption Text.txt");
}
}
package TextProcessing;
import main_pipeline.Consumer;
import main_pipeline.Producer;
import main_pipeline.TextProcessorConsumer;
import benefit_classes.LineSequence;
import benefit_classes.LineSequenceComparator;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
public class TextProcessingSystem {
private final int numberOfTextProcessor;
public TextProcessingSystem(int numberOfTextProcessor) {
this.numberOfTextProcessor = numberOfTextProcessor;
}
public void encryption(String inputFilePath, String outputFilePath){
BlockingQueue<LineSequence> inputQueue = new LinkedBlockingQueue<>();
BlockingQueue<LineSequence> outputQueue = new PriorityBlockingQueue<>(50, new LineSequenceComparator());
new Thread(new Producer(inputQueue, inputFilePath)).start();
for(int i = 0;i<numberOfTextProcessor;i++)
new Thread(new TextProcessorConsumer(inputQueue, outputQueue, true)).start();
new Thread(new Consumer(outputQueue, outputFilePath)).start();
}
public void decryption(String inputFilePath, String outputFilePath){
BlockingQueue<LineSequence> inputQueue = new LinkedBlockingQueue<>();
BlockingQueue<LineSequence> outputQueue = new PriorityBlockingQueue<>(50, new LineSequenceComparator());
new Thread(new Producer(inputQueue, inputFilePath)).start();
for(int i = 0;i<numberOfTextProcessor;i++)
new Thread(new TextProcessorConsumer(inputQueue, outputQueue, false)).start();
new Thread(new Consumer(outputQueue, outputFilePath)).start();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment