Connection.java :  » Net » hyperpool-0.4.0 » vicazh » hyperpool » stream » net » http » Java Open Source

Java Open Source » Net » hyperpool 0.4.0 
hyperpool 0.4.0 » vicazh » hyperpool » stream » net » http » Connection.java
package vicazh.hyperpool.stream.net.http;

import java.io.*;
import java.util.*;
import vicazh.hyperpool.Start;
import vicazh.hyperpool.stream.*;

/**
 * This class is the superclass of all http connections
 * 
 * @author Victor Zhigunov
 * @version 0.4.0
 */
public class Connection extends vicazh.hyperpool.stream.net.Connection {
  public Connection() {
  }

  /**
   * @param element
   *            parent element
   */
  public Connection(Element element) {
    super(element);
  }

  public void setClient(OutputStream outputstream) throws IOException {
    Session session = (Session) sessions.get(sessions.size() - 1);
    session.setClient(outputstream);
    super.setClient((OutputStream) session.getClient());
  }

  public void setServer(OutputStream outputstream) throws IOException {
    Session session = getSession();
    session.setServer(outputstream);
    add(session);
    super.setServer((OutputStream) session.getServer());
  }

  private List<Session> sessions = new ArrayList<Session>();

  /**
   * Add session
   */
  public void add(Session session) {
    sessions.add(session);
    Start.logger.finest(element.getClass().getName() + ":sessions.size:"
        + sessions.size());
  }

  /**
   * Remove session
   */
  public void remove(Session session) {
    sessions.remove(session);
    Start.logger.finest(element.getClass().getName() + ":sessions.size:"
        + sessions.size());
  }

  /**
   * Return connections session
   * 
   * @return connections session
   */
  protected Session getSession() {
    return new Session(this);
  }

  /**
   * Return connections sessions
   * 
   * @return connections sessions
   */
  public List<Session> getSessions() {
    return sessions;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.