2020
2121package com .arangodb .internal .net ;
2222
23+ import java .util .Arrays ;
2324import java .util .Collection ;
2425import java .util .List ;
2526
27+ import org .slf4j .Logger ;
28+ import org .slf4j .LoggerFactory ;
29+
2630import com .arangodb .internal .util .HostUtils ;
2731
2832/**
2933 * @author Mark Vollmary
3034 *
3135 */
3236public class ExtendedHostResolver implements HostResolver {
37+
38+ private static final Logger LOGGER = LoggerFactory .getLogger (ExtendedHostResolver .class );
3339
3440 private static final long MAX_CACHE_TIME = 60 * 60 * 1000 ;
3541 private EndpointResolver resolver ;
@@ -54,22 +60,39 @@ public void init(final EndpointResolver resolver) {
5460
5561 @ Override
5662 public List <Host > resolve (final boolean initial , final boolean closeConnections ) {
63+
5764 if (!initial && isExpired ()) {
65+
5866 lastUpdate = System .currentTimeMillis ();
67+
5968 final Collection <String > endpoints = resolver .resolve (closeConnections );
69+ LOGGER .info ("Resolve " + endpoints .size () + " Endpoints" );
70+ LOGGER .debug ("Endpoints " + Arrays .deepToString (endpoints .toArray ()));
71+
72+
6073 if (!endpoints .isEmpty ()) {
6174 hosts .clear ();
6275 }
76+
6377 for (final String endpoint : endpoints ) {
78+ LOGGER .debug ("Create HOST from " + endpoint );
79+
6480 if (endpoint .matches (".*://.+:[0-9]+" )) {
81+
6582 final String [] s = endpoint .replaceAll (".*://" , "" ).split (":" );
6683 if (s .length == 2 ) {
6784 final HostDescription description = new HostDescription (s [0 ], Integer .valueOf (s [1 ]));
6885 hosts .add (HostUtils .createHost (description , maxConnections , connectionFactory ));
86+ } else {
87+ LOGGER .warn ("Skip Endpoint (Missung Port)" + endpoint );
6988 }
89+
90+ } else {
91+ LOGGER .warn ("Skip Endpoint (Format)" + endpoint );
7092 }
7193 }
7294 }
95+
7396 return hosts ;
7497 }
7598
0 commit comments