|
@@ -24,16 +24,20 @@ import java.util.concurrent.ConcurrentMap; |
|
|
|
|
|
|
|
|
import com.alibaba.csp.sentinel.util.AssertUtil; |
|
|
import com.alibaba.csp.sentinel.util.AssertUtil; |
|
|
|
|
|
|
|
|
import lombok.extern.log4j.Log4j; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @author leyou |
|
|
* @author leyou |
|
|
*/ |
|
|
*/ |
|
|
@Log4j |
|
|
|
|
|
@Component |
|
|
@Component |
|
|
public class SimpleMachineDiscovery implements MachineDiscovery { |
|
|
public class SimpleMachineDiscovery implements MachineDiscovery { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(SimpleMachineDiscovery.class); |
|
|
private final ConcurrentMap<String, AppInfo> apps = new ConcurrentHashMap<>(); |
|
|
private final ConcurrentMap<String, AppInfo> apps = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@@ -46,7 +50,7 @@ public class SimpleMachineDiscovery implements MachineDiscovery { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean removeMachine(String app, String ip, int port) { |
|
|
public boolean removeMachine(String app, String ip, int port) { |
|
|
log.debug("app is " + app); |
|
|
|
|
|
|
|
|
logger.info("app is " + app); |
|
|
AssertUtil.assertNotBlank(app, "app name cannot be blank"); |
|
|
AssertUtil.assertNotBlank(app, "app name cannot be blank"); |
|
|
AppInfo appInfo = apps.get(app); |
|
|
AppInfo appInfo = apps.get(app); |
|
|
if (appInfo != null) { |
|
|
if (appInfo != null) { |
|
@@ -59,20 +63,20 @@ public class SimpleMachineDiscovery implements MachineDiscovery { |
|
|
public List<String> getAppNames() { |
|
|
public List<String> getAppNames() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.debug("apps.keySet is " + apps.keySet()); |
|
|
|
|
|
|
|
|
logger.info("apps.keySet is " + apps.keySet()); |
|
|
return new ArrayList<>(apps.keySet()); |
|
|
return new ArrayList<>(apps.keySet()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public AppInfo getDetailApp(String app) { |
|
|
public AppInfo getDetailApp(String app) { |
|
|
log.debug("app is " + app); |
|
|
|
|
|
|
|
|
logger.info("app is " + app); |
|
|
AssertUtil.assertNotBlank(app, "app name cannot be blank"); |
|
|
AssertUtil.assertNotBlank(app, "app name cannot be blank"); |
|
|
return apps.get(app); |
|
|
return apps.get(app); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Set<AppInfo> getBriefApps() { |
|
|
public Set<AppInfo> getBriefApps() { |
|
|
log.debug("apps is " + apps.toString()); |
|
|
|
|
|
|
|
|
logger.info("apps is " + apps.toString()); |
|
|
return new HashSet<>(apps.values()); |
|
|
return new HashSet<>(apps.values()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|