Skip to content

Commit 4bb2285

Browse files
committed
create actor builder, add cluster join actor
1 parent adc3c18 commit 4bb2285

File tree

11 files changed

+368
-211
lines changed

11 files changed

+368
-211
lines changed

config/config.hocon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jvmMetricsCollectionInterval="PT.5S"
1212
maxConnectionTimeout="PT2M"
1313
minConnectionTimeout="PT1M"
1414
clusterHostSuffix=".cluster"
15+
clusterJoinActor.type="com.arpnetworking.akka.NonJoiningClusterJoiner"
1516
rebalanceConfiguration {
1617
maxParallel=100
1718
threshold=500
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright 2016 InscopeMetrics, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.arpnetworking.akka;
17+
18+
import akka.actor.Props;
19+
import com.arpnetworking.commons.builder.OvalBuilder;
20+
21+
import java.util.function.Function;
22+
23+
/**
24+
* Builder for actors.
25+
*
26+
* @param <B> The type of the builder
27+
* @author Brandon Arp (brandon dot arp at inscopemetrics dot com)
28+
*/
29+
public abstract class ActorBuilder<B extends ActorBuilder<B>> extends OvalBuilder<Props> {
30+
/**
31+
* Protected constructor.
32+
*
33+
* @param createProps method to create a {@link Props} from the {@link ActorBuilder}
34+
*/
35+
protected ActorBuilder(final Function<B, Props> createProps) {
36+
super(createProps);
37+
}
38+
39+
/**
40+
* Called by setters to always return appropriate subclass of
41+
* {@link ActorBuilder}, even from setters of base class.
42+
*
43+
* @return instance with correct {@link ActorBuilder} class type.
44+
*/
45+
protected abstract B self();
46+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Copyright 2016 Inscope Metrics, Inc
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.arpnetworking.akka;
17+
18+
import akka.actor.Props;
19+
import akka.actor.UntypedActor;
20+
import com.arpnetworking.steno.Logger;
21+
import com.arpnetworking.steno.LoggerFactory;
22+
23+
/**
24+
* Actor that does not attempt to join a cluster.
25+
*
26+
* @author Brandon Arp (brandon dot arp at inscopemetrics dot com)
27+
*/
28+
public final class NonJoiningClusterJoiner extends UntypedActor {
29+
/**
30+
* Static factory method for creating a {@link Props} to create a {@link NonJoiningClusterJoiner} actor.
31+
*
32+
* @return a new {@link Props}
33+
*/
34+
public static Props props() {
35+
return Props.create(NonJoiningClusterJoiner.class);
36+
}
37+
38+
/**
39+
* Static factory method for creating a {@link Props} to create a {@link NonJoiningClusterJoiner} actor from a
40+
* {@link Builder}.
41+
*
42+
* @param builder Builder to create the Props from
43+
* @return a new {@link Props}
44+
*/
45+
private static Props props(final Builder builder) {
46+
return props();
47+
}
48+
49+
/**
50+
* Public constructor.
51+
*/
52+
public NonJoiningClusterJoiner() {
53+
LOGGER.info()
54+
.setMessage("NonJoiningClusterJoiner starting up")
55+
.log();
56+
}
57+
58+
59+
/**
60+
* {@inheritDoc}
61+
*/
62+
@Override
63+
public void onReceive(final Object message) throws Exception {
64+
unhandled(message);
65+
}
66+
67+
private static final Logger LOGGER = LoggerFactory.getLogger(NonJoiningClusterJoiner.class);
68+
69+
/**
70+
* Implementation of the {@link com.arpnetworking.commons.builder.Builder} pattern for a {@link NonJoiningClusterJoiner}.
71+
*
72+
* @author Brandon Arp (brandon dot arp at inscopemetrics dot com)
73+
*/
74+
public static class Builder extends ActorBuilder<Builder> {
75+
/**
76+
* Public constructor.
77+
*/
78+
public Builder() {
79+
super(NonJoiningClusterJoiner::props);
80+
}
81+
82+
/**
83+
* {@inheritDoc}
84+
*/
85+
@Override
86+
public Builder self() {
87+
return this;
88+
}
89+
}
90+
}

src/main/java/com/arpnetworking/clusteraggregator/GuiceModule.java

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -164,54 +164,39 @@ private ActorSystem provideActorSystem(@Named("akka-config") final Config akkaCo
164164
@Named("cluster-emitter")
165165
@SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD") // Invoked reflectively by Guice
166166
private ActorRef provideClusterEmitter(final Injector injector, final ActorSystem system) {
167+
return launchEmitter(injector, system, _configuration.getClusterPipelineConfiguration(), "cluster-emitter-configurator");
168+
}
169+
170+
@Provides
171+
@Singleton
172+
@Named("host-emitter")
173+
@SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD") // Invoked reflectively by Guice
174+
private ActorRef provideHostEmitter(final Injector injector, final ActorSystem system) {
175+
return launchEmitter(injector, system, _configuration.getHostPipelineConfiguration(), "host-emitter-configurator");
176+
}
177+
178+
private ActorRef launchEmitter(final Injector injector, final ActorSystem system, final File pipelineFile, final String name) {
167179
final ActorRef emitterConfigurationProxy = system.actorOf(
168180
ConfigurableActorProxy.props(new RoundRobinEmitterFactory()),
169-
"cluster-emitter-configurator");
181+
name);
170182
final ActorConfigurator<EmitterConfiguration> configurator =
171183
new ActorConfigurator<>(emitterConfigurationProxy, EmitterConfiguration.class);
172184
final ObjectMapper objectMapper = EmitterConfiguration.createObjectMapper(injector);
173-
final File configurationFile = _configuration.getClusterPipelineConfiguration();
174185
final Builder<? extends JsonNodeSource> sourceBuilder;
175-
if (configurationFile.getName().toLowerCase(Locale.getDefault()).endsWith(HOCON_FILE_EXTENSION)) {
186+
if (pipelineFile.getName().toLowerCase(Locale.getDefault()).endsWith(HOCON_FILE_EXTENSION)) {
176187
sourceBuilder = new HoconFileSource.Builder()
177188
.setObjectMapper(objectMapper)
178-
.setFile(configurationFile);
189+
.setFile(pipelineFile);
179190
} else {
180191
sourceBuilder = new JsonNodeFileSource.Builder()
181192
.setObjectMapper(objectMapper)
182-
.setFile(configurationFile);
193+
.setFile(pipelineFile);
183194
}
184195

185196
final DynamicConfiguration configuration = new DynamicConfiguration.Builder()
186197
.setObjectMapper(objectMapper)
187198
.addSourceBuilder(sourceBuilder)
188-
.addTrigger(new FileTrigger.Builder().setFile(_configuration.getClusterPipelineConfiguration()).build())
189-
.addListener(configurator)
190-
.build();
191-
192-
configuration.launch();
193-
194-
return emitterConfigurationProxy;
195-
}
196-
197-
@Provides
198-
@Singleton
199-
@Named("host-emitter")
200-
@SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD") // Invoked reflectively by Guice
201-
private ActorRef provideHostEmitter(final Injector injector, final ActorSystem system) {
202-
final ActorRef emitterConfigurationProxy = system.actorOf(
203-
ConfigurableActorProxy.props(new RoundRobinEmitterFactory()),
204-
"host-emitter-configurator");
205-
final ActorConfigurator<EmitterConfiguration> configurator =
206-
new ActorConfigurator<>(emitterConfigurationProxy, EmitterConfiguration.class);
207-
final ObjectMapper objectMapper = EmitterConfiguration.createObjectMapper(injector);
208-
final DynamicConfiguration configuration = new DynamicConfiguration.Builder()
209-
.setObjectMapper(objectMapper)
210-
.addSourceBuilder(
211-
new JsonNodeFileSource.Builder()
212-
.setObjectMapper(objectMapper)
213-
.setFile(_configuration.getHostPipelineConfiguration()))
214-
.addTrigger(new FileTrigger.Builder().setFile(_configuration.getHostPipelineConfiguration()).build())
199+
.addTrigger(new FileTrigger.Builder().setFile(pipelineFile).build())
215200
.addListener(configurator)
216201
.build();
217202

@@ -259,6 +244,14 @@ private ActorRef provideTcpServer(final Injector injector, final ActorSystem sys
259244
return system.actorOf(GuiceActorCreator.props(injector, AggClientServer.class), "tcp-server");
260245
}
261246

247+
@Provides
248+
@Singleton
249+
@Named("cluster-joiner")
250+
@SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD") // Invoked reflectively by Guice
251+
private ActorRef provideClusterJoiner(final ActorSystem system, final ClusterAggregatorConfiguration config) {
252+
return system.actorOf(config.getClusterJoinActor(), "cluster-joiner");
253+
}
254+
262255
@Provides
263256
@Singleton
264257
@Named("aggregator-lifecycle")

src/main/java/com/arpnetworking/clusteraggregator/Main.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ private void launchActors(final Injector injector) {
196196
.log();
197197
injector.getInstance(Key.get(ActorRef.class, Names.named("jvm-metrics-collector")));
198198

199+
LOGGER.info()
200+
.setMessage("Launching cluster joiner")
201+
.log();
202+
injector.getInstance(Key.get(ActorRef.class, Names.named("cluster-joiner")));
203+
199204
LOGGER.info()
200205
.setMessage("Launching http server")
201206
.log();

0 commit comments

Comments
 (0)