2 * Copyright (c) 2009 The openGion Project.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
16 package org.opengion.plugin.daemon;
18 import java.util.Date;
20 import org.opengion.fukurou.util.HybsTimerTask;
21 import org.opengion.fukurou.system.LogWriter; // Ver6
22 import org.opengion.hayabusa.common.HybsSystem;
23 import org.opengion.plugin.cloud.MailManager_DB_SendGridAPI;
26 * メールパラメータテーブルを監視して、SengGridAPIを利用したメール送信プログラムを呼び出します。
27 * このクラスは、HybsTimerTask を継承した タイマータスククラスです。
28 * startDaemon() がタイマータスクによって、呼び出されます。
30 * 通常のメールモジュールはSMTPを利用した送信で、hayabusa.mail内のクラスをCallしていますが、
31 * こちらはplugin.cloud内のsendGridのAPIをCallしてメールを送信します。
32 * そのため、sendGridを利用出来る状態(jarファイルの配備等)となっている必要があります。
34 * システムリソースにMAIL_SENDGRID_APIKEYが登録されていない場合は動作しません。
38 * @og.rev 5.9.26.0 (2017/11/02) 新規作成
39 * @og.rev 8.0.1.0 (2021/10/22) 廃止
43 public class MailDaemon_SendGridAPI extends HybsTimerTask {
47 private static final int LOOP_COUNTER = 24; // カウンタを24回に設定
52 * @og.rev 6.9.7.0 (2018/05/14) PMD Each class should declare at least one constructor
54 public MailDaemon_SendGridAPI() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
57 * このタイマータスクによって初期化されるアクションです。
62 public void initDaemon() {
63 // 何もありません。(PMD エラー回避)
67 * タイマータスクのデーモン処理の開始ポイントです。
71 protected void startDaemon() {
73 final String sendGridApiKey = HybsSystem.sys("MAIL_SENDGRID_APIKEY");
74 if(sendGridApiKey == null || sendGridApiKey.length() == 0){
75 // SendGridのAPIキーが設定されていない場合は終了
79 if( loopCnt % LOOP_COUNTER == 0 ) {
81 System.out.println( toString() + " " + new Date() + " " );
84 String systemId = null;
86 systemId = getValue( "SYSTEM_ID" );
87 // SengGridAPI利用のメール送信機能呼び出し
88 final MailManager_DB_SendGridAPI manager = new MailManager_DB_SendGridAPI();
89 manager.sendDBMail( systemId );
91 catch( final RuntimeException rex ) {
92 // final String errMsg = "メール送信失敗しました。SYSTEM_ID=" + systemId ;
93 final String errMsg = "メール送信失敗しました。SYSTEM_ID=" + systemId + " , ERR=" + rex.getMessage();
94 LogWriter.log( errMsg );