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();