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.fukurou.util;
017
018import java.util.Date ;
019
020import org.opengion.fukurou.system.LogWriter;                                           // 6.4.2.0 (2016/01/29) package変更 fukurou.util → fukurou.system
021
022/**
023 * StopTimer は、指定の一定時間の間、実行を停止します。
024 * 引数に、停止時間を秒単位で指定します。
025 * 初期値は、5(秒)です。
026 *
027 * Usage: java org.opengion.fukurou.fukurou.util.StopTimer 停止時間(秒) [-T]
028 *
029 * @og.group ユーティリティ
030 *
031 * @version  4.0
032 * @author   Kazuhiko Hasegawa
033 * @since    JDK5.0,
034 */
035public final class StopTimer {
036
037        /**
038         * すべてが staticメソッドなので、コンストラクタを呼び出さなくしておきます。
039         *
040         */
041        private StopTimer() {}
042
043        /**
044         * 処理を実行する main メソッドです。
045         *
046         * 引数には、処理を停止する 秒数 を入力します。
047         * -T を入力した場合は、処理開始時刻を表示します。
048         *
049         * Usage: java org.opengion.fukurou.fukurou.util.StopTimer 停止時間(秒) [-T]
050         *
051         * @param       args    コマンド引数配列
052         */
053        public static void main( final String[] args ) {
054                long stopTime ;
055
056                if( args.length >= 1 ) { stopTime = 1000L * Long.parseLong( args[0] ) ; }
057                else {
058                        LogWriter.log("Usage: java org.opengion.fukurou.fukurou.util.StopTimer 停止時間(秒) [-T]");
059                        return;
060                }
061
062                if( args.length ==2 && "-T".equals( args[1] ) ) {
063                        System.out.println( new Date() );
064                }
065
066                try {
067                        Thread.sleep( stopTime );
068                }
069                catch( final InterruptedException ex ) {
070                        LogWriter.log( "InterruptedException:" + ex.getMessage() );
071                }
072        }
073}