Skip to content

Commit

Permalink
Replace concrete tree set primitive with abstract sorted/navigable se…
Browse files Browse the repository at this point in the history
…t primitives.
  • Loading branch information
kuujo committed Jul 11, 2018
1 parent 9f84d57 commit 8692633
Show file tree
Hide file tree
Showing 27 changed files with 477 additions and 271 deletions.
13 changes: 9 additions & 4 deletions core/src/main/java/io/atomix/core/Atomix.java
Expand Up @@ -45,16 +45,16 @@
import io.atomix.core.queue.DistributedQueue; import io.atomix.core.queue.DistributedQueue;
import io.atomix.core.semaphore.AtomicSemaphore; import io.atomix.core.semaphore.AtomicSemaphore;
import io.atomix.core.semaphore.DistributedSemaphore; import io.atomix.core.semaphore.DistributedSemaphore;
import io.atomix.core.set.DistributedNavigableSet;
import io.atomix.core.set.DistributedSet; import io.atomix.core.set.DistributedSet;
import io.atomix.core.set.DistributedTreeSet; import io.atomix.core.set.DistributedSortedSet;
import io.atomix.core.transaction.TransactionBuilder; import io.atomix.core.transaction.TransactionBuilder;
import io.atomix.core.transaction.TransactionService; import io.atomix.core.transaction.TransactionService;
import io.atomix.core.tree.AtomicDocumentTree; import io.atomix.core.tree.AtomicDocumentTree;
import io.atomix.core.utils.config.PolymorphicConfigMapper; import io.atomix.core.utils.config.PolymorphicConfigMapper;
import io.atomix.core.utils.config.PolymorphicTypeMapper; import io.atomix.core.utils.config.PolymorphicTypeMapper;
import io.atomix.core.value.AtomicValue; import io.atomix.core.value.AtomicValue;
import io.atomix.core.workqueue.WorkQueue; import io.atomix.core.workqueue.WorkQueue;
import io.atomix.primitive.DistributedPrimitive;
import io.atomix.primitive.PrimitiveBuilder; import io.atomix.primitive.PrimitiveBuilder;
import io.atomix.primitive.PrimitiveInfo; import io.atomix.primitive.PrimitiveInfo;
import io.atomix.primitive.PrimitiveType; import io.atomix.primitive.PrimitiveType;
Expand Down Expand Up @@ -395,8 +395,13 @@ public <E> DistributedSet<E> getSet(String name) {
} }


@Override @Override
public <E extends Comparable<E>> DistributedTreeSet<E> getTreeSet(String name) { public <E extends Comparable<E>> DistributedSortedSet<E> getSortedSet(String name) {
return primitives.getTreeSet(name); return primitives.getSortedSet(name);
}

@Override
public <E extends Comparable<E>> DistributedNavigableSet<E> getNavigableSet(String name) {
return primitives.getNavigableSet(name);
} }


@Override @Override
Expand Down
63 changes: 49 additions & 14 deletions core/src/main/java/io/atomix/core/PrimitivesService.java
Expand Up @@ -75,12 +75,15 @@
import io.atomix.core.semaphore.DistributedSemaphore; import io.atomix.core.semaphore.DistributedSemaphore;
import io.atomix.core.semaphore.DistributedSemaphoreBuilder; import io.atomix.core.semaphore.DistributedSemaphoreBuilder;
import io.atomix.core.semaphore.DistributedSemaphoreType; import io.atomix.core.semaphore.DistributedSemaphoreType;
import io.atomix.core.set.DistributedNavigableSet;
import io.atomix.core.set.DistributedNavigableSetBuilder;
import io.atomix.core.set.DistributedNavigableSetType;
import io.atomix.core.set.DistributedSet; import io.atomix.core.set.DistributedSet;
import io.atomix.core.set.DistributedSetBuilder; import io.atomix.core.set.DistributedSetBuilder;
import io.atomix.core.set.DistributedSetType; import io.atomix.core.set.DistributedSetType;
import io.atomix.core.set.DistributedTreeSet; import io.atomix.core.set.DistributedSortedSet;
import io.atomix.core.set.DistributedTreeSetBuilder; import io.atomix.core.set.DistributedSortedSetBuilder;
import io.atomix.core.set.DistributedTreeSetType; import io.atomix.core.set.DistributedSortedSetType;
import io.atomix.core.transaction.TransactionBuilder; import io.atomix.core.transaction.TransactionBuilder;
import io.atomix.core.tree.AtomicDocumentTree; import io.atomix.core.tree.AtomicDocumentTree;
import io.atomix.core.tree.AtomicDocumentTreeBuilder; import io.atomix.core.tree.AtomicDocumentTreeBuilder;
Expand Down Expand Up @@ -330,26 +333,49 @@ default <E> DistributedSetBuilder<E> setBuilder(String name, PrimitiveProtocol p
} }


/** /**
* Creates a new DistributedTreeSetBuilder. * Creates a new DistributedSortedSetBuilder.
* *
* @param name the primitive name * @param name the primitive name
* @param <E> set element type * @param <E> set element type
* @return builder for an distributed set * @return builder for a distributed set
*/ */
default <E extends Comparable<E>> DistributedTreeSetBuilder<E> treeSetBuilder(String name) { default <E extends Comparable<E>> DistributedSortedSetBuilder<E> sortedSetBuilder(String name) {
return primitiveBuilder(name, DistributedTreeSetType.instance()); return primitiveBuilder(name, DistributedSortedSetType.instance());
} }


/** /**
* Creates a new DistributedTreeSetBuilder. * Creates a new DistributedSortedSetBuilder.
* *
* @param name the primitive name * @param name the primitive name
* @param protocol the primitive protocol * @param protocol the primitive protocol
* @param <E> set element type * @param <E> set element type
* @return builder for an distributed set * @return builder for a distributed set
*/
default <E extends Comparable<E>> DistributedSortedSetBuilder<E> sortedSetBuilder(String name, PrimitiveProtocol protocol) {
return primitiveBuilder(name, DistributedSortedSetType.instance(), protocol);
}

/**
* Creates a new DistributedNavigableSetBuilder.
*
* @param name the primitive name
* @param <E> set element type
* @return builder for a distributed set
*/ */
default <E extends Comparable<E>> DistributedTreeSetBuilder<E> treeSetBuilder(String name, PrimitiveProtocol protocol) { default <E extends Comparable<E>> DistributedNavigableSetBuilder<E> navigableSetBuilder(String name) {
return primitiveBuilder(name, DistributedTreeSetType.instance(), protocol); return primitiveBuilder(name, DistributedNavigableSetType.instance());
}

/**
* Creates a new DistributedNavigableSetBuilder.
*
* @param name the primitive name
* @param protocol the primitive protocol
* @param <E> set element type
* @return builder for a distributed set
*/
default <E extends Comparable<E>> DistributedNavigableSetBuilder<E> navigableSetBuilder(String name, PrimitiveProtocol protocol) {
return primitiveBuilder(name, DistributedNavigableSetType.instance(), protocol);
} }


/** /**
Expand Down Expand Up @@ -782,13 +808,22 @@ default TransactionBuilder transactionBuilder() {
<E> DistributedSet<E> getSet(String name); <E> DistributedSet<E> getSet(String name);


/** /**
* Creates a new DistributedTreeSet. * Creates a new DistributedSortedSet.
*
* @param name the primitive name
* @param <E> set element type
* @return a multiton instance of a distributed sorted set
*/
<E extends Comparable<E>> DistributedSortedSet<E> getSortedSet(String name);

/**
* Creates a new DistributedNavigableSet.
* *
* @param name the primitive name * @param name the primitive name
* @param <E> set element type * @param <E> set element type
* @return a multiton instance of a distributed tree set * @return a multiton instance of a distributed navigable set
*/ */
<E extends Comparable<E>> DistributedTreeSet<E> getTreeSet(String name); <E extends Comparable<E>> DistributedNavigableSet<E> getNavigableSet(String name);


/** /**
* Creates a new DistributedQueue. * Creates a new DistributedQueue.
Expand Down
15 changes: 11 additions & 4 deletions core/src/main/java/io/atomix/core/impl/CorePrimitivesService.java
Expand Up @@ -61,10 +61,12 @@
import io.atomix.core.semaphore.AtomicSemaphoreType; import io.atomix.core.semaphore.AtomicSemaphoreType;
import io.atomix.core.semaphore.DistributedSemaphore; import io.atomix.core.semaphore.DistributedSemaphore;
import io.atomix.core.semaphore.DistributedSemaphoreType; import io.atomix.core.semaphore.DistributedSemaphoreType;
import io.atomix.core.set.DistributedNavigableSet;
import io.atomix.core.set.DistributedNavigableSetType;
import io.atomix.core.set.DistributedSet; import io.atomix.core.set.DistributedSet;
import io.atomix.core.set.DistributedSetType; import io.atomix.core.set.DistributedSetType;
import io.atomix.core.set.DistributedTreeSet; import io.atomix.core.set.DistributedSortedSet;
import io.atomix.core.set.DistributedTreeSetType; import io.atomix.core.set.DistributedSortedSetType;
import io.atomix.core.transaction.ManagedTransactionService; import io.atomix.core.transaction.ManagedTransactionService;
import io.atomix.core.transaction.TransactionBuilder; import io.atomix.core.transaction.TransactionBuilder;
import io.atomix.core.transaction.TransactionConfig; import io.atomix.core.transaction.TransactionConfig;
Expand Down Expand Up @@ -200,8 +202,13 @@ public <E> DistributedSet<E> getSet(String name) {
} }


@Override @Override
public <E extends Comparable<E>> DistributedTreeSet<E> getTreeSet(String name) { public <E extends Comparable<E>> DistributedSortedSet<E> getSortedSet(String name) {
return getPrimitive(name, DistributedTreeSetType.instance(), configService.getConfig(name)); return getPrimitive(name, DistributedSortedSetType.instance(), configService.getConfig(name));
}

@Override
public <E extends Comparable<E>> DistributedNavigableSet<E> getNavigableSet(String name) {
return getPrimitive(name, DistributedNavigableSetType.instance(), configService.getConfig(name));
} }


@Override @Override
Expand Down
@@ -0,0 +1,31 @@
/*
* Copyright 2015-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.set;

import io.atomix.core.collection.DistributedCollectionBuilder;
import io.atomix.primitive.PrimitiveManagementService;

/**
* Builder for distributed navigable set.
*
* @param <E> type set elements.
*/
public abstract class DistributedNavigableSetBuilder<E extends Comparable<E>>
extends DistributedCollectionBuilder<DistributedNavigableSetBuilder<E>, DistributedNavigableSetConfig, DistributedNavigableSet<E>, E> {
public DistributedNavigableSetBuilder(String name, DistributedNavigableSetConfig config, PrimitiveManagementService managementService) {
super(DistributedNavigableSetType.instance(), name, config, managementService);
}
}
Expand Up @@ -15,17 +15,15 @@
*/ */
package io.atomix.core.set; package io.atomix.core.set;


import java.time.Duration; import io.atomix.core.collection.DistributedCollectionConfig;
import io.atomix.primitive.PrimitiveType;


/** /**
* Asynchronous distributed tree set. * Distributed navigable set configuration.
*/ */
public interface AsyncDistributedTreeSet<E extends Comparable<E>> extends AsyncDistributedNavigableSet<E> { public class DistributedNavigableSetConfig extends DistributedCollectionConfig<DistributedNavigableSetConfig> {
@Override @Override
default DistributedTreeSet<E> sync() { public PrimitiveType getType() {
return sync(Duration.ofMillis(DEFAULT_OPERATION_TIMEOUT_MILLIS)); return DistributedNavigableSetType.instance();
} }

@Override
DistributedTreeSet<E> sync(Duration operationTimeout);
} }
111 changes: 111 additions & 0 deletions core/src/main/java/io/atomix/core/set/DistributedNavigableSetType.java
@@ -0,0 +1,111 @@
/*
* Copyright 2017-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.set;

import io.atomix.core.collection.CollectionEvent;
import io.atomix.core.collection.impl.CollectionUpdateResult;
import io.atomix.core.iterator.impl.IteratorBatch;
import io.atomix.core.set.impl.DefaultDistributedNavigableSetBuilder;
import io.atomix.core.set.impl.DefaultDistributedNavigableSetService;
import io.atomix.core.set.impl.DistributedSetResource;
import io.atomix.core.set.impl.SetUpdate;
import io.atomix.core.transaction.TransactionId;
import io.atomix.core.transaction.TransactionLog;
import io.atomix.core.transaction.impl.CommitResult;
import io.atomix.core.transaction.impl.PrepareResult;
import io.atomix.core.transaction.impl.RollbackResult;
import io.atomix.primitive.PrimitiveManagementService;
import io.atomix.primitive.PrimitiveType;
import io.atomix.primitive.resource.PrimitiveResource;
import io.atomix.primitive.service.PrimitiveService;
import io.atomix.primitive.service.ServiceConfig;
import io.atomix.utils.serializer.Namespace;
import io.atomix.utils.serializer.Namespaces;

import static com.google.common.base.MoreObjects.toStringHelper;

/**
* Distributed navigable set primitive type.
*/
public class DistributedNavigableSetType<E extends Comparable<E>> implements PrimitiveType<DistributedNavigableSetBuilder<E>, DistributedNavigableSetConfig, DistributedNavigableSet<E>> {
private static final String NAME = "navigable-set";
private static final DistributedNavigableSetType INSTANCE = new DistributedNavigableSetType();

/**
* Returns a new distributed set type.
*
* @param <E> the set element type
* @return a new distributed set type
*/
@SuppressWarnings("unchecked")
public static <E extends Comparable<E>> DistributedNavigableSetType<E> instance() {
return INSTANCE;
}

@Override
public String name() {
return NAME;
}

@Override
public Namespace namespace() {
return Namespace.builder()
.register(PrimitiveType.super.namespace())
.register(Namespaces.BASIC)
.nextId(Namespaces.BEGIN_USER_CUSTOM_ID)
.register(CollectionUpdateResult.class)
.register(CollectionUpdateResult.Status.class)
.register(CollectionEvent.class)
.register(CollectionEvent.Type.class)
.register(IteratorBatch.class)
.register(TransactionId.class)
.register(TransactionLog.class)
.register(SetUpdate.class)
.register(SetUpdate.Type.class)
.register(PrepareResult.class)
.register(CommitResult.class)
.register(RollbackResult.class)
.build();
}

@Override
public PrimitiveService newService(ServiceConfig config) {
return new DefaultDistributedNavigableSetService<>();
}

@Override
@SuppressWarnings("unchecked")
public PrimitiveResource newResource(DistributedNavigableSet<E> primitive) {
return new DistributedSetResource((AsyncDistributedSet<String>) primitive.async());
}

@Override
public DistributedNavigableSetConfig newConfig() {
return new DistributedNavigableSetConfig();
}

@Override
public DistributedNavigableSetBuilder<E> newBuilder(String name, DistributedNavigableSetConfig config, PrimitiveManagementService managementService) {
return new DefaultDistributedNavigableSetBuilder<>(name, config, managementService);
}

@Override
public String toString() {
return toStringHelper(this)
.add("name", name())
.toString();
}
}
Expand Up @@ -19,13 +19,13 @@
import io.atomix.primitive.PrimitiveManagementService; import io.atomix.primitive.PrimitiveManagementService;


/** /**
* Builder for distributed tree set. * Builder for distributed sorted set.
* *
* @param <E> type set elements. * @param <E> type set elements.
*/ */
public abstract class DistributedTreeSetBuilder<E extends Comparable<E>> public abstract class DistributedSortedSetBuilder<E extends Comparable<E>>
extends DistributedCollectionBuilder<DistributedTreeSetBuilder<E>, DistributedTreeSetConfig, DistributedTreeSet<E>, E> { extends DistributedCollectionBuilder<DistributedSortedSetBuilder<E>, DistributedSortedSetConfig, DistributedSortedSet<E>, E> {
public DistributedTreeSetBuilder(String name, DistributedTreeSetConfig config, PrimitiveManagementService managementService) { public DistributedSortedSetBuilder(String name, DistributedSortedSetConfig config, PrimitiveManagementService managementService) {
super(DistributedTreeSetType.instance(), name, config, managementService); super(DistributedSortedSetType.instance(), name, config, managementService);
} }
} }
Expand Up @@ -19,11 +19,11 @@
import io.atomix.primitive.PrimitiveType; import io.atomix.primitive.PrimitiveType;


/** /**
* Distributed tree set configuration. * Distributed sorted set configuration.
*/ */
public class DistributedTreeSetConfig extends DistributedCollectionConfig<DistributedTreeSetConfig> { public class DistributedSortedSetConfig extends DistributedCollectionConfig<DistributedSortedSetConfig> {
@Override @Override
public PrimitiveType getType() { public PrimitiveType getType() {
return DistributedTreeSetType.instance(); return DistributedNavigableSetType.instance();
} }
} }

0 comments on commit 8692633

Please sign in to comment.