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 boolean DEBUG = false;
046//      private static boolean debug = false;           // 4.3.1.1 (2008/08/23) 変数は小文字へ
047        private static AtomicBoolean debug = new AtomicBoolean( false );                // 5.5.2.6 (2012/05/25) findbugs対応
048
049        /**
050         * このタイマータスクによって初期化されるアクションです。
051         * パラメータを使用した初期化を行います。
052         *
053         * @og.rev 5.5.2.6 (2012/05/25) findbugs対応。staticフィールドへの書き込みに、AtomicInteger を利用します。
054         */
055        @Override
056        public void initDaemon() {
057//              DEBUG = StringUtil.nval( getValue( "DEBUG" ),DEBUG ) ;
058//              ExecThreadManager.setDebug( DEBUG ); // 4.3.0.0 (2008/04/15) デバッグ処理の追加
059//              debug = StringUtil.nval( getValue( "DEBUG" ),debug ) ;
060//              ExecThreadManager.setDebug( debug ); // 4.3.0.0 (2008/04/15) デバッグ処理の追加
061
062                boolean flag = StringUtil.nval( getValue( "DEBUG" ),debug.get() );
063                ExecThreadManager.setDebug( flag ); // 4.3.0.0 (2008/04/15) デバッグ処理の追加
064                debug.set( flag );
065        }
066
067        /**
068         * タイマータスクのデーモン処理の開始ポイントです。
069         *
070         */
071        @Override
072        protected void startDaemon() {
073                if( loopCnt % LOOP_COUNTER == 0 ) {
074                        loopCnt = 1;
075//                      System.out.println();
076                        System.out.println( toString() + " " + new Date()  + " " );
077                }
078                else {
079//                      System.out.print( "." );
080                        loopCnt++ ;
081                }
082
083                QueueManager_DB.getInstance().create();
084        }
085
086        /**
087         * このタイマータスクのcancel() メソッドをオーバーライドします。
088         * HybsTimerTaskManager#cancelTask( int ) を実行します。
089         *
090         * @og.rev 4.3.1.1 (2008/08/23) super.cancel() のみ実行なら、オーバーライドの必要はない
091         *
092         * @see java.util.TimerTask#cancel()
093         */
094//      public boolean cancel() {
095//              return super.cancel();
096//      }
097}