shink opened a new issue #1875:
URL: https://github.com/apache/incubator-inlong/issues/1875


   ### Description
   
   We can abstract an interface so that we can use the same interface with 
different monitor implementations.
   
   For example.
   
   ```java
   public abstract class AbstractSourceStatManager {
   
       // metric
       protected CounterMetric successCount;
   
       public void incrSuccessCount() {
           successCount.incr();
       }
   }
   ```
   
   After `SourceJMXStatManager` and `SourcePrometheusStatManager` implement it, 
we can use the same interface with different implementations in 
`DatabaseSource`.
   
   ```java
   public class DatabaseSource {
   
       private final AbstractSourceStatManager statManager;
   
       public MySource() {
           statManager = new SourceJMXStatManager();
       }
   
       public MySource(AbstractSourceStatManager statManager) {
           this.statManager = statManager;
       }
   
       public void split() {
           // do something
           // increment metric
           statManager.incrSuccessCount();
       }
   }
   ```
   
   ```java
   // prometheus.enable=false
   DatabaseSource source = new DatabaseSource();
   // prometheus.enable=true
   DatabaseSource source = new DatabaseSource(new 
SourcePrometheusStatManager(...));
   
   source.split();
   ```
   
   
   ### InLong Component
   
   Other for not specified component
   
   ### Are you willing to submit PR?
   
   - [X] Yes, I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to