OSDN Git Service

Ver8.5.1.0
[opengion/opengionV8.git] / uap / webapps / gf / src / org / opengion / plugin / daemon / MailDaemon_SendGridAPI.java_haishi
1 /*
2  * Copyright (c) 2009 The openGion Project.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.opengion.plugin.daemon;
17
18 import java.util.Date;
19
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;
24
25 /**
26  * メールパラメータテーブルを監視して、SengGridAPIを利用したメール送信プログラムを呼び出します。
27  * このクラスは、HybsTimerTask を継承した タイマータスククラスです。
28  * startDaemon() がタイマータスクによって、呼び出されます。
29  *
30  * 通常のメールモジュールはSMTPを利用した送信で、hayabusa.mail内のクラスをCallしていますが、
31  * こちらはplugin.cloud内のsendGridのAPIをCallしてメールを送信します。
32  * そのため、sendGridを利用出来る状態(jarファイルの配備等)となっている必要があります。
33  *
34  * システムリソースにMAIL_SENDGRID_APIKEYが登録されていない場合は動作しません。
35  *
36  * @og.group メールモジュール
37  *
38  * @og.rev 5.9.26.0 (2017/11/02) 新規作成
39  * @og.rev 8.0.1.0 (2021/10/22) 廃止
40  * @author   T.OTA
41  * @since    JDK1.7
42  */
43 public class MailDaemon_SendGridAPI extends HybsTimerTask {
44
45         private int loopCnt ;
46
47         private static final int LOOP_COUNTER = 24; // カウンタを24回に設定
48
49         /**
50          * デフォルトコンストラクター
51          *
52          * @og.rev 6.9.7.0 (2018/05/14) PMD Each class should declare at least one constructor
53          */
54         public MailDaemon_SendGridAPI() { super(); }            // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
55
56         /**
57          * このタイマータスクによって初期化されるアクションです。
58          * パラメータを使用した初期化を行います。
59          *
60          */
61         @Override
62         public void initDaemon() {
63                 // 何もありません。(PMD エラー回避)
64         }
65
66         /**
67          * タイマータスクのデーモン処理の開始ポイントです。
68          *
69          */
70         @Override
71         protected void startDaemon() {
72                 // SendGridのAPIキー
73                 final String sendGridApiKey = HybsSystem.sys("MAIL_SENDGRID_APIKEY");
74                 if(sendGridApiKey == null || sendGridApiKey.length() == 0){
75                         // SendGridのAPIキーが設定されていない場合は終了
76                         return;
77                 }
78
79                 if( loopCnt % LOOP_COUNTER == 0 ) {
80                         loopCnt = 1;
81                         System.out.println( toString() + " " + new Date()  + " " );
82                 }
83                 else {
84                         String systemId = null;
85                         try {
86                                 systemId = getValue( "SYSTEM_ID" );
87                                 // SengGridAPI利用のメール送信機能呼び出し
88                                 final MailManager_DB_SendGridAPI manager = new MailManager_DB_SendGridAPI();
89                                 manager.sendDBMail( systemId );
90                         }
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 );
95                         }
96                         loopCnt++ ;
97                 }
98         }
99 }