io.vlingo.lattice.grid.GridAddressFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vlingo-lattice Show documentation
Show all versions of vlingo-lattice Show documentation
Tooling for reactive Domain-Driven Design projects that are highly concurrent. Includes compute grid, actor caching, spaces, cross-node cluster messaging, CQRS, and Event Sourcing support.
// 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.lattice.grid;
import java.util.UUID;
import io.vlingo.actors.Address;
import io.vlingo.actors.AddressFactory;
import io.vlingo.common.identity.IdentityGenerator;
import io.vlingo.common.identity.IdentityGeneratorType;
public final class GridAddressFactory implements AddressFactory {
private static final Address None = new GridAddress(null, "(none)");
private final IdentityGenerator generator;
private final IdentityGeneratorType type;
public GridAddressFactory(final IdentityGeneratorType type) {
this.type = type;
this.generator = this.type.generator();
}
@Override
public Address findableBy(final T id) {
return new GridAddress((UUID) id);
}
@Override
public Address from(final long reservedId, final String name) {
return new GridAddress(uuidFrom(reservedId), name);
}
@Override
public Address from(final String idString) {
return new GridAddress(UUID.fromString(idString));
}
@Override
public Address from(final String idString, final String name) {
return new GridAddress(UUID.fromString(idString), name);
}
@Override
public Address none() {
return None;
}
@Override
public Address unique() {
return new GridAddress(generator.generate());
}
@Override
public Address uniquePrefixedWith(final String prefixedWith) {
return new GridAddress(generator.generate(), prefixedWith, true);
}
@Override
public Address uniqueWith(final String name) {
return new GridAddress(generator.generate(name), name);
}
@Override
public Address withHighId() {
throw new UnsupportedOperationException("Unsupported for GridAddress.");
}
@Override
public Address withHighId(final String name) {
throw new UnsupportedOperationException("Unsupported for GridAddress.");
}
@Override
public long testNextIdValue() {
throw new UnsupportedOperationException("Unsupported for GridAddress.");
}
private UUID uuidFrom(final long id) {
return new UUID(Long.MAX_VALUE, id);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy