Skip to content

Commit

Permalink
Add atomic/distributed sorted map primitives.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuujo committed Jul 11, 2018
1 parent cadaa37 commit 9715ddb
Show file tree
Hide file tree
Showing 18 changed files with 689 additions and 5 deletions.
12 changes: 12 additions & 0 deletions core/src/main/java/io/atomix/core/Atomix.java
Expand Up @@ -35,8 +35,10 @@
import io.atomix.core.map.AtomicCounterMap;
import io.atomix.core.map.AtomicMap;
import io.atomix.core.map.AtomicNavigableMap;
import io.atomix.core.map.AtomicSortedMap;
import io.atomix.core.map.DistributedMap;
import io.atomix.core.map.DistributedNavigableMap;
import io.atomix.core.map.DistributedSortedMap;
import io.atomix.core.multimap.AtomicMultimap;
import io.atomix.core.multimap.DistributedMultimap;
import io.atomix.core.multiset.DistributedMultiset;
Expand Down Expand Up @@ -354,6 +356,11 @@ public <K, V> DistributedMap<K, V> getMap(String name) {
return primitives.getMap(name);
}

@Override
public <K extends Comparable<K>, V> DistributedSortedMap<K, V> getSortedMap(String name) {
return primitives.getSortedMap(name);
}

@Override
public <K extends Comparable<K>, V> DistributedNavigableMap<K, V> getNavigableMap(String name) {
return primitives.getNavigableMap(name);
Expand All @@ -374,6 +381,11 @@ public <V> AtomicDocumentTree<V> getAtomicDocumentTree(String name) {
return primitives.getAtomicDocumentTree(name);
}

@Override
public <K extends Comparable<K>, V> AtomicSortedMap<K, V> getAtomicSortedMap(String name) {
return primitives.getAtomicSortedMap(name);
}

@Override
public <K extends Comparable<K>, V> AtomicNavigableMap<K, V> getAtomicNavigableMap(String name) {
return primitives.getAtomicNavigableMap(name);
Expand Down
78 changes: 77 additions & 1 deletion core/src/main/java/io/atomix/core/PrimitivesService.java
Expand Up @@ -51,12 +51,18 @@
import io.atomix.core.map.AtomicNavigableMap;
import io.atomix.core.map.AtomicNavigableMapBuilder;
import io.atomix.core.map.AtomicNavigableMapType;
import io.atomix.core.map.AtomicSortedMap;
import io.atomix.core.map.AtomicSortedMapBuilder;
import io.atomix.core.map.AtomicSortedMapType;
import io.atomix.core.map.DistributedMap;
import io.atomix.core.map.DistributedMapBuilder;
import io.atomix.core.map.DistributedMapType;
import io.atomix.core.map.DistributedNavigableMap;
import io.atomix.core.map.DistributedNavigableMapBuilder;
import io.atomix.core.map.DistributedNavigableMapType;
import io.atomix.core.map.DistributedSortedMap;
import io.atomix.core.map.DistributedSortedMapBuilder;
import io.atomix.core.map.DistributedSortedMapType;
import io.atomix.core.multimap.AtomicMultimap;
import io.atomix.core.multimap.AtomicMultimapBuilder;
import io.atomix.core.multimap.AtomicMultimapType;
Expand Down Expand Up @@ -138,6 +144,31 @@ default <K, V> DistributedMapBuilder<K, V> mapBuilder(String name, PrimitiveProt
return primitiveBuilder(name, DistributedMapType.instance(), protocol);
}

/**
* Creates a new AtomicMapBuilder.
*
* @param name the primitive name
* @param <K> key type
* @param <V> value type
* @return builder for a tree map
*/
default <K extends Comparable<K>, V> DistributedSortedMapBuilder<K, V> sortedMapBuilder(String name) {
return primitiveBuilder(name, DistributedSortedMapType.instance());
}

/**
* Creates a new AtomicMapBuilder.
*
* @param name the primitive name
* @param protocol the primitive protocol
* @param <K> key type
* @param <V> value type
* @return builder for a tree map
*/
default <K extends Comparable<K>, V> DistributedSortedMapBuilder<K, V> sortedMapBuilder(String name, PrimitiveProtocol protocol) {
return primitiveBuilder(name, DistributedSortedMapType.instance(), protocol);
}

/**
* Creates a new AtomicMapBuilder.
*
Expand Down Expand Up @@ -236,6 +267,31 @@ default <V> AtomicDocumentTreeBuilder<V> atomicDocumentTreeBuilder(String name,
return primitiveBuilder(name, AtomicDocumentTreeType.instance(), protocol);
}

/**
* Creates a new {@code AtomicSortedMapBuilder}.
*
* @param name the primitive name
* @param <K> key type
* @param <V> value type
* @return builder for a async atomic tree map
*/
default <K extends Comparable<K>, V> AtomicSortedMapBuilder<K, V> atomicSortedMapBuilder(String name) {
return primitiveBuilder(name, AtomicSortedMapType.instance());
}

/**
* Creates a new {@code AtomicSortedMapBuilder}.
*
* @param name the primitive name
* @param protocol the primitive protocol
* @param <K> key type
* @param <V> value type
* @return builder for a async atomic tree map
*/
default <K extends Comparable<K>, V> AtomicSortedMapBuilder<K, V> atomicSortedMapBuilder(String name, PrimitiveProtocol protocol) {
return primitiveBuilder(name, AtomicSortedMapType.instance(), protocol);
}

/**
* Creates a new {@code AtomicNavigableMapBuilder}.
*
Expand Down Expand Up @@ -730,6 +786,16 @@ default TransactionBuilder transactionBuilder() {
*/
<K, V> DistributedMap<K, V> getMap(String name);

/**
* Creates a new DistributedSortedMap.
*
* @param name the primitive name
* @param <K> key type
* @param <V> value type
* @return a new distributed map
*/
<K extends Comparable<K>, V> DistributedSortedMap<K, V> getSortedMap(String name);

/**
* Creates a new DistributedNavigableMap.
*
Expand Down Expand Up @@ -770,7 +836,17 @@ default TransactionBuilder transactionBuilder() {
<V> AtomicDocumentTree<V> getAtomicDocumentTree(String name);

/**
* Creates a new {@code AtomicTreeMap}.
* Creates a new {@code AtomicSortedMap}.
*
* @param name the primitive name
* @param <K> key type
* @param <V> value type
* @return a new atomic tree map
*/
<K extends Comparable<K>, V> AtomicSortedMap<K, V> getAtomicSortedMap(String name);

/**
* Creates a new {@code AtomicNavigableMap}.
*
* @param name the primitive name
* @param <K> key type
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/io/atomix/core/impl/CorePrimitivesService.java
Expand Up @@ -45,10 +45,14 @@
import io.atomix.core.map.AtomicMapType;
import io.atomix.core.map.AtomicNavigableMap;
import io.atomix.core.map.AtomicNavigableMapType;
import io.atomix.core.map.AtomicSortedMap;
import io.atomix.core.map.AtomicSortedMapType;
import io.atomix.core.map.DistributedMap;
import io.atomix.core.map.DistributedMapType;
import io.atomix.core.map.DistributedNavigableMap;
import io.atomix.core.map.DistributedNavigableMapType;
import io.atomix.core.map.DistributedSortedMap;
import io.atomix.core.map.DistributedSortedMapType;
import io.atomix.core.multimap.AtomicMultimap;
import io.atomix.core.multimap.AtomicMultimapType;
import io.atomix.core.multimap.DistributedMultimap;
Expand Down Expand Up @@ -161,6 +165,11 @@ public <K, V> DistributedMap<K, V> getMap(String name) {
return getPrimitive(name, DistributedMapType.instance(), configService.getConfig(name));
}

@Override
public <K extends Comparable<K>, V> DistributedSortedMap<K, V> getSortedMap(String name) {
return getPrimitive(name, DistributedSortedMapType.instance(), configService.getConfig(name));
}

@Override
public <K extends Comparable<K>, V> DistributedNavigableMap<K, V> getNavigableMap(String name) {
return getPrimitive(name, DistributedNavigableMapType.instance(), configService.getConfig(name));
Expand All @@ -181,6 +190,11 @@ public <V> AtomicDocumentTree<V> getAtomicDocumentTree(String name) {
return getPrimitive(name, AtomicDocumentTreeType.instance(), configService.getConfig(name));
}

@Override
public <K extends Comparable<K>, V> AtomicSortedMap<K, V> getAtomicSortedMap(String name) {
return getPrimitive(name, AtomicSortedMapType.instance(), configService.getConfig(name));
}

@Override
public <K extends Comparable<K>, V> AtomicNavigableMap<K, V> getAtomicNavigableMap(String name) {
return getPrimitive(name, AtomicNavigableMapType.instance(), configService.getConfig(name));
Expand Down
Expand Up @@ -30,7 +30,7 @@
*/
public class AtomicNavigableMapType<K extends Comparable<K>, V>
implements PrimitiveType<AtomicNavigableMapBuilder<K, V>, AtomicNavigableMapConfig, AtomicNavigableMap<K, V>> {
private static final String NAME = "atomic-tree-map";
private static final String NAME = "atomic-navigable-map";
private static final AtomicNavigableMapType INSTANCE = new AtomicNavigableMapType();

/**
Expand Down
30 changes: 30 additions & 0 deletions core/src/main/java/io/atomix/core/map/AtomicSortedMapBuilder.java
@@ -0,0 +1,30 @@
/*
* Copyright 2016-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.map;

import io.atomix.primitive.PrimitiveBuilder;
import io.atomix.primitive.PrimitiveManagementService;

/**
* Builder for {@link AtomicSortedMap}.
*/
public abstract class AtomicSortedMapBuilder<K extends Comparable<K>, V>
extends PrimitiveBuilder<AtomicSortedMapBuilder<K, V>, AtomicSortedMapConfig, AtomicSortedMap<K, V>> {
public AtomicSortedMapBuilder(String name, AtomicSortedMapConfig config, PrimitiveManagementService managementService) {
super(AtomicSortedMapType.instance(), name, config, managementService);
}
}
29 changes: 29 additions & 0 deletions core/src/main/java/io/atomix/core/map/AtomicSortedMapConfig.java
@@ -0,0 +1,29 @@
/*
* 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.core.map;

import io.atomix.primitive.PrimitiveType;
import io.atomix.primitive.config.PrimitiveConfig;

/**
* Consistent sorted map configuration.
*/
public class AtomicSortedMapConfig extends PrimitiveConfig<AtomicSortedMapConfig> {
@Override
public PrimitiveType getType() {
return AtomicSortedMapType.instance();
}
}
79 changes: 79 additions & 0 deletions core/src/main/java/io/atomix/core/map/AtomicSortedMapType.java
@@ -0,0 +1,79 @@
/*
* 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.map;

import io.atomix.core.map.impl.DefaultAtomicNavigableMapService;
import io.atomix.core.map.impl.DefaultAtomicSortedMapBuilder;
import io.atomix.primitive.PrimitiveManagementService;
import io.atomix.primitive.PrimitiveType;
import io.atomix.primitive.service.PrimitiveService;
import io.atomix.primitive.service.ServiceConfig;
import io.atomix.utils.serializer.Namespace;

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

/**
* Consistent sorted map primitive type.
*/
public class AtomicSortedMapType<K extends Comparable<K>, V>
implements PrimitiveType<AtomicSortedMapBuilder<K, V>, AtomicSortedMapConfig, AtomicSortedMap<K, V>> {
private static final String NAME = "atomic-sortedf-map";
private static final AtomicSortedMapType INSTANCE = new AtomicSortedMapType();

/**
* Returns a new consistent tree map type.
*
* @param <K> the key type
* @param <V> the value type
* @return a new consistent tree map type
*/
@SuppressWarnings("unchecked")
public static <K extends Comparable<K>, V> AtomicSortedMapType<K, V> instance() {
return INSTANCE;
}

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

@Override
public Namespace namespace() {
return AtomicMapType.instance().namespace();
}

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

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

@Override
public AtomicSortedMapBuilder<K, V> newBuilder(String name, AtomicSortedMapConfig config, PrimitiveManagementService managementService) {
return new DefaultAtomicSortedMapBuilder<>(name, config, managementService);
}

@Override
public String toString() {
return toStringHelper(this)
.add("name", name())
.toString();
}
}
Expand Up @@ -26,7 +26,7 @@ public class DistributedNavigableMapConfig extends CachedPrimitiveConfig<Distrib

@Override
public PrimitiveType getType() {
return DistributedMapType.instance();
return DistributedNavigableMapType.instance();
}

/**
Expand Down
Expand Up @@ -29,7 +29,7 @@
* Distributed tree map primitive type.
*/
public class DistributedNavigableMapType<K extends Comparable<K>, V> implements PrimitiveType<DistributedNavigableMapBuilder<K, V>, DistributedNavigableMapConfig, DistributedNavigableMap<K, V>> {
private static final String NAME = "treemap";
private static final String NAME = "navigable-map";

private static final DistributedNavigableMapType INSTANCE = new DistributedNavigableMapType();

Expand Down

0 comments on commit 9715ddb

Please sign in to comment.