io.vlingo.directory.model.DirectoryService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vlingo-directory Show documentation
Show all versions of vlingo-directory Show documentation
Service registration and discovery for the vlingo/platform.
// Copyright © 2012-2020 VLINGO LABS. All rights reserved.
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL
// was not distributed with this file, You can obtain
// one at https://mozilla.org/MPL/2.0/.
package io.vlingo.directory.model;
import io.vlingo.actors.ActorInstantiator;
import io.vlingo.actors.Definition;
import io.vlingo.actors.Stage;
import io.vlingo.actors.Startable;
import io.vlingo.actors.Stoppable;
import io.vlingo.cluster.model.attribute.AttributesProtocol;
import io.vlingo.wire.multicast.Group;
import io.vlingo.wire.node.Node;
public interface DirectoryService extends Startable, Stoppable {
public static DirectoryService instance(
final Stage stage,
final Node localNode) {
final Network network =
new Network(
new Group(Properties.instance.directoryGroupAddress(), Properties.instance.directoryGroupPort()),
Properties.instance.directoryIncomingPort());
final int maxMessageSize = Properties.instance.directoryMessageBufferSize();
final Timing timing =
new Timing(
Properties.instance.directoryMessageProcessingInterval(),
Properties.instance.directoryMessagePublishingInterval());
final int unpublishedNotifications = Properties.instance.directoryUnregisteredServiceNotifications();
final DirectoryService directoryService =
DirectoryService.instance(
stage,
localNode,
network,
maxMessageSize,
timing,
unpublishedNotifications);
return directoryService;
}
public static DirectoryService instance(
final Stage stage,
final Node localNode,
final Network network,
final int maxMessageSize,
final Timing timing,
final int unpublishedNotifications) {
final Definition definition =
Definition.has(
DirectoryServiceActor.class,
new DirectoryServiceInstantiator(localNode, network, maxMessageSize, timing, unpublishedNotifications),
"vlingo-directory-service");
return stage.actorFor(DirectoryService.class, definition);
}
public void assignLeadership();
public void relinquishLeadership();
public void use(final AttributesProtocol client);
public static class Network {
public final Group publisherGroup;
public final int incomingPort;
public Network(final Group publisherGroup, final int incomingPort) {
this.publisherGroup = publisherGroup;
this.incomingPort = incomingPort;
}
}
public static class Timing {
public final int processingInterval;
public final int publishingInterval;
public Timing(final int processingInterval, final int publishingInterval) {
this.processingInterval = processingInterval;
this.publishingInterval = publishingInterval;
}
}
static class DirectoryServiceInstantiator implements ActorInstantiator {
private static final long serialVersionUID = -5865652881873161440L;
private final Node localNode;
private final Network network;
private final int maxMessageSize;
private final Timing timing;
private final int unpublishedNotifications;
public DirectoryServiceInstantiator(
final Node localNode,
final Network network,
final int maxMessageSize,
final Timing timing,
final int unpublishedNotifications) {
this.localNode = localNode;
this.network = network;
this.maxMessageSize = maxMessageSize;
this.timing = timing;
this.unpublishedNotifications = unpublishedNotifications;
}
@Override
public DirectoryServiceActor instantiate() {
try {
return new DirectoryServiceActor(localNode, network, maxMessageSize, timing, unpublishedNotifications);
} catch (Throwable e) {
throw new IllegalArgumentException("Failed to instantiate " + type() + " because: " + e.getMessage(), e);
}
}
@Override
public Class type() {
return DirectoryServiceActor.class;
}
}
}