All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.dubbo.registry.pages.SubscribedPageHandler Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 1999-2011 Alibaba Group.
 *  
 * Licensed 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.registry.pages;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.container.page.Page;
import com.alibaba.dubbo.container.page.PageHandler;
import com.alibaba.dubbo.registry.Registry;
import com.alibaba.dubbo.registry.support.AbstractRegistry;
import com.alibaba.dubbo.registry.support.AbstractRegistryFactory;

/**
 * SubscribedPageHandler
 * 
 * @author william.liangf
 */
public class SubscribedPageHandler 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).getSubscribed().keySet();
            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", "Subscribed (" + rows.size() + ")",
                new String[] { "Consumer URL:" }, rows);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy