wms-winstone-1.0.5

16:54:38.231 INFO  jd.cli.Main - Decompiling wms-winstone-1.0.5.jar
package net.winstone.accesslog;

import net.winstone.core.WinstoneRequest;
import net.winstone.core.WinstoneResponse;

public abstract interface AccessLogger
{
  public abstract void log(String paramString, WinstoneRequest paramWinstoneRequest, WinstoneResponse paramWinstoneResponse);
}

/* Location:
 * Qualified Name:     net.winstone.accesslog.AccessLogger
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.accesslog;

public abstract interface AccessLoggerProvider
{
  public abstract AccessLogger getAccessLogger(String paramString1, String paramString2, PatternType paramPatternType, String paramString3);
  
  public abstract void destroy(AccessLogger paramAccessLogger);
}

/* Location:
 * Qualified Name:     net.winstone.accesslog.AccessLoggerProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.accesslog;

class AccessLoggerProviderFactory$1 {}

/* Location:
 * Qualified Name:     net.winstone.accesslog.AccessLoggerProviderFactory.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.accesslog;

class AccessLoggerProviderFactory$AccessLoggerProviderFactoryHolder
{
  private static AccessLoggerProviderFactory loggerFactory = new AccessLoggerProviderFactory(null);
}

/* Location:
 * Qualified Name:     net.winstone.accesslog.AccessLoggerProviderFactory.AccessLoggerProviderFactoryHolder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.accesslog;

import java.util.Iterator;
import java.util.ServiceLoader;

public final class AccessLoggerProviderFactory
{
  private final AccessLoggerProvider provider;
  
  private static class AccessLoggerProviderFactoryHolder
  {
    private static AccessLoggerProviderFactory loggerFactory = new AccessLoggerProviderFactory(null);
  }
  
  public static AccessLogger getAccessLogger(String host, String webapp, PatternType patternType, String filePattern)
  {
    return loggerFactoryprovider.getAccessLogger(host, webapp, patternType, filePattern);
  }
  
  public static void destroy(AccessLogger accessLogger)
  {
    loggerFactoryprovider.destroy(accessLogger);
  }
  
  private AccessLoggerProviderFactory()
  {
    ServiceLoader<AccessLoggerProvider> loader = ServiceLoader.load(AccessLoggerProvider.class);
    Iterator<AccessLoggerProvider> iterator = loader.iterator();
    AccessLoggerProvider accessLoggerProvider = null;
    while ((accessLoggerProvider == null) && (iterator.hasNext())) {
      try
      {
        accessLoggerProvider = (AccessLoggerProvider)iterator.next();
      }
      catch (Throwable e) {}
    }
    if (accessLoggerProvider == null) {
      throw new Error("No Access Logger Provider registered");
    }
    provider = accessLoggerProvider;
  }
}

/* Location:
 * Qualified Name:     net.winstone.accesslog.AccessLoggerProviderFactory
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.accesslog;

public enum PatternType
{
  COMMON("###ip### - ###user### ###time### \"###uriLine###\" ###status### ###size###"),  COMBINED("###ip### - ###user### ###time### \"###uriLine###\" ###status### ###size### \"###referer###\" \"###userAgent###\""),  RESIN("###ip### - ###user### ###time### \"###uriLine###\" ###status### ###size### \"###userAgent###\"");
  
  private final String pattern;
  
  private PatternType(String pattern)
  {
    this.pattern = pattern;
  }
  
  public final String getPattern()
  {
    return pattern;
  }
}

/* Location:
 * Qualified Name:     net.winstone.accesslog.PatternType
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.accesslog;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import net.winstone.core.WinstoneOutputStream;
import net.winstone.core.WinstoneRequest;
import net.winstone.core.WinstoneResponse;
import net.winstone.util.DateCache;
import net.winstone.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class SimpleAccessLogger
  implements AccessLogger
{
  protected Logger logger = LoggerFactory.getLogger(getClass());
  private final DateCache dateCache;
  private final String pattern;
  private PrintWriter outWriter;
  
  SimpleAccessLogger(String host, String webapp, PatternType patternType, String filePattern)
  {
    dateCache = new DateCache(new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss Z"));
    pattern = patternType.getPattern();
    String fileName = StringUtils.replace(filePattern, new String[][] { { "###host###", host }, { "###webapp###", webapp } });
    
    File file = new File(fileName);
    file.getParentFile().mkdirs();
    try
    {
      outWriter = new PrintWriter(new FileOutputStream(file, Boolean.TRUE.booleanValue()), Boolean.TRUE.booleanValue());
    }
    catch (FileNotFoundException e)
    {
      logger.error("Unable to open " + fileName, e);
    }
    logger.info(String.format("Initialized access log at %s (format: %s)", new Object[] { fileName, patternType }));
  }
  
  public void log(String originalURL, WinstoneRequest request, WinstoneResponse response)
  {
    if (outWriter == null) {
      return;
    }
    String uriLine = request.getMethod() + " " + originalURL + " " + request.getProtocol();
    int status = response.getErrorStatusCode() == null ? response.getStatus() : response.getErrorStatusCode().intValue();
    long size = response.getWinstoneOutputStream().getBytesCommitted();
    String date = dateCache.now();
    String logLine = StringUtils.replace(pattern, new String[][] { { "###ip###", request.getRemoteHost() }, { "###user###", nvl(request.getRemoteUser()) }, { "###time###", "[" + date + "]" }, { "###uriLine###", uriLine }, { "###status###", "" + status }, { "###size###", "" + size }, { "###referer###", nvl(request.getHeader("Referer")) }, { "###userAgent###", nvl(request.getHeader("User-Agent")) } });
    
    outWriter.println(logLine);
  }
  
  private static String nvl(String input)
  {
    return input == null ? "-" : input;
  }
  
  public void destroy()
  {
    logger.info("Closed access log");
    if (outWriter != null)
    {
      outWriter.flush();
      outWriter.close();
      outWriter = null;
    }
  }
}

/* Location:
 * Qualified Name:     net.winstone.accesslog.SimpleAccessLogger
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.accesslog;

public final class SimpleAccessLoggerProvider
  implements AccessLoggerProvider
{
  public void destroy(AccessLogger accessLogger)
  {
    if ((accessLogger != null) && 
      ((accessLogger instanceof SimpleAccessLogger))) {
      ((SimpleAccessLogger)accessLogger).destroy();
    }
  }
  
  public AccessLogger getAccessLogger(String host, String webapp, PatternType patternType, String filePattern)
  {
    return new SimpleAccessLogger(host, webapp, patternType, filePattern);
  }
}

/* Location:
 * Qualified Name:     net.winstone.accesslog.SimpleAccessLoggerProvider
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.boot;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import net.winstone.Server;
import net.winstone.WinstoneResourceBundle;
import net.winstone.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BootStrap
{
  protected static Logger logger = LoggerFactory.getLogger(BootStrap.class);
  private static final String EMBEDDED_WAR = "/embedded.war";
  private static final String WS_EMBEDDED_WAR = "winstoneEmbeddedWebroot";
  private static final String EMBEDDED_PROPERTIES = "/embedded.properties";
  private static final String WINSTONE_PROPERTIES = "winstone.properties";
  private final String[] argv;
  private final Map<String, String> arguments;
  private String usage;
  
  public BootStrap(String[] argv)
  {
    this.argv = (argv == null ? new String[0] : argv);
    arguments = null;
  }
  
  public BootStrap(Map<String, String> arguments)
  {
    argv = null;
    this.arguments = arguments;
  }
  
  public Server boot()
  {
    Server server = null;
    
    logger.info("stage 1/3: Loading arguments...");
    Map<String, String> args = arguments;
    if (args == null)
    {
      args = loadArgs("nonSwitch");
      
      String firstNonSwitchArgument = (String)args.get("nonSwitch");
      args.remove("nonSwitch");
      if (firstNonSwitchArgument != null)
      {
        File webapp = new File(firstNonSwitchArgument);
        if (webapp.exists()) {
          if (webapp.isDirectory()) {
            args.put("webroot", firstNonSwitchArgument);
          } else if (webapp.isFile()) {
            args.put("warfile", firstNonSwitchArgument);
          }
        }
      }
    }
    if ((args.containsKey("usage")) || (args.containsKey("help")))
    {
      printUsage();
      return server;
    }
    logger.info("stage 2/3: Loading WebApplication configuration...");
    if (deployEmbeddedWarfile(args))
    {
      logger.info("embedded file was found");
    }
    else if ((!args.containsKey("webroots")) && (!args.containsKey("webroot")) && (!args.containsKey("warfile")) && (!args.containsKey("webappsDir")) && (!args.containsKey("hostsDir")))
    {
      printUsage();
      return server;
    }
    logger.info("stage 3/3: compute JSP classpath...");
    computeJSPClassPath(args);
    return new Server(args);
  }
  
  private void computeJSPClassPath(Map<String, String> args)
  {
    String javaHome = StringUtils.stringArg(args, "javaHome", null);
    if (javaHome != null) {
      logger.warn("argument --javaHome is deprecated. Set JAVA_HOME variable instead.");
    }
    String toolsJar = StringUtils.stringArg(args, "toolsJar", null);
    if (toolsJar != null) {
      logger.warn("argument --toolsJar is deprecated. Default is JAVA_HOME/lib/tools.jar, or in the winstone server libraries.");
    }
    String commonLibFolder = StringUtils.stringArg(args, "commonLibFolder", null);
    if (commonLibFolder != null) {
      logger.warn("argument --commonLibFolder is deprecated. See --Bootstrap.extraLibrariesFolderPath.");
    }
    try
    {
      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      URLClassLoader loader = (URLClassLoader)classLoader;
      URL[] urls = loader.getURLs();
      logger.debug("Initializing JSP Common Lib classloader: {}", urls.toString());
      StringBuilder cp = new StringBuilder();
      for (URL url : urls) {
        cp.append(new File(url.getFile()).getCanonicalPath()).append(File.pathSeparatorChar);
      }
      String jspClasspath = cp.length() > 0 ? cp.substring(0, cp.length() - 1) : "";
      if (!args.containsKey("jspClasspath")) {
        args.put("jspClasspath", jspClasspath);
      }
    }
    catch (IOException ex)
    {
      logger.error("computeClassPath", ex);
    }
  }
  
  public Map<String, String> loadArgs(String nonSwitchArgName)
  {
    Map<String, String> args = new HashMap();
    
    String embeddedPropertiesFilename = "/embedded.properties";
    InputStream embeddedPropsStream = BootStrap.class.getResourceAsStream("/embedded.properties");
    if (embeddedPropsStream != null) {
      try
      {
        loadPropsFromStream(embeddedPropsStream, args);
        embeddedPropsStream.close();
      }
      catch (IOException ex)
      {
        logger.error("loadArgs", ex);
      }
    }
    String configFilename = "winstone.properties";
    for (int n = 0; n < argv.length; n++)
    {
      String option = argv[n];
      if (option.startsWith("--"))
      {
        int equalPos = option.indexOf('=');
        String paramName = option.substring(2, equalPos == -1 ? option.length() : equalPos);
        if (equalPos != -1) {
          args.put(paramName, option.substring(equalPos + 1));
        } else {
          args.put(paramName, "Boolean.TRUE");
        }
        if (paramName.equals("config")) {
          configFilename = (String)args.get(paramName);
        }
      }
      else
      {
        args.put(nonSwitchArgName, option);
      }
    }
    File configFile = new File(configFilename);
    if ((configFile.exists()) && (configFile.isFile()))
    {
      logger.debug("Property file found ({}) - loading", configFilename);
      try
      {
        InputStream inConfig = new FileInputStream(configFile);
        loadPropsFromStream(inConfig, args);
        inConfig.close();
      }
      catch (IOException ex)
      {
        logger.error("loadArgs", ex);
      }
    }
    return args;
  }
  
  private void loadPropsFromStream(InputStream inConfig, Map<String, String> args)
    throws IOException
  {
    Properties props = new Properties();
    props.load(inConfig);
    for (Iterator<Object> i = props.keySet().iterator(); i.hasNext();)
    {
      String key = ((String)i.next()).trim();
      if (!args.containsKey(key)) {
        args.put(key, props.getProperty(key));
      }
    }
    props.clear();
  }
  
  private boolean deployEmbeddedWarfile(Map<String, String> args)
  {
    boolean result = Boolean.FALSE.booleanValue();
    InputStream embeddedWarfile = BootStrap.class.getResourceAsStream("/embedded.war");
    if (embeddedWarfile != null) {
      try
      {
        File tempWarfile = File.createTempFile("embedded", ".war").getAbsoluteFile();
        tempWarfile.getParentFile().mkdirs();
        tempWarfile.deleteOnExit();
        
        File tempWebroot = new File(tempWarfile.getParentFile(), "winstoneEmbeddedWebroot");
        tempWebroot.mkdirs();
        logger.debug("Extracting embedded warfile to {}", tempWarfile.getAbsolutePath());
        OutputStream out = new FileOutputStream(tempWarfile, Boolean.TRUE.booleanValue());
        int read = 0;
        byte[] buffer = new byte['?'];
        while ((read = embeddedWarfile.read(buffer)) != -1) {
          out.write(buffer, 0, read);
        }
        out.close();
        embeddedWarfile.close();
        
        args.put("warfile", tempWarfile.getAbsolutePath());
        args.put("webroot", tempWebroot.getAbsolutePath());
        args.remove("webappsDir");
        args.remove("hostsDir");
        result = Boolean.TRUE.booleanValue();
      }
      catch (IOException e)
      {
        logger.error("deployEmbeddedWarfile", e);
      }
    }
    return result;
  }
  
  private void printUsage()
  {
    if (usage == null) {
      usage = WinstoneResourceBundle.getInstance().getString("UsageInstructions", new String[] { WinstoneResourceBundle.getInstance().getString("ServerVersion") });
    }
    System.out.println(usage);
  }
  
  public final String getUsage()
  {
    return usage;
  }
  
  public final void setUsage(String usage)
  {
    this.usage = usage;
  }
}

/* Location:
 * Qualified Name:     net.winstone.boot.BootStrap
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.boot;

public enum Command
{
  SHUTDOWN((byte)48),  RELOAD((byte)52);
  
  private final byte code;
  
  private Command(byte code)
  {
    this.code = code;
  }
  
  public byte getCode()
  {
    return code;
  }
}

/* Location:
 * Qualified Name:     net.winstone.boot.Command
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.boot;

public class ServerConfigurationParser {}

/* Location:
 * Qualified Name:     net.winstone.boot.ServerConfigurationParser
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.boot;

import net.winstone.Server;

public class ShutdownHook
  extends Thread
{
  private Server server;
  
  public ShutdownHook(Server server)
  {
    this.server = server;
  }
  
  public void run()
  {
    if (server != null)
    {
      server.info("JVM is terminating. Shutting down Winstone");
      
      server.shutdown();
      server = null;
    }
  }
}

/* Location:
 * Qualified Name:     net.winstone.boot.ShutdownHook
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.cluster;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import net.winstone.core.HostGroup;
import net.winstone.core.WebAppConfiguration;
import net.winstone.core.WinstoneSession;

public abstract interface Cluster
{
  public abstract void destroy();
  
  public abstract WinstoneSession askClusterForSession(String paramString, WebAppConfiguration paramWebAppConfiguration);
  
  public abstract void clusterRequest(byte paramByte, InputStream paramInputStream, OutputStream paramOutputStream, Socket paramSocket, HostGroup paramHostGroup)
    throws IOException;
}

/* Location:
 * Qualified Name:     net.winstone.cluster.Cluster
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.cluster;

import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import net.winstone.core.WinstoneSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class ClusterSessionSearch
  implements Runnable
{
  protected Logger logger = LoggerFactory.getLogger(getClass());
  final int TIMEOUT = 2000;
  public static final byte SESSION_CHECK_TYPE = 49;
  public static final String SESSION_NOT_FOUND = "NOTFOUND";
  public static final String SESSION_FOUND = "FOUND";
  public static final String SESSION_RECEIVED = "OK";
  private boolean started;
  private boolean isFinished;
  private WinstoneSession result;
  private final String searchWebAppHostname;
  private final String searchWebAppPrefix;
  private final String searchId;
  private final String searchAddressPort;
  private final int controlPort;
  
  public ClusterSessionSearch(String webAppPrefix, String hostName, String sessionId, String ipPort, int controlPort)
  {
    isFinished = Boolean.FALSE.booleanValue();
    searchWebAppHostname = hostName;
    searchWebAppPrefix = webAppPrefix;
    searchId = sessionId;
    searchAddressPort = ipPort;
    result = null;
    this.controlPort = controlPort;
    started = Boolean.FALSE.booleanValue();
  }
  
  public void start()
  {
    if (!started)
    {
      started = Boolean.TRUE.booleanValue();
      Thread searchThread = new Thread(this);
      searchThread.setDaemon(Boolean.TRUE.booleanValue());
      searchThread.start();
    }
  }
  
  public void run()
  {
    try
    {
      int colonPos = searchAddressPort.indexOf(':');
      String ipAddress = searchAddressPort.substring(0, colonPos);
      String port = searchAddressPort.substring(colonPos + 1);
      
      Socket controlConnection = new Socket(ipAddress, Integer.parseInt(port));
      controlConnection.setSoTimeout(2000);
      OutputStream out = controlConnection.getOutputStream();
      out.write(49);
      out.flush();
      
      ObjectOutputStream outControl = new ObjectOutputStream(out);
      outControl.writeInt(controlPort);
      outControl.writeUTF(searchId);
      outControl.writeUTF(searchWebAppHostname);
      outControl.writeUTF(searchWebAppPrefix);
      outControl.flush();
      InputStream in = controlConnection.getInputStream();
      ObjectInputStream inSession = new ObjectInputStream(in);
      String reply = inSession.readUTF();
      if ((reply != null) && (reply.equals("FOUND")))
      {
        WinstoneSession session = (WinstoneSession)inSession.readObject();
        outControl.writeUTF("OK");
        result = session;
      }
      outControl.close();
      inSession.close();
      out.close();
      in.close();
      controlConnection.close();
    }
    catch (Throwable err)
    {
      logger.warn("Error during cluster session search", err);
    }
    isFinished = Boolean.TRUE.booleanValue();
    started = Boolean.FALSE.booleanValue();
  }
  
  public boolean isFinished()
  {
    return isFinished;
  }
  
  public boolean isStarted()
  {
    return started;
  }
  
  public WinstoneSession getResult()
  {
    return result;
  }
  
  public void destroy() {}
  
  public String getAddressPort()
  {
    return searchAddressPort;
  }
}

/* Location:
 * Qualified Name:     net.winstone.cluster.ClusterSessionSearch
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.cluster;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import net.winstone.core.HostConfiguration;
import net.winstone.core.HostGroup;
import net.winstone.core.WebAppConfiguration;
import net.winstone.core.WinstoneSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class SimpleCluster
  implements Runnable, Cluster
{
  protected Logger logger = LoggerFactory.getLogger(getClass());
  final int SESSION_CHECK_TIMEOUT = 100;
  final int HEARTBEAT_PERIOD = 5000;
  final int MAX_NO_OF_MISSING_HEARTBEATS = 3;
  final byte NODELIST_DOWNLOAD_TYPE = 50;
  final byte NODE_HEARTBEAT_TYPE = 51;
  private int controlPort;
  private final String initialClusterNodes;
  private final Map<String, Date> clusterAddresses;
  private boolean interrupted;
  
  public SimpleCluster(Map<String, String> args, Integer controlPort)
  {
    interrupted = Boolean.FALSE.booleanValue();
    clusterAddresses = new HashMap();
    if (controlPort != null) {
      this.controlPort = controlPort.intValue();
    }
    initialClusterNodes = ((String)args.get("clusterNodes"));
    Thread thread = new Thread(this, "Cluster monitor thread");
    thread.setDaemon(Boolean.TRUE.booleanValue());
    thread.setPriority(1);
    thread.start();
  }
  
  public void destroy()
  {
    interrupted = Boolean.TRUE.booleanValue();
  }
  
  public void run()
  {
    if (initialClusterNodes != null)
    {
      StringTokenizer st = new StringTokenizer(initialClusterNodes, ",");
      while ((st.hasMoreTokens()) && (!interrupted)) {
        askClusterNodeForNodeList(st.nextToken());
      }
    }
    logger.info("Cluster initialised with {} nodes", Integer.toString(clusterAddresses.size()));
    while (!interrupted) {
      try
      {
        Set<String> addresses = new HashSet(clusterAddresses.keySet());
        Date noHeartbeatDate = new Date(System.currentTimeMillis() - 15000L);
        for (Iterator<String> i = addresses.iterator(); i.hasNext();)
        {
          String ipPort = (String)i.next();
          
          Date lastHeartBeat = (Date)clusterAddresses.get(ipPort);
          if (lastHeartBeat.before(noHeartbeatDate))
          {
            clusterAddresses.remove(ipPort);
            logger.debug("Removing address from cluster node list: {}", ipPort);
          }
          else
          {
            sendHeartbeat(ipPort);
          }
        }
        Thread.sleep(5000L);
      }
      catch (Throwable err)
      {
        logger.error("Error in cluster monitor thread", err);
      }
    }
    logger.info("Cluster monitor thread finished");
  }
  
  public WinstoneSession askClusterForSession(String sessionId, WebAppConfiguration webAppConfig)
  {
    Collection<String> addresses = new ArrayList(clusterAddresses.keySet());
    Collection<ClusterSessionSearch> searchThreads = new ArrayList();
    for (Iterator<String> i = addresses.iterator(); i.hasNext();)
    {
      String ipPort = (String)i.next();
      ClusterSessionSearch search = new ClusterSessionSearch(webAppConfig.getContextPath(), webAppConfig.getOwnerHostname(), sessionId, ipPort, controlPort);
      search.start();
      searchThreads.add(search);
    }
    WinstoneSession answer = null;
    String senderThread = null;
    boolean finished = Boolean.FALSE.booleanValue();
    while (!finished)
    {
      List<ClusterSessionSearch> finishedThreads = new ArrayList();
      for (Iterator<ClusterSessionSearch> i = searchThreads.iterator(); i.hasNext();)
      {
        ClusterSessionSearch searchThread = (ClusterSessionSearch)i.next();
        if (searchThread.isFinished()) {
          if (searchThread.getResult() == null)
          {
            finishedThreads.add(searchThread);
          }
          else
          {
            answer = searchThread.getResult();
            senderThread = searchThread.getAddressPort();
          }
        }
      }
      for (Iterator<ClusterSessionSearch> i = finishedThreads.iterator(); i.hasNext();) {
        searchThreads.remove(i.next());
      }
      if ((searchThreads.isEmpty()) || (answer != null)) {
        finished = Boolean.TRUE.booleanValue();
      } else {
        try
        {
          Thread.sleep(100L);
        }
        catch (InterruptedException err) {}
      }
    }
    for (Iterator<ClusterSessionSearch> i = searchThreads.iterator(); i.hasNext();)
    {
      ClusterSessionSearch searchThread = (ClusterSessionSearch)i.next();
      searchThread.destroy();
    }
    if (answer != null)
    {
      answer.activate(webAppConfig);
      logger.debug("Session transferred from: {}", senderThread);
    }
    return answer;
  }
  
  private void askClusterNodeForNodeList(String address)
  {
    try
    {
      int colonPos = address.indexOf(':');
      String ipAddress = address.substring(0, colonPos);
      String port = address.substring(colonPos + 1);
      Socket clusterListSocket = new Socket(ipAddress, Integer.parseInt(port));
      clusterAddresses.put(clusterListSocket.getInetAddress().getHostAddress() + ":" + port, new Date());
      InputStream in = clusterListSocket.getInputStream();
      OutputStream out = clusterListSocket.getOutputStream();
      out.write(50);
      out.flush();
      
      ObjectOutputStream outControl = new ObjectOutputStream(out);
      outControl.writeInt(controlPort);
      outControl.flush();
      
      ObjectInputStream inData = new ObjectInputStream(in);
      int nodeCount = inData.readInt();
      for (int n = 0; n < nodeCount; n++) {
        clusterAddresses.put(inData.readUTF(), new Date());
      }
      inData.close();
      outControl.close();
      out.close();
      in.close();
      clusterListSocket.close();
    }
    catch (ConnectException err)
    {
      logger.debug("No cluster node detected at {} - ignoring", address);
    }
    catch (Throwable err)
    {
      logger.error("Error getting nodelist from: " + address, err);
    }
  }
  
  private void sendHeartbeat(String address)
  {
    try
    {
      int colonPos = address.indexOf(':');
      String ipAddress = address.substring(0, colonPos);
      String port = address.substring(colonPos + 1);
      Socket heartbeatSocket = new Socket(ipAddress, Integer.parseInt(port));
      OutputStream out = heartbeatSocket.getOutputStream();
      out.write(51);
      out.flush();
      ObjectOutputStream outData = new ObjectOutputStream(out);
      outData.writeInt(controlPort);
      outData.close();
      heartbeatSocket.close();
      logger.debug("Heartbeat sent to: {}", address);
    }
    catch (ConnectException err) {}catch (Throwable err)
    {
      logger.error("Error sending heartbeat to: " + address, err);
    }
  }
  
  public void clusterRequest(byte requestType, InputStream in, OutputStream out, Socket socket, HostGroup hostGroup)
    throws IOException
  {
    if (requestType == 49) {
      handleClusterSessionRequest(socket, in, out, hostGroup);
    } else if (requestType == 50) {
      handleNodeListDownloadRequest(socket, in, out);
    } else if (requestType == 51) {
      handleNodeHeartBeatRequest(socket, in);
    } else {
      logger.error("Unknown cluster request type: " + (char)requestType);
    }
  }
  
  public void handleClusterSessionRequest(Socket socket, InputStream in, OutputStream out, HostGroup hostGroup)
    throws IOException
  {
    ObjectInputStream inControl = new ObjectInputStream(in);
    int port = inControl.readInt();
    String ipPortSender = socket.getInetAddress().getHostAddress() + ":" + port;
    String sessionId = inControl.readUTF();
    String hostname = inControl.readUTF();
    HostConfiguration hostConfig = hostGroup.getHostByName(hostname);
    String webAppPrefix = inControl.readUTF();
    WebAppConfiguration webAppConfig = hostConfig.getWebAppByURI(webAppPrefix);
    ObjectOutputStream outData = new ObjectOutputStream(out);
    if (webAppConfig == null)
    {
      outData.writeUTF("NOTFOUND");
    }
    else
    {
      WinstoneSession session = webAppConfig.getSessionById(sessionId, Boolean.TRUE.booleanValue());
      if (session != null)
      {
        outData.writeUTF("FOUND");
        outData.writeObject(session);
        outData.flush();
        if (inControl.readUTF().equals("OK")) {
          session.passivate();
        }
        logger.debug("Session transferred to: {}", ipPortSender);
      }
      else
      {
        outData.writeUTF("NOTFOUND");
      }
    }
    outData.close();
    inControl.close();
  }
  
  public void handleNodeListDownloadRequest(Socket socket, InputStream in, OutputStream out)
    throws IOException
  {
    ObjectInputStream inControl = new ObjectInputStream(in);
    int port = inControl.readInt();
    String ipPortSender = socket.getInetAddress().getHostAddress() + ":" + port;
    List<String> allClusterNodes = new ArrayList(clusterAddresses.keySet());
    List<String> relevantClusterNodes = new ArrayList();
    for (Iterator<String> i = allClusterNodes.iterator(); i.hasNext();)
    {
      String node = (String)i.next();
      if (!node.equals(ipPortSender)) {
        relevantClusterNodes.add(node);
      }
    }
    ObjectOutputStream outData = new ObjectOutputStream(out);
    outData.writeInt(relevantClusterNodes.size());
    outData.flush();
    for (Iterator<String> i = relevantClusterNodes.iterator(); i.hasNext();)
    {
      String ipPort = (String)i.next();
      if (!ipPort.equals(ipPortSender)) {
        outData.writeUTF(ipPort);
      }
      outData.flush();
    }
    outData.close();
    inControl.close();
  }
  
  public void handleNodeHeartBeatRequest(Socket socket, InputStream in)
    throws IOException
  {
    ObjectInputStream inData = new ObjectInputStream(in);
    int remoteControlPort = inData.readInt();
    inData.close();
    String ipPort = socket.getInetAddress().getHostAddress() + ":" + remoteControlPort;
    clusterAddresses.put(ipPort, new Date());
    logger.debug("Heartbeat received from: {}", ipPort);
  }
}

/* Location:
 * Qualified Name:     net.winstone.cluster.SimpleCluster
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config;

import java.io.Serializable;

public class AccessLoggerConfiguration
  implements Serializable
{
  private static final long serialVersionUID = 635193612842569504L;
  protected String className;
  
  public AccessLoggerConfiguration()
  {
    this(null);
  }
  
  public AccessLoggerConfiguration(String className)
  {
    this.className = className;
  }
  
  public Boolean enabled()
  {
    return Boolean.valueOf(className != null);
  }
  
  public final String getClassName()
  {
    return className;
  }
}

/* Location:
 * Qualified Name:     net.winstone.config.AccessLoggerConfiguration
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config;

import java.io.Serializable;

public class AddressConfiguration
  implements Serializable
{
  private static final long serialVersionUID = 3088393476849694363L;
  private final int port;
  private final String address;
  
  public AddressConfiguration(int port, String address)
  {
    this.port = port;
    this.address = address;
  }
  
  public final Boolean isEnabled()
  {
    return Boolean.valueOf(port != -1);
  }
  
  public final int getPort()
  {
    return port;
  }
  
  public final String getAddress()
  {
    return address;
  }
}

/* Location:
 * Qualified Name:     net.winstone.config.AddressConfiguration
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config;

public class Ajp13ListenerConfiguration
  extends AddressConfiguration
{
  private static final long serialVersionUID = -4100806360220081365L;
  
  public Ajp13ListenerConfiguration(int port, String address)
  {
    super(port, address);
  }
}

/* Location:
 * Qualified Name:     net.winstone.config.Ajp13ListenerConfiguration
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config.builder;

public class AddressConfigurationBuilder
{
  protected int port = -1;
  protected String address = null;
  
  public AddressConfigurationBuilder setAddress(int port, String address)
  {
    this.port = port;
    this.address = address;
    return this;
  }
  
  public final AddressConfigurationBuilder setPort(int port)
  {
    this.port = port;
    return this;
  }
  
  public final AddressConfigurationBuilder setAddress(String address)
  {
    this.address = address;
    return this;
  }
}

/* Location:
 * Qualified Name:     net.winstone.config.builder.AddressConfigurationBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config.builder;

import net.winstone.config.Ajp13ListenerConfiguration;

public class Ajp13ListenerConfigurationBuilder
  extends CompositeBuilder
{
  protected int port = -1;
  protected String address = null;
  
  public Ajp13ListenerConfigurationBuilder(ServerConfigurationBuilder builder)
  {
    super(builder);
  }
  
  public Ajp13ListenerConfigurationBuilder setAddress(int port, String address)
  {
    this.port = port;
    this.address = address;
    return this;
  }
  
  public final Ajp13ListenerConfigurationBuilder setPort(int port)
  {
    this.port = port;
    return this;
  }
  
  public final Ajp13ListenerConfigurationBuilder setAddress(String address)
  {
    this.address = address;
    return this;
  }
  
  public ServerConfigurationBuilder build()
  {
    return builder.setAjp13ListenerConfiguration(new Ajp13ListenerConfiguration(port, address));
  }
}

/* Location:
 * Qualified Name:     net.winstone.config.builder.Ajp13ListenerConfigurationBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config.builder;

import java.util.ArrayList;
import java.util.List;
import net.winstone.cluster.SimpleCluster;
import net.winstone.config.AddressConfiguration;
import net.winstone.config.ClusterConfiguration;

public class ClusterConfigurationBuilder
  extends CompositeBuilder
{
  private Boolean useCluster = Boolean.FALSE;
  private String className = SimpleCluster.class.getName();
  private List<AddressConfiguration> nodes = new ArrayList();
  
  public ClusterConfigurationBuilder(ServerConfigurationBuilder builder)
  {
    super(builder);
  }
  
  public ServerConfigurationBuilder build()
  {
    return builder.setClusterConfiguration(new ClusterConfiguration(useCluster, className, nodes));
  }
  
  public ClusterConfigurationBuilder setClassName(String className)
  {
    this.className = className;
    return this;
  }
  
  public ClusterNodeConfigurationBuilder addNode()
  {
    return new ClusterNodeConfigurationBuilder(this);
  }
  
  public ClusterConfigurationBuilder addNodeAddress(int port, String address)
  {
    ClusterNodeConfigurationBuilder node = new ClusterNodeConfigurationBuilder(this);
    return node.build();
  }
  
  ClusterConfigurationBuilder addAddressConfiguration(AddressConfiguration addressConfiguration)
  {
    nodes.add(addressConfiguration);
    return this;
  }
}

/* Location:
 * Qualified Name:     net.winstone.config.builder.ClusterConfigurationBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config.builder;

import net.winstone.config.AddressConfiguration;

public class ClusterNodeConfigurationBuilder
{
  protected int port = -1;
  protected String address = null;
  private ClusterConfigurationBuilder builder;
  
  public ClusterNodeConfigurationBuilder(ClusterConfigurationBuilder builder)
  {
    this.builder = builder;
  }
  
  public ClusterNodeConfigurationBuilder setAddress(int port, String address)
  {
    this.port = port;
    this.address = address;
    return this;
  }
  
  public final ClusterNodeConfigurationBuilder setPort(int port)
  {
    this.port = port;
    return this;
  }
  
  public final ClusterNodeConfigurationBuilder setAddress(String address)
  {
    this.address = address;
    return this;
  }
  
  public ClusterConfigurationBuilder build()
  {
    return builder.addAddressConfiguration(new AddressConfiguration(port, address));
  }
}

/* Location:
 * Qualified Name:     net.winstone.config.builder.ClusterNodeConfigurationBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config.builder;

public abstract class CompositeBuilder
{
  protected final ServerConfigurationBuilder builder;
  
  public CompositeBuilder(ServerConfigurationBuilder builder)
  {
    this.builder = builder;
  }
  
  public abstract ServerConfigurationBuilder build();
}

/* Location:
 * Qualified Name:     net.winstone.config.builder.CompositeBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config.builder;

import net.winstone.config.ControlConfiguration;

public class ControlConfigurationBuilder
  extends CompositeBuilder
{
  protected int port = -1;
  protected String address = null;
  
  public ControlConfigurationBuilder(ServerConfigurationBuilder builder)
  {
    super(builder);
  }
  
  public ControlConfigurationBuilder setAddress(int port, String address)
  {
    this.port = port;
    this.address = address;
    return this;
  }
  
  public final ControlConfigurationBuilder setPort(int port)
  {
    this.port = port;
    return this;
  }
  
  public final ControlConfigurationBuilder setAddress(String address)
  {
    this.address = address;
    return this;
  }
  
  public ServerConfigurationBuilder build()
  {
    return builder.setControlConfiguration(new ControlConfiguration(port, address));
  }
}

/* Location:
 * Qualified Name:     net.winstone.config.builder.ControlConfigurationBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config.builder;

import net.winstone.config.HandlerConfiguration;

public class HandlerConfigurationBuilder
  extends CompositeBuilder
{
  private int countStartup = 5;
  private int countMax = 300;
  private int countMaxIdle = 50;
  
  public HandlerConfigurationBuilder(ServerConfigurationBuilder builder)
  {
    super(builder);
  }
  
  public final HandlerConfigurationBuilder setCountStartup(int countStartup)
  {
    this.countStartup = countStartup;
    return this;
  }
  
  public final HandlerConfigurationBuilder setCountMax(int countMax)
  {
    this.countMax = countMax;
    return this;
  }
  
  public final HandlerConfigurationBuilder setCountMaxIdle(int countMaxIdle)
  {
    this.countMaxIdle = countMaxIdle;
    return this;
  }
  
  public ServerConfigurationBuilder build()
  {
    return builder.setHandlerConfiguration(new HandlerConfiguration(countStartup, countMax, countMaxIdle));
  }
}

/* Location:
 * Qualified Name:     net.winstone.config.builder.HandlerConfigurationBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package net.winstone.config.builder;

import net.winstone.config.HttpListenerConfiguration;

public class HttpListenerConfigurationBuilder
  extends Com
1 2 3 4 5 6 7 8 9 10 11 12 13 14

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd