
package cust.report;

import java.util.*;
import java.sql.Timestamp;

import wt.util.*;
import wt.queue.*;
import wt.scheduler.*;

import wt.org.WTPrincipalReference;
import wt.inf.container.*;

import wt.fc.*;
import wt.query.*;

import wt.method.RemoteMethodServer;
import wt.httpgw.GatewayAuthenticator;

public class schedQue_01e {

	static String div = "\n\n************************************************************\n";
    private static WtQueue selectedQueue = null;
    private static WtQueueEntry selectedEntry = null;

	public static void main(String[] args) throws Exception {
		RemoteMethodServer rms = RemoteMethodServer.getDefault();
		GatewayAuthenticator auth = new GatewayAuthenticator();
		auth.setRemoteUser("wcadmin");
		rms.setAuthenticator(auth);

		new schedQue_01e();
	}

	public schedQue_01e() throws Exception {

		System.out.println("\n");

		// ScheduleItem.class
		QueryResult resSI=PersistenceHelper.manager.find(new QuerySpec(ScheduleItem.class));
		while(resSI.hasMoreElements()) {

			ScheduleItem wtobj=(ScheduleItem)resSI.nextElement();

			System.out.println("Queue Name: "+wtobj.getQueueName());
			System.out.println("Target Class: "+wtobj.getTargetClass());
			System.out.println("Target Method: "+wtobj.getTargetMethod());
			System.out.println("To Be Run: "+(long)wtobj.getToBeRun());
			System.out.println("Periodicity: "+(long)wtobj.getPeriodicity());
			System.out.println("Item Name: "+wtobj.getItemName());
			System.out.println("Item Description: "+wtobj.getItemDescription());
			System.out.println("User=PrincipalRef: "+(WTPrincipalReference)wtobj.getPrincipalRef());
			System.out.println("Start Date: "+(Timestamp)wtobj.getStartDate());
			System.out.println("Next Time: "+(Timestamp)wtobj.getNextTime());
			System.out.println("Current Run Count: "+(long)wtobj.getCurrentRunCount());
			System.out.println("Current Next Time: "+(Timestamp)wtobj.getCurrentNextTime());
			System.out.println("Current Run Status: "+(WTMessage)wtobj.getCurrentRunStatus());
			System.out.println("Immediate Mode: "+(boolean)wtobj.isImmediateMode());

			QuerySpec queryspec = new QuerySpec(wt.scheduler.ScheduleHistory.class);
			queryspec.appendWhere(new SearchCondition(wt.scheduler.ScheduleHistory.class, "theScheduleItemReference.key", "=", PersistenceHelper.getObjectIdentifier(wtobj)));
			ClassAttribute classattribute = new ClassAttribute(wt.scheduler.ScheduleHistory.class, "submissionTime");
			OrderBy orderby = new OrderBy(classattribute, true);
			queryspec.appendOrderBy(orderby, queryspec.getFromClause().getPosition(wt.scheduler.ScheduleHistory.class));
			QueryResult queryresult = PersistenceHelper.manager.find(queryspec);
			ScheduleHistory schedulehistory = null;
			if(queryresult.hasMoreElements()) {
				schedulehistory = (ScheduleHistory)queryresult.nextElement();
				System.out.println("Schedule History: "+schedulehistory);
			}

    		System.out.println("\n");
		}
		System.out.println("Number of ScheduleItem Objects: "+resSI.size()+div);

		// ScheduleHistory.class
		QueryResult resSH=PersistenceHelper.manager.find(new QuerySpec(ScheduleHistory.class));
		while(resSH.hasMoreElements()) {

			ScheduleHistory wtobj=(ScheduleHistory)resSH.nextElement();

			System.out.println("Instance Status: "+(SchedStatusInfo)wtobj.getInstanceStatus());
			System.out.println("Submission Time: "+(Timestamp)wtobj.getSubmissionTime());
			System.out.println("Completion Time: "+(Timestamp)wtobj.getCompletionTime());
			System.out.println("Execution Start Time: "+(Timestamp)wtobj.getExecutionStartTime());
			System.out.println("Schedule Item: "+(ScheduleItem)wtobj.getScheduleItem());
			System.out.println("Schedule Item Reference: "+(ObjectReference)wtobj.getScheduleItemReference());
			System.out.println("Status Message: "+(WTMessage)wtobj.getStatusMessage());

    		System.out.println("\n");
		}
		System.out.println("Number of ScheduleHistory Objects: "+resSH.size()+div);

		// ScheduleQueue.class
		QueryResult resSQ=PersistenceHelper.manager.find(new QuerySpec(ScheduleQueue.class));
		while(resSQ.hasMoreElements()) {

			ScheduleQueue wtobj=(ScheduleQueue)resSQ.nextElement();

			System.out.println("Queue Name: "+wtobj.getName());
			System.out.println("Next Process Time: "+(Timestamp)wtobj.getNextProcessTime());
			System.out.println("Type: "+(Class)wtobj.getQType());
			System.out.println("Late Entries Count: "+(int)wtobj.getLateEntriesCount());

    		System.out.println("\n");
		}
		System.out.println("Number of ScheduleQueue Objects: "+resSQ.size()+div);

		// QueueWatcher.class
		QueryResult resQW=PersistenceHelper.manager.find(new QuerySpec(QueueWatcher.class));
		while(resQW.hasMoreElements()) {

			QueueWatcher wtobj=(QueueWatcher)resQW.nextElement();

			System.out.println("Watcher Name: "+wtobj.getName());
			System.out.println("Queue Enabled: "+(boolean)wtobj.getQueueEnabled());
			System.out.println("Queue Host: "+(boolean)wtobj.getThisQueueHost());
			System.out.println("Queue: "+(WtQueue)wtobj.getQueue());
			System.out.println("Runner: "+(Thread)wtobj.getRunner());
			System.out.println("Runner Thread: "+(boolean)wtobj.activeRunnerThread());
			System.out.println("Start Runner: "+(boolean)wtobj.getStartRunner());

    		System.out.println("\n");
		}
		System.out.println("Number of QueueWatcher Objects: "+resQW.size()+div);
	}
}