Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-1978 Extensible configuration parser for modules #1234

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions core/src/main/java/org/infinispan/configuration/Builder.java
@@ -0,0 +1,48 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.infinispan.configuration;

/**
* Builder. Validates and constructs a configuration bean
*
* @author Tristan Tarrant
* @since 5.2
*/
public interface Builder<T> {
/**
* Validate the data in this builder before building the configuration bean
*/
void validate();

/**
* Create the configuration bean
*
* @return
*/
T create();

/**
* Reads the configuration from an already created configuration bean into this builder.
* Returns an appropriate builder to allow fluent configuration
*
* @param template
* @return
*/
Builder<?> read(T template);
}
35 changes: 35 additions & 0 deletions core/src/main/java/org/infinispan/configuration/BuiltBy.java
@@ -0,0 +1,35 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.infinispan.configuration;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* BuiltBy. An annotation for configuration beans to specify what builder builds them.
* This annotation is required on all non-core configuration classes (i.e. ones which reside
* in external modules)
*
* @author Tristan Tarrant
* @since 5.2
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface BuiltBy {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you've used the annotation for a custom config builder, but shouldn't this be used in core configuration classes?

I guess in core/ things are tighter and we know which builder goes with which build object.

If that's the case, we should explicitly indicate that this annotation is purely for non-core configuration extensions.

Either way, we need to be explicit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be more accurate in the javadoc

Class<? extends Builder<?>> value();
}
Expand Up @@ -18,74 +18,76 @@
*/
package org.infinispan.configuration.cache;

abstract class AbstractConfigurationChildBuilder<T> implements ConfigurationChildBuilder {

import org.infinispan.configuration.Builder;

abstract class AbstractConfigurationChildBuilder<T> implements ConfigurationChildBuilder, Builder<T> {

private final ConfigurationBuilder builder;

protected AbstractConfigurationChildBuilder(ConfigurationBuilder builder) {
this.builder = builder;
}

@Override
public ClusteringConfigurationBuilder clustering() {
return builder.clustering();
}

@Override
public CustomInterceptorsConfigurationBuilder customInterceptors() {
return builder.customInterceptors();
}

@Override
public DataContainerConfigurationBuilder dataContainer() {
return builder.dataContainer();
}

@Override
public DeadlockDetectionConfigurationBuilder deadlockDetection() {
return builder.deadlockDetection();
}

@Override
public EvictionConfigurationBuilder eviction() {
return builder.eviction();
}

@Override
public ExpirationConfigurationBuilder expiration() {
return builder.expiration();
}

@Override
public IndexingConfigurationBuilder indexing() {
return builder.indexing();
}

@Override
public InvocationBatchingConfigurationBuilder invocationBatching() {
return builder.invocationBatching();
}

@Override
public JMXStatisticsConfigurationBuilder jmxStatistics() {
return builder.jmxStatistics();
}

@Override
public LoadersConfigurationBuilder loaders() {
return builder.loaders();
}

@Override
public LockingConfigurationBuilder locking() {
return builder.locking();
}

@Override
public StoreAsBinaryConfigurationBuilder storeAsBinary() {
return builder.storeAsBinary();
}

@Override
public TransactionConfigurationBuilder transaction() {
return builder.transaction();
Expand All @@ -95,12 +97,12 @@ public TransactionConfigurationBuilder transaction() {
public VersioningConfigurationBuilder versioning() {
return builder.versioning();
}

@Override
public UnsafeConfigurationBuilder unsafe() {
return builder.unsafe();
}

protected ConfigurationBuilder getBuilder() {
return builder;
}
Expand All @@ -110,10 +112,4 @@ public Configuration build() {
return builder.build();
}

abstract void validate();

abstract T create();

public abstract ConfigurationChildBuilder read(T template);

}
@@ -0,0 +1,33 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @author tags. All rights reserved.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU Lesser General Public License, v. 2.1.
* This program is distributed in the hope that it will be useful, but WITHOUT A
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License,
* v.2.1 along with this distribution; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.infinispan.configuration.cache;

/**
* AbstractModuleConfigurationBuilder.
*
* @author Tristan Tarrant
* @since 5.2
*/
public abstract class AbstractModuleConfigurationBuilder<T> extends AbstractConfigurationChildBuilder<T> {

protected AbstractModuleConfigurationBuilder(ConfigurationBuilder builder) {
super(builder);
}

}
Expand Up @@ -70,7 +70,7 @@ public AsyncConfigurationBuilder syncMarshalling() {

/**
* The replication queue in use, by default {@link ReplicationQueueImpl}.
*
*
* NOTE: Currently Infinispan will not use the object instance, but instead instantiate a new
* instance of the class. Therefore, do not expect any state to survive, and provide a no-args
* constructor to any instance. This will be resolved in Infinispan 5.2.0
Expand Down Expand Up @@ -116,6 +116,7 @@ public AsyncConfigurationBuilder useReplQueue(boolean use) {
}

@Override
public
void validate() {
if (useReplicationQueue && getClusteringBuilder().cacheMode().isDistributed())
throw new ConfigurationException("Use of the replication queue is invalid when using DISTRIBUTED mode.");
Expand All @@ -125,10 +126,11 @@ void validate() {
}

@Override
public
AsyncConfiguration create() {
return new AsyncConfiguration(asyncMarshalling, replicationQueue, replicationQueueInterval, replicationQueueMaxElements, useReplicationQueue);
}

@Override
public AsyncConfigurationBuilder read(AsyncConfiguration template) {
this.asyncMarshalling = template.asyncMarshalling();
Expand Down
Expand Up @@ -23,9 +23,9 @@
/**
* Configuration for the async cache loader. If enabled, this provides you with asynchronous writes
* to the cache store, giving you 'write-behind' caching.
*
*
* @author pmuir
*
*
*/
public class AsyncLoaderConfigurationBuilder extends AbstractLoaderConfigurationChildBuilder<AsyncLoaderConfiguration> {

Expand Down Expand Up @@ -113,10 +113,12 @@ public AsyncLoaderConfigurationBuilder threadPoolSize(int i) {
}

@Override
public
void validate() {
}

@Override
public
AsyncLoaderConfiguration create() {
return new AsyncLoaderConfiguration(enabled, flushLockTimeout, modificationQueueSize, shutdownTimeout, threadPoolSize);
}
Expand Down
Expand Up @@ -20,9 +20,9 @@

/**
* Defines clustered characteristics of the cache.
*
*
* @author pmuir
*
*
*/
public class ClusteringConfigurationBuilder extends AbstractConfigurationChildBuilder<ClusteringConfiguration> implements
ClusteringConfigurationChildBuilder {
Expand Down Expand Up @@ -102,6 +102,7 @@ public SyncConfigurationBuilder sync() {
}

@Override
public
void validate() {
asyncConfigurationBuilder.validate();
hashConfigurationBuilder.validate();
Expand All @@ -111,6 +112,7 @@ void validate() {
}

@Override
public
ClusteringConfiguration create() {
return new ClusteringConfiguration(cacheMode, asyncConfigurationBuilder.create(), hashConfigurationBuilder.create(),
l1ConfigurationBuilder.create(), stateTransferConfigurationBuilder.create(), syncConfigurationBuilder.create());
Expand Down