001/** 002 * //////////////////////////////////////////////////////////////////////////////// 003 * // 004 * // D SOFTWARE INCORPORATED 005 * // Copyright 2007-2014 D Software Incorporated 006 * // All Rights Reserved. 007 * // 008 * // NOTICE: D Software permits you to use, modify, and distribute this file 009 * // in accordance with the terms of the license agreement accompanying it. 010 * // 011 * // Unless required by applicable law or agreed to in writing, software 012 * // distributed under the License is distributed on an "AS IS" BASIS, 013 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * // 015 * //////////////////////////////////////////////////////////////////////////////// 016 */ 017package com.thed.util; 018import com.thed.wrapper.ZephyrWrapperSimpleApp; 019 020/** 021 * @serial exclude 022 * @author zephyrDev 023 */ 024public class MonitorThread implements Runnable { 025 026 private boolean done = false ; 027 028 /** 029 * <b>Description</b>: 030 * @see java.lang.Runnable#run() 031 */ 032 public void run() { 033 while (!done) { 034 try { 035 Thread.sleep(ZephyrWrapperSimpleApp.FREQUENCEY * 1000); 036 037 // if monitor file has been updated, user's login script would have been triggered. 038 long newTimestamp = Utils.lastModifiedTimeOfMonitorFile(ZephyrWrapperSimpleApp.MONITOR_FILE); 039 040 if ( newTimestamp > ZephyrWrapperSimpleApp.getLastModifiedTime()) { 041 042 System.out.println("**MonitorThread**: User logged in. Resetting the menu."); 043 044 ZephyrWrapperSimpleApp.setLastModifiedTime(newTimestamp); 045 046 /* 047 * Once it happened that two menus were visible on tray, although couldn't reproduce the issue. 048 * Defensive coding: removeAll() removes reference to previous menu. CreateMenu() recreates it. 049 */ 050 ZephyrWrapperSimpleApp.getZBotSysTray().getMenu().removeAll(); 051 ZephyrWrapperSimpleApp.getZBotSysTray().createMenu(); 052 053 // user has logged in, purpose of this thread is completed. 054 done = true ; 055 056 } 057 058 } catch (InterruptedException ie) { 059 System.out.println("**MonitorThread**: InterruptedException :" + ie.getMessage()); 060 } 061 } 062 System.out.println("**MonitorThread**: end of run() method in thread."); 063 064 } 065 066}