alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Jetty example source code file (WadiCluster.java)

This example Jetty source code file (WadiCluster.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Jetty tags/keywords

adminservicespace, adminservicespace, dispatcher, dispatcher, exception, exception, illegalargumentexception, net, network, override, string, string, tribesdispatcher, uri, uriendpoint, util, wadicluster

The Jetty WadiCluster.java source code

package org.mortbay.jetty.servlet.wadi;

import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;

import org.apache.catalina.tribes.Member;
import org.codehaus.wadi.core.reflect.base.DeclaredMemberFilter;
import org.codehaus.wadi.core.reflect.jdk.JDKClassIndexerRegistry;
import org.codehaus.wadi.group.Dispatcher;
import org.codehaus.wadi.group.DispatcherRegistry;
import org.codehaus.wadi.group.StaticDispatcherRegistry;
import org.codehaus.wadi.servicespace.admin.AdminServiceSpace;
import org.codehaus.wadi.tribes.TribesDispatcher;
import org.codehaus.wadi.web.impl.URIEndPoint;
import org.mortbay.component.AbstractLifeCycle;

public class WadiCluster extends AbstractLifeCycle
{

    private final String _clusterName;
    private final String _nodeName;
    private final URI _endPointURI;
    private final Collection<Member> _staticMembers;
    
    private Dispatcher _dispatcher;

    /**
     * Constructs a cluster having the specified details.
     * 
     * @param clusterName name of the cluster.
     * @param nodeName name of the node this cluster instance is running on
     * @param endPointURI base URL to use from other nodes to reach this node. This value is actually not used and you 
     * pretty much do not need to define a meaningful value; however, it must be a valid URI.
     * 
     * @throws Exception
     */
    public WadiCluster(String clusterName, String nodeName, String endPointURI) throws Exception {
        if (null == clusterName) {
            throw new IllegalArgumentException("clusterName is required");
        } else if (null == nodeName) {
            throw new IllegalArgumentException("nodeName is required");
        }
        _clusterName = clusterName;
        _nodeName = nodeName;
        _endPointURI = new URI(endPointURI);
        
        _staticMembers = new ArrayList<Member>();
    }

    public void addStaticMember(Member member)
    {
        _staticMembers.add(member);
    }

    public Dispatcher getDispatcher()
    {
        return _dispatcher;
    }
    
    public String getNodeName()
    {
        return _nodeName;
    }

    @Override
    protected void doStart() throws Exception {
        _dispatcher = newDispatcher();
        DispatcherRegistry dispatcherRegistry = new StaticDispatcherRegistry();
        dispatcherRegistry.register(_dispatcher);
        _dispatcher.start();
        
        AdminServiceSpace adminServiceSpace = new AdminServiceSpace(_dispatcher,
            new JDKClassIndexerRegistry(new DeclaredMemberFilter()));
        adminServiceSpace.start();
    }

    @Override
    protected void doStop() throws Exception {
        _dispatcher.stop();
    }
    
    protected Dispatcher newDispatcher()
    {
        return new TribesDispatcher(_clusterName, _nodeName, new URIEndPoint(_endPointURI), _staticMembers);
    }

}

Other Jetty examples (source code examples)

Here is a short list of links related to this Jetty WadiCluster.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.