// Path: src/org/h3270/logicalunit/LogicalUnitPool.java
// public class LogicalUnitPool implements Serializable {
// 
//   public final static String SERVLET_CONTEXT_KEY = "org.h3270.LogicalUnitPool";
// 
//   private final static Log logger = LogFactory.getLog(LogicalUnitPool.class);
// 
//   private Map luPool;
// 
//   public LogicalUnitPool(LogicalUnitBuilder builder) {
//     Collection logicalUnits = builder.getLogicalUnits();
// 
//     luPool = Collections.synchronizedMap(new HashMap(logicalUnits.size()));
// 
//     for (Iterator iter = logicalUnits.iterator(); iter.hasNext();) {
//       String name = (String) iter.next();
//       luPool.put(name, new Boolean(false));
//     }
//   }
// 
//   public String leaseLogicalUnit() throws LogicalUnitException {
//     Set names = luPool.keySet();
//     synchronized (luPool) {
//       for (Iterator iter = names.iterator(); iter.hasNext();) {
//         String name = (String) iter.next();
//         boolean isInUse = ((Boolean) luPool.get(name)).booleanValue();
//         if (!isInUse) {
//           luPool.put(name, new Boolean(true));
//           logger.debug("LU akquired = " + name);
//           return name; // new LogicalUnit(name);
//         }
//       }
//     }
//     throw new LogicalUnitException("All logical units are in use");
//   }
// 
//   public void releaseLogicalUnit(String logicalUnit) {
//     if (luPool.get(logicalUnit) == null)
//       logger.error("Trying to release non-existent logical unit!");
//     else {
//       synchronized (luPool) {
//         luPool.put(logicalUnit, new Boolean(false));
//         logger.debug("LU released = " + logicalUnit);
//       }
//     }
//   }
// }


import org.apache.commons.logging.LogFactory;
import org.h3270.host.*;
import org.h3270.logicalunit.LogicalUnitPool;
import org.h3270.render.*;
import java.io.*;
import java.util.*;
import javax.servlet.ServletContext;
import javax.servlet.http.*;
import org.apache.commons.codec.*;
import org.apache.commons.codec.net.URLCodec;
import org.apache.commons.logging.Log;
    return getBooleanProperty(RENDERER, true);
  }

  public void setException (HttpServletRequest request, Throwable exception) {
    getTerminalState(request).setException(exception);
  }

  public Throwable getException (HttpServletRequest request) {
    return getTerminalState(request).getException();
  }

  public void valueBound(HttpSessionBindingEvent arg0) {
    // nothing
  }

  public void valueUnbound(HttpSessionBindingEvent event) {
    // disconnect all s3270 sessions when the HttpSession times out and release
    // associated logical units in the pool
    for (Iterator i = terminalStates.iterator(); i.hasNext();) {
      TerminalState ts = (TerminalState) i.next();
      if (ts.getTerminal() != null && ts.getTerminal().isConnected()) {
        if (logger.isInfoEnabled())
          logger.info("Session unbound, disconnecting terminal "
              + ts.getTerminal());
        ts.getTerminal().disconnect();

        String logicalUnit = ts.getTerminal().getLogicalUnit();
        if (logicalUnit != null) {
          ServletContext servletContext = event.getSession()
              .getServletContext();
// Path: src/org/h3270/logicalunit/LogicalUnitPool.java
// public class LogicalUnitPool implements Serializable {
// 
//   public final static String SERVLET_CONTEXT_KEY = "org.h3270.LogicalUnitPool";
// 
//   private final static Log logger = LogFactory.getLog(LogicalUnitPool.class);
// 
//   private Map luPool;
// 
//   public LogicalUnitPool(LogicalUnitBuilder builder) {
//     Collection logicalUnits = builder.getLogicalUnits();
// 
//     luPool = Collections.synchronizedMap(new HashMap(logicalUnits.size()));
// 
//     for (Iterator iter = logicalUnits.iterator(); iter.hasNext();) {
//       String name = (String) iter.next();
//       luPool.put(name, new Boolean(false));
//     }
//   }
// 
//   public String leaseLogicalUnit() throws LogicalUnitException {
//     Set names = luPool.keySet();
//     synchronized (luPool) {
//       for (Iterator iter = names.iterator(); iter.hasNext();) {
//         String name = (String) iter.next();
//         boolean isInUse = ((Boolean) luPool.get(name)).booleanValue();
//         if (!isInUse) {
//           luPool.put(name, new Boolean(true));
//           logger.debug("LU akquired = " + name);
//           return name; // new LogicalUnit(name);
//         }
//       }
//     }
//     throw new LogicalUnitException("All logical units are in use");
//   }
// 
//   public void releaseLogicalUnit(String logicalUnit) {
//     if (luPool.get(logicalUnit) == null)
//       logger.error("Trying to release non-existent logical unit!");
//     else {
//       synchronized (luPool) {
//         luPool.put(logicalUnit, new Boolean(false));
//         logger.debug("LU released = " + logicalUnit);
//       }
//     }
//   }
// }


// Path: src/org/h3270/web/SessionState.java
import org.apache.commons.logging.LogFactory;
import org.h3270.host.*;
import org.h3270.logicalunit.LogicalUnitPool;
import org.h3270.render.*;
import java.io.*;
import java.util.*;
import javax.servlet.ServletContext;
import javax.servlet.http.*;
import org.apache.commons.codec.*;
import org.apache.commons.codec.net.URLCodec;
import org.apache.commons.logging.Log;

    return getBooleanProperty(RENDERER, true);
  }

  public void setException (HttpServletRequest request, Throwable exception) {
    getTerminalState(request).setException(exception);
  }

  public Throwable getException (HttpServletRequest request) {
    return getTerminalState(request).getException();
  }

  public void valueBound(HttpSessionBindingEvent arg0) {
    // nothing
  }

  public void valueUnbound(HttpSessionBindingEvent event) {
    // disconnect all s3270 sessions when the HttpSession times out and release
    // associated logical units in the pool
    for (Iterator i = terminalStates.iterator(); i.hasNext();) {
      TerminalState ts = (TerminalState) i.next();
      if (ts.getTerminal() != null && ts.getTerminal().isConnected()) {
        if (logger.isInfoEnabled())
          logger.info("Session unbound, disconnecting terminal "
              + ts.getTerminal());
        ts.getTerminal().disconnect();

        String logicalUnit = ts.getTerminal().getLogicalUnit();
        if (logicalUnit != null) {
          ServletContext servletContext = event.getSession()
              .getServletContext();
          LogicalUnitPool pool = (LogicalUnitPool) servletContext