-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fileCacheDir in FileSystemOptions, defaults to ${jboss.server.temp.dir}/vertx-cache if not specified * hostsRefreshPeriod in AddressResolverOptions
- Loading branch information
Showing
11 changed files
with
169 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,12 @@ | |
*/ | ||
package org.wildfly.extension.vertx; | ||
|
||
import io.vertx.core.VertxOptions; | ||
import io.vertx.core.dns.AddressResolverOptions; | ||
import org.jboss.as.controller.OperationContext; | ||
import org.jboss.as.controller.OperationFailedException; | ||
import org.jboss.as.server.ServerEnvironment; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.msc.Service; | ||
import org.jboss.msc.service.ServiceBuilder; | ||
import org.jboss.msc.service.ServiceController; | ||
|
@@ -14,9 +18,13 @@ | |
import org.jboss.msc.service.StartException; | ||
import org.jboss.msc.service.StopContext; | ||
|
||
import java.nio.file.Path; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import static org.wildfly.extension.vertx.VertxConstants.ATTR_FS_FILE_CACHE_DIR; | ||
import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Lin Gao</a> | ||
*/ | ||
|
@@ -25,39 +33,65 @@ public class NamedVertxOptionsService implements Service { | |
private final NamedVertxOptions namedVertxOptions; | ||
private final Consumer<NamedVertxOptions> consumer; | ||
private final Supplier<AddressResolverOptions> addressResolverOptionsSupplier; | ||
private final Supplier<ServerEnvironment> serverEnvironmentSupplier; | ||
private final boolean defaultFileCacheDir; | ||
|
||
NamedVertxOptionsService(NamedVertxOptions namedVertxOptions, Consumer<NamedVertxOptions> consumer) { | ||
this(namedVertxOptions, null, consumer); | ||
NamedVertxOptionsService(NamedVertxOptions namedVertxOptions, | ||
Consumer<NamedVertxOptions> consumer) { | ||
this(namedVertxOptions, null, null, false, consumer); | ||
} | ||
|
||
NamedVertxOptionsService(NamedVertxOptions namedVertxOptions, | ||
Supplier<AddressResolverOptions> addressResolverOptionsSupplier, | ||
Supplier<ServerEnvironment> serverEnvironmentSupplier, | ||
boolean defaultFileCacheDir, | ||
Consumer<NamedVertxOptions> consumer) { | ||
this.namedVertxOptions = namedVertxOptions; | ||
this.addressResolverOptionsSupplier = addressResolverOptionsSupplier; | ||
this.serverEnvironmentSupplier = serverEnvironmentSupplier; | ||
this.defaultFileCacheDir = defaultFileCacheDir; | ||
this.consumer = consumer; | ||
} | ||
|
||
static void installService(OperationContext context, NamedVertxOptions namedVertxOptions, | ||
String addressResolverOptionName) { | ||
ServiceName vertxServiceName = VertxOptionFileResourceDefinition.VERTX_OPTIONS_CAPABILITY.getCapabilityServiceName(namedVertxOptions.getName()); | ||
/** | ||
* Install NamedVertxOptionsService from '/subsystem=vertx/vertx-option=xx:add()' | ||
* <p> | ||
* When 'file-cache-dir' is not configured, it defaults to '${jboss.server.temp.dir}/vertx-cache' | ||
* </p> | ||
* @param context the OperationContext to add a VertxOptions with a name | ||
* @param operation the operation ModelNode to add a VertxOptions with a name | ||
* @throws OperationFailedException when anything goes wrong | ||
*/ | ||
static void installVertxOptionsService(OperationContext context, ModelNode operation) throws OperationFailedException { | ||
final String name = context.getCurrentAddressValue(); | ||
VertxOptions vertxOptions = VertxOptionsResourceDefinition.parseOptions(operation); | ||
ServiceName vertxServiceName = VertxOptionFileResourceDefinition.VERTX_OPTIONS_CAPABILITY.getCapabilityServiceName(name); | ||
ServiceBuilder<?> vertxServiceBuilder = context.getCapabilityServiceTarget().addService(); | ||
Consumer<NamedVertxOptions> consumer = vertxServiceBuilder.provides(vertxServiceName); | ||
Supplier<AddressResolverOptions> addressResolverOptionsSupplier = null; | ||
if (addressResolverOptionName != null) { | ||
addressResolverOptionsSupplier = vertxServiceBuilder.requires(AddressResolverResourceDefinition.VERTX_OPTIONS_ADDRESS_RESOLVER_CAPABILITY.getCapabilityServiceName(addressResolverOptionName)); | ||
if (operation.hasDefined(ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER)) { | ||
String addressResolverOptionName = VertxOptionsAttributes.ATTR_VERTX_OPTION_ADDRESS_RESOLVER.validateOperation(operation).asString(); | ||
ServiceName addressResolverServiceName = AddressResolverResourceDefinition.VERTX_OPTIONS_ADDRESS_RESOLVER_CAPABILITY.getCapabilityServiceName(addressResolverOptionName); | ||
addressResolverOptionsSupplier = vertxServiceBuilder.requires(addressResolverServiceName); | ||
} | ||
vertxServiceBuilder.setInstance(new NamedVertxOptionsService(namedVertxOptions, addressResolverOptionsSupplier, consumer)); | ||
NamedVertxOptions namedVertxOptions = new NamedVertxOptions(name, vertxOptions); | ||
ServiceName serverEnvServiceName = context.getCapabilityServiceName(ServerEnvironment.SERVICE_DESCRIPTOR); | ||
Supplier<ServerEnvironment> environmentSupplier = vertxServiceBuilder.requires(serverEnvServiceName); | ||
vertxServiceBuilder.setInstance(new NamedVertxOptionsService(namedVertxOptions, addressResolverOptionsSupplier, | ||
environmentSupplier, !operation.hasDefined(ATTR_FS_FILE_CACHE_DIR), vertxServiceBuilder.provides(vertxServiceName))); | ||
vertxServiceBuilder | ||
.setInitialMode(ServiceController.Mode.ACTIVE) | ||
.install(); | ||
.setInitialMode(ServiceController.Mode.ACTIVE) | ||
.install(); | ||
} | ||
|
||
@Override | ||
public void start(StartContext startContext) throws StartException { | ||
if (this.addressResolverOptionsSupplier != null && this.addressResolverOptionsSupplier.get() != null) { | ||
this.namedVertxOptions.getVertxOptions().setAddressResolverOptions(this.addressResolverOptionsSupplier.get()); | ||
} | ||
if (defaultFileCacheDir) { | ||
String defaultCacheDir = serverEnvironmentSupplier.get().getServerTempDir().toPath().resolve(Path.of("vertx-cache")).normalize().toString(); | ||
this.namedVertxOptions.getVertxOptions().getFileSystemOptions().setFileCacheDir(defaultCacheDir); | ||
} | ||
this.consumer.accept(this.namedVertxOptions); | ||
VertxOptionsRegistry.getInstance().addVertxOptions(this.namedVertxOptions); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import static org.wildfly.extension.vertx.VertxConstants.ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT; | ||
import static org.wildfly.extension.vertx.VertxConstants.ATTR_EVENTLOOP_POOL_SIZE; | ||
import static org.wildfly.extension.vertx.VertxConstants.ATTR_FS_CLASS_PATH_RESOLVING_ENABLED; | ||
import static org.wildfly.extension.vertx.VertxConstants.ATTR_FS_FILE_CACHE_DIR; | ||
import static org.wildfly.extension.vertx.VertxConstants.ATTR_FS_FILE_CACHE_ENABLED; | ||
import static org.wildfly.extension.vertx.VertxConstants.ATTR_INTERNAL_BLOCKING_POOL_SIZE; | ||
import static org.wildfly.extension.vertx.VertxConstants.ATTR_MAX_EVENTLOOP_EXECUTE_TIME; | ||
|
@@ -36,7 +37,6 @@ | |
import static org.wildfly.extension.vertx.VertxConstants.ATTR_WARNING_EXECUTION_TIME_UNIT; | ||
import static org.wildfly.extension.vertx.VertxConstants.ATTR_WORKER_POOL_SIZE; | ||
import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTION; | ||
import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Lin Gao</a> | ||
|
@@ -79,66 +79,60 @@ static class VertxOptionAddHandler extends AbstractAddStepHandler { | |
|
||
@Override | ||
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { | ||
final String name = context.getCurrentAddressValue(); | ||
VertxOptions vertxOptions = parseOptions(operation); | ||
NamedVertxOptions namedVertxOptions = new NamedVertxOptions(name, vertxOptions); | ||
|
||
String addressResolverOptionName = null; | ||
if (operation.hasDefined(ELEMENT_VERTX_OPTION_ADDRESS_RESOLVER)) { | ||
addressResolverOptionName = VertxOptionsAttributes.ATTR_VERTX_OPTION_ADDRESS_RESOLVER.validateOperation(operation).asString(); | ||
} | ||
NamedVertxOptionsService.installService(context, namedVertxOptions, addressResolverOptionName); | ||
NamedVertxOptionsService.installVertxOptionsService(context, operation); | ||
} | ||
} | ||
|
||
VertxOptions parseOptions(ModelNode operation) throws OperationFailedException { | ||
VertxOptions vertxOptions = new VertxOptions(); | ||
if (operation.hasDefined(ATTR_EVENTLOOP_POOL_SIZE)) { | ||
vertxOptions.setEventLoopPoolSize(VertxOptionsAttributes.ATTR_EVENTLOOP_POOL_SIZE.validateOperation(operation).asInt()); | ||
} | ||
if (operation.hasDefined(ATTR_WORKER_POOL_SIZE)) { | ||
vertxOptions.setWorkerPoolSize(VertxOptionsAttributes.ATTR_WORKER_POOL_SIZE.validateOperation(operation).asInt()); | ||
} | ||
if (operation.hasDefined(ATTR_INTERNAL_BLOCKING_POOL_SIZE)) { | ||
vertxOptions.setInternalBlockingPoolSize(VertxOptionsAttributes.ATTR_INTERNAL_BLOCKING_POOL_SIZE.validateOperation(operation).asInt()); | ||
} | ||
if (operation.hasDefined(ATTR_PREFER_NATIVE_TRANSPORT)) { | ||
vertxOptions.setPreferNativeTransport(VertxOptionsAttributes.ATTR_PREFER_NATIVE_TRANSPORT.validateOperation(operation).asBoolean()); | ||
} | ||
if (operation.hasDefined(ATTR_BLOCKED_THREAD_CHECK_INTERVAL)) { | ||
vertxOptions.setBlockedThreadCheckInterval(VertxOptionsAttributes.ATTR_BLOCKED_THREAD_CHECK_INTERVAL.validateOperation(operation).asLong()); | ||
} | ||
if (operation.hasDefined(ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT)) { | ||
vertxOptions.setBlockedThreadCheckIntervalUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT.validateOperation(operation).asString())); | ||
} | ||
if (operation.hasDefined(ATTR_MAX_EVENTLOOP_EXECUTE_TIME)) { | ||
vertxOptions.setMaxEventLoopExecuteTime(VertxOptionsAttributes.ATTR_MAX_EVENTLOOP_EXECUTE_TIME.validateOperation(operation).asLong()); | ||
} | ||
if (operation.hasDefined(ATTR_MAX_EVENTLOOP_EXECUTE_TIME_UNIT)) { | ||
vertxOptions.setMaxEventLoopExecuteTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_MAX_EVENTLOOP_EXECUTE_TIME_UNIT.validateOperation(operation).asString())); | ||
} | ||
if (operation.hasDefined(ATTR_MAX_WORKER_EXECUTE_TIME)) { | ||
vertxOptions.setMaxWorkerExecuteTime(VertxOptionsAttributes.ATTR_MAX_WORKER_EXECUTE_TIME.validateOperation(operation).asLong()); | ||
} | ||
if (operation.hasDefined(ATTR_MAX_WORKER_EXECUTE_TIME_UNIT)) { | ||
vertxOptions.setMaxWorkerExecuteTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_MAX_WORKER_EXECUTE_TIME_UNIT.validateOperation(operation).asString())); | ||
} | ||
if (operation.hasDefined(ATTR_WARNING_EXECUTION_TIME)) { | ||
vertxOptions.setWarningExceptionTime(VertxOptionsAttributes.ATTR_WARNING_EXECUTION_TIME.validateOperation(operation).asLong()); | ||
} | ||
if (operation.hasDefined(ATTR_WARNING_EXECUTION_TIME_UNIT)) { | ||
vertxOptions.setWarningExceptionTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_WARNING_EXECUTION_TIME_UNIT.validateOperation(operation).asString())); | ||
} | ||
|
||
// file system options | ||
if (operation.hasDefined(ATTR_FS_CLASS_PATH_RESOLVING_ENABLED)) { | ||
vertxOptions.getFileSystemOptions().setClassPathResolvingEnabled(VertxOptionsAttributes.ATTR_FS_CLASS_PATH_RESOLVING_ENABLED.validateOperation(operation).asBoolean()); | ||
} | ||
if (operation.hasDefined(ATTR_FS_FILE_CACHE_ENABLED)) { | ||
vertxOptions.getFileSystemOptions().setFileCachingEnabled(VertxOptionsAttributes.ATTR_FS_FILE_CACHE_ENABLED.validateOperation(operation).asBoolean()); | ||
} | ||
return vertxOptions; | ||
static VertxOptions parseOptions(ModelNode operation) throws OperationFailedException { | ||
VertxOptions vertxOptions = new VertxOptions(); | ||
if (operation.hasDefined(ATTR_EVENTLOOP_POOL_SIZE)) { | ||
vertxOptions.setEventLoopPoolSize(VertxOptionsAttributes.ATTR_EVENTLOOP_POOL_SIZE.validateOperation(operation).asInt()); | ||
} | ||
if (operation.hasDefined(ATTR_WORKER_POOL_SIZE)) { | ||
vertxOptions.setWorkerPoolSize(VertxOptionsAttributes.ATTR_WORKER_POOL_SIZE.validateOperation(operation).asInt()); | ||
} | ||
if (operation.hasDefined(ATTR_INTERNAL_BLOCKING_POOL_SIZE)) { | ||
vertxOptions.setInternalBlockingPoolSize(VertxOptionsAttributes.ATTR_INTERNAL_BLOCKING_POOL_SIZE.validateOperation(operation).asInt()); | ||
} | ||
if (operation.hasDefined(ATTR_PREFER_NATIVE_TRANSPORT)) { | ||
vertxOptions.setPreferNativeTransport(VertxOptionsAttributes.ATTR_PREFER_NATIVE_TRANSPORT.validateOperation(operation).asBoolean()); | ||
} | ||
if (operation.hasDefined(ATTR_BLOCKED_THREAD_CHECK_INTERVAL)) { | ||
vertxOptions.setBlockedThreadCheckInterval(VertxOptionsAttributes.ATTR_BLOCKED_THREAD_CHECK_INTERVAL.validateOperation(operation).asLong()); | ||
} | ||
if (operation.hasDefined(ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT)) { | ||
vertxOptions.setBlockedThreadCheckIntervalUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_BLOCKED_THREAD_CHECK_INTERVAL_UNIT.validateOperation(operation).asString())); | ||
} | ||
if (operation.hasDefined(ATTR_MAX_EVENTLOOP_EXECUTE_TIME)) { | ||
vertxOptions.setMaxEventLoopExecuteTime(VertxOptionsAttributes.ATTR_MAX_EVENTLOOP_EXECUTE_TIME.validateOperation(operation).asLong()); | ||
} | ||
if (operation.hasDefined(ATTR_MAX_EVENTLOOP_EXECUTE_TIME_UNIT)) { | ||
vertxOptions.setMaxEventLoopExecuteTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_MAX_EVENTLOOP_EXECUTE_TIME_UNIT.validateOperation(operation).asString())); | ||
} | ||
if (operation.hasDefined(ATTR_MAX_WORKER_EXECUTE_TIME)) { | ||
vertxOptions.setMaxWorkerExecuteTime(VertxOptionsAttributes.ATTR_MAX_WORKER_EXECUTE_TIME.validateOperation(operation).asLong()); | ||
} | ||
if (operation.hasDefined(ATTR_MAX_WORKER_EXECUTE_TIME_UNIT)) { | ||
vertxOptions.setMaxWorkerExecuteTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_MAX_WORKER_EXECUTE_TIME_UNIT.validateOperation(operation).asString())); | ||
} | ||
if (operation.hasDefined(ATTR_WARNING_EXECUTION_TIME)) { | ||
vertxOptions.setWarningExceptionTime(VertxOptionsAttributes.ATTR_WARNING_EXECUTION_TIME.validateOperation(operation).asLong()); | ||
} | ||
if (operation.hasDefined(ATTR_WARNING_EXECUTION_TIME_UNIT)) { | ||
vertxOptions.setWarningExceptionTimeUnit(TimeUnit.valueOf(VertxOptionsAttributes.ATTR_WARNING_EXECUTION_TIME_UNIT.validateOperation(operation).asString())); | ||
} | ||
|
||
// file system options | ||
if (operation.hasDefined(ATTR_FS_CLASS_PATH_RESOLVING_ENABLED)) { | ||
vertxOptions.getFileSystemOptions().setClassPathResolvingEnabled(VertxOptionsAttributes.ATTR_FS_CLASS_PATH_RESOLVING_ENABLED.validateOperation(operation).asBoolean()); | ||
} | ||
if (operation.hasDefined(ATTR_FS_FILE_CACHE_ENABLED)) { | ||
vertxOptions.getFileSystemOptions().setFileCachingEnabled(VertxOptionsAttributes.ATTR_FS_FILE_CACHE_ENABLED.validateOperation(operation).asBoolean()); | ||
} | ||
if (operation.hasDefined(ATTR_FS_FILE_CACHE_DIR)) { | ||
vertxOptions.getFileSystemOptions().setFileCacheDir(VertxOptionsAttributes.ATTR_FS_FILE_CACHE_DIR.validateOperation(operation).asString()); | ||
} | ||
return vertxOptions; | ||
} | ||
|
||
private static class ShowInfoHandler implements OperationStepHandler { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.