I have multiple classes in my current project like HTMLRequest
, SPDYRequest
, BHIVERequest
. I get data from a network stream and I want to find out, which of the classes can handle this data. For this I read the header of the Stream packet (All protocols are in the same form, so I can read until I get empty line (\r\n) ) and then pass this header to a static function in the request classes which returns a boolean which tells whether it is a header for this kind of request or not. Now I want to be able to load specific Protocols at runtime (from plug-ins). What is the best way to be able to check whether I have a Protocol for a header or not.
My thoughts were:
An extra class
Protocol
as a singleton, which then is registered in aRequestFactory
, that then has to find out which Protocol can create a request for this kind of header and calls Protocol.assemble()A static List of
Class<? extends Request>
so I can call the static methods through reflection or byClass.newInstance()
I don't like both that ideas, so what is the right way to dynamically do this stuff in Java?