mxsm commented on PR #4131:
URL: https://github.com/apache/eventmesh/pull/4131#issuecomment-1608844515

   > What is the intent and purpose of this pr? @mxsm
   
   I have the following two interfaces in the same module
   ```
   @EventMeshSPI(eventMeshExtensionType = 
EventMeshExtensionType.JDBC_DATABASE_DIALECT)
   public interface DatabaseDialectFactory {
   
       /**
        * Creates a database dialect based on the provided source configuration.
        *
        * @param config the source configuration to create a database dialect 
for
        * @return the created database dialect
        */
       DatabaseDialect createDatabaseDialect(SourceConfig config);
   
   }
   
   @EventMeshSPI(eventMeshExtensionType = 
EventMeshExtensionType.JDBC_CDC_ENGINE)
   public interface CdcEngineFactory {
   
       /**
        * Determines whether the provided JDBC URL is compatible with the CDC 
engine
        *
        * @param url jdbc url, e.g. mysql: jdbc:mysql://localhost:3306/
        * @return
        */
       boolean acceptJdbcProtocol(String url);
   
       /**
        * Creates a new CDC engine
        *
        * @return cdc engine
        */
       CdcEngine createCdcEngine(SourceConfig config, DatabaseDialect 
databaseDialect);
   
   }
   ```
   
![image](https://github.com/apache/eventmesh/assets/15797831/29ace0eb-9a2f-4657-a807-ad96a52cf456)
   ```
   
mysql=org.apache.eventmesh.source.connector.jdbc.dialect.cdc.mysql.MysqlCdcEngineFactory
   
   ```
   ```
   
mysql=org.apache.eventmesh.source.connector.jdbc.dialect.mysql.MysqlDatabaseDialectFactory
   ```
   When I use utility class loading
   ```
   @UtilityClass
   public class JdbcAllFactoryLoader {
   
       /**
        * Returns a CdcEngineFactory for the given database name.
        * <p>Throws NullPointerException if databaseName is null.</p>
        * <p>Throws IllegalArgumentException if CdcEngineFactory is not 
supported for the given database name.</p>
        *
        * @param databaseName Name of the database for which CdcEngineFactory 
is required.
        * @return CdcEngineFactory for the given database name.
        */
       public static CdcEngineFactory getCdcEngineFactory(String databaseName) {
           checkNotNull(databaseName, "database name can not be null");
           CdcEngineFactory engineFactory = 
EventMeshExtensionFactory.getExtension(CdcEngineFactory.class, databaseName);
           return checkNotNull(engineFactory, "CdcEngineFactory: " + 
databaseName + " is not supported");
       }
   
       /**
        * Returns a DatabaseDialectFactory based on the specified database name.
        *
        * @param databaseName the name of the database
        * @return the DatabaseDialectFactory for the specified database name
        * @throws NullPointerException     if the database name is null
        * @throws IllegalArgumentException if the specified database name is 
not supported
        */
       public static DatabaseDialectFactory getDatabaseDialectFactory(String 
databaseName) {
           Objects.requireNonNull(databaseName, "database name can not be 
null");
           DatabaseDialectFactory databaseDialectFactory = 
EventMeshExtensionFactory.getExtension(DatabaseDialectFactory.class, 
databaseName);
           Objects.requireNonNull(databaseDialectFactory, 
"DatabaseDialectFactory: " + databaseName + " is not supported");
           return databaseDialectFactory;
       }
   }
   ```
   Because the key in the file is mysql. Will throw
   ```
   2023-06-17 21:53:26,101 INFO  [main] 
MetaInfExtensionClassLoader(MetaInfExtensionClassLoader.java:86) - load 
extension class success, extensionType: interface 
org.apache.eventmesh.source.connector.jdbc.dialect.DatabaseDialectFactory, 
extensionClass: class 
org.apache.eventmesh.source.connector.jdbc.dialect.mysql.MysqlDatabaseDialectFactory
   2023-06-17 21:53:26,106 INFO  [main] 
EventMeshExtensionFactory(EventMeshExtensionFactory.java:92) - initialize 
extension instance success, extensionType: interface 
org.apache.eventmesh.source.connector.jdbc.dialect.DatabaseDialectFactory, 
extensionInstanceName: mysql
   2023-06-17 21:53:26,616 INFO  [main] 
MysqlDatabaseDialect(MysqlDatabaseDialect.java:87) - Mysql Connection 
initialize Success,JDBC driver metadata:JdbcDriverMetaData(JdbcMajorVersion=4, 
jdbcMinorVersion=2, jdbcDriverName=MySQL Connector/J, 
databaseProductName=MySQL, databaseProductVersion=8.0.33)
   Exception in thread "main" java.lang.ClassCastException: 
org.apache.eventmesh.source.connector.jdbc.dialect.mysql.MysqlDatabaseDialectFactory
 cannot be cast to 
org.apache.eventmesh.source.connector.jdbc.dialect.cdc.CdcEngineFactory
        at 
org.apache.eventmesh.source.connector.jdbc.JdbcAllFactoryLoader.getCdcEngineFactory(JdbcAllFactoryLoader.java:46)
        at 
org.apache.eventmesh.source.connector.jdbc.connector.JdbcSourceConnector.init(JdbcSourceConnector.java:91)
        at 
org.apache.eventmesh.openconnect.SourceWorker.<init>(SourceWorker.java:59)
        at org.apache.eventmesh.openconnect.Application.run(Application.java:55)
        at 
org.apache.eventmesh.source.connector.jdbc.JdbcSourceWorker.main(JdbcSourceWorker.java:26)
   ```
   
![image](https://github.com/apache/eventmesh/assets/15797831/eeff15d0-e33b-4de0-b780-7177bd83727c)
   The first time you get the DatabaseDialectFactory instance. When the second 
call JdbcAllFactoryLoader getDatabaseDialectFactory method, because the 
databaseName will again get to cache CdcEngineFactory instance.
   
   **So this problem is solved by this PR**
   
   
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to