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;
019
020import org.opengion.fukurou.util.HybsTimerTask;
021import org.opengion.fukurou.util.LogWriter;
022
023import org.opengion.hayabusa.mail.MailManager_DB;
024
025/**
026 * メールパラメータテーブルを監視して、メール送信プログラムを呼び出します。
027 * このクラスは、HybsTimerTask を継承した タイマータスククラスです。
028 * startDaemon() がタイマータスクによって、呼び出されます。
029 *
030 * @og.group メールモジュール
031 *
032 * @version  4.0
033 * @author   Sen.Li
034 * @since    JDK1.6
035 */
036public class MailDaemon extends HybsTimerTask {
037
038        private int loopCnt = 0;
039
040        private static final int LOOP_COUNTER = 24; // カウンタを24回に設定
041
042        /**
043         * このタイマータスクによって初期化されるアクションです。
044         * パラメータを使用した初期化を行います。
045         *
046         */
047        @Override
048        public void initDaemon() {
049                // 何もありません。(PMD エラー回避)
050        }
051
052        /**
053         * タイマータスクのデーモン処理の開始ポイントです。
054         *
055         */
056        @Override
057        protected void startDaemon() {
058                if( loopCnt % LOOP_COUNTER == 0 ) {
059                        loopCnt = 1;
060                        System.out.println( toString() + " " + new Date()  + " " );
061                }
062                else {
063                        String systemId = null;
064                        try {
065                                systemId = getValue( "SYSTEM_ID" );
066                                MailManager_DB manager = new MailManager_DB();
067                                manager.sendDBMail( systemId );
068                        }
069                        catch( RuntimeException rex ) {
070                                String errMsg = "メール送信失敗しました。"
071                                                        + " SYSTEM_ID=" + systemId ;                    // 5.1.8.0 (2010/07/01) errMsg 修正
072                                LogWriter.log( errMsg );
073                        }
074                        loopCnt++ ;
075                }
076        }
077}