Removing uneeded file.
[and.git] / PC^2 / pc2team / samps / pc2 / ex / SampleGetRunsClient.java
blob444c6d08ddf86a55f320b02bcc0165a94e2fd1b7
1 package pc2.ex;
3 import java.io.*;
4 import java.net.*;
5 import java.rmi.*;
6 import java.rmi.registry.*;
7 import java.rmi.server.*;
8 import java.security.*;
9 import java.util.*;
10 import pc2.*;
12 import javax.swing.*;
14 /**
15 * SampleGetRunsClient is a sample implmentation of the abstract {@link GetRunsClient}
17 * @author PC<sup>2</sup> Team, pc2@ecs.csus.edu
19 public class SampleGetRunsClient extends GetRunsClient {
21 /**
24 public SampleGetRunsClient() throws java.rmi.RemoteException {
25 super();
27 /**
28 * Handle New Run (Sample)
29 * <P>
30 * Outputs most information to the log <Br>
31 * Unpacks the input files into the current directory
32 * prepending RunXX onto the start of the filename.
34 public void handleNewRun(RunInfoAndFiles run) {
36 String nl = System.getProperty("line.separator");
38 PC2Log.message("handleNewRun: "+
39 run.getUserSiteId() + ":" + run.getRunId() );
41 PC2Log.message("handleNewRun: "+
42 nl + "Run Info " +
43 nl + "site:id " + run.toString() +
44 nl + "user id " + run.getUserId() +
45 nl + "user name " + run.getUserTitle() +
46 nl + "problem id " + run.getProblemId() +
47 nl + "problem name " + run.getProblemTitle() +
48 nl + "language id " + run.getLanguageId() +
49 nl + "language name " + run.getLanguageTitle() +
50 nl + "main file name " + run.getMainFileName()
53 if (run.getNumUserFiles() == 0)
54 PC2Log.message("handleNewRun: There are no files");
55 else
57 PC2Log.message("handleNewRun: There are "+run.getNumUserFiles()+" files");
58 for (int i = 0; i < run.getNumUserFiles();i ++)
60 String newfilename = "Run"+run.getRunId()+"."+run.getUserFileName(i);
61 PC2Log.message("handleNewRun: File ["+i+"] "+run.getUserFileName(i)+" written to: "+newfilename);
62 try {
63 run.writeUserFile(i, newfilename);
64 } catch (Exception ex)
66 System.err.println("Exception in handleNewRun "+ex.getMessage());
71 /**
72 * Starts the application.
73 * @param args an array of command-line arguments
75 public static void main(java.lang.String[] args) {
77 SampleGetRunsClient sc =null;
78 try {
79 sc = new SampleGetRunsClient();
80 } catch (Exception e){
81 PC2Log.message("error in new SampleClient()",e);
82 System.exit(12);
85 String loginId = "custom1";
87 if (args.length > 0)
89 loginId = args[0];
90 System.err.println("From Command line using login: "+loginId);
93 // This sets the debug level for the log according to pc2v8.ini
94 if (new PC2ini().containsKey("client.debugLevel")) {
95 String temp=PC2ini.getKey("client.debugLevel");
96 try {
97 int value=new Integer(temp).intValue();
98 PC2Log.setDebugLevel(value);
99 } catch (NumberFormatException nfe) {
104 try {
105 if (! sc.loginToPC2("127.0.0.1", PC2Constants.DEFAULT_PC2_PORT, 1, loginId, loginId))
107 PC2Log.message("Could not login as "+loginId);
108 JFrame frame = new JFrame("Invisible JFrame... ooh");
109 JOptionPane.showMessageDialog
111 frame,
112 "Could not login as "+loginId,
113 "Login failure",
114 JOptionPane.INFORMATION_MESSAGE
116 System.exit(5);
119 } catch (Exception exc) {
120 PC2Log.message("Exception ",exc);
123 sc.showContestInfo(System.out);
125 sc.waitAround(); // Wait for new runs, see the doc
126 // for this method to find out why.
129 * Displays all contest info
131 public void showContestInfo(PrintStream ps) {
133 try {
135 // Problems
137 ps.println("showContestInfo");
138 ps.println("- - Problems - - ");
139 for (int i = 1; i <= getNumProblems(); i ++)
141 ps.println("Problem "+i+" \""+getProblemTitle(new Long(i))+"\"");
143 ps.println(getNumProblems()+" problems defined");
145 // Languages
147 ps.println("- - Languages - - ");
148 for (int i = 1; i <= getNumLanguages(); i ++)
150 ps.println("Language "+i+" \""+getLanguageTitle(new Long(i))+"\"");
152 ps.println(getNumLanguages()+" languages defined");
154 // Team Names
156 ps.println("- - Team Names - - ");
157 for (int i = 1; i <= getNumTeamAccounts(); i ++)
159 ps.println("Team "+i+" \""+getTeamName (new Long(1), new Long (i))+"\"");
161 ps.println(getNumTeamAccounts()+" accounts defined");
164 } catch (Exception ex) {
165 PC2Log.message("Exception ",ex);
171 * Wait around so that we can get incoming runs.
172 * <P>
173 * Wait around until a sentinel file 'stopcust' is
174 * created. When file is found in current directory
175 * will stop waiting.
176 * <P>
177 * This functionality is done within PC<sup>2</sup> by
178 * using JFrame to keep the JVM alive.
180 public void waitAround() {
182 long secs = 5;
183 String filename = "stopcust";
185 Thread th = new Thread();
187 PC2Log.message("Create file named '"+filename+"' to exit client.");
189 try {
190 for (long i = 1; ; i ++)
192 PC2Log.message("["+i+"] waiting for "+secs+" secs...");
193 th.sleep(secs * 1000);
194 th.yield();
196 File checkFile = new File(filename);
197 if (checkFile.exists())
199 checkFile = null;
200 PC2Log.message("Logging off...");
201 if (logoffPC2())
203 PC2Log.message("Logged out.");
204 th.yield();
205 th.sleep (secs * 1000);
206 System.exit(3);
210 } catch (Exception ex)
212 PC2Log.message("Exception ",ex);