FileDocCategorySizeDatePackage
Main.javaAPI DocGlassfish v2 API6143Thu Jun 21 12:35:24 BST 2007com.sun.enterprise.web.connector.grizzly.standalone

Main

public class Main extends Object
Basic startup class used when Grizzly standalone is used
author
Jeanfrancois Arcand

Fields Summary
private static final String
SELECTOR_THREAD
System property for the SelectorThread value.
private static final String
ADAPTER
static int
port
static String
folder
Constructors Summary
public Main()

    
      
    
Methods Summary
private static java.lang.ObjectloadInstance(java.lang.String property)
Util to load classes using reflection.

        
        Class className = null;                               
        try{                              
            className = Class.forName(property,true,
                    Thread.currentThread().getContextClassLoader());
            return className.newInstance();
        } catch (Throwable t) {
            t.printStackTrace();
            // Log me 
        }   
        return null;
    
public static voidmain(java.lang.String[] args)

       
        Main main = new Main();        
        main.start(args);
    
private static voidstart(java.lang.String[] args)
Create a single Grizzly http listener.

        
        try{
            if ( args != null && args.length > 0) {
                port = Integer.parseInt(args[0]);
            }
        } catch (Exception ex){
            ex.printStackTrace();
        }
         
        try{
            if ( args != null && args.length > 1) {
                folder = args[1];
            }
        } catch (Exception ex){
            ex.printStackTrace();
        }       
  
        URL[] urls;
        File libDir = new File("lib");
        if (libDir.exists()){
            if (libDir.isDirectory()){
                String[] jars = libDir.list(new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        if (name.endsWith(".jar") || name.endsWith(".zip")){
                            return true;
                        } else {
                            return false;
                        }
                        
                    }
                });
                urls = new URL[jars.length];
                for (int i=0; i < jars.length; i++){
                   String path = new File("lib" + File.separator + jars[i])
                        .getCanonicalFile().toURL().toString();
                   urls[i] = new URL(path); 
                }
                URLClassLoader urlClassloader = new URLClassLoader(urls,
                        Main.class.getClassLoader());
                Thread.currentThread().setContextClassLoader(urlClassloader);
            }
        } else {
            System.out.println("lib folder is missing");
        }
        
        SelectorThread selectorThread = null;
        String selectorThreadClassname = System.getProperty(SELECTOR_THREAD);
        if ( selectorThreadClassname != null){
            selectorThread = (SelectorThread)loadInstance(selectorThreadClassname);
        } else {
            selectorThread = new SelectorThread();
            selectorThread
                    .setAlgorithmClassName(StaticStreamAlgorithm.class.getName());
        }        
        selectorThread.setPort(port);
        selectorThread.setWebAppRootPath(folder);
        
        String adapterClass =  System.getProperty(ADAPTER);
        Adapter adapter;
        if (adapterClass == null){
            adapter = new StaticResourcesAdapter();
        } else {
            adapter = (Adapter)loadInstance(adapterClass);
        }

        selectorThread.setAdapter(adapter);
        selectorThread.setDisplayConfiguration(true);
        selectorThread.initEndpoint();
        selectorThread.startEndpoint();