📄 acctserver.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.acct;
import java.util.*;
import java.sql.*;
import org.apache.log4j.*;
import org.compiere.util.DB;
/**
* Posting Controller
* Without setting parameters, one worker is created per Client
*
* @author Jorg Janke
* @version $Id: AcctServer.java,v 1.8 2002/11/18 06:11:57 jjanke Exp $
*/
public class AcctServer extends Thread
{
/**
* Post Immediate
* @param AD_Table_ID Table ID of Document
* @param AD_Client_ID Client ID of Document
* @param Record_ID Record ID of this document
* @param force force posting
* @return true if success
*/
public static boolean postImmediate (int AD_Table_ID, int AD_Client_ID, int Record_ID, boolean force)
{
return Doc.post(AD_Table_ID, AD_Client_ID, Record_ID, force);
} // postImmediate
/** Logger */
private static Logger log = Logger.getLogger(AcctServer.class);
/*************************************************************************/
/**
* Constructor
* @param workerNo Worker number
* @param sleepMinutes Minutes to sleep after empty batch
* @param maxSleepMinutes Max Minutes to sleep after empty batch
* @param batchSize Number of rows to retrieve per query
* @param queue Work Queue
* @param runOnce Run just once
*/
public AcctServer (int workerNo, int sleepMinutes, int maxSleepMinutes,
int batchSize, AcctServerWork[] queue, boolean runOnce)
{
super("AcctServer_" + workerNo);
m_workerNo = workerNo;
m_sleepMinutes = sleepMinutes;
m_maxSleepMinutes = maxSleepMinutes;
m_batchSize = batchSize;
m_queue = queue;
m_runOnce = runOnce;
} // AcctServerWorker
/** Worker Number */
private int m_workerNo;
/** Sleeping time in minutes */
private int m_sleepMinutes;
/** Sleeping time in minutes */
private int m_maxSleepMinutes;
/** Batch Size per query */
private int m_batchSize;
/** Work Queue */
private AcctServerWork[] m_queue;
private boolean m_runOnce;
/**
* Run - Post documents.
* <pre>
* while not interrupted
* initWorkQueue
* while workQueue
* postQueue
* sleep, if there were no Trx
* </pre>
*/
public void run()
{
try
{
// wait server startup
this.sleep(60000); // 60 sec
}
catch (InterruptedException ex)
{
log.info("run_" + m_workerNo + ": " + ex.getMessage());
return;
}
int noTrx = 0;
int noSleeps = 0;
// Outer Loop
while (!isInterrupted())
{
log.info("run_" + m_workerNo);
// Work on Queue
noTrx = 0;
for (int i = 0; !isInterrupted() && i < m_queue.length; i++)
{
// The document to post
Doc doc = Doc.get(m_queue[i].get_AD_Table_ID(), m_queue[i].get_AD_Client_ID());
if (doc == null)
continue;
m_queue[i].addRun();
// Select id FROM table
StringBuffer sql = new StringBuffer ("SELECT ");
sql.append(doc.getTableName()).append("_ID")
.append(" FROM ").append(doc.getTableName())
.append(" WHERE AD_Client_ID=?")
.append(" AND Processed='Y' AND Posted='N'");
if (m_batchSize > 0)
sql.append(" AND ROWNUM <= ").append(m_batchSize);
sql.append(" ORDER BY Created");
//
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString());
pstmt.setInt(1, m_queue[i].get_AD_Client_ID());
ResultSet rs = pstmt.executeQuery();
while (!isInterrupted() && rs.next())
{
m_queue[i].addPost (doc.post(rs.getInt(1), false)); // no force
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.error("run_" + m_workerNo, e);
}
if (m_queue[i].getTrxInRun() > 0)
log.info("run_" + m_workerNo + " "
+ m_queue[i].toString());
noTrx += m_queue[i].getTrxInRun();
} // work on queue
if (isInterrupted())
break;
// Create Automatic Matching
new Matcher(m_queue[0].get_AD_Client_ID()).match ();
if (isInterrupted() || m_runOnce)
break;
// sleep a bit if there was nothing to do
if (noTrx == 0)
{
m_queue[0].addSleep();
if (noSleeps++ > 0 && m_sleepMinutes < m_maxSleepMinutes)
m_sleepMinutes++;
log.debug("run_" + m_workerNo + " - sleeping - min=" + m_sleepMinutes);
try
{
for (int i = 0; i < m_sleepMinutes * 6; i++)
sleep (10000); // 10 sec
if (isInterrupted())
break;
}
catch (Exception e)
{
log.info ("run_" + m_workerNo + ": " + e.getMessage());
return;
}
}
else
noSleeps = 0;
} // outer loop
log.info ("run_" + m_workerNo + " - done ");
} // run
} // AcctServer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -