001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.plugin.daemon;
017
018import java.util.Date;
019import java.util.concurrent.atomic.AtomicBoolean;       // 5.5.2.6 (2012/05/25) findbugs対応
020
021import org.opengion.fukurou.util.HybsTimerTask;
022import org.opengion.fukurou.util.StringUtil;
023import org.opengion.hayabusa.report2.ExecThreadManager;
024import org.opengion.hayabusa.report2.QueueManager_DB;
025
026/**
027 * 【レポート出力】帳票要求テーブルを監視して、帳票処理プログラムを呼び出します。
028 * このクラスは、HybsTimerTask を継承した タイマータスククラスです。
029 * startDaemon() がタイマータスクによって、呼び出されます。
030 *
031 * @og.rev 4.3.4.4 (2009/01/01) プラグイン化
032 * @og.group デーモン
033 *
034 * @version  4.0
035 * @author   Hiroki.Nakamura
036 * @since    JDK1.6
037 */
038public class Daemon_Report2 extends HybsTimerTask {
039        //* このプログラムのVERSION文字列を設定します。   {@value} */
040        private static final String VERSION = "5.5.2.6 (2012/05/25)" ;
041
042        private int loopCnt = 0;
043
044        private static final int LOOP_COUNTER = 24; // カウンタを24回に設定
045        private static AtomicBoolean debug = new AtomicBoolean( false );                // 5.5.2.6 (2012/05/25) findbugs対応
046
047        /**
048         * このタイマータスクによって初期化されるアクションです。
049         * パラメータを使用した初期化を行います。
050         *
051         * @og.rev 5.5.2.6 (2012/05/25) findbugs対応。staticフィールドへの書き込みに、AtomicInteger を利用します。
052         */
053        @Override
054        public void initDaemon() {
055                boolean flag = StringUtil.nval( getValue( "DEBUG" ),debug.get() );
056                ExecThreadManager.setDebug( flag ); // 4.3.0.0 (2008/04/15) デバッグ処理の追加
057                debug.set( flag );
058        }
059
060        /**
061         * タイマータスクのデーモン処理の開始ポイントです。
062         *
063         */
064        @Override
065        protected void startDaemon() {
066                if( loopCnt % LOOP_COUNTER == 0 ) {
067                        loopCnt = 1;
068                        System.out.println( toString() + " " + new Date()  + " " );
069                }
070                else {
071                        loopCnt++ ;
072                }
073
074                QueueManager_DB.getInstance().create();
075        }
076}