Skip to content

Commit

Permalink
Move profile configuration/builder into separate un-nested class.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Jul 5, 2018
1 parent c73b88a commit bd06d10
Show file tree
Hide file tree
Showing 14 changed files with 535 additions and 412 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/io/atomix/core/Atomix.java
Expand Up @@ -34,6 +34,7 @@
import io.atomix.core.multimap.AtomicMultimap; import io.atomix.core.multimap.AtomicMultimap;
import io.atomix.core.multiset.DistributedMultiset; import io.atomix.core.multiset.DistributedMultiset;
import io.atomix.core.profile.Profile; import io.atomix.core.profile.Profile;
import io.atomix.core.profile.ProfileConfig;
import io.atomix.core.queue.DistributedQueue; import io.atomix.core.queue.DistributedQueue;
import io.atomix.core.semaphore.DistributedSemaphore; import io.atomix.core.semaphore.DistributedSemaphore;
import io.atomix.core.set.DistributedSet; import io.atomix.core.set.DistributedSet;
Expand Down Expand Up @@ -77,7 +78,6 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
Expand Down Expand Up @@ -162,7 +162,7 @@ private static AtomixConfig config(File file, ClassLoader classLoader, AtomixReg
new PolymorphicTypeMapper(PartitionGroupConfig.class, PartitionGroup.Type.class), new PolymorphicTypeMapper(PartitionGroupConfig.class, PartitionGroup.Type.class),
new PolymorphicTypeMapper(PrimitiveConfig.class, PrimitiveType.class), new PolymorphicTypeMapper(PrimitiveConfig.class, PrimitiveType.class),
new PolymorphicTypeMapper(PrimitiveProtocolConfig.class, PrimitiveProtocol.Type.class), new PolymorphicTypeMapper(PrimitiveProtocolConfig.class, PrimitiveProtocol.Type.class),
new PolymorphicTypeMapper(Profile.Config.class, Profile.Type.class), new PolymorphicTypeMapper(ProfileConfig.class, Profile.Type.class),
new PolymorphicTypeMapper(NodeDiscoveryProvider.Config.class, NodeDiscoveryProvider.Type.class)); new PolymorphicTypeMapper(NodeDiscoveryProvider.Config.class, NodeDiscoveryProvider.Type.class));
return mapper.loadFile(AtomixConfig.class, file, RESOURCES); return mapper.loadFile(AtomixConfig.class, file, RESOURCES);
} }
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/io/atomix/core/AtomixConfig.java
Expand Up @@ -16,7 +16,7 @@
package io.atomix.core; package io.atomix.core;


import io.atomix.cluster.ClusterConfig; import io.atomix.cluster.ClusterConfig;
import io.atomix.core.profile.Profile; import io.atomix.core.profile.ProfileConfig;
import io.atomix.primitive.config.PrimitiveConfig; import io.atomix.primitive.config.PrimitiveConfig;
import io.atomix.primitive.partition.PartitionGroupConfig; import io.atomix.primitive.partition.PartitionGroupConfig;
import io.atomix.utils.config.Config; import io.atomix.utils.config.Config;
Expand All @@ -39,7 +39,7 @@ public class AtomixConfig implements Config {
private PartitionGroupConfig managementGroup; private PartitionGroupConfig managementGroup;
private Map<String, PartitionGroupConfig<?>> partitionGroups = new HashMap<>(); private Map<String, PartitionGroupConfig<?>> partitionGroups = new HashMap<>();
private Map<String, PrimitiveConfig> primitives = new HashMap<>(); private Map<String, PrimitiveConfig> primitives = new HashMap<>();
private List<Profile.Config> profiles = new ArrayList<>(); private List<ProfileConfig> profiles = new ArrayList<>();


/** /**
* Returns the cluster configuration. * Returns the cluster configuration.
Expand Down Expand Up @@ -183,7 +183,7 @@ public <C extends PrimitiveConfig<C>> C getPrimitive(String name) {
* *
* @return the Atomix profile * @return the Atomix profile
*/ */
public List<Profile.Config> getProfiles() { public List<ProfileConfig> getProfiles() {
return profiles; return profiles;
} }


Expand All @@ -193,7 +193,7 @@ public List<Profile.Config> getProfiles() {
* @param profiles the profiles * @param profiles the profiles
* @return the Atomix configuration * @return the Atomix configuration
*/ */
public AtomixConfig setProfiles(List<Profile.Config> profiles) { public AtomixConfig setProfiles(List<ProfileConfig> profiles) {
this.profiles = profiles; this.profiles = profiles;
return this; return this;
} }
Expand All @@ -204,7 +204,7 @@ public AtomixConfig setProfiles(List<Profile.Config> profiles) {
* @param profile the profile to add * @param profile the profile to add
* @return the Atomix configuration * @return the Atomix configuration
*/ */
public AtomixConfig addProfile(Profile.Config profile) { public AtomixConfig addProfile(ProfileConfig profile) {
profiles.add(checkNotNull(profile, "profile cannot be null")); profiles.add(checkNotNull(profile, "profile cannot be null"));
return this; return this;
} }
Expand Down
26 changes: 8 additions & 18 deletions core/src/main/java/io/atomix/core/profile/ClientProfile.java
Expand Up @@ -26,7 +26,7 @@ public class ClientProfile implements Profile {
/** /**
* Client profile type. * Client profile type.
*/ */
public static class Type implements Profile.Type<Config> { public static class Type implements Profile.Type<ClientProfileConfig> {
private static final String NAME = "client"; private static final String NAME = "client";


@Override @Override
Expand All @@ -35,38 +35,28 @@ public String name() {
} }


@Override @Override
public Config newConfig() { public ClientProfileConfig newConfig() {
return new Config(); return new ClientProfileConfig();
} }


@Override @Override
public Profile newProfile(Config config) { public Profile newProfile(ClientProfileConfig config) {
return new ClientProfile(); return new ClientProfile();
} }
} }


/** private final ClientProfileConfig config;
* Client profile configuration.
*/
public static class Config implements Profile.Config {
@Override
public Profile.Type getType() {
return TYPE;
}
}

private final Config config;


ClientProfile() { ClientProfile() {
this(new Config()); this(new ClientProfileConfig());
} }


ClientProfile(Config config) { ClientProfile(ClientProfileConfig config) {
this.config = config; this.config = config;
} }


@Override @Override
public Config config() { public ClientProfileConfig config() {
return config; return config;
} }


Expand Down
28 changes: 28 additions & 0 deletions core/src/main/java/io/atomix/core/profile/ClientProfileConfig.java
@@ -0,0 +1,28 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.atomix.core.profile;

import static io.atomix.core.profile.ClientProfile.TYPE;

/**
* Client profile configuration.
*/
public class ClientProfileConfig extends ProfileConfig {
@Override
public Profile.Type getType() {
return TYPE;
}
}

0 comments on commit bd06d10

Please sign in to comment.