I am writing a library in Java. A object in the library is referenced by the main application.
The application requires a method to be called at a certain point on one of its objects. The library object wants to invoke this method in the application, with parameters.
I do not want to pass the application object to the library object as a reference because I want it loosely coupled and the Application object is specific to that application. If I pass it just as a Object data type, it will not have the method attached as not that type without casting.
As they are separate jars, static will not work either and want it loosely coupled again.
Example
Application A is running and has class watched. In its own jar.
public class WatchedInApplication extends BaseRichBolt {
// has a reference to the lib class
private WatcherInLibrary lib;
...
public void invoke (string.. args) {
// invoke this method from another jar reference as a API.
// to replay some data.
outputCollector.emit(args)
}
}
The library B is referenced by Application A and it wants to invoke a method in a object in Application A at a certain point. This library B is also another jar, that is running and monitoring Application A.
public class WatcherInLibrary {
public void invokeApplicationsinvokeMethod() {
// invoke the applications method invoke, but with no specific reference to it
// basically want to invoke the output collector.emit to replay tuples.
}
}
Points
I could simply pass the outputcollector or the BaseRichBolt to the library class B. But I want to keep it loosely coupled. Also both applications are referencing Storm which may cause future issues, even if no issues it is tied closely to Storm if I start passing outputcollector or BaseRichBolt around.
- Does a clever design pattern exist? Simply user interface see below