java - Instantiate classes of an interface at server startup -


i have set of subscribers need start when server starts up. right i'm instantiating them , calling run method on them in application.java.

was thinking wonderful if these instantiated on own, may using custom annotation or belonging interface (get classes of interface , instantiate). way writing new subscriber in future doesn't need create object , call run() on it.

wondering if has solved earlier , whether makes sense it.

example:

i have interface event handlers:

interface eventhandler {   void process(string data); } 

and implementation classes:

public class cooleventhandler implements eventhandler {    public void process(string data) {     //handle cool event   } }  public class hoteventhandler implements eventhandler {    public void process(string data) {     //handle hot event   } } 

and have subscriber service listens remote apis , if there's data, passes handler:

public class pollservice {    public static void register(string api, eventhandler eventhandler) {     //create thread poll api      //and if data received, call eventhandler.process()   } } 

at start of application i'm registering handlers in application.java

pollservice.register("/cool", new cooleventhandler()); pollservice.register("/hot", new hoteventhandler()); 

tomorrow if there's new handler, warmeventhandler, i'll have call register again. i'm trying avoid last step. best way register classes of eventhandler?


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -