forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from cvictory/merge-3.x
refactor online and offline
- Loading branch information
Showing
5 changed files
with
129 additions
and
64 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
dubbo-common/src/main/java/org/apache/dubbo/common/ServiceDescriptor.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,94 @@ | ||
package org.apache.dubbo.common; | ||
|
||
import org.apache.dubbo.common.utils.StringUtils; | ||
|
||
/** | ||
* 2019-10-10 | ||
*/ | ||
public class ServiceDescriptor { | ||
public static final char COLON_SEPERATOR = ':'; | ||
|
||
protected String serviceKey; | ||
protected String serviceInterfaceName; | ||
protected String version; | ||
protected volatile String group; | ||
|
||
public static String buildServiceKey(String path, String group, String version) { | ||
StringBuilder buf = new StringBuilder(); | ||
if (group != null && group.length() > 0) { | ||
buf.append(group).append("/"); | ||
} | ||
buf.append(path); | ||
if (version != null && version.length() > 0) { | ||
buf.append(":").append(version); | ||
} | ||
return buf.toString(); | ||
} | ||
|
||
/** | ||
* Format : interface:version:group | ||
* | ||
* @return | ||
*/ | ||
public String getDisplayServiceKey() { | ||
StringBuilder serviceNameBuilder = new StringBuilder(); | ||
serviceNameBuilder.append(serviceInterfaceName); | ||
serviceNameBuilder.append(COLON_SEPERATOR).append(version); | ||
serviceNameBuilder.append(COLON_SEPERATOR).append(group); | ||
return serviceNameBuilder.toString(); | ||
} | ||
|
||
public static ServiceDescriptor revertDisplayServiceKey(String displayKey) { | ||
String[] eles = StringUtils.split(displayKey, COLON_SEPERATOR); | ||
if (eles == null || eles.length < 1 || eles.length > 3) { | ||
return new ServiceDescriptor(); | ||
} | ||
ServiceDescriptor serviceDescriptor = new ServiceDescriptor(); | ||
serviceDescriptor.setServiceInterfaceName(eles[0]); | ||
if (eles.length > 1) { | ||
serviceDescriptor.setVersion(eles[1]); | ||
} | ||
if (eles.length == 3) { | ||
serviceDescriptor.setGroup(eles[2]); | ||
} | ||
|
||
return serviceDescriptor; | ||
} | ||
|
||
public String getServiceKey() { | ||
return serviceKey; | ||
} | ||
|
||
public void generateServiceKey() { | ||
this.serviceKey = buildServiceKey(serviceInterfaceName, group, version); | ||
} | ||
|
||
public void setServiceKey(String serviceKey) { | ||
this.serviceKey = serviceKey; | ||
} | ||
|
||
public String getServiceInterfaceName() { | ||
return serviceInterfaceName; | ||
} | ||
|
||
public void setServiceInterfaceName(String serviceInterfaceName) { | ||
this.serviceInterfaceName = serviceInterfaceName; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(String version) { | ||
this.version = version; | ||
} | ||
|
||
public String getGroup() { | ||
return group; | ||
} | ||
|
||
public void setGroup(String group) { | ||
this.group = group; | ||
} | ||
|
||
} |
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