if (store.hasDefined(ModelKeys.TCP_NO_DELAY)) {
builder.tcpNoDelay(store.require(ModelKeys.TCP_NO_DELAY).asBoolean());
}
return builder;
} else if (storeKey.equals(ModelKeys.LEVELDB_STORE)) {
final LevelDBStoreConfigurationBuilder builder = persistenceBuilder.addStore(LevelDBStoreConfigurationBuilder.class);
final String path = ((resolvedValue = LevelDBStoreResource.PATH.resolveModelAttribute(context, store)).isDefined()) ? resolvedValue.asString() : InfinispanExtension.SUBSYSTEM_NAME + File.separatorChar + containerName + File.separatorChar + "data";
final String relativeTo = ((resolvedValue = LevelDBStoreResource.RELATIVE_TO.resolveModelAttribute(context, store)).isDefined()) ? resolvedValue.asString() : ServerEnvironment.SERVER_DATA_DIR;
Injector<PathManager> injector = new SimpleInjector<PathManager>() {
volatile PathManager.Callback.Handle callbackHandle;
@Override
public void inject(PathManager value) {
callbackHandle = value.registerCallback(relativeTo, PathManager.ReloadServerCallback.create(), PathManager.Event.UPDATED, PathManager.Event.REMOVED);
builder.location(value.resolveRelativePathEntry(path, relativeTo));
}
@Override
public void uninject() {
super.uninject();
if (callbackHandle != null) {
callbackHandle.remove();
}
}
};
dependencies.add(new Dependency<PathManager>(PathManagerService.SERVICE_NAME, PathManager.class, injector));
final boolean expirationDefined = store.hasDefined(ModelKeys.EXPIRATION) && store.get(ModelKeys.EXPIRATION, ModelKeys.EXPIRATION_NAME).isDefined();
final String expirationPath;
if (expirationDefined) {
ModelNode expiration = store.get(ModelKeys.EXPIRATION, ModelKeys.EXPIRATION_NAME);
expirationPath = LevelDBExpirationResource.PATH.resolveModelAttribute(context, expiration).asString();
builder.expiryQueueSize(LevelDBExpirationResource.QUEUE_SIZE.resolveModelAttribute(context, expiration).asInt());
} else {
expirationPath = InfinispanExtension.SUBSYSTEM_NAME + File.separatorChar + containerName + File.separatorChar + "expiration";
}
injector = new SimpleInjector<PathManager>() {
volatile PathManager.Callback.Handle callbackHandle;
@Override
public void inject(PathManager value) {
callbackHandle = value.registerCallback(relativeTo, PathManager.ReloadServerCallback.create(), PathManager.Event.UPDATED, PathManager.Event.REMOVED);
builder.expiredLocation(value.resolveRelativePathEntry(expirationPath, relativeTo));
}
@Override
public void uninject() {
super.uninject();
if (callbackHandle != null) {
callbackHandle.remove();
}
}
};
dependencies.add(new Dependency<PathManager>(PathManagerService.SERVICE_NAME, PathManager.class, injector));
if (store.hasDefined(ModelKeys.BLOCK_SIZE))
builder.blockSize(store.get(ModelKeys.BLOCK_SIZE).asInt());
if (store.hasDefined(ModelKeys.CACHE_SIZE))
builder.cacheSize(store.get(ModelKeys.CACHE_SIZE).asLong());
if (store.hasDefined(ModelKeys.CLEAR_THRESHOLD))
builder.clearThreshold(store.get(ModelKeys.CLEAR_THRESHOLD).asInt());
if (store.hasDefined(ModelKeys.COMPRESSION)) {
ModelNode node = store.get(ModelKeys.COMPRESSION, ModelKeys.COMPRESSION_NAME);
final CompressionType compressionType = CompressionType.valueOf(LevelDBCompressionResource.TYPE.resolveModelAttribute(context, node).asString());
builder.compressionType(compressionType);
}
if (store.hasDefined(ModelKeys.IMPLEMENTATION)) {
ModelNode node = store.get(ModelKeys.IMPLEMENTATION, ModelKeys.IMPLEMENTATION_NAME);
final LevelDBStoreConfiguration.ImplementationType implementationType = LevelDBStoreConfiguration.ImplementationType.valueOf(LevelDBImplementationResource.TYPE.resolveModelAttribute(context, node).asString());
builder.implementationType(implementationType);
}
return builder;
} else if (storeKey.equals(ModelKeys.REST_STORE)) {
final RestStoreConfigurationBuilder builder = persistenceBuilder.addStore(RestStoreConfigurationBuilder.class);
builder.host("localhost"); // To pass builder validation, the builder will be configured properly when the outbound socket is ready to be injected
for (ModelNode server : store.require(ModelKeys.REMOTE_SERVERS).asList()) {
String outboundSocketBinding = server.get(ModelKeys.OUTBOUND_SOCKET_BINDING).asString();
Injector<OutboundSocketBinding> injector = new SimpleInjector<OutboundSocketBinding>() {
@Override
public void inject(OutboundSocketBinding value) {
try {
builder.host(value.getDestinationAddress().getHostAddress()).port(value.getDestinationPort()); // FIXME: add support for multiple hosts
} catch (UnknownHostException e) {
throw InfinispanMessages.MESSAGES.failedToInjectSocketBinding(e, value);
}
}
};
dependencies.add(new Dependency<OutboundSocketBinding>(OutboundSocketBinding.OUTBOUND_SOCKET_BINDING_BASE_SERVICE_NAME.append(outboundSocketBinding), OutboundSocketBinding.class, injector));
}
if (store.hasDefined(ModelKeys.APPEND_CACHE_NAME_TO_PATH)) {
builder.appendCacheNameToPath(store.require(ModelKeys.APPEND_CACHE_NAME_TO_PATH).asBoolean());
}
if (store.hasDefined(ModelKeys.PATH)) {
builder.path(store.get(ModelKeys.PATH).asString());
}
builder.rawValues(true);
builder.metadataHelper(MimeMetadataHelper.class);
if (store.hasDefined(ModelKeys.CONNECTION_POOL)) {
ModelNode pool = store.get(ModelKeys.CONNECTION_POOL);
if (pool.hasDefined(ModelKeys.CONNECTION_TIMEOUT)) {
builder.connectionPool().connectionTimeout(pool.require(ModelKeys.CONNECTION_TIMEOUT).asInt());
}
if (pool.hasDefined(ModelKeys.MAX_CONNECTIONS_PER_HOST)) {
builder.connectionPool().maxConnectionsPerHost(pool.require(ModelKeys.MAX_CONNECTIONS_PER_HOST).asInt());
}
if (pool.hasDefined(ModelKeys.MAX_TOTAL_CONNECTIONS)) {
builder.connectionPool().maxTotalConnections(pool.require(ModelKeys.MAX_TOTAL_CONNECTIONS).asInt());
}
if (pool.hasDefined(ModelKeys.BUFFER_SIZE)) {
builder.connectionPool().bufferSize(pool.require(ModelKeys.BUFFER_SIZE).asInt());
}
if (pool.hasDefined(ModelKeys.SOCKET_TIMEOUT)) {
builder.connectionPool().socketTimeout(pool.require(ModelKeys.SOCKET_TIMEOUT).asInt());
}
if (pool.hasDefined(ModelKeys.TCP_NO_DELAY)) {
builder.connectionPool().tcpNoDelay(pool.require(ModelKeys.TCP_NO_DELAY).asBoolean());
}
}
return builder;
} else if (storeKey.equals(ModelKeys.STORE)) {
String className = store.require(ModelKeys.CLASS).asString();