private TResult Balance <TResult>(Func <ISolrOperations <T>, TResult> operation, bool leader = false) { var attempt = 0; while (attempt++ < maxAttempts) { var replica = clusterBalancer.Balance(usableReplicas, leader); if (replica == null) { throw new ApplicationException("No appropriate replica was selected to perform the operation."); } Debug.WriteLine("using replica " + replica.Name); var operations = operationsProvider.GetOperations <T>(replica.Url); if (operations == null) { throw new ApplicationException("Operation provider returned null."); } try { return(operation(operations)); } catch (Exception exception) { // todo: possibly deactivate zombie node when status is not 401, 500 exceptionHandlers.Handle(exception); } } throw new ApplicationException("Atempts limit was depleted."); }
private bool Update() { try { if (zooKeeper == null) { zooKeeper = new ZooKeeper(zooKeeperConnection, TimeSpan.FromSeconds(10), this); } Collections = SolrClusterStateParser.ParseJsonToCollections( Encoding.Default.GetString( zooKeeper.GetData("/clusterstate.json", true, null))); return(true); } catch (Exception exception) { exceptionHandlers.Handle(exception); } return(false); }