001package org.opengion.fukurou.queue; 002 003import java.util.Locale; 004 005// import org.opengion.fukurou.util.StringUtil; 006 007/** 008 * キュータイプ別の受信クラス生成 009 * 指定されたキュータイプの受信クラスを生成します。 010 * 011 * 下記のキュータイプを指定可能です。 012 * MQ:Active MQ or Amazon MQ 013 * SQS:Amazon SQS。 014 * 015 * @og.group メッセージ連携 016 * 017 * @og.rev 5.10.15.2 (2019/09/20) 新規作成 018 * @og.rev 7.2.9.4 (2020/11/20) コーディングのみ修正 019 * 020 * @version 5 021 * @author oota 022 * @since JDK7 023 * 024 */ 025final public class QueueReceiveFactory { 026// private static final int BUFFER_MIDDLE = 200; 027 028 private static final String QUEUE_CLS = "org.opengion.fukurou.queue.QueueReceive_" ; 029 030 /** 031 * デフォルトコンストラクター 032 * static用クラスのため、クラス生成は不可にします。 033 */ 034 private QueueReceiveFactory() { 035 } 036 037 /** 038 * キュー受信クラス生成 039 * 040 * 引数のキュータイプのキュー受信クラスを生成します。 041 * MQ:Apache ActiveMq、amazonMQの場合に設定します。 042 * SQS:Amazon SQSの場合に設定します。 043 * 044 * @param queueType キュータイプ 045 * @return キュータイプのキュー受信クラス 046 */ 047 public static QueueReceive newQueueReceive(final String queueType) { 048 try { 049 // 1. 前処理 大文字変換。queueType が null なら、当然エラーになる。 050 // 2. 生成クラスの文字列生成 051 final String cls = QUEUE_CLS + queueType.toUpperCase(Locale.JAPAN); 052 053 // 3. 対象クラスの生成 054 return (QueueReceive) Class.forName( cls ).getDeclaredConstructor().newInstance(); 055 056 } catch (final Throwable th) { 057 final String errMsg = "キュー受信クラス生成に失敗しました。" 058 + " queueType =" + queueType ; 059 throw new RuntimeException( errMsg ,th ); 060 } 061 062// QueueReceive queueReceive = null; 063// String setQueueType = null; 064// 065// final StringBuilder path = new StringBuilder(BUFFER_MIDDLE); 066// 067// // 1. 前処理 068// // 大文字変換 069// if (!StringUtil.isNull(queueType)) { 070// setQueueType = queueType.toUpperCase(Locale.JAPAN); 071// } 072// 073// // 2. 生成クラスの文字列生成 074// path.append("org.opengion.fukurou.queue.") 075// .append("QueueReceive_") 076// .append(setQueueType); 077// 078// try { 079// // 3. 対象クラスの生成 080// queueReceive = (QueueReceive) Class.forName(path.toString()).newInstance(); 081// } catch (final Throwable th) { 082// // キャッチしたエラー情報をスロー 083// throw new RuntimeException(th); 084// } 085// 086// return queueReceive; 087 } 088}