Package vicazh.hyperpool.stream.net.http.html

Source Code of vicazh.hyperpool.stream.net.http.html.AnalyzerService

package vicazh.hyperpool.stream.net.http.html;

import java.io.*;
import java.net.*;
import vicazh.hyperpool.*;
import vicazh.hyperpool.stream.net.http.*;
import vicazh.hyperpool.stream.*;
import vicazh.hyperpool.stream.Connection;
import vicazh.hyperpool.stream.Element;

/**
* The analyzer service
*
* @author Victor Zhigunov
* @version 0.4.11
*/
public class AnalyzerService extends Task implements AnalyzerServiceMBean,
    Serializable {

  public AnalyzerService() {
  }

  transient private BaseService baseService;

  transient private Element element;

  /**
   * @param baseService
   *            base service
   * @param element
   *            next element
   */
  public AnalyzerService(BaseService baseService, Element element) {
    super(null);
    this.baseService = baseService;
    this.element = element;
  }

  public OutputStream get(OutputStream outputstream) throws IOException {
    Connection connection = getConnection();
    connection.setServer(outputstream);
    connection.setClient(element.get(connection.getServer()));
    add(connection);
    return connection.getClient();
  }

  /**
   * Get the service directory
   */
  public String getDir() {
    return baseService == null ? null : baseService.getDir();
  }

  /**
   * Set the service directory
   */
  public void setDir(String dir) {
    if (baseService != null)
      baseService.setDir(dir);
  }

  private boolean c;

  protected void setStatus(Status status) {
    if (c)
      return;
    super.setStatus(status);
    sendAttribute(AnalyzerServiceMBean.GO, getFileData());
  }

  private void go(String address) throws IOException {
    URL url = new URL(address);
    setStart(url.getProtocol() + "://" + url.getHost());
    index = 0;
    list.clear();
    setStatus(Status.RUN);
    list.add(new Record(address, 0));
    size = 1;
    next();
  }

  public void setAttribute(String name, Object value) throws Exception {
    if (name.equals(ElementMBean.INIT))
      super.setAttribute(name, getFileData());
    else if (name.equals(AnalyzerServiceMBean.BREAK))
      close();
    else if (name.equals(AnalyzerServiceMBean.GO)) {
      baseService.clear();
      sendAttribute(FileServiceMBean.CLEAR, getFileData());
      go((String) value);
    } else if (name.equals(FileServiceMBean.OPTIONS)) {
      baseService.path2dir(((AnalyzerService) value).path);
      setLevel(((AnalyzerService) value).getLevel());
      setThreads(((AnalyzerService) value).getThreads());
    } else {
      baseService.clear();
      sendAttribute(name, getFileData());
    }
  }

  public void start() throws Exception {
    super.start();
    baseService.start();
  }

  public void stop() throws Exception {
    c = true;
    close();
    super.stop();
    baseService.stop();
  }

  public byte[] get(File file, long index) throws IOException {
    return baseService.get(file, index);
  }

  String path;

  public AnalyzerService getOptions() {
    path = baseService.dir2path();
    return this;
  }

  public ExplorerFile[] listFiles(File file) throws Exception {
    return baseService.listFiles(file);
  }

  public File[] select(File file) {
    return baseService.select(file);
  }

  private FileData getFileData() {
    return new AnalyzerData(baseService.getFileData().isDirExists, status);
  }

  synchronized void action(TaskConnection connection) throws IOException {
    super.action(connection);
    sendAttribute(AnalyzerServiceMBean.INDEX, index);
  }

  synchronized void add(String address, int level) throws IOException {
    super.add(address, level);
    sendAttribute(AnalyzerServiceMBean.SIZE, size);
  }

  protected synchronized void next() throws IOException {
    super.next();
    sendAttribute(AnalyzerServiceMBean.INDEX, index);
  }

  public Connection getConnection() {
    return new AnalyzerConnection(this);
  }

}
TOP

Related Classes of vicazh.hyperpool.stream.net.http.html.AnalyzerService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.