/** * Returns the first partition group that matches the given primitive type. * * @param type the primitive type * @return the first partition group that matches the given primitive type */ @SuppressWarnings("unchecked") default PartitionGroup getPartitionGroup(PrimitiveProtocol.Type type) { return getPartitionGroups().stream() .filter(group -> group.protocol().name().equals(type.name())) .findFirst() .orElse(null); }
/** * Returns the primitive protocol. * * @return the primitive protocol */ protected PrimitiveProtocol protocol() { PrimitiveProtocol protocol = this.protocol; if (protocol == null) { PrimitiveProtocolConfig<?> protocolConfig = config.getProtocolConfig(); if (protocolConfig == null) { Collection<PartitionGroup> partitionGroups = managementService.getPartitionService().getPartitionGroups(); if (partitionGroups.size() == 1) { protocol = partitionGroups.iterator().next().newProtocol(); } else { String groups = Joiner.on(", ").join(partitionGroups.stream() .map(group -> group.name()) .collect(Collectors.toList())); throw new ConfigurationException(String.format("Primitive protocol is ambiguous: %d partition groups found (%s)", partitionGroups.size(), groups)); } } else { protocol = protocolConfig.getType().newProtocol(protocolConfig); } } return protocol; }
/** * Returns the first partition group that matches the given primitive protocol. * * @param protocol the primitive protocol * @return the first partition group that matches the given primitive protocol */ @SuppressWarnings("unchecked") default PartitionGroup getPartitionGroup(ProxyProtocol protocol) { if (protocol.group() != null) { PartitionGroup group = getPartitionGroup(protocol.group()); if (group != null) { return group; } PartitionGroup systemGroup = getSystemPartitionGroup(); if (systemGroup != null && systemGroup.name().equals(protocol.group())) { return systemGroup; } return null; } for (PartitionGroup partitionGroup : getPartitionGroups()) { if (partitionGroup.protocol().name().equals(protocol.type().name())) { return partitionGroup; } } return null; }