io.atomix.utils.serializer.Serializer Java Examples

The following examples show how to use io.atomix.utils.serializer.Serializer. 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: 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 #2
Source File: LogPartitionServer.java    From atomix with Apache License 2.0 6 votes vote down vote up
private DistributedLogServer buildServer() {
  return DistributedLogServer.builder()
      .withServerName(partition.name())
      .withMembershipService(managementService.getMembershipService())
      .withMemberGroupProvider(config.getMemberGroupProvider())
      .withProtocol(new LogServerCommunicator(
          partition.name(),
          Serializer.using(LogNamespaces.PROTOCOL),
          managementService.getMessagingService()))
      .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id()))
      .withStorageLevel(config.getStorageConfig().getLevel())
      .withDirectory(config.getStorageConfig().getDirectory(partition.name()))
      .withMaxSegmentSize((int) config.getStorageConfig().getSegmentSize().bytes())
      .withMaxEntrySize((int) config.getStorageConfig().getMaxEntrySize().bytes())
      .withFlushOnCommit(config.getStorageConfig().isFlushOnCommit())
      .withMaxLogSize(config.getCompactionConfig().getSize().bytes())
      .withMaxLogAge(config.getCompactionConfig().getAge())
      .withThreadContextFactory(threadFactory)
      .build();
}
 
Example #3
Source File: DefaultDistributedQueueBuilder.java    From atomix with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedQueue<E>> buildAsync() {
  return newProxy(DistributedQueueService.class, new ServiceConfig())
      .thenCompose(proxy -> new DistributedQueueProxy(proxy, managementService.getPrimitiveRegistry()).connect())
      .thenApply(rawQueue -> {
        Serializer serializer = serializer();
        AsyncDistributedQueue<E> queue = new TranscodingAsyncDistributedQueue<>(
            rawQueue,
            element -> BaseEncoding.base16().encode(serializer.encode(element)),
            string -> serializer.decode(BaseEncoding.base16().decode(string)));

        if (config.getCacheConfig().isEnabled()) {
          queue = new CachingAsyncDistributedQueue<>(queue, config.getCacheConfig());
        }

        if (config.isReadOnly()) {
          queue = new UnmodifiableAsyncDistributedQueue<>(queue);
        }
        return queue.sync();
      });
}
 
Example #4
Source File: RaftServiceManager.java    From atomix with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes a new service.
 */
@SuppressWarnings("unchecked")
private RaftServiceContext initializeService(PrimitiveId primitiveId, PrimitiveType primitiveType, String serviceName, byte[] config) {
  RaftServiceContext oldService = raft.getServices().getService(serviceName);
  ServiceConfig serviceConfig = config == null ? new ServiceConfig() : Serializer.using(primitiveType.namespace()).decode(config);
  RaftServiceContext service = new RaftServiceContext(
      primitiveId,
      serviceName,
      primitiveType,
      serviceConfig,
      primitiveType.newService(serviceConfig),
      raft,
      threadContextFactory);
  raft.getServices().registerService(service);

  // If a service with this name was already registered, remove all of its sessions.
  if (oldService != null) {
    raft.getSessions().removeSessions(oldService.serviceId());
  }
  return service;
}
 
Example #5
Source File: DefaultDistributedMultimapBuilder.java    From atomix with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedMultimap<K, V>> buildAsync() {
  return newProxy(AtomicMultimapService.class, new ServiceConfig())
      .thenCompose(proxy -> new AtomicMultimapProxy(proxy, managementService.getPrimitiveRegistry()).connect())
      .thenApply(rawMultimap -> {
        Serializer serializer = serializer();
        AsyncAtomicMultimap<K, V> multimap = new TranscodingAsyncAtomicMultimap<>(
            rawMultimap,
            key -> BaseEncoding.base16().encode(serializer.encode(key)),
            string -> serializer.decode(BaseEncoding.base16().decode(string)),
            value -> serializer.encode(value),
            bytes -> serializer.decode(bytes));
        if (config.getCacheConfig().isEnabled()) {
          multimap = new CachingAsyncAtomicMultimap<>(multimap, config.getCacheConfig());
        }
        return multimap;
      }).thenApply(atomicMultimap -> new DelegatingAsyncDistributedMultimap<>(atomicMultimap).sync());
}
 
Example #6
Source File: DefaultDistributedMultisetBuilder.java    From atomix with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<DistributedMultiset<E>> buildAsync() {
  return newProxy(DistributedMultisetService.class, new ServiceConfig())
      .thenCompose(proxy -> new DistributedMultisetProxy(proxy, managementService.getPrimitiveRegistry()).connect())
      .thenApply(rawList -> {
        Serializer serializer = serializer();
        AsyncDistributedMultiset<E> list = new TranscodingAsyncDistributedMultiset<>(
            rawList,
            element -> BaseEncoding.base16().encode(serializer.encode(element)),
            string -> serializer.decode(BaseEncoding.base16().decode(string)));

        if (config.getCacheConfig().isEnabled()) {
          list = new CachingAsyncDistributedMultiset<>(list, config.getCacheConfig());
        }

        if (config.isReadOnly()) {
          list = new UnmodifiableAsyncDistributedMultiset<>(list);
        }
        return list.sync();
      });
}
 
Example #7
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 #8
Source File: DefaultAtomicCounterMapBuilder.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<AtomicCounterMap<K>> buildAsync() {
  return newProxy(AtomicCounterMapService.class, new ServiceConfig())
      .thenCompose(proxy -> new AtomicCounterMapProxy(proxy, managementService.getPrimitiveRegistry()).connect())
      .thenApply(map -> {
        Serializer serializer = serializer();
        return new TranscodingAsyncAtomicCounterMap<K, String>(
            map,
            key -> BaseEncoding.base16().encode(serializer.encode(key)),
            string -> serializer.decode(BaseEncoding.base16().decode(string)))
            .sync();
      });
}
 
Example #9
Source File: DefaultAtomicSortedMapBuilder.java    From atomix with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<AtomicSortedMap<K, V>> buildAsync() {
  return newProxy(AtomicTreeMapService.class, new ServiceConfig())
      .thenCompose(proxy -> new AtomicNavigableMapProxy(proxy, managementService.getPrimitiveRegistry()).connect())
      .thenApply(map -> {
        Serializer serializer = serializer();
        return new TranscodingAsyncAtomicSortedMap<K, V, byte[]>(
            (AsyncAtomicSortedMap) map,
            value -> serializer.encode(value),
            bytes -> serializer.decode(bytes))
            .sync();
      });
}
 
Example #10
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 #11
Source File: LogProxySession.java    From atomix with Apache License 2.0 5 votes vote down vote up
LocalSession(
    SessionId sessionId,
    String primitiveName,
    PrimitiveType primitiveType,
    MemberId memberId,
    Serializer serializer) {
  super(sessionId, primitiveName, primitiveType, memberId, serializer);
}
 
Example #12
Source File: CrdtSetDelegate.java    From atomix with Apache License 2.0 5 votes vote down vote up
public CrdtSetDelegate(String name, Serializer serializer, CrdtProtocolConfig config, PrimitiveManagementService managementService) {
  this.clusterCommunicator = managementService.getCommunicationService();
  this.executorService = managementService.getExecutorService();
  this.elementSerializer = serializer;
  this.timestampProvider = config.getTimestampProvider();
  this.subject = String.format("atomix-crdt-set-%s", name);
  clusterCommunicator.subscribe(subject, SERIALIZER::decode, this::updateElements, executorService);
  broadcastFuture = executorService.scheduleAtFixedRate(
      this::broadcastElements, config.getGossipInterval().toMillis(), config.getGossipInterval().toMillis(), TimeUnit.MILLISECONDS);
}
 
Example #13
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 #14
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 #15
Source File: ValueBuilder.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the protocol serializer.
 *
 * @return the protocol serializer
 */
protected Serializer serializer() {
  if (serializer == null) {
    NamespaceConfig namespaceConfig = this.config.getNamespaceConfig();
    if (namespaceConfig == null) {
      namespaceConfig = new NamespaceConfig();
    }

    SerializerBuilder serializerBuilder = managementService.getSerializationService().newBuilder(name);
    serializerBuilder.withNamespace(new Namespace(namespaceConfig));

    if (config.isRegistrationRequired()) {
      serializerBuilder.withRegistrationRequired();
    }
    if (config.isCompatibleSerialization()) {
      serializerBuilder.withCompatibleSerialization();
    }

    if (config.getValueType() != null) {
      serializerBuilder.addType(config.getValueType());
    }
    if (!config.getExtraTypes().isEmpty()) {
      serializerBuilder.withTypes(config.getExtraTypes().toArray(new Class<?>[config.getExtraTypes().size()]));
    }

    serializer = serializerBuilder.build();
  }
  return serializer;
}
 
Example #16
Source File: LogPartitionClient.java    From atomix with Apache License 2.0 5 votes vote down vote up
private DistributedLogSessionClient newClient() {
  return DistributedLogSessionClient.builder()
      .withClientName(partition.name())
      .withPartitionId(partition.id())
      .withMembershipService(managementService.getMembershipService())
      .withProtocol(new LogClientCommunicator(
          partition.name(),
          Serializer.using(LogNamespaces.PROTOCOL),
          managementService.getMessagingService()))
      .withSessionIdProvider(() -> managementService.getSessionIdService().nextSessionId())
      .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id()))
      .withThreadContextFactory(threadFactory)
      .build();
}
 
Example #17
Source File: DistributedCollectionBuilder.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the protocol serializer.
 *
 * @return the protocol serializer
 */
protected Serializer serializer() {
  if (serializer == null) {
    NamespaceConfig namespaceConfig = this.config.getNamespaceConfig();
    if (namespaceConfig == null) {
      namespaceConfig = new NamespaceConfig();
    }

    SerializerBuilder serializerBuilder = managementService.getSerializationService().newBuilder(name);
    serializerBuilder.withNamespace(new Namespace(namespaceConfig));

    if (config.isRegistrationRequired()) {
      serializerBuilder.withRegistrationRequired();
    }
    if (config.isCompatibleSerialization()) {
      serializerBuilder.withCompatibleSerialization();
    }

    if (config.getElementType() != null) {
      serializerBuilder.addType(config.getElementType());
    }
    if (!config.getExtraTypes().isEmpty()) {
      serializerBuilder.withTypes(config.getExtraTypes().toArray(new Class<?>[config.getExtraTypes().size()]));
    }

    serializer = serializerBuilder.build();
  }
  return serializer;
}
 
Example #18
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 #19
Source File: LogProxySession.java    From atomix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public LogProxySession(String name, PrimitiveType type, Class<S> serviceType, ServiceConfig serviceConfig, Serializer serializer, LogSession session) {
  this.name = checkNotNull(name, "name cannot be null");
  this.type = checkNotNull(type, "type cannot be null");
  this.service = type.newService(serviceConfig);
  this.serviceConfig = serviceConfig;
  this.userSerializer = checkNotNull(serializer, "serializer cannot be null");
  this.session = checkNotNull(session, "session cannot be null");
  ServiceProxyHandler serviceProxyHandler = new ServiceProxyHandler(serviceType);
  S serviceProxy = (S) java.lang.reflect.Proxy.newProxyInstance(serviceType.getClassLoader(), new Class[]{serviceType}, serviceProxyHandler);
  proxy = new ServiceProxy<>(serviceProxy, serviceProxyHandler);
}
 
Example #20
Source File: AbstractSession.java    From atomix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected AbstractSession(
    SessionId sessionId,
    String primitiveName,
    PrimitiveType primitiveType,
    MemberId memberId,
    Serializer serializer) {
  this.sessionId = checkNotNull(sessionId);
  this.primitiveName = checkNotNull(primitiveName);
  this.primitiveType = checkNotNull(primitiveType);
  this.memberId = memberId;
  this.serializer = checkNotNull(serializer);
}
 
Example #21
Source File: DefaultAsyncDistributedLog.java    From atomix with Apache License 2.0 5 votes vote down vote up
public DefaultAsyncDistributedLog(String name, LogClient client, Serializer serializer) {
  this.name = checkNotNull(name);
  this.client = checkNotNull(client);
  this.serializer = checkNotNull(serializer);
  client.getPartitions().forEach(partition -> {
    DefaultAsyncDistributedLogPartition<E> logPartition = new DefaultAsyncDistributedLogPartition<>(this, partition, serializer);
    partitions.put(partition.partitionId().id(), logPartition);
    sortedPartitions.add(logPartition);
  });
}
 
Example #22
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 #23
Source File: DefaultServiceExecutor.java    From atomix with Apache License 2.0 5 votes vote down vote up
public DefaultServiceExecutor(ServiceContext context, Serializer serializer) {
  this.serializer = checkNotNull(serializer);
  this.context = checkNotNull(context);
  this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(PrimitiveService.class)
      .addValue(context.serviceId())
      .add("type", context.serviceType())
      .add("name", context.serviceName())
      .build());
}
 
Example #24
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 #25
Source File: RaftSession.java    From atomix with Apache License 2.0 5 votes vote down vote up
public RaftSession(
    SessionId sessionId,
    MemberId member,
    String name,
    PrimitiveType primitiveType,
    ReadConsistency readConsistency,
    long minTimeout,
    long maxTimeout,
    long lastUpdated,
    Serializer serializer,
    RaftServiceContext context,
    RaftContext server,
    ThreadContextFactory threadContextFactory) {
  super(sessionId, name, primitiveType, member, serializer);
  this.readConsistency = readConsistency;
  this.minTimeout = minTimeout;
  this.maxTimeout = maxTimeout;
  this.lastUpdated = lastUpdated;
  this.eventIndex = sessionId.id();
  this.completeIndex = sessionId.id();
  this.lastApplied = sessionId.id();
  this.protocol = server.getProtocol();
  this.context = context;
  this.server = server;
  this.eventExecutor = threadContextFactory.createContext();
  this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(Session.class)
      .addValue(sessionId)
      .add("type", context.serviceType())
      .add("name", context.serviceName())
      .build());
}
 
Example #26
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 #27
Source File: PrimaryBackupServiceContext.java    From atomix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public PrimaryBackupServiceContext(
    String serverName,
    PrimitiveId primitiveId,
    PrimitiveType primitiveType,
    PrimitiveDescriptor descriptor,
    ThreadContext threadContext,
    ClusterMembershipService clusterMembershipService,
    MemberGroupService memberGroupService,
    PrimaryBackupServerProtocol protocol,
    PrimaryElection primaryElection) {
  this.localMemberId = clusterMembershipService.getLocalMember().id();
  this.serverName = checkNotNull(serverName);
  this.primitiveId = checkNotNull(primitiveId);
  this.primitiveType = checkNotNull(primitiveType);
  this.serviceConfig = Serializer.using(primitiveType.namespace()).decode(descriptor.config());
  this.descriptor = checkNotNull(descriptor);
  this.service = primitiveType.newService(serviceConfig);
  this.threadContext = checkNotNull(threadContext);
  this.clusterMembershipService = checkNotNull(clusterMembershipService);
  this.memberGroupService = checkNotNull(memberGroupService);
  this.protocol = checkNotNull(protocol);
  this.primaryElection = checkNotNull(primaryElection);
  this.log = ContextualLoggerFactory.getLogger(getClass(), LoggerContext.builder(PrimitiveService.class)
      .addValue(serverName)
      .add("type", descriptor.type())
      .add("name", descriptor.name())
      .build());
  clusterMembershipService.addListener(membershipEventListener);
  primaryElection.addListener(primaryElectionListener);
}
 
Example #28
Source File: PrimaryBackupPartitionServer.java    From atomix with Apache License 2.0 5 votes vote down vote up
private PrimaryBackupServer buildServer() {
  return PrimaryBackupServer.builder()
      .withServerName(partition.name())
      .withMembershipService(managementService.getMembershipService())
      .withMemberGroupProvider(memberGroupProvider)
      .withProtocol(new PrimaryBackupServerCommunicator(
          partition.name(),
          Serializer.using(PrimaryBackupNamespaces.PROTOCOL),
          managementService.getMessagingService()))
      .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id()))
      .withPrimitiveTypes(managementService.getPrimitiveTypes())
      .withThreadContextFactory(threadFactory)
      .build();
}
 
Example #29
Source File: MapBuilder.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the protocol serializer.
 *
 * @return the protocol serializer
 */
protected Serializer serializer() {
  if (serializer == null) {
    NamespaceConfig namespaceConfig = this.config.getNamespaceConfig();
    if (namespaceConfig == null) {
      namespaceConfig = new NamespaceConfig();
    }

    SerializerBuilder serializerBuilder = managementService.getSerializationService().newBuilder(name);
    serializerBuilder.withNamespace(new Namespace(namespaceConfig));

    if (config.isRegistrationRequired()) {
      serializerBuilder.withRegistrationRequired();
    }
    if (config.isCompatibleSerialization()) {
      serializerBuilder.withCompatibleSerialization();
    }

    if (config.getKeyType() != null) {
      serializerBuilder.addType(config.getKeyType());
    }
    if (config.getValueType() != null) {
      serializerBuilder.addType(config.getValueType());
    }
    if (!config.getExtraTypes().isEmpty()) {
      serializerBuilder.withTypes(config.getExtraTypes().toArray(new Class<?>[config.getExtraTypes().size()]));
    }

    serializer = serializerBuilder.build();
  }
  return serializer;
}
 
Example #30
Source File: PrimaryBackupPartitionClient.java    From atomix with Apache License 2.0 5 votes vote down vote up
private PrimaryBackupClient newClient() {
  return PrimaryBackupClient.builder()
      .withClientName(partition.name())
      .withPartitionId(partition.id())
      .withMembershipService(managementService.getMembershipService())
      .withProtocol(new PrimaryBackupClientCommunicator(
          partition.name(),
          Serializer.using(PrimaryBackupNamespaces.PROTOCOL),
          managementService.getMessagingService()))
      .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id()))
      .withSessionIdProvider(managementService.getSessionIdService())
      .withThreadContextFactory(threadFactory)
      .build();
}