Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move discovery configurations/builders into separate un-nested class.
- Loading branch information
Showing
14 changed files
with
472 additions
and
356 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
104 changes: 104 additions & 0 deletions
104
cluster/src/main/java/io/atomix/cluster/BootstrapDiscoveryBuilder.java
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,104 @@ | |||
/* | |||
* 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.cluster; | |||
|
|||
import io.atomix.utils.net.Address; | |||
|
|||
import java.time.Duration; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.Stream; | |||
|
|||
/** | |||
* Bootstrap discovery builder. | |||
*/ | |||
public class BootstrapDiscoveryBuilder extends NodeDiscoveryBuilder { | |||
private final BootstrapDiscoveryConfig config = new BootstrapDiscoveryConfig(); | |||
|
|||
/** | |||
* Sets the bootstrap nodes. | |||
* | |||
* @param nodes the bootstrap nodes | |||
* @return the location provider builder | |||
*/ | |||
public BootstrapDiscoveryBuilder withNodes(Address... nodes) { | |||
return withNodes(Stream.of(nodes) | |||
.map(address -> Node.builder() | |||
.withAddress(address) | |||
.build()) | |||
.collect(Collectors.toSet())); | |||
} | |||
|
|||
/** | |||
* Sets the bootstrap nodes. | |||
* | |||
* @param nodes the bootstrap nodes | |||
* @return the location provider builder | |||
*/ | |||
public BootstrapDiscoveryBuilder withNodes(Node... nodes) { | |||
return withNodes(Arrays.asList(nodes)); | |||
} | |||
|
|||
/** | |||
* Sets the bootstrap nodes. | |||
* | |||
* @param locations the bootstrap member locations | |||
* @return the location provider builder | |||
*/ | |||
public BootstrapDiscoveryBuilder withNodes(Collection<Node> locations) { | |||
config.setNodes(locations); | |||
return this; | |||
} | |||
|
|||
/** | |||
* Sets the failure detection heartbeat interval. | |||
* | |||
* @param heartbeatInterval the failure detection heartbeat interval | |||
* @return the location provider builder | |||
*/ | |||
public BootstrapDiscoveryBuilder withHeartbeatInterval(Duration heartbeatInterval) { | |||
config.setHeartbeatInterval(heartbeatInterval); | |||
return this; | |||
} | |||
|
|||
/** | |||
* Sets the phi accrual failure threshold. | |||
* | |||
* @param failureThreshold the phi accrual failure threshold | |||
* @return the location provider builder | |||
*/ | |||
public BootstrapDiscoveryBuilder withFailureThreshold(int failureThreshold) { | |||
config.setFailureThreshold(failureThreshold); | |||
return this; | |||
} | |||
|
|||
/** | |||
* Sets the failure timeout to use prior to phi failure detectors being populated. | |||
* | |||
* @param failureTimeout the failure timeout | |||
* @return the location provider builder | |||
*/ | |||
public BootstrapDiscoveryBuilder withFailureTimeout(Duration failureTimeout) { | |||
config.setFailureTimeout(failureTimeout); | |||
return this; | |||
} | |||
|
|||
@Override | |||
public NodeDiscoveryProvider build() { | |||
return new BootstrapDiscoveryProvider(config); | |||
} | |||
} |
121 changes: 121 additions & 0 deletions
121
cluster/src/main/java/io/atomix/cluster/BootstrapDiscoveryConfig.java
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,121 @@ | |||
/* | |||
* 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.cluster; | |||
|
|||
import java.time.Duration; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
|
|||
import static com.google.common.base.Preconditions.checkNotNull; | |||
|
|||
/** | |||
* Bootstrap discovery configuration. | |||
*/ | |||
public class BootstrapDiscoveryConfig extends NodeDiscoveryConfig { | |||
private static final int DEFAULT_HEARTBEAT_INTERVAL = 1000; | |||
private static final int DEFAULT_FAILURE_TIMEOUT = 10000; | |||
private static final int DEFAULT_PHI_FAILURE_THRESHOLD = 10; | |||
|
|||
private Duration heartbeatInterval = Duration.ofMillis(DEFAULT_HEARTBEAT_INTERVAL); | |||
private int failureThreshold = DEFAULT_PHI_FAILURE_THRESHOLD; | |||
private Duration failureTimeout = Duration.ofMillis(DEFAULT_FAILURE_TIMEOUT); | |||
private Collection<Node> nodes = Collections.emptySet(); | |||
|
|||
@Override | |||
public NodeDiscoveryProvider.Type getType() { | |||
return BootstrapDiscoveryProvider.TYPE; | |||
} | |||
|
|||
/** | |||
* Returns the configured bootstrap nodes. | |||
* | |||
* @return the configured bootstrap nodes | |||
*/ | |||
public Collection<Node> getNodes() { | |||
return nodes; | |||
} | |||
|
|||
/** | |||
* Sets the bootstrap nodes. | |||
* | |||
* @param nodes the bootstrap nodes | |||
* @return the bootstrap provider configuration | |||
*/ | |||
public BootstrapDiscoveryConfig setNodes(Collection<Node> nodes) { | |||
this.nodes = nodes; | |||
return this; | |||
} | |||
|
|||
/** | |||
* Returns the heartbeat interval. | |||
* | |||
* @return the heartbeat interval | |||
*/ | |||
public Duration getHeartbeatInterval() { | |||
return heartbeatInterval; | |||
} | |||
|
|||
/** | |||
* Sets the heartbeat interval. | |||
* | |||
* @param heartbeatInterval the heartbeat interval | |||
* @return the group membership configuration | |||
*/ | |||
public BootstrapDiscoveryConfig setHeartbeatInterval(Duration heartbeatInterval) { | |||
this.heartbeatInterval = checkNotNull(heartbeatInterval); | |||
return this; | |||
} | |||
|
|||
/** | |||
* Returns the failure detector threshold. | |||
* | |||
* @return the failure detector threshold | |||
*/ | |||
public int getFailureThreshold() { | |||
return failureThreshold; | |||
} | |||
|
|||
/** | |||
* Sets the failure detector threshold. | |||
* | |||
* @param failureThreshold the failure detector threshold | |||
* @return the group membership configuration | |||
*/ | |||
public BootstrapDiscoveryConfig setFailureThreshold(int failureThreshold) { | |||
this.failureThreshold = failureThreshold; | |||
return this; | |||
} | |||
|
|||
/** | |||
* Returns the base failure timeout. | |||
* | |||
* @return the base failure timeout | |||
*/ | |||
public Duration getFailureTimeout() { | |||
return failureTimeout; | |||
} | |||
|
|||
/** | |||
* Sets the base failure timeout. | |||
* | |||
* @param failureTimeout the base failure timeout | |||
* @return the group membership configuration | |||
*/ | |||
public BootstrapDiscoveryConfig setFailureTimeout(Duration failureTimeout) { | |||
this.failureTimeout = checkNotNull(failureTimeout); | |||
return this; | |||
} | |||
} |
Oops, something went wrong.