use of org.wildfly.swarm.spi.api.Customizer in project wildfly-swarm by wildfly-swarm.
the class RuntimeServer method start.
public Deployer start(boolean eagerOpen) throws Exception {
UUID uuid = UUIDFactory.getUUID();
System.setProperty("jboss.server.management.uuid", uuid.toString());
File configurationFile;
try {
configurationFile = TempFileManager.INSTANCE.newTempFile("swarm-config-", ".xml");
} catch (IOException e) {
throw new RuntimeException(e);
}
this.networkConfigurer.configure();
List<ModelNode> bootstrapOperations = new ArrayList<>();
BootstrapConfiguration bootstrapConfiguration = () -> bootstrapOperations;
this.container = new SelfContainedContainer(new Bootstrap.ConfigurationPersisterFactory() {
@Override
public ExtensibleConfigurationPersister createConfigurationPersister(ServerEnvironment serverEnvironment, ExecutorService executorService) {
return new BootstrapPersister(bootstrapConfiguration, configurationFile);
}
});
try (AutoCloseable handle = Performance.time("pre-customizers")) {
for (Customizer each : this.preCustomizers) {
SwarmMessages.MESSAGES.callingPreCustomizer(each);
each.customize();
}
}
try (AutoCloseable handle = Performance.time("post-customizers")) {
for (Customizer each : this.postCustomizers) {
SwarmMessages.MESSAGES.callingPostCustomizer(each);
each.customize();
}
}
this.networkConfigurer.configure();
try (AutoCloseable handle = Performance.time("configurable-manager rescan")) {
this.configurableManager.rescan();
this.configurableManager.log();
}
try (AutoCloseable handle = Performance.time("marshall DMR")) {
this.dmrMarshaller.marshal(bootstrapOperations);
}
SwarmMessages.MESSAGES.wildflyBootstrap(bootstrapOperations.toString());
Thread.currentThread().setContextClassLoader(RuntimeServer.class.getClassLoader());
List<ServiceActivator> activators = new ArrayList<>();
StreamSupport.stream(serviceActivators.spliterator(), false).filter(Objects::nonNull).forEach(activators::add);
activators.add(new ContentRepositoryServiceActivator(this.contentRepository));
try (AutoCloseable wildflyStart = Performance.time("WildFly start")) {
ServiceContainer serviceContainer = null;
try (AutoCloseable startWildflyItself = Performance.time("Starting WildFly itself")) {
// serviceContainer = this.container.start(bootstrapOperations, this.contentProvider, activators);
serviceContainer = this.container.start(bootstrapOperations, activators);
this.containerStarted = true;
}
try (AutoCloseable checkFailedServices = Performance.time("Checking for failed services")) {
for (ServiceName serviceName : serviceContainer.getServiceNames()) {
ServiceController<?> serviceController = serviceContainer.getService(serviceName);
/*
if (serviceController.getImmediateUnavailableDependencies().size() > 0) {
System.err.println("Service missing dependencies: " + serviceController.getName());
for (ServiceName name : serviceController.getImmediateUnavailableDependencies()) {
System.err.println(" - " + name);
}
}
*/
StartException exception = serviceController.getStartException();
if (exception != null) {
throw exception;
}
}
}
/*
for (ServiceName serviceName : serviceContainer.getServiceNames()) {
System.err.println(" === " + serviceName);
}
*/
ModelController controller = (ModelController) serviceContainer.getService(Services.JBOSS_SERVER_CONTROLLER).getValue();
Executor executor = Executors.newSingleThreadExecutor();
try (AutoCloseable creatingControllerClient = Performance.time("Creating controller client")) {
// Can't use controller.getClientFactory() due to non-public nature of that method.
// noinspection deprecation
this.client = controller.createClient(executor);
}
RuntimeDeployer deployer = this.deployer.get();
try (AutoCloseable installDeployer = Performance.time("Installing deployer")) {
serviceContainer.addService(ServiceName.of("swarm", "deployer"), new ValueService<>(new ImmediateValue<Deployer>(deployer))).install();
}
try (AutoCloseable configUserSpaceExt = Performance.time("Configure user-space extensions")) {
configureUserSpaceExtensions();
}
try (AutoCloseable deployments = Performance.time("Implicit Deployments")) {
for (Archive each : this.implicitDeployments) {
if (each != null) {
deployer.deploy(each);
}
}
}
this.artifactDeployer.deploy();
deployer.implicitDeploymentsComplete();
return deployer;
}
}
use of org.wildfly.swarm.spi.api.Customizer in project wildfly-swarm by wildfly-swarm.
the class OutboundSocketBindingExtension method afterBeanDiscovery.
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
try (AutoCloseable handle = Performance.time("OutboundSocketBindingExtension.afterBeanDiscovery")) {
for (OutboundSocketBindingRequest each : this.bindings) {
Supplier<Customizer> customizerSupplier = () -> (Customizer) () -> {
Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
groups.stream().map((Bean<?> e) -> {
CreationalContext<?> ctx = beanManager.createCreationalContext(e);
return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
}).filter(group -> group.name().equals(each.socketBindingGroup())).findFirst().ifPresent((group) -> group.outboundSocketBinding(each.outboundSocketBinding()));
};
CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class).beanClass(OutboundSocketBindingExtension.class).scope(Singleton.class).addQualifier(Pre.Literal.INSTANCE).addQualifier(AnyLiteral.INSTANCE).createSupplier(customizerSupplier).addType(Customizer.class).addType(Object.class).build();
abd.addBean(customizerBean);
}
}
}
use of org.wildfly.swarm.spi.api.Customizer in project wildfly-swarm by wildfly-swarm.
the class SocketBindingExtension method afterBeanDiscovery.
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
try (AutoCloseable handle = Performance.time("SocketBindingExtension.afterBeanDiscovery")) {
for (SocketBindingRequest each : this.bindings) {
Supplier<Customizer> supplier = () -> (Customizer) () -> {
Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
groups.stream().map((Bean<?> e) -> {
CreationalContext<?> ctx = beanManager.createCreationalContext(e);
return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx);
}).filter(group -> group.name().equals(each.socketBindingGroup())).findFirst().ifPresent((group) -> group.socketBinding(each.socketBinding()));
};
CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class).beanClass(SocketBindingExtension.class).scope(Singleton.class).addQualifier(Pre.Literal.INSTANCE).addQualifier(AnyLiteral.INSTANCE).createSupplier(supplier).addType(Customizer.class).addType(Object.class).build();
abd.addBean(customizerBean);
}
}
}
Aggregations