use of org.jboss.msc.value.InjectedValue in project wildfly by wildfly.
the class RemotingProfileAdd method installServices.
protected void installServices(final OperationContext context, final PathAddress address, final ModelNode profileNode) throws OperationFailedException {
try {
final ModelNode staticEjbDiscoery = StaticEJBDiscoveryDefinition.INSTANCE.resolveModelAttribute(context, profileNode);
List<StaticEJBDiscoveryDefinition.StaticEjbDiscovery> discoveryList = StaticEJBDiscoveryDefinition.createStaticEjbList(context, staticEjbDiscoery);
final List<ServiceURL> urls = new ArrayList<>();
for (StaticEJBDiscoveryDefinition.StaticEjbDiscovery resource : discoveryList) {
ServiceURL.Builder builder = new ServiceURL.Builder();
builder.setAbstractType("ejb").setAbstractTypeAuthority("jboss").setUri(new URI(resource.getUrl()));
String distinctName = resource.getDistinct() == null ? "" : resource.getDistinct();
String appName = resource.getApp() == null ? "" : resource.getApp();
String moduleName = resource.getModule();
if (distinctName.isEmpty()) {
if (appName.isEmpty()) {
builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(moduleName));
} else {
builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(appName + "/" + moduleName));
}
} else {
if (appName.isEmpty()) {
builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(moduleName + "/" + distinctName));
} else {
builder.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(appName + "/" + moduleName + "/" + distinctName));
}
}
urls.add(builder.create());
}
final Map<String, RemotingProfileService.RemotingConnectionSpec> map = new HashMap<>();
final List<RemotingProfileService.HttpConnectionSpec> httpConnectionSpecs = new ArrayList<>();
final RemotingProfileService profileService = new RemotingProfileService(urls, map, httpConnectionSpecs);
// populating the map after the fact is cheating, but it works thanks to the MSC start service "fence"
final CapabilityServiceBuilder capabilityServiceBuilder = context.getCapabilityServiceTarget().addCapability(RemotingProfileResourceDefinition.REMOTING_PROFILE_CAPABILITY, profileService);
if (profileNode.hasDefined(EJB3SubsystemModel.REMOTING_EJB_RECEIVER)) {
for (final Property receiverProperty : profileNode.get(EJB3SubsystemModel.REMOTING_EJB_RECEIVER).asPropertyList()) {
final ModelNode receiverNode = receiverProperty.getValue();
final String connectionRef = RemotingEjbReceiverDefinition.OUTBOUND_CONNECTION_REF.resolveModelAttribute(context, receiverNode).asString();
final long timeout = RemotingEjbReceiverDefinition.CONNECT_TIMEOUT.resolveModelAttribute(context, receiverNode).asLong();
final InjectedValue<OutboundConnection> connectionInjector = new InjectedValue<>();
capabilityServiceBuilder.addCapabilityRequirement(OUTBOUND_CONNECTION_CAPABILITY_NAME, OutboundConnection.class, connectionInjector, connectionRef);
final ModelNode channelCreationOptionsNode = receiverNode.get(EJB3SubsystemModel.CHANNEL_CREATION_OPTIONS);
OptionMap channelCreationOptions = createChannelOptionMap(context, channelCreationOptionsNode);
map.put(connectionRef, new RemotingProfileService.RemotingConnectionSpec(connectionRef, connectionInjector, channelCreationOptions, timeout));
}
}
final boolean isLocalReceiverExcluded = RemotingProfileResourceDefinition.EXCLUDE_LOCAL_RECEIVER.resolveModelAttribute(context, profileNode).asBoolean();
if (profileNode.hasDefined(EJB3SubsystemModel.REMOTE_HTTP_CONNECTION)) {
for (final Property receiverProperty : profileNode.get(EJB3SubsystemModel.REMOTE_HTTP_CONNECTION).asPropertyList()) {
final ModelNode receiverNode = receiverProperty.getValue();
final String uri = RemoteHttpConnectionDefinition.URI.resolveModelAttribute(context, receiverNode).asString();
httpConnectionSpecs.add(new RemotingProfileService.HttpConnectionSpec(uri));
}
}
// if the local receiver is enabled for this context, then add a dependency on the appropriate LocalEjbReceive service
if (!isLocalReceiverExcluded) {
final ModelNode passByValueNode = RemotingProfileResourceDefinition.LOCAL_RECEIVER_PASS_BY_VALUE.resolveModelAttribute(context, profileNode);
if (passByValueNode.isDefined()) {
final ServiceName localTransportProviderServiceName = passByValueNode.asBoolean() == true ? LocalTransportProvider.BY_VALUE_SERVICE_NAME : LocalTransportProvider.BY_REFERENCE_SERVICE_NAME;
capabilityServiceBuilder.addDependency(localTransportProviderServiceName, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
} else {
// setup a dependency on the default local Jakarta Enterprise Beans receiver service configured at the subsystem level
capabilityServiceBuilder.addDependency(LocalTransportProvider.DEFAULT_LOCAL_TRANSPORT_PROVIDER_SERVICE_NAME, EJBTransportProvider.class, profileService.getLocalTransportProviderInjector());
}
}
capabilityServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE).install();
} catch (IllegalArgumentException | URISyntaxException e) {
throw new OperationFailedException(e.getLocalizedMessage());
}
}
Aggregations