public static Object invokeServiceMethod(final ServiceDescription description, final ServiceTempus serviceTempus, final Service instance, final Object... arguments) throws CouldNotPerformException { try { return detectServiceMethod(description, serviceTempus, instance.getClass(), getArgumentClasses(arguments)).invoke(instance, arguments); } catch (IllegalAccessException | ExceptionInInitializerError ex) { throw new NotSupportedException("ServiceType[" + description.getType().name() + "] with Pattern[" + description.getPattern() + "]", instance, ex); } catch (NullPointerException ex) { throw new CouldNotPerformException("Invocation failed because given instance is not available!", ex); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof CouldNotPerformException) { throw (CouldNotPerformException) ex.getTargetException(); } else { throw new CouldNotPerformException("Invocation failed!", ex.getTargetException()); } } }
private boolean serviceDescriptionListContainsDescription(List<ServiceDescription> serviceDescriptionList, ServiceDescription serviceDescription) { return serviceDescriptionList.stream().anyMatch((description) -> (description.getType() == serviceDescription.getType() && description.getPattern() == serviceDescription.getPattern())); }
private boolean unitConfigContainsServiceDescription(UnitConfig.Builder unitConfig, ServiceDescription serviceDescription) { return unitConfig.getServiceConfigList().stream().map((serviceConfig) -> serviceConfig.getServiceDescription()).anyMatch((description) -> (description.getType() == serviceDescription.getType() && description.getPattern() == serviceDescription.getPattern())); }
serviceDescriptionsOnLocation.put(serviceDescription.getType(), serviceDescription); } else { if (serviceDescriptionsOnLocation.get(serviceDescription.getType()).getPattern() == ServiceTemplate.ServicePattern.PROVIDER && serviceDescription.getPattern() == ServiceTemplate.ServicePattern.OPERATION) { serviceDescriptionsOnLocation.put(serviceDescription.getType(), serviceDescription); if (serviceConfig.getServiceDescription().getPattern() == ServicePattern.CONSUMER) { continue; if (serviceConfig.getServiceDescription().getPattern() == ServicePattern.PROVIDER) { if (unitHasServiceAsOperationService(unitConfig, serviceConfig.getServiceDescription().getType())) { continue;
if (serviceConfig.getServiceDescription().getPattern().equals(ServicePattern.CONSUMER)) { continue;
for (ServiceDescription serviceDescription : getUnitTemplate().getServiceDescriptionList()) { serviceInterfaceMap.put(StringProcessor.transformUpperCaseToCamelCase(serviceDescription.getType().name()) + StringProcessor.transformUpperCaseToCamelCase(serviceDescription.getPattern().name()), serviceDescription); for (Entry<String, ServiceDescription> serviceInterfaceMapEntry : serviceInterfaceMap.entrySet()) { try { if (null != serviceInterfaceMapEntry.getValue().getPattern()) // Identify package switch (serviceInterfaceMapEntry.getValue().getPattern()) { case CONSUMER: servicePackage = ConsumerService.class.getPackage(); String servicePatternName = StringProcessor.transformUpperCaseToCamelCase(serviceInterfaceMapEntry.getValue().getPattern().name()); String serviceClassName = servicePackage.getName() + "." + serviceDataTypeName + servicePatternName + "Service"; try {
if (serviceDescription.getPattern() == ServicePattern.PROVIDER && serviceTempus == ServiceTempus.REQUESTED) { continue;
if (serviceDescription.getPattern() != ServiceTemplate.ServicePattern.OPERATION) { continue;
final Set<ServiceType> serviceTypeSet = new HashSet<>(); for (final ServiceDescription serviceDescription : getUnitTemplate().getServiceDescriptionList()) { if (serviceDescription.getPattern() == ServicePattern.PROVIDER && serviceTempus == ServiceTempus.REQUESTED) { continue;
private void setServiceConfig(final ServiceConfig serviceConfig) throws CouldNotPerformException { try { try { switch (serviceConfig.getServiceDescription().getPattern()) { case OPERATION: if (operationServiceConfig != null) { break; default: throw new EnumNotSupportedException(serviceConfig.getServiceDescription().getPattern(), this);
private static boolean hasPowerStateService(UnitConfig config) throws InterruptedException { for (ServiceConfig sc : config.getServiceConfigList()) { ServiceTemplate.ServiceType type; try { type = getUnitRegistry().getServiceTemplateById(sc.getServiceDescription().getServiceTemplateId()).getType(); } catch (CouldNotPerformException ex) { type = sc.getServiceDescription().getType(); } if (ServiceTemplate.ServiceType.POWER_STATE_SERVICE == type && ServiceTemplate.ServicePattern.OPERATION == sc.getServiceDescription().getPattern()) { return true; } } return false; }
public static Method detectServiceMethod(final ServiceDescription description, final ServiceTempus serviceTempus, final Class instanceClass, final Class... argumentClasses) throws CouldNotPerformException { return detectServiceMethod(description.getType(), description.getPattern(), serviceTempus, instanceClass, argumentClasses); }
private boolean unitHasServiceAsOperationService(UnitConfig unitConfig, ServiceType serviceType) { return unitConfig.getServiceConfigList().stream().anyMatch((tmpServiceConfig) -> (tmpServiceConfig.getServiceDescription().getType() == serviceType && tmpServiceConfig.getServiceDescription().getPattern() == ServiceTemplate.ServicePattern.OPERATION)); } }
default long getLatestTransactionId() throws CouldNotPerformException { long latestTransactionId = -1; for (ServiceDescription serviceDescription : getUnitTemplate().getServiceDescriptionList()) { if (serviceDescription.getPattern() != ServicePattern.OPERATION) { continue; } latestTransactionId = Math.max(latestTransactionId, getTransactionIdByServiceType(serviceDescription.getType())); } if (latestTransactionId == -1) { throw new NotAvailableException("transaction id"); } return latestTransactionId; }
private boolean hasOperationServiceForType(ServiceType serviceType) throws NotAvailableException { for (ServiceDescription serviceDescription : getUnitTemplate().getServiceDescriptionList()) { if (serviceDescription.getType() == serviceType && serviceDescription.getPattern() == OPERATION) { return true; } } return false; }
private void setRequestedState() throws CouldNotPerformException { try (ClosableDataBuilder dataBuilder = unit.getDataBuilder(this)) { // set the responsible action for the service attribute Message.Builder serviceStateBuilder = serviceAttribute.toBuilder(); Descriptors.FieldDescriptor fieldDescriptor = ProtoBufFieldProcessor.getFieldDescriptor(serviceStateBuilder, Service.RESPONSIBLE_ACTION_FIELD_NAME); serviceStateBuilder.setField(fieldDescriptor, actionDescriptionBuilder.build()); // set the updated service attribute as requested state in the unit data builder Services.invokeServiceMethod(serviceDescription.getType(), serviceDescription.getPattern(), ServiceTempus.REQUESTED, dataBuilder.getInternalBuilder(), serviceStateBuilder); } }