Package org.jboss.fresh.deployer

Source Code of org.jboss.fresh.deployer.PoolService

package org.jboss.fresh.deployer;

import org.jboss.fresh.pool.pool.Pool;
import org.jboss.fresh.pool.pool.PoolFactory;
import org.jboss.fresh.pool.pool.impl.PoolImpl;


/**
* This is a simple service that sustains a file on the disk. It it it simply puts an integer specifying the number of invocations made from beginning of its running.
*/
@Deprecated
public class PoolService extends RegistryNamingBinder implements PoolServiceMBean {

  private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(PoolService.class);
  private String poolname;
  private String factoryName;
  //private String factoryName="com.parsek.cpii.services.PoolRunnerFactory";


  private int minsize = 0;      // default: 0
  private int maxsize = 100;      // default: 100
  private boolean isBlocking = true;    // default: true
  private long blockingTimeout = 30000// default: 30 secs - even this is unacceptible - who will wait this long !!!


  public void setFactoryName(String name) {
    factoryName = name;
  }

  public String getFactoryName() {
    return factoryName;
  }

  public void setPoolName(String name) {
    poolname = name;
  }

  public String getPoolName() {
    return poolname;
  }

  public void setMinSize(int val) {
    minsize = val;
  }

  public int getMinSize() {
    return minsize;
  }

  public void setMaxSize(int i) {
    maxsize = i;
  }

  public int getMaxSize() {
    return maxsize;
  }

  public void setBlocking(boolean val) {
    isBlocking = val;
  }

  public boolean getBlocking() {
    return isBlocking;
  }

  public void setBlockingTimeout(long val) {
    blockingTimeout = val;
  }

  public long getBlockingTimeout() {
    return blockingTimeout;
  }

  // pretty generic code comes here

  public String getName() {
    return "Generic Pool MBean";
  }


  protected String getBindClass() {
    return Pool.class.getName();
  }


  protected Object classToInstance(Class c) {

    // instaliraj se kot NotificationListener

    // create pool instance.
    // set factory

    try {

      PoolImpl pool = (PoolImpl) getServiceObject();

      if (pool != null) pool.stop();

      String fname = getFactoryName();
      ClassLoader cl = Thread.currentThread().getContextClassLoader();

      Class fc = cl.loadClass(fname);
      PoolFactory f = (PoolFactory) fc.newInstance();

      pool = new PoolImpl(poolname, f);
      pool.setMinSize(minsize);
      pool.setMaxSize(maxsize);
      pool.setNonBlocking(!isBlocking);
      pool.setTimeout(blockingTimeout); // why is it int ???

      pool.start();

      setServiceObject(pool);

      return pool;

    } catch (Exception ex) {
      throw new RuntimeException(ex.toString());
    }
  }

  protected boolean bindByReference() {
    return true;
  }

  public void doStop() {
    try {
      log.debug("doStop() called");
      super.doStop();
    } finally {
      try {
        PoolImpl pool = (PoolImpl) getServiceObject();
        log.info("pool: " + pool);
        if (pool != null) pool.stop();
      } catch (Exception ex) {
        log.error("Exception while stopping the pool: ", ex);
        throw new RuntimeException(ex.toString());
      }
    }
  }
}
TOP

Related Classes of org.jboss.fresh.deployer.PoolService

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.