/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.alibaba.dubbo.monitor.simple.pages; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.monitor.simple.common.Page; import com.alibaba.dubbo.monitor.simple.servlet.PageHandler; import com.alibaba.dubbo.registry.Registry; import com.alibaba.dubbo.registry.support.AbstractRegistry; import com.alibaba.dubbo.registry.support.AbstractRegistryFactory; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; /** * RegisteredPageHandler */ public class RegisteredPageHandler implements PageHandler { public Page handle(URL url) { String registryAddress = url.getParameter("registry", ""); List> rows = new ArrayList>(); Collection registries = AbstractRegistryFactory.getRegistries(); StringBuilder select = new StringBuilder(); Registry registry = null; if (registries != null && registries.size() > 0) { if (registries.size() == 1) { registry = registries.iterator().next(); select.append(" > " + registry.getUrl().getAddress()); } else { select.append(" > "); } } if (registry instanceof AbstractRegistry) { Set services = ((AbstractRegistry) registry).getRegistered(); if (services != null && services.size() > 0) { for (URL u : services) { List row = new ArrayList(); row.add(u.toFullString().replace("<", "<").replace(">", ">")); rows.add(row); } } } return new Page("Registries" + select.toString() + " > Registered | Subscribed", "Registered (" + rows.size() + ")", new String[]{"Provider URL:"}, rows); } }