public class FilterServiceFactory extends java.lang.Object implements ServiceFactory
sets up a filter service as returned by any ServiceFactory
as an element of a distributed pipe. A
filter denotes a method thats reads from an
InputStream
and writes to an
OutputStream
. A ServiceFactory
creates such a
filter and is normally used by TcpServer
to create a new
filter instance for every connection it receives. This class is a
filter service which fetches input from another server further
upstream. Details can be found in the description of createService()
.
A typical use involves the following steps:
Service
, i.e. it has a
run()
method that reads data from an
InputStream
, possibly manipulates it, and then sends
it to an OutputStream
. Lets call this class
Blorg
. Normally it will have a constructor like
Blorg(InputStream, OutputStream)
FilterServiceFactory
:
FilterServiceFactory fsf = new FilterServiceFactory(new ServiceFactory() { public Service createService(InputStream in, OutputStream out) { return new Blorg(in, out); } });
TcpServer
:int port = 3344; new TcpServer(port, fsf).setLogging(System.err).serve();
Constructor and Description |
---|
FilterServiceFactory(ServiceFactory clientFactory)
create a filter service factory to connect services created by
clientFactory to an upstream server. |
Modifier and Type | Method and Description |
---|---|
Service |
createService(java.io.InputStream controlIn,
java.io.OutputStream filterOut,
java.lang.Object param)
contacts an upstream server and connects a service to the
resulting input and the given output.
|
public FilterServiceFactory(ServiceFactory clientFactory)
create a filter service factory to connect services created by
clientFactory
to an upstream server.
public Service createService(java.io.InputStream controlIn, java.io.OutputStream filterOut, java.lang.Object param) throws ServiceCreateException
contacts an upstream server and connects a service to the resulting input and the given output. The following steps are performed.
controlIn
. The request must
originate from a PipelineRequest
, i.e. it was typically
send with a DistPipeFilter
.filterOut
Any key
value pairs read from controlIn
orgininating from a
PipelineRequest
object will be passed as a Map
to the client service factory.The resulting service is returned.
createService
in interface ServiceFactory
param
- is ignored because parameters for the client
service factory are read from controlIn
.ServiceCreateException
- as thrown by the client service factoryServiceUnavailException
- as thrown by the client service factory