ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/java/Config.java
Revision: 1.2
Committed: Mon Nov 27 20:36:13 2000 UTC (23 years, 9 months ago) by ab11
Branch: MAIN
Changes since 1.1: +178 -133 lines
Log Message:
changed the layout so it conforms to the Templateclass.java

File Contents

# User Rev Content
1 ab11 1.2 //---PACKAGE DECLARATION---
2    
3     //---IMPORTS---
4    
5 ab11 1.1 import java.net.*;
6     import java.util.*;
7     import java.io.*;
8    
9 ab11 1.2 /**
10     * Configurator object for the JavaHost
11     * Will connect to the configurator manager and collect its specific
12     * configuration
13     *
14     * @author $Author: ab11 $
15     * @version $Id: Config.java,v 1.1 2000/11/27 20:10 ab11 Exp $
16     */
17 ab11 1.1 class Config {
18    
19 ab11 1.2 //---FINAL ATTRIBUTES---
20    
21     //---STATIC METHODS---
22    
23     //---CONSTRUCTORS---
24    
25     public Config( String serverName, int serverPort ){
26     // takes in the master config settings and creates a connection with
27     // this computer, and downloads all the values listed in config.values.txt
28     // which should be in the local directory
29    
30     // read in from the file.
31     try {
32     BufferedReader inFile = new BufferedReader(new FileReader("config.values.txt"));
33     aList = new ArrayList();
34     numProperties = 0;
35     String tmpIn = inFile.readLine();
36     while ( tmpIn != null ){
37     aList.add(tmpIn);
38     numProperties++;
39     tmpIn = inFile.readLine();
40     }
41     }
42     catch ( FileNotFoundException e ){
43     // do something
44     }
45     catch ( IOException e ){
46     // do something
47     }
48    
49     // do the funky jibble
50     connect(serverName, serverPort);
51     }
52    
53     //---PUBLIC METHODS---
54    
55     public InetAddress getFilterName(){
56     // will return the most recient IP address (if it is dynamic for whatever reason
57     try {
58     return InetAddress.getByName(filterName);
59     }
60     catch ( UnknownHostException e ){
61     // do something
62     return null;
63     }
64    
65     }
66    
67     /**
68     * Used to retrieve the port to send UDP packets to on the filter
69     *
70     * @return an integer corrisponding to the UDP port of the filter
71     */
72     public int getFilterUDPPort(){
73    
74     return filterUDPPort;
75     }
76    
77     /**
78     * Used to retrieve the port to send TCP heartbeats to on the filter
79     *
80     * @return an integer corrisponding to the TCP of the filter
81     */
82     public int getFilterTCPPort(){
83    
84     return filterTCPPort;
85     }
86    
87     /**
88     * Used to get the hostname of the filter we are to talk to.
89     *
90     * @return a string representing the hostname of the filter
91     */
92     public String getProperty( String name ){
93    
94     if ( myProperties.containsKey(name) ){
95     // its in there, may return ERROR
96     return (String) myProperties.get(name);
97     }
98     else
99     {
100     // can't have been in the config.values.txt file!
101     return "ERROR";
102     }
103     }
104    
105    
106     //---PRIVATE METHODS---
107    
108     private void connect( String serverName, int serverPort ){
109     Socket mySocket;
110    
111     // might throw a UnknownHostException
112     try {
113     mySocket = new Socket(serverName, serverPort );
114     // ok we have our socket connected ok. grab their input and output streams
115     socketIn = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
116     socketOut = new PrintWriter(mySocket.getOutputStream());
117    
118    
119     if (sendCommand("STARTCONFIG") == "OK"){
120     // everything is fine
121     sendCommand("LASTMODIFIED");
122     sendCommand("FILELIST");
123    
124     // get all the properties
125     for ( int i = 0; i < numProperties; i++ ){
126     String property = (String) aList.get(i);
127     myProperties.put(property, sendCommand(property));
128     }
129    
130     sendCommand("ENDCONFIG");
131     String filter_data = sendCommand("FILTER");
132     StringTokenizer tok = new StringTokenizer(filter_data,";");
133     filterName = tok.nextToken();
134     filterUDPPort = Integer.parseInt(tok.nextToken());
135     filterTCPPort = Integer.parseInt(tok.nextToken());
136    
137     sendCommand("END");
138    
139     }
140    
141     // close the socket
142     mySocket.close();
143    
144     }
145     catch ( UnknownHostException e ){
146     // what to do
147     }
148     catch ( IOException e ){
149     // what to do
150     }
151    
152     } // connect
153    
154    
155     private String sendCommand(String command){
156    
157     socketOut.println(command);
158     try {
159     return socketIn.readLine();
160     }
161     catch ( IOException e ){
162     // something went wrong
163     return "ERROR";
164     }
165     }
166    
167     //---ACCESSOR/MUTATOR METHODS---
168    
169     //---ATTRIBUTES---
170    
171    
172     private String lastModified;
173     private int numProperties;
174     private Hashtable myProperties;
175     private String filterName;
176     private int filterUDPPort;
177     private int filterTCPPort;
178     private ArrayList aList;
179     private BufferedReader socketIn;
180     private PrintWriter socketOut;
181    
182    
183    
184     //---STATIC ATTRIBUTES---
185 ab11 1.1
186     } // class