use of org.jboss.ejb.client.EJBModuleIdentifier in project wildfly by wildfly.
the class AssociationImpl method registerModuleAvailabilityListener.
@Override
public ListenerHandle registerModuleAvailabilityListener(@NotNull final ModuleAvailabilityListener moduleAvailabilityListener) {
final DeploymentRepositoryListener listener = new DeploymentRepositoryListener() {
@Override
public void listenerAdded(final DeploymentRepository repository) {
List<EJBModuleIdentifier> list = new ArrayList<>();
if (!repositoryIsSuspended()) {
// only send out the initial list if the deployment repository (i.e. the server + clean transaction state) is not in a suspended state
for (DeploymentModuleIdentifier deploymentModuleIdentifier : repository.getModules().keySet()) {
EJBModuleIdentifier ejbModuleIdentifier = toModuleIdentifier(deploymentModuleIdentifier);
list.add(ejbModuleIdentifier);
}
EjbLogger.EJB3_INVOCATION_LOGGER.debugf("Sending initial module availability to connecting client: server is not suspended");
} else {
// send out empty list if the deploymentRepository is suspended
EjbLogger.EJB3_INVOCATION_LOGGER.debugf("Sending empty initial module availability to connecting client: server is suspended");
}
moduleAvailabilityListener.moduleAvailable(list);
}
@Override
public void deploymentAvailable(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
}
@Override
public void deploymentStarted(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
// only send out moduleAvailability until module has started (WFLY-13009)
moduleAvailabilityListener.moduleAvailable(Collections.singletonList(toModuleIdentifier(deployment)));
}
@Override
public void deploymentRemoved(final DeploymentModuleIdentifier deployment) {
moduleAvailabilityListener.moduleUnavailable(Collections.singletonList(toModuleIdentifier(deployment)));
}
@Override
public void deploymentSuspended(DeploymentModuleIdentifier deployment) {
moduleAvailabilityListener.moduleUnavailable(Collections.singletonList(toModuleIdentifier(deployment)));
}
@Override
public void deploymentResumed(DeploymentModuleIdentifier deployment) {
moduleAvailabilityListener.moduleAvailable(Collections.singletonList(toModuleIdentifier(deployment)));
}
private boolean repositoryIsSuspended() {
return deploymentRepository.isSuspended();
}
};
deploymentRepository.addListener(listener);
return () -> deploymentRepository.removeListener(listener);
}
use of org.jboss.ejb.client.EJBModuleIdentifier in project wildfly by wildfly.
the class AssociationService method start.
@Override
public void start(final StartContext context) throws StartException {
// todo suspendController
// noinspection unchecked
List<Map.Entry<ProtocolSocketBinding, Registry<String, List<ClientMapping>>>> clientMappingsRegistries = this.clientMappingsRegistries.isEmpty() ? Collections.emptyList() : new ArrayList<>(this.clientMappingsRegistries.size());
for (Map.Entry<Value<ProtocolSocketBinding>, Value<Registry>> entry : this.clientMappingsRegistries) {
clientMappingsRegistries.add(new SimpleImmutableEntry<>(entry.getKey().getValue(), entry.getValue().getValue()));
}
value = new AssociationImpl(deploymentRepositoryInjector.getValue(), clientMappingsRegistries);
String ourNodeName = serverEnvironmentServiceInjector.getValue().getNodeName();
// track deployments at an association level for local dispatchers to utilize
moduleAvailabilityListener = value.registerModuleAvailabilityListener(new ModuleAvailabilityListener() {
public void moduleAvailable(final List<EJBModuleIdentifier> modules) {
synchronized (serviceLock) {
ourModules.addAll(modules);
cachedServiceURL = null;
}
}
public void moduleUnavailable(final List<EJBModuleIdentifier> modules) {
synchronized (serviceLock) {
ourModules.removeAll(modules);
cachedServiceURL = null;
}
}
});
// do this last
mutableDiscoveryProvider.setDiscoveryProvider((serviceType, filterSpec, result) -> {
ServiceURL serviceURL = this.cachedServiceURL;
if (serviceURL == null) {
synchronized (serviceLock) {
serviceURL = this.cachedServiceURL;
if (serviceURL == null) {
ServiceURL.Builder b = new ServiceURL.Builder();
b.setUri(Affinity.LOCAL.getUri()).setAbstractType("ejb").setAbstractTypeAuthority("jboss");
b.addAttribute(EJBClientContext.FILTER_ATTR_NODE, AttributeValue.fromString(ourNodeName));
for (Map.Entry<ProtocolSocketBinding, Registry<String, List<ClientMapping>>> entry : clientMappingsRegistries) {
Group group = entry.getValue().getGroup();
if (!group.isSingleton()) {
b.addAttribute(EJBClientContext.FILTER_ATTR_CLUSTER, AttributeValue.fromString(group.getName()));
}
}
for (EJBModuleIdentifier moduleIdentifier : ourModules) {
final String appName = moduleIdentifier.getAppName();
final String moduleName = moduleIdentifier.getModuleName();
final String distinctName = moduleIdentifier.getDistinctName();
if (distinctName.isEmpty()) {
if (appName.isEmpty()) {
b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(moduleName));
} else {
b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE, AttributeValue.fromString(appName + '/' + moduleName));
}
} else {
if (appName.isEmpty()) {
b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(moduleName + '/' + distinctName));
} else {
b.addAttribute(EJBClientContext.FILTER_ATTR_EJB_MODULE_DISTINCT, AttributeValue.fromString(appName + '/' + moduleName + '/' + distinctName));
}
}
}
serviceURL = this.cachedServiceURL = b.create();
}
}
}
if (serviceURL.satisfies(filterSpec)) {
result.addMatch(serviceURL);
}
result.complete();
return DiscoveryRequest.NULL;
});
}
Aggregations