class ConnectionImpl implements InvocationHandler, Connection {

  public void end() {
    if (--beginCalls <= 0) {

      synchronized (resultStack) {
        if (resultStack.isEmpty()) {
          writeResult(LispWriter.NIL);
        } else {
          while (!resultStack.isEmpty()) {
            writeResult(resultStack.removeLast());
          }
        }
      }

      if (global != null) {
        try {
          global.getNameSpace().setVariable(variableName, null, true);
        } catch (bsh.UtilEvalError ee) {
          // All we're doing is attempting to unset the variable here, so if
          // we fail at that, the consequences are probably harmless...
        }
      }

      synchronized (ConnectionFactory.connectionLock) {
        ConnectionFactory.currentConnection = null;
      }
    }
    logger.debug("*** end " + beginCalls);
  }

  public  ConnectionImpl();
  public  ConnectionImpl(This global, Map impls, String variableName);

}