⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 requestservice.java

📁 Java写的ERP系统
💻 JAVA
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.request;

import javax.management.*;
import org.jboss.system.*;

/**
 *  Request Sevive
 *
 * 	@author 	Jorg Janke
 * 	@version 	$Id: RequestService.java,v 1.3 2002/11/18 06:11:58 jjanke Exp $
 */
public class RequestService extends ServiceMBeanSupport
   implements RequestServiceMBean, Runnable
{
	/**
	 *  Request Service
	 */
	public RequestService()
	{
		super();
	}   //  RequestService

	/**
	 * 	Get Name
	 * 	@return Name
	 */
	public String getName()
	{
		return NAME;
	}	//	getName

	/**	Worker Thread			*/
	private Thread			m_worker = null;
	/**	Array of Processors		*/
	private RequestProcessorVO[] m_rpVO = null;

	/** SleepMinutes        	*/
	private int				m_sleepMinutes = 10;
	/**	Number of Invocations	*/
	private volatile int	m_count = 0;
	/**	DataSource Name		*/
	private String 			m_dataSourceName;


	/*************************************************************************/

	/**
	 * 	Create Service
	 * 	@throws Exception
	 */
	protected void createService() throws Exception
	{
		m_worker = new Thread (this, getName());
		m_worker.setDaemon(true);
		m_worker.setPriority(Thread.MIN_PRIORITY);
		m_rpVO = RequestProcessorVO.get();
	}	//	createService

	/**
	 * 	Start Service
	 * 	@throws Exception
	 */
	protected void startService() throws Exception
	{
		m_worker.start();
	}	//	startService

	/**
	 * 	Stop Service
	 * 	@throws Exception
	 */
	protected void stopService() throws Exception
	{
		m_worker.interrupt();
	}	//	stopService

	/**
	 * 	Destroy Service
	 * 	@throws Exception
	 */
	protected void destroyService() throws Exception
	{
		int maxTime = 10000;
		int waitTime = 1000;	//	1 sec
		while (m_worker.isAlive())
		{
			m_worker.interrupt();
			if (maxTime <= 0)
				break;
			log.debug("Waiting for Worker");
			Thread.currentThread().sleep(waitTime);
			maxTime -= waitTime;
		}
		m_worker = null;
		m_rpVO = null;
	}	//	destroyService


	/**
	 * 	Run
	 */
	public void run()
	{
		try
		{
			//	wait server startup
			Thread.currentThread().sleep(60000);	//	60 sec
		}
		catch (InterruptedException ex)
		{
			log.info ("run: " + ex.getMessage());
			return;
		}

		while (!m_worker.isInterrupted())
		{
			try
			{
				for (int i = 0; i < m_rpVO.length; i++)
				{
					RequestProcessor rp = new RequestProcessor (m_rpVO[i]);
					if (m_worker.isInterrupted())
						break;
				}
				if (!m_worker.isInterrupted())
				{
					m_count++;
					// put the thread to sleep for the interval specified
				//	Thread.currentThread().sleep(m_sleepMinutes * 60000);
					m_worker.sleep (m_sleepMinutes * 60000);
				}
			}
			catch (InterruptedException e)
			{
				log.info ("run: " + e.getMessage());
				return;
			}
		}	//	while running
	}	//	run

	/*************************************************************************/

	/**
	 *  Set Sleep Minutes
	 *  @param sleepMinutes sleep time in minutes
	 */
	public void setSleepMinutes (int sleepMinutes)
	{
		m_sleepMinutes = sleepMinutes;
	}	//  setSleepMinutes

	/**
	 *  Get Sleep Minutes
	 *  @return sleep minutes
	 */
	public int getSleepMinutes ()
	{
		return m_sleepMinutes;
	}	//  getSleepMinutes

	/**
	 *  Get Statistics
	 *  @return statistical info
	 */
	public String getStatistics()
	{
		StringBuffer sb = new StringBuffer();
		//	Processor
		sb.append("ProcessorCount=");
		if (m_rpVO == null)
			sb.append("null");
		else
			sb.append(m_rpVO.length);
		sb.append(",RunCount=").append(m_count);
		//	Worker
		sb.append(";Worker=");
		if (m_worker == null)
			sb.append("null");
		else if (!m_worker.isAlive())
			sb.append("NotAlive");
		else if (m_worker.isInterrupted())
			sb.append("Interrupted");
		else
			sb.append("Alive");
		//
		return sb.toString();
	}   //  getStatistics

	/**
	 * 	Get DataSource Name
	 * 	@return DataSource Name
	 */
	public String getDataSourceName()
	{
		return m_dataSourceName;
	}	//	getDataSourceName

	/**
	 * 	Set DataSource Name
	 * 	@param dataSourceName DataSource Name
	 */
	public void setDataSourceName (String dataSourceName)
	{
		m_dataSourceName = dataSourceName;
	}	//	setDataSourceName

	/*************************************************************************/

	/**
	 * 	Run Now
	 */
	public void runNow()
	{
		for (int i = 0; i < m_rpVO.length; i++)
		{
			RequestProcessor rp = new RequestProcessor (m_rpVO[i]);
		}
	}	//	runNow

}   //  RequestService

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -