forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix review issue and refactor metadata
- Loading branch information
Showing
17 changed files
with
136 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
.../src/main/java/org/apache/dubbo/metadata/store/RemoteWritableMetadataServiceDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.apache.dubbo.metadata.store; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.metadata.WritableMetadataService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.SortedSet; | ||
import java.util.function.BiFunction; | ||
|
||
/** | ||
* 2019-08-14 | ||
* | ||
* @since 2.7.5 | ||
*/ | ||
public class RemoteWritableMetadataServiceDelegate implements WritableMetadataService { | ||
List<WritableMetadataService> metadataServiceList = new ArrayList<>(2); | ||
|
||
public RemoteWritableMetadataServiceDelegate() { | ||
metadataServiceList.add(WritableMetadataService.getDefaultExtension()); | ||
metadataServiceList.add(new RemoteWritableMetadataService()); | ||
} | ||
|
||
private WritableMetadataService getInMemoryWritableMetadataService() { | ||
for (WritableMetadataService writableMetadataService : metadataServiceList) { | ||
if (writableMetadataService instanceof InMemoryWritableMetadataService) { | ||
return writableMetadataService; | ||
} | ||
} | ||
return metadataServiceList.get(0); | ||
} | ||
|
||
@Override | ||
public boolean exportURL(URL url) { | ||
return doFunction(WritableMetadataService::exportURL, url); | ||
} | ||
|
||
@Override | ||
public boolean unexportURL(URL url) { | ||
return doFunction(WritableMetadataService::unexportURL, url); | ||
} | ||
|
||
@Override | ||
public boolean subscribeURL(URL url) { | ||
return doFunction(WritableMetadataService::subscribeURL, url); | ||
} | ||
|
||
@Override | ||
public boolean unsubscribeURL(URL url) { | ||
return doFunction(WritableMetadataService::unsubscribeURL, url); | ||
} | ||
|
||
@Override | ||
public boolean refreshMetadata(String exportedRevision, String subscribedRevision) { | ||
boolean result = true; | ||
for (WritableMetadataService writableMetadataService : metadataServiceList) { | ||
result &= writableMetadataService.refreshMetadata(exportedRevision, subscribedRevision); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public void publishServiceDefinition(URL providerUrl) { | ||
for (WritableMetadataService writableMetadataService : metadataServiceList) { | ||
writableMetadataService.publishServiceDefinition(providerUrl); | ||
} | ||
} | ||
|
||
@Override | ||
public SortedSet<String> getExportedURLs(String serviceInterface, String group, String version, String protocol) { | ||
return getInMemoryWritableMetadataService().getExportedURLs(serviceInterface, group, version, protocol); | ||
} | ||
@Override | ||
public SortedSet<String> getSubscribedURLs() { | ||
return getInMemoryWritableMetadataService().getSubscribedURLs(); | ||
} | ||
|
||
@Override | ||
public String getServiceDefinition(String interfaceName, String version, String group) { | ||
return getInMemoryWritableMetadataService().getServiceDefinition(interfaceName, version, group); | ||
} | ||
|
||
@Override | ||
public String getServiceDefinition(String serviceKey) { | ||
return getInMemoryWritableMetadataService().getServiceDefinition(serviceKey); | ||
} | ||
|
||
private boolean doFunction(BiFunction<WritableMetadataService, URL, Boolean> func, URL url) { | ||
boolean result = true; | ||
for (WritableMetadataService writableMetadataService : metadataServiceList) { | ||
result &= func.apply(writableMetadataService, url); | ||
} | ||
return result; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.WritableMetadataService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
default=org.apache.dubbo.metadata.store.InMemoryWritableMetadataService | ||
remote=org.apache.dubbo.metadata.store.RemoteWritableMetadataService | ||
remote=org.apache.dubbo.metadata.store.RemoteWritableMetadataServiceDelegate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters