use of com.alipay.sofa.runtime.api.component.Property in project sofa-boot by sofastack.
the class ServiceClientImpl method removeService.
@Override
public void removeService(Class<?> interfaceClass, String uniqueId, int millisecondsToDelay) {
if (millisecondsToDelay < 0) {
throw new IllegalArgumentException(ErrorCode.convert("01-00202"));
}
Collection<ComponentInfo> serviceComponents = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ServiceComponent.SERVICE_COMPONENT_TYPE);
for (ComponentInfo componentInfo : serviceComponents) {
if (!(componentInfo instanceof ServiceComponent)) {
continue;
}
ServiceComponent serviceComponent = (ServiceComponent) componentInfo;
if (serviceComponent.getService().getInterfaceType() == interfaceClass && serviceComponent.getService().getUniqueId().equals(uniqueId)) {
Map<String, Property> properties = serviceComponent.getProperties();
Property property = new Property();
property.setValue(millisecondsToDelay);
properties.put(ServiceComponent.UNREGISTER_DELAY_MILLISECONDS, property);
sofaRuntimeContext.getComponentManager().unregister(serviceComponent);
}
}
}
use of com.alipay.sofa.runtime.api.component.Property in project sofa-boot by alipay.
the class ServiceClientImpl method removeService.
@Override
public void removeService(Class<?> interfaceClass, String uniqueId, int millisecondsToDelay) {
if (millisecondsToDelay < 0) {
throw new IllegalArgumentException(ErrorCode.convert("01-00202"));
}
Collection<ComponentInfo> serviceComponents = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ServiceComponent.SERVICE_COMPONENT_TYPE);
for (ComponentInfo componentInfo : serviceComponents) {
if (!(componentInfo instanceof ServiceComponent)) {
continue;
}
ServiceComponent serviceComponent = (ServiceComponent) componentInfo;
if (serviceComponent.getService().getInterfaceType() == interfaceClass && serviceComponent.getService().getUniqueId().equals(uniqueId)) {
Map<String, Property> properties = serviceComponent.getProperties();
Property property = new Property();
property.setValue(millisecondsToDelay);
properties.put(ServiceComponent.UNREGISTER_DELAY_MILLISECONDS, property);
sofaRuntimeContext.getComponentManager().unregister(serviceComponent);
}
}
}
use of com.alipay.sofa.runtime.api.component.Property in project sofa-boot by alipay.
the class ServiceComponent method unregister.
@Override
public void unregister() throws ServiceRuntimeException {
super.unregister();
Property unregisterDelayMillisecondsProperty = properties.get(UNREGISTER_DELAY_MILLISECONDS);
if (unregisterDelayMillisecondsProperty != null) {
int unregisterDelayMilliseconds = unregisterDelayMillisecondsProperty.getInteger();
try {
TimeUnit.MILLISECONDS.sleep(unregisterDelayMilliseconds);
} catch (InterruptedException e) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00010", service), e);
}
}
Object target = service.getTarget();
if (target == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00000"));
}
if (service.hasBinding()) {
boolean allPassed = true;
Set<Binding> bindings = service.getBindings();
for (Binding binding : bindings) {
BindingAdapter<Binding> bindingAdapter = this.bindingAdapterFactory.getBindingAdapter(binding.getBindingType());
if (bindingAdapter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00001", binding.getBindingType(), service));
}
SofaLogger.info(" <<Post un-out Binding [{}] Begins - {}.", binding.getBindingType(), service);
try {
bindingAdapter.postUnoutBinding(service, binding, target, getContext());
} catch (Throwable t) {
allPassed = false;
SofaLogger.error(ErrorCode.convert("01-00008", binding.getBindingType(), service), t);
continue;
}
SofaLogger.info(" <<Post un-out Binding [{}] Ends - {}.", binding.getBindingType(), service);
}
if (!allPassed) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00009", service));
}
}
}
use of com.alipay.sofa.runtime.api.component.Property in project sofa-boot by sofastack.
the class ServiceComponent method unregister.
@Override
public void unregister() throws ServiceRuntimeException {
super.unregister();
Property unregisterDelayMillisecondsProperty = properties.get(UNREGISTER_DELAY_MILLISECONDS);
if (unregisterDelayMillisecondsProperty != null) {
int unregisterDelayMilliseconds = unregisterDelayMillisecondsProperty.getInteger();
try {
TimeUnit.MILLISECONDS.sleep(unregisterDelayMilliseconds);
} catch (InterruptedException e) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00010", service), e);
}
}
Object target = service.getTarget();
if (target == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00000"));
}
if (service.hasBinding()) {
boolean allPassed = true;
Set<Binding> bindings = service.getBindings();
for (Binding binding : bindings) {
BindingAdapter<Binding> bindingAdapter = this.bindingAdapterFactory.getBindingAdapter(binding.getBindingType());
if (bindingAdapter == null) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00001", binding.getBindingType(), service));
}
SofaLogger.info(" <<Post un-out Binding [{}] Begins - {}.", binding.getBindingType(), service);
try {
bindingAdapter.postUnoutBinding(service, binding, target, getContext());
} catch (Throwable t) {
allPassed = false;
SofaLogger.error(ErrorCode.convert("01-00008", binding.getBindingType(), service), t);
continue;
}
SofaLogger.info(" <<Post un-out Binding [{}] Ends - {}.", binding.getBindingType(), service);
}
if (!allPassed) {
throw new ServiceRuntimeException(ErrorCode.convert("01-00009", service));
}
}
}
Aggregations