Pipes & Filters

Component PipeTester{

//Source Src = void GetVal; // won't work as return type is void //Source Src = private int GetVal; // does modifier work ? No. All ports are implicitly public //Source Src = int GetNum(int input); // does source take input ? No. Source port only returns value Source Src = int GetNum;

//Handler Hnd = int SumUp; //does Handler compulsorily need an input ? Yes. //Handler Hnd = void SumUp(int number); //will it work if return type is void ? No.	//Handler Hnd = protected int SumUp(int number); //does modifier work ? No.	Handler Hnd = int SumUp(int number);

//Sink Snk = int PutVal; //won't work since Sink can not return value //Sink Snk = public void PutVal(int finalnum); //does modifier work ? No.	Sink Snk = void PutVal(int finalnum);

} Component definition : PipeTester.indus

import java.util.random;

class PipeTesterClass implements PipeTester{

Context{ setServantType("SESSION"); setNetworkTypes("SocketMulticast"); }

public int GetNum{ int random = new Random.nextInt; return (random); }

public int SumUp(int number){ int finalnum = number + 1000; return finalnum;

}

public void PutVal(int finalnum){ }

} Component implementation : PipeTesterClass.indus

Agent Composer{

} Agent definition : Composer.indus

class PipeComposer implements Composer{

Context{ setServantType("user"); setNetworkTypes("SocketMulticast"); }

public static void main(String[] args){

PipeTesterClass pipeTesterClass = newType PipeTesterClass("test");

// Invoke Source only pipeTesterClass.Src; //won't work - cannot invoke Port as method

// Invoke Handler only pipeTesterClass.Hnd(515); //won't work - cannot invoke Port as method

// Invoke Sink only pipeTesterClass.Snk(100); //won't work - cannot invoke Port as method

// Source -> Source pipeTesterClass.Src -> pipeTesterClass.Src; //Violation of composition rule (Source cannot pipe to Source) // Handler -> Handler pipeTesterClass.Hnd(100) -> pipeTesterClass.Hnd; //won't work - cannot invoke Port as method // Sink -> Sink pipeTesterClass.Snk(1000) -> pipeTesterClass.Snk(1000); //won't work - cannot invoke Port as method + Sink can not pipe to Sink

// Source -> Handler pipeTesterClass.Src -> pipeTesterClass.Hnd; //won't work - handler needs to assign return value to a variable pipeTesterClass.Src -> pipeTesterClass.Hnd; //won't work - cannot invoke Port as method + handler needs to assign return variable pipeTesterClass.Src -> pipeTesterClass.SumUp; //won't work - cannot have a mix of ports and qualified methods pipeTesterClass.GetNum -> pipeTesterClass.SumUp; //won't work - cannot use qualified methods

// Source -> Sink pipeTesterClass.Src -> pipeTesterClass.Snk; //will work

// Handler -> Sink pipeTesterClass.Hnd -> pipeTesterClass.Snk; //won't work - violates composition rule (handler or source needs to pipe to handler) pipeTesterClass.Hnd(1000) -> pipeTesterClass.Snk; //won't work - violates composition rule (handler or source needs to pipe to handler) pipeTesterClass.Hnd(1000) -> pipeTesterClass.Snk; //won't work - violates composition rule + // a port (here, Sink) can not be invoked as a method pipeTesterClass.SumUp(1000) -> pipeTesterClass.PutVal; //won't work - ports can not be invoked as methods

// Source -> Handler -> Sink pipeTesterClass.Src -> pipeTesterClass.Hnd -> pipeTesterClass.Snk; //will work

// Source -> Handler -> Handler -> Sink pipeTesterClass.Src -> pipeTesterClass.Hnd -> pipeTesterClass.Hnd -> pipeTesterClass.Snk; //will work

// Handler -> Source pipeTesterClass.Hnd -> pipeTesterClass.Src; //won't work - violates composition rule // Sink -> Handler pipeTesterClass.Snk -> pipeTesterClass.Hnd; //won't work - violates composition rule

// Sink -> Source pipeTesterClass.Snk -> pipeTesterClass.Src; //won't work - violates composition rule

// result = Source -> Handler int result1 = pipeTesterClass.Src -> pipeTesterClass.Hnd; //will work

// result = Handler -> Handler int result2 = pipeTesterClass.Hnd(1000) -> pipeTesterClass.Hnd; //won't work - Handler needs to be piped data from a Source or Handler

// result = Source int result3 = pipeTesterClass.Src; //will it work ?

// result = Handler int result4 = pipeTesterClass.Hnd(100); //will it work ?

// result = Source -> Sink int result5 = pipeTesterClass.Src -> pipeTesterClass.Snk; //won't work - Sink will not return anything

// result = Handler -> Sink int result6 = pipeTesterClass.Hnd -> pipeTesterClass.Snk; //won't work - Sink will not return anything

}

}

Implementation file : PipeComposer.indus