示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public java.util.Optional<org.neo4j.causalclustering.identity.MemberId> upstreamDatabase() throws org.neo4j.causalclustering.upstream.UpstreamDatabaseSelectionException
        public override Optional <MemberId> UpstreamDatabase()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.discovery.CoreTopology coreTopology = topologyService.localCoreServers();
            CoreTopology coreTopology = TopologyService.localCoreServers();

            if (coreTopology.Members().Count == 0)
            {
                throw new UpstreamDatabaseSelectionException("No core servers available");
            }

            int skippedServers = _random.Next(coreTopology.Members().Count);

            return(coreTopology.Members().Keys.Skip(skippedServers).First());
        }
示例#2
0
        private IList <Endpoint> RouteEndpoints(string dbName)
        {
            CoreTopology            filtered = _topologyService.allCoreServers().filterTopologyByDb(dbName);
            Stream <CoreServerInfo> filteredCoreMemberInfo = filtered.Members().Values.stream();

            return(filteredCoreMemberInfo.map(extractBoltAddress()).map(Endpoint.route).collect(Collectors.toList()));
        }
示例#3
0
        private IList <Endpoint> ReadEndpoints(CoreTopology coreTopology, ReadReplicaTopology rrTopology, Policy policy)
        {
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
            ISet <ServerInfo> possibleReaders = rrTopology.Members().SetOfKeyValuePairs().Select(entry => new ServerInfo(entry.Value.connectors().boltAddress(), entry.Key, entry.Value.groups())).collect(Collectors.toSet());

            if (_allowReadsOnFollowers || possibleReaders.Count == 0)
            {
                ISet <MemberId> validCores = coreTopology.Members().Keys;
                try
                {
                    MemberId leader = _leaderLocator.Leader;
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
                    validCores = validCores.Where(memberId => !memberId.Equals(leader)).collect(Collectors.toSet());
                }
                catch (NoLeaderFoundException)
                {
                    // we might end up using the leader for reading during this ttl, should be fine in general
                }

                foreach (MemberId validCore in validCores)
                {
                    Optional <CoreServerInfo> coreServerInfo = coreTopology.find(validCore);
                    coreServerInfo.ifPresent(coreServerInfo1 => possibleReaders.Add(new ServerInfo(coreServerInfo1.connectors().boltAddress(), validCore, coreServerInfo1.groups())));
                }
            }

            ISet <ServerInfo> readers = policy.Apply(possibleReaders);

            return(readers.Select(r => Endpoint.read(r.boltAddress())).ToList());
        }
示例#4
0
        public override RawIterator <object[], ProcedureException> Apply(Context ctx, object[] input, ResourceTracker resourceTracker)
        {
            IDictionary <MemberId, RoleInfo> roleMap   = _topologyService.allCoreRoles();
            IList <ReadWriteEndPoint>        endpoints = new List <ReadWriteEndPoint>();

            CoreTopology    coreTopology = _topologyService.allCoreServers();
            ISet <MemberId> coreMembers  = coreTopology.Members().Keys;

            foreach (MemberId memberId in coreMembers)
            {
                Optional <CoreServerInfo> coreServerInfo = coreTopology.find(memberId);
                if (coreServerInfo.Present)
                {
                    CoreServerInfo info = coreServerInfo.get();
                    RoleInfo       role = roleMap.getOrDefault(memberId, RoleInfo.UNKNOWN);
                    endpoints.Add(new ReadWriteEndPoint(info.Connectors(), role, memberId.Uuid, new IList <string> {
                        info.Groups()
                    }, info.DatabaseName));
                }
                else
                {
                    _log.debug("No Address found for " + memberId);
                }
            }

            foreach (KeyValuePair <MemberId, ReadReplicaInfo> readReplica in _topologyService.allReadReplicas().members().SetOfKeyValuePairs())
            {
                ReadReplicaInfo readReplicaInfo = readReplica.Value;
                endpoints.Add(new ReadWriteEndPoint(readReplicaInfo.Connectors(), RoleInfo.READ_REPLICA, readReplica.Key.Uuid, new IList <string> {
                    readReplicaInfo.Groups()
                }, readReplicaInfo.DatabaseName));
            }

            endpoints.sort(comparing(o => o.addresses().ToString()));

            return(map(endpoint => new object[] { endpoint.memberId().ToString(), endpoint.addresses().uriList().Select(URI.toString).ToList(), endpoint.role().name(), endpoint.groups(), endpoint.dbName() }, asRawIterator(endpoints.GetEnumerator())));
        }
示例#5
0
            public override Optional <MemberId> UpstreamDatabase()
            {
                CoreTopology coreTopology = TopologyService.allCoreServers();

                return(Optional.ofNullable(coreTopology.Members().Keys.GetEnumerator().next()));
            }
示例#6
0
 private IList <Endpoint> RouteEndpoints(CoreTopology cores)
 {
     return(cores.Members().Values.Select(extractBoltAddress()).Select(Endpoint.route).ToList());
 }