use of org.apache.dubbo.rpc.model.ProviderModel in project dubbo by alibaba.
the class ListTelnetHandler method printAllProvidedServices.
private void printAllProvidedServices(StringBuilder buf, boolean detail) {
List<ProviderModel> providerModels = serviceRepository.getExportedServices();
if (!providerModels.isEmpty()) {
buf.append("PROVIDER:\r\n");
}
for (ProviderModel provider : providerModels) {
buf.append(provider.getServiceKey());
if (detail) {
buf.append(" -> ");
buf.append(" published: ");
buf.append(ServiceCheckUtils.isRegistered(provider) ? "Y" : "N");
}
buf.append("\r\n");
}
}
use of org.apache.dubbo.rpc.model.ProviderModel in project dubbo by alibaba.
the class Online method online.
public static boolean online(String servicePattern) {
boolean hasService = false;
Collection<ProviderModel> providerModelList = serviceRepository.getExportedServices();
for (ProviderModel providerModel : providerModelList) {
if (providerModel.getServiceMetadata().getDisplayServiceKey().matches(servicePattern)) {
hasService = true;
List<ProviderModel.RegisterStatedURL> statedUrls = providerModel.getStatedUrl();
for (ProviderModel.RegisterStatedURL statedURL : statedUrls) {
if (!statedURL.isRegistered()) {
Registry registry = registryFactory.getRegistry(statedURL.getRegistryUrl());
registry.register(statedURL.getProviderUrl());
statedURL.setRegistered(true);
}
}
}
}
return hasService;
}
use of org.apache.dubbo.rpc.model.ProviderModel in project dubbo by alibaba.
the class Offline method offline.
public static boolean offline(String servicePattern) {
boolean hasService = false;
Collection<ProviderModel> providerModelList = serviceRepository.getExportedServices();
for (ProviderModel providerModel : providerModelList) {
if (providerModel.getServiceMetadata().getDisplayServiceKey().matches(servicePattern)) {
hasService = true;
List<ProviderModel.RegisterStatedURL> statedUrls = providerModel.getStatedUrl();
for (ProviderModel.RegisterStatedURL statedURL : statedUrls) {
if (statedURL.isRegistered()) {
Registry registry = registryFactory.getRegistry(statedURL.getRegistryUrl());
registry.unregister(statedURL.getProviderUrl());
statedURL.setRegistered(false);
}
}
}
}
return hasService;
}
use of org.apache.dubbo.rpc.model.ProviderModel in project dubbo by alibaba.
the class Ready method isServiceReady.
/**
* judge service provider is started
* @param serviceName service name,eg: org.apache.dubbo.demo.DemoService
* @return Map[serviceKey,isStarted] eg:[org.apache.dubbo.demo.DemoService,true] or [group1/org.apache.dubbo.demo.DemoService,false]
*/
private Map<String, Boolean> isServiceReady(String serviceName) {
Map<String, Boolean> res = new HashMap<>();
for (ProviderModel providerModel : ApplicationModel.allProviderModels()) {
String serviceKey = providerModel.getServiceKey();
String interfaceName = providerModel.getServiceConfig().getInterface();
if (interfaceName.equals(serviceName)) {
List<URL> needRegistryURLs = ConfigValidationUtils.loadRegistries(providerModel.getServiceConfig(), true);
List<URL> registeredRegistryURLs = providerModel.getStatedUrl().stream().filter(x -> Boolean.TRUE.equals(x.isRegistered())).map(ProviderModel.RegisterStatedURL::getRegistryUrl).collect(Collectors.toList());
if (needRegistryURLs.size() == registeredRegistryURLs.size()) {
res.put(serviceKey, true);
} else {
res.put(serviceKey, false);
}
}
}
return res;
}
use of org.apache.dubbo.rpc.model.ProviderModel in project dubbo by alibaba.
the class CodecSupport method checkSerialization.
public static void checkSerialization(String path, String version, Byte id) throws IOException {
ServiceRepository repository = ApplicationModel.getServiceRepository();
ProviderModel providerModel = repository.lookupExportedServiceWithoutGroup(path + ":" + version);
if (providerModel == null) {
throw new IOException("Service " + path + " with version " + version + " not found, invocation rejected.");
} else {
List<URL> urls = providerModel.getServiceConfig().getExportedUrls();
if (CollectionUtils.isNotEmpty(urls)) {
URL url = urls.get(0);
String serializationName = url.getParameter(org.apache.dubbo.remoting.Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION);
Byte localId = SERIALIZATIONNAME_ID_MAP.get(serializationName);
if (localId != null && !localId.equals(id)) {
throw new IOException("Unexpected serialization id:" + id + " received from network, please check if the peer send the right id.");
}
}
}
}
Aggregations