Java Code Examples for io.atomix.utils.serializer.Serializer#using()

The following examples show how to use io.atomix.utils.serializer.Serializer#using() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAtomicMapService.java    From atomix with Apache License 2.0 6 votes vote down vote up
public AbstractAtomicMapService(PrimitiveType primitiveType) {
  super(primitiveType, AtomicMapClient.class);
  serializer = Serializer.using(Namespace.builder()
      .register(primitiveType.namespace())
      .register(SessionId.class)
      .register(TransactionId.class)
      .register(TransactionScope.class)
      .register(MapEntryValue.class)
      .register(MapEntryValue.Type.class)
      .register(new HashMap().keySet().getClass())
      .register(DefaultIterator.class)
      .register(LockContext.class)
      .register(LockHolder.class)
      .build());
  map = createMap();
}
 
Example 2
Source File: RaftSessionRegistryTest.java    From atomix with Apache License 2.0 6 votes vote down vote up
private RaftSession createSession(long sessionId) {
  RaftServiceContext context = mock(RaftServiceContext.class);
  when(context.serviceType()).thenReturn(TestPrimitiveType.instance());
  when(context.serviceName()).thenReturn("test");
  when(context.serviceId()).thenReturn(PrimitiveId.from(1));

  RaftContext server = mock(RaftContext.class);
  when(server.getProtocol()).thenReturn(mock(RaftServerProtocol.class));
  RaftServiceManager manager = mock(RaftServiceManager.class);
  when(manager.executor()).thenReturn(mock(ThreadContext.class));
  when(server.getServiceManager()).thenReturn(manager);

  return new RaftSession(
      SessionId.from(sessionId),
      MemberId.from("1"),
      "test",
      TestPrimitiveType.instance(),
      ReadConsistency.LINEARIZABLE,
      100,
      5000,
      System.currentTimeMillis(),
      Serializer.using(Namespaces.BASIC),
      context,
      server,
      mock(ThreadContextFactory.class));
}
 
Example 3
Source File: LogProxyClient.java    From atomix with Apache License 2.0 5 votes vote down vote up
public LogProxyClient(
    String name,
    PrimitiveType type,
    PrimitiveProtocol protocol,
    Class<S> serviceType,
    ServiceConfig serviceConfig,
    LogClient client) {
  super(name, type, protocol, createSessions(name, type, serviceType, serviceConfig, client.getPartitions()));
  this.client = client;
  this.serializer = Serializer.using(type.namespace());
}
 
Example 4
Source File: DefaultDistributedMultisetService.java    From atomix with Apache License 2.0 5 votes vote down vote up
public DefaultDistributedMultisetService() {
  super(DistributedMultisetType.instance(), HashMultiset.create());
  this.serializer = Serializer.using(Namespace.builder()
      .register(DistributedMultisetType.instance().namespace())
      .register(SessionId.class)
      .register(DefaultDistributedCollectionService.IteratorContext.class)
      .register(IteratorContext.class)
      .build());
}
 
Example 5
Source File: DefaultDistributedCollectionService.java    From atomix with Apache License 2.0 5 votes vote down vote up
protected DefaultDistributedCollectionService(PrimitiveType primitiveType, T collection) {
  super(primitiveType, DistributedCollectionClient.class);
  this.collection = collection;
  this.serializer = Serializer.using(Namespace.builder()
      .register(primitiveType.namespace())
      .register(SessionId.class)
      .register(IteratorContext.class)
      .build());
}
 
Example 6
Source File: DefaultDistributedListService.java    From atomix with Apache License 2.0 5 votes vote down vote up
public DefaultDistributedListService() {
  super(DistributedListType.instance(), Collections.synchronizedList(new ArrayList<>()));
  this.serializer = Serializer.using(Namespace.builder()
      .register(DistributedListType.instance().namespace())
      .register(SessionId.class)
      .register(DefaultDistributedCollectionService.IteratorContext.class)
      .register(IteratorContext.class)
      .build());
}
 
Example 7
Source File: DefaultDistributedNavigableSetService.java    From atomix with Apache License 2.0 5 votes vote down vote up
public DefaultDistributedNavigableSetService() {
  super(DistributedNavigableSetType.instance(), new ConcurrentSkipListSet<>());
  this.serializer = Serializer.using(Namespace.builder()
      .register(DistributedNavigableSetType.instance().namespace())
      .register(SessionId.class)
      .register(IteratorContext.class)
      .register(SubSetIteratorContext.class)
      .register(DescendingIteratorContext.class)
      .register(DescendingSubSetIteratorContext.class)
      .build());
}
 
Example 8
Source File: AbstractAtomicNavigableMapService.java    From atomix with Apache License 2.0 5 votes vote down vote up
public AbstractAtomicNavigableMapService(PrimitiveType primitiveType) {
  super(primitiveType);
  serializer = Serializer.using(Namespace.builder()
      .register(AtomicNavigableMapType.instance().namespace())
      .register(SessionId.class)
      .register(TransactionId.class)
      .register(TransactionScope.class)
      .register(MapEntryValue.class)
      .register(MapEntryValue.Type.class)
      .register(new HashMap().keySet().getClass())
      .register(DefaultIterator.class)
      .register(AscendingIterator.class)
      .register(DescendingIterator.class)
      .build());
}
 
Example 9
Source File: RaftPartition.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Raft client.
 */
private RaftPartitionClient createClient(PartitionManagementService managementService) {
  return new RaftPartitionClient(
      this,
      managementService.getMembershipService().getLocalMember().id(),
      new RaftClientCommunicator(
          name(),
          Serializer.using(RaftNamespaces.RAFT_PROTOCOL),
          managementService.getMessagingService()),
      threadContextFactory);
}
 
Example 10
Source File: DefaultServiceExecutorTest.java    From atomix with Apache License 2.0 5 votes vote down vote up
private ServiceExecutor executor() {
  ServiceContext context = mock(ServiceContext.class);
  when(context.serviceId()).thenReturn(PrimitiveId.from(1));
  when(context.serviceType()).thenReturn(TestPrimitiveType.instance());
  when(context.serviceName()).thenReturn("test");
  when(context.currentOperation()).thenReturn(OperationType.COMMAND);
  return new DefaultServiceExecutor(context, Serializer.using(Namespaces.BASIC));
}
 
Example 11
Source File: DefaultPartitionGroupMembershipService.java    From atomix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public DefaultPartitionGroupMembershipService(
    ClusterMembershipService membershipService,
    ClusterCommunicationService messagingService,
    ManagedPartitionGroup systemGroup,
    Collection<ManagedPartitionGroup> groups,
    PartitionGroupTypeRegistry groupTypeRegistry) {
  this.membershipService = membershipService;
  this.messagingService = messagingService;
  this.systemGroup = systemGroup != null
      ? new PartitionGroupMembership(
      systemGroup.name(),
      systemGroup.config(),
      ImmutableSet.of(membershipService.getLocalMember().id()), true) : null;
  groups.forEach(group -> {
    this.groups.put(group.name(), new PartitionGroupMembership(
        group.name(),
        group.config(),
        ImmutableSet.of(membershipService.getLocalMember().id()), false));
  });

  Namespace.Builder namespaceBuilder = Namespace.builder()
      .register(Namespaces.BASIC)
      .register(MemberId.class)
      .register(PartitionGroupMembership.class)
      .register(PartitionGroupInfo.class)
      .register(PartitionGroupConfig.class)
      .register(MemberGroupStrategy.class);

  List<PartitionGroup.Type> groupTypes = Lists.newArrayList(groupTypeRegistry.getGroupTypes());
  groupTypes.sort(Comparator.comparing(PartitionGroup.Type::name));
  for (PartitionGroup.Type groupType : groupTypes) {
    namespaceBuilder.register(groupType.namespace());
  }

  serializer = Serializer.using(namespaceBuilder.build());
}
 
Example 12
Source File: DefaultProxyClient.java    From atomix with Apache License 2.0 5 votes vote down vote up
private static <S> Collection<ProxySession<S>> createSessions(
    PrimitiveType primitiveType, Class<S> serviceType, Collection<SessionClient> partitions) {
  Serializer serializer = Serializer.using(primitiveType.namespace());
  return partitions.stream()
      .map(partition -> new DefaultProxySession<>(partition, serviceType, serializer))
      .collect(Collectors.toList());
}
 
Example 13
Source File: DefaultProxyClient.java    From atomix with Apache License 2.0 5 votes vote down vote up
public DefaultProxyClient(
    String name,
    PrimitiveType type,
    PrimitiveProtocol protocol,
    Class<S> serviceType,
    Collection<SessionClient> partitions,
    Partitioner<String> partitioner) {
  super(name, type, protocol, createSessions(type, serviceType, partitions));
  this.partitioner = checkNotNull(partitioner);
  this.serializer = Serializer.using(type.namespace());
}
 
Example 14
Source File: LogProxyClient.java    From atomix with Apache License 2.0 5 votes vote down vote up
private static <S> Collection<ProxySession<S>> createSessions(
    String name,
    PrimitiveType primitiveType,
    Class<S> serviceType,
    ServiceConfig serviceConfig,
    Collection<LogSession> partitions) {
  Serializer serializer = Serializer.using(primitiveType.namespace());
  return partitions.stream()
      .map(partition -> new LogProxySession<S>(name, primitiveType, serviceType, serviceConfig, serializer, partition))
      .collect(Collectors.toList());
}
 
Example 15
Source File: AtomixClusterManager.java    From atomix-vertx with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new Vert.x compatible serializer.
 */
private Serializer createSerializer() {
  return Serializer.using(Namespace.builder()
      .setRegistrationRequired(false)
      .register(Namespaces.BASIC)
      .register(ServerID.class)
      .register(new ClusterSerializableSerializer<>(), ClusterSerializable.class)
      .build());
}
 
Example 16
Source File: RaftTest.java    From atomix with Apache License 2.0 4 votes vote down vote up
@Override
public Serializer serializer() {
  return Serializer.using(TestPrimitiveType.INSTANCE.namespace());
}
 
Example 17
Source File: AbstractPrimitiveService.java    From atomix with Apache License 2.0 4 votes vote down vote up
protected AbstractPrimitiveService(PrimitiveType primitiveType, Class<C> clientInterface) {
  this.primitiveType = primitiveType;
  this.clientInterface = clientInterface;
  this.serializer = Serializer.using(primitiveType.namespace());
}
 
Example 18
Source File: RaftStorage.java    From atomix with Apache License 2.0 2 votes vote down vote up
/**
 * Opens a new {@link MetaStore}, recovering metadata from disk if it exists.
 * <p>
 * The meta store will be loaded using based on the configured {@link StorageLevel}. If the storage level is persistent
 * then the meta store will be loaded from disk, otherwise a new meta store will be created.
 *
 * @return The metastore.
 */
public MetaStore openMetaStore() {
  return new MetaStore(this, Serializer.using(namespace));
}