You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by "mxsm (via GitHub)" <gi...@apache.org> on 2023/06/17 16:05:03 UTC
[PR] [ISSUE #4129]Enhance the functionality of EventMeshExtensionFactory (eventmesh)
mxsm opened a new pull request, #4131:
URL: https://github.com/apache/eventmesh/pull/4131
<!--
### Contribution Checklist
- Name the pull request in the form "[ISSUE #XXXX] Title of the pull request",
where *XXXX* should be replaced by the actual issue number.
Skip *[ISSUE #XXXX]* if there is no associated github issue for this pull request.
- Fill out the template below to describe the changes contributed by the pull request.
That will give reviewers the context they need to do the review.
- Each pull request should address only one issue.
Please do not mix up code from multiple issues.
- Each commit in the pull request should have a meaningful commit message.
- Once all items of the checklist are addressed, remove the above text and this checklist,
leaving only the filled out template below.
(The sections below can be removed for hotfixes of typos)
-->
<!--
(If this PR fixes a GitHub issue, please add `Fixes #<XXX>` or `Closes #<XXX>`.)
-->
Fixes #4129
### Motivation
*Explain the content here.*
*Explain why you want to make the changes and what problem you're trying to solve.*
### Modifications
- *Enhance the functionality of EventMeshExtensionFactory*
### Documentation
- Does this pull request introduce a new feature? (yes / no)
- If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
- If a feature is not applicable for documentation, explain why?
- If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
--
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: dev-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org
Re: [PR] [ISSUE #4129]Enhance the functionality of EventMeshExtensionFactory (eventmesh)
Posted by "mxsm (via GitHub)" <gi...@apache.org>.
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);
}
```

```
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)
```

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: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org
Re: [PR] [ISSUE #4129]Enhance the functionality of EventMeshExtensionFactory (eventmesh)
Posted by "xwm1992 (via GitHub)" <gi...@apache.org>.
xwm1992 commented on PR #4131:
URL: https://github.com/apache/eventmesh/pull/4131#issuecomment-1608699496
What is the intent and purpose of this pr? @mxsm
--
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: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org
Re: [PR] [ISSUE #4129]Enhance the functionality of EventMeshExtensionFactory (eventmesh)
Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm merged PR #4131:
URL: https://github.com/apache/eventmesh/pull/4131
--
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: dev-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org
Re: [PR] [ISSUE #4129]Enhance the functionality of EventMeshExtensionFactory (eventmesh)
Posted by "Pil0tXia (via GitHub)" <gi...@apache.org>.
Pil0tXia commented on code in PR #4131:
URL: https://github.com/apache/eventmesh/pull/4131#discussion_r1308313551
##########
eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshExtensionFactory.java:
##########
@@ -56,52 +57,72 @@ private EventMeshExtensionFactory() {
}
/**
- * @param extensionType extension plugin class type
- * @param extensionName extension instance name
- * @param <T> the type of the plugin
+ * Get an instance of an extension plugin.
+ *
+ * @param extensionClass extension plugin class type
+ * @param extensionName extension instance name
+ * @param <T> the type of the plugin
* @return plugin instance
*/
- public static <T> T getExtension(Class<T> extensionType, String extensionName) {
- if (extensionType == null) {
- throw new ExtensionException("extensionType is null");
+ public static <T> T getExtension(Class<T> extensionClass, String extensionName) {
+ if (extensionClass == null) {
+ throw new ExtensionException("extensionClass is null");
}
if (StringUtils.isEmpty(extensionName)) {
throw new ExtensionException("extensionName is null");
}
- if (!extensionType.isInterface() || !extensionType.isAnnotationPresent(EventMeshSPI.class)) {
- throw new ExtensionException(String.format("extensionType:%s is invalided", extensionType));
+ if (!extensionClass.isInterface() || !extensionClass.isAnnotationPresent(EventMeshSPI.class)) {
+ throw new ExtensionException(String.format("extensionClass:%s is invalided", extensionClass));
}
- EventMeshSPI eventMeshSPIAnnotation = extensionType.getAnnotation(EventMeshSPI.class);
+ EventMeshSPI eventMeshSPIAnnotation = extensionClass.getAnnotation(EventMeshSPI.class);
if (eventMeshSPIAnnotation.isSingleton()) {
- return getSingletonExtension(extensionType, extensionName);
+ return getSingletonExtension(extensionClass, eventMeshSPIAnnotation, extensionName);
}
- return getPrototypeExtension(extensionType, extensionName);
+ return getPrototypeExtension(extensionClass, extensionName);
}
+ /**
+ * Get a singleton instance of an extension plugin.
+ *
+ * @param extensionClass the type of the extension plugin
+ * @param spi the type of the spi
+ * @param extensionInstanceName the name of the extension instance
+ * @param <T> the type of the extension plugin
+ * @return a singleton instance of the extension plugin
+ */
@SuppressWarnings("unchecked")
- private static <T> T getSingletonExtension(Class<T> extensionType, String extensionInstanceName) {
- return (T) EXTENSION_INSTANCE_CACHE.computeIfAbsent(extensionInstanceName, name -> {
- Class<T> extensionInstanceClass = getExtensionInstanceClass(extensionType, extensionInstanceName);
+ private static <T> T getSingletonExtension(Class<T> extensionClass, EventMeshSPI spi, String extensionInstanceName) {
+ return (T) EXTENSION_INSTANCE_CACHE.computeIfAbsent(new Extension(spi, extensionInstanceName), name -> {
Review Comment:
This review is a comment.
--
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: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org
Re: [PR] [ISSUE #4129]Enhance the functionality of EventMeshExtensionFactory (eventmesh)
Posted by "Pil0tXia (via GitHub)" <gi...@apache.org>.
Pil0tXia commented on code in PR #4131:
URL: https://github.com/apache/eventmesh/pull/4131#discussion_r1308310611
##########
eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshExtensionFactory.java:
##########
@@ -56,52 +57,72 @@ private EventMeshExtensionFactory() {
}
/**
- * @param extensionType extension plugin class type
- * @param extensionName extension instance name
- * @param <T> the type of the plugin
+ * Get an instance of an extension plugin.
+ *
+ * @param extensionClass extension plugin class type
+ * @param extensionName extension instance name
+ * @param <T> the type of the plugin
* @return plugin instance
*/
- public static <T> T getExtension(Class<T> extensionType, String extensionName) {
- if (extensionType == null) {
- throw new ExtensionException("extensionType is null");
+ public static <T> T getExtension(Class<T> extensionClass, String extensionName) {
+ if (extensionClass == null) {
+ throw new ExtensionException("extensionClass is null");
}
if (StringUtils.isEmpty(extensionName)) {
throw new ExtensionException("extensionName is null");
}
- if (!extensionType.isInterface() || !extensionType.isAnnotationPresent(EventMeshSPI.class)) {
- throw new ExtensionException(String.format("extensionType:%s is invalided", extensionType));
+ if (!extensionClass.isInterface() || !extensionClass.isAnnotationPresent(EventMeshSPI.class)) {
+ throw new ExtensionException(String.format("extensionClass:%s is invalided", extensionClass));
}
- EventMeshSPI eventMeshSPIAnnotation = extensionType.getAnnotation(EventMeshSPI.class);
+ EventMeshSPI eventMeshSPIAnnotation = extensionClass.getAnnotation(EventMeshSPI.class);
if (eventMeshSPIAnnotation.isSingleton()) {
- return getSingletonExtension(extensionType, extensionName);
+ return getSingletonExtension(extensionClass, eventMeshSPIAnnotation, extensionName);
}
- return getPrototypeExtension(extensionType, extensionName);
+ return getPrototypeExtension(extensionClass, extensionName);
}
+ /**
+ * Get a singleton instance of an extension plugin.
+ *
+ * @param extensionClass the type of the extension plugin
+ * @param spi the type of the spi
+ * @param extensionInstanceName the name of the extension instance
+ * @param <T> the type of the extension plugin
+ * @return a singleton instance of the extension plugin
+ */
@SuppressWarnings("unchecked")
- private static <T> T getSingletonExtension(Class<T> extensionType, String extensionInstanceName) {
- return (T) EXTENSION_INSTANCE_CACHE.computeIfAbsent(extensionInstanceName, name -> {
- Class<T> extensionInstanceClass = getExtensionInstanceClass(extensionType, extensionInstanceName);
+ private static <T> T getSingletonExtension(Class<T> extensionClass, EventMeshSPI spi, String extensionInstanceName) {
+ return (T) EXTENSION_INSTANCE_CACHE.computeIfAbsent(new Extension(spi, extensionInstanceName), name -> {
Review Comment:
@xwm1992 The main purpose of this PR is to change the cache key from String to an `Extension` class specified with its SPI annotation, in order to support **two extensions** loading in **one module**.
--
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: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org
Re: [PR] [ISSUE #4129]Enhance the functionality of EventMeshExtensionFactory (eventmesh)
Posted by "mxsm (via GitHub)" <gi...@apache.org>.
mxsm commented on PR #4131:
URL: https://github.com/apache/eventmesh/pull/4131#issuecomment-1696802481
ping @xwm1992 @pandaapo @Pil0tXia
--
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: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org
Re: [PR] [ISSUE #4129]Enhance the functionality of EventMeshExtensionFactory (eventmesh)
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #4131:
URL: https://github.com/apache/eventmesh/pull/4131#issuecomment-1607837433
## [Codecov](https://app.codecov.io/gh/apache/eventmesh/pull/4131?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#4131](https://app.codecov.io/gh/apache/eventmesh/pull/4131?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (5073553) into [master](https://app.codecov.io/gh/apache/eventmesh/commit/991cbdae829fcc15698654ca2c737575141f5286?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (991cbda) will **increase** coverage by `0.02%`.
> The diff coverage is `62.50%`.
> :exclamation: Current head 5073553 differs from pull request most recent head c7190ac. Consider uploading reports for the commit c7190ac to get more accurate results
```diff
@@ Coverage Diff @@
## master #4131 +/- ##
============================================
+ Coverage 16.93% 16.95% +0.02%
- Complexity 1410 1411 +1
============================================
Files 588 588
Lines 25739 25751 +12
Branches 2387 2390 +3
============================================
+ Hits 4358 4366 +8
- Misses 20946 20948 +2
- Partials 435 437 +2
```
| [Impacted Files](https://app.codecov.io/gh/apache/eventmesh/pull/4131?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [...pache/eventmesh/spi/EventMeshExtensionFactory.java](https://app.codecov.io/gh/apache/eventmesh/pull/4131?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZXZlbnRtZXNoLXNwaS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZXZlbnRtZXNoL3NwaS9FdmVudE1lc2hFeHRlbnNpb25GYWN0b3J5LmphdmE=) | `56.66% <62.50%> (-1.67%)` | :arrow_down: |
... and [1 file with indirect coverage changes](https://app.codecov.io/gh/apache/eventmesh/pull/4131/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
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: issues-unsubscribe@eventmesh.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: issues-help@eventmesh.apache.org