use of org.jboss.ejb.server.ModuleAvailabilityListener in project wildfly by wildfly.
the class AssociationImpl method registerModuleAvailabilityListener.
@Override
public ListenerHandle registerModuleAvailabilityListener(@NotNull final ModuleAvailabilityListener moduleAvailabilityListener) {
final DeploymentRepositoryListener listener = new DeploymentRepositoryListener() {
public void listenerAdded(final DeploymentRepository repository) {
List<ModuleAvailabilityListener.ModuleIdentifier> identifierList = new ArrayList<>();
for (DeploymentModuleIdentifier identifier : repository.getModules().keySet()) {
final ModuleAvailabilityListener.ModuleIdentifier moduleIdentifier = toModuleIdentifier(identifier);
identifierList.add(moduleIdentifier);
}
moduleAvailabilityListener.moduleAvailable(identifierList);
}
private ModuleAvailabilityListener.ModuleIdentifier toModuleIdentifier(final DeploymentModuleIdentifier identifier) {
return new ModuleAvailabilityListener.ModuleIdentifier(identifier.getApplicationName(), identifier.getModuleName(), identifier.getDistinctName());
}
public void deploymentAvailable(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
moduleAvailabilityListener.moduleAvailable(Collections.singletonList(toModuleIdentifier(deployment)));
}
public void deploymentStarted(final DeploymentModuleIdentifier deployment, final ModuleDeployment moduleDeployment) {
}
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)));
}
};
deploymentRepository.addListener(listener);
return () -> deploymentRepository.removeListener(listener);
}
use of org.jboss.ejb.server.ModuleAvailabilityListener in project wildfly by wildfly.
the class AssociationService method start.
public void start(final StartContext context) throws StartException {
// todo suspendController
value = new AssociationImpl(deploymentRepositoryInjector.getValue(), registryCollectorInjector.getValue());
// register the fact that the local receiver can handle invocations targeted at its node name
final ServiceURL.Builder builder = new ServiceURL.Builder();
builder.setAbstractType("ejb").setAbstractTypeAuthority("jboss");
builder.setUri(Affinity.LOCAL.getUri());
builder.addAttribute(EJBClientContext.FILTER_ATTR_NODE, AttributeValue.fromString(serverEnvironmentServiceInjector.getValue().getNodeName()));
serviceRegistration = getLocalRegistryProvider().registerService(builder.create());
// track deployments at an association level for local dispatchers to utilize
handle = value.registerModuleAvailabilityListener(new ModuleAvailabilityListener() {
private final ConcurrentHashMap<ModuleIdentifier, ServiceRegistration> map = new ConcurrentHashMap<ModuleIdentifier, ServiceRegistration>();
public void moduleAvailable(final List<ModuleIdentifier> modules) {
for (ModuleIdentifier module : modules) {
final String appName = module.getAppName();
final String moduleName = module.getModuleName();
final String distinctName = module.getDistinctName();
final ServiceURL.Builder builder = new ServiceURL.Builder();
builder.setUri(Affinity.LOCAL.getUri());
builder.setAbstractType("ejb");
builder.setAbstractTypeAuthority("jboss");
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));
}
}
final ServiceRegistration serviceRegistration = localRegistry.registerService(builder.create());
// should never conflict normally!
map.putIfAbsent(module, serviceRegistration);
}
}
public void moduleUnavailable(final List<ModuleIdentifier> modules) {
for (ModuleIdentifier module : modules) {
map.computeIfPresent(module, (i, old) -> {
old.close();
return null;
});
}
}
});
}
Aggregations