Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/telefonicasoluciones/search/server/HLHandler.java


1   package com.telefonicasoluciones.search.server;
2   
3   /**
4    * Enlaza los procesos de la aplicación.
5    * Creation date: (17/04/2001 9:57:14)
6    *     
7    * @author: Ricardo Lorenzo
8    */
9   import java.util.*;
10  import java.io.*;
11  import java.net.*;
12  import com.telefonicasoluciones.search.server.util.*;
13   
14  public class HLHandler {
15    private HLConfig config;
16    private boolean loaded;
17    public static final ThreadGroup CTG = new ThreadGroup("HEADLIGHT CTG");
18    public static final ThreadGroup TG = new ThreadGroup("HEADLIGHT TG");
19    private String indexDirectory;
20    private String temporaryDirectory;
21    private HashMap fileTypes;
22    private OutputStream connectionStream;
23    private OutputStream indexStream;
24          private OutputStream searchStream;
25    private OutputStream errorStream;
26    private Socket connector;
27    private HTTPClient session;
28  /**
29   * HLSyncronyze constructor comment.
30   */
31      public HLHandler(HLConfig newConfig) {
32    config = newConfig;
33          loaded = false;
34      }
35  /**
36   * Insert the method's description here.
37   * Creation date: (10/01/2002 9:46:26)
38   * @return java.net.Socket
39   */
40      public java.net.Socket getConnector() {
41              return connector;
42      }
43  /**
44   * Insert the method's description here.
45   * Creation date: (10/01/2002 9:40:10)
46   * @return java.util.Hashtable
47   */
48      public java.util.HashMap getFileTypes() {
49              return fileTypes;
50      }
51      /**
52   * Insert the method's description here.
53   * Creation date: (24/01/2002 19:51:46)
54   * @return artmedia.search.engine.HLWebSurfer
55   */
56      public HTTPClient getSession() {
57              return session;
58      }
59  /**
60   * Insert the method's description here.
61   * Creation date: (10/01/2002 10:37:39)
62   * @return java.lang.String
63   */
64      public java.lang.String getIndexDirectory() {
65              return indexDirectory;
66      }
67  /**
68   * Insert the method's description here.
69   * Creation date: (10/01/2002 10:37:39)
70   * @return java.lang.String
71   */
72      public java.lang.String getTemporaryDirectory() {
73              return temporaryDirectory;
74      }
75  /**
76   * Crea una instancia de HLSyncronize.
77   * Creation date: (10/01/2002 9:47:39)
78   * @return artmedia.search.engine.HLSyncronize
79   * @param newConnector java.net.Socket
80   */
81      public HLHandler getInstance(Socket newConnector) throws HLHandlerException {
82    HLHandler hls = new HLHandler(config);
83          HashMap configuration = config.getConfiguration("default");
84          if(configuration!=null) {
85              String logDirectory = (String) configuration.get("logdir");
86              verifyDirectory(logDirectory);
87              try {
88                  hls.connectionStream = new FileOutputStream(logDirectory+"connection.log",true);
89              } catch (FileNotFoundException fnfe) {
90                  throw new HLHandlerException("Log directory not found");  
91              }
92          }
93          hls.connector = newConnector;
94    return hls;
95      }
96  /**
97   * Insert the method's description here.
98   * Creation date: (10/01/2002 10:35:51)
99   * @return boolean
100  */
101     public boolean isLoaded() {
102   return loaded;
103     }
104 /**
105  * Carga la configuración correspondiente a
106  * una instancia del servidor.
107  * Creation date: (10/01/2002 9:15:47)
108  * @param user java.lang.String
109  */
110     public void load(String user) throws HLHandlerException {
111   HashMap configuration = config.getConfiguration(user);
112   if (configuration!=null) {
113             indexDirectory = (String) configuration.get("indexdir");
114             String logDirectory = (String) configuration.get("logdir");
115             temporaryDirectory = (String) configuration.get("tempdir");
116             verifyDirectory(indexDirectory);
117             verifyDirectory(logDirectory);
118             verifyDirectory(temporaryDirectory);
119             fileTypes = (HashMap) configuration.get("file-type");
120             try {
121                 connectionStream = new FileOutputStream(logDirectory+"connection.log",true);
122                 indexStream = new FileOutputStream(logDirectory+"index.log",true);
123                 searchStream = new FileOutputStream(logDirectory+"search.log",true);
124                 errorStream = new FileOutputStream(logDirectory+"error.log",true);
125             } catch (FileNotFoundException fnfe) {
126                 throw new HLHandlerException("Log directory not found");  
127             }
128             loaded = true;
129   } else {
130             throw new HLHandlerException("User not found");
131   }
132 }
133 /**
134  * Define la sesión HTTP de.
135  * Creation date: (24/01/2002 19:51:46)
136  * @param session artmedia.search.engine.HLWebSurfer
137  */
138     public void setSession(HTTPClient session) {
139   this.session = session;
140     }
141 /**
142  * Insert the method's description here.
143  * Creation date: (10/01/2002 10:00:03)
144  * @param text java.lang.String
145  */
146     public void writeSocketResponse(String text) {
147   try { 
148             connector.getOutputStream().write((text+"\n").getBytes());
149             connector.getOutputStream().flush();
150   } catch (IOException ioe) {
151   } catch (NullPointerException npe) {}
152     }
153 /**
154  * Insert the method's description here.
155  * Creation date: (10/01/2002 10:00:03)
156  * @param text java.lang.String
157  */
158     public void writeConnectionLog(String text) {
159   try { connectionStream.write((text+"\n").getBytes());
160   } catch (IOException ioe) {
161   } catch (NullPointerException npe) {}
162     }
163 /**
164  * Insert the method's description here.
165  * Creation date: (10/01/2002 10:00:03)
166  * @param text java.lang.String
167  */
168     public void writeErrorLog(String text) {
169   try { errorStream.write((text+"\n").getBytes());
170   } catch (IOException ioe) {
171   } catch (NullPointerException npe) {}  
172     }
173 /**
174  * Insert the method's description here.
175  * Creation date: (10/01/2002 10:00:03)
176  * @param text java.lang.String
177  */
178     public void writeSearchLog(String text) {
179   try { searchStream.write((text+"\n").getBytes());
180   } catch (IOException ioe) {
181   } catch (NullPointerException npe) {}  
182     }
183 /**
184  * Insert the method's description here.
185  * Creation date: (10/01/2002 10:00:03)
186  * @param text java.lang.String
187  */
188     public void writeIndexLog(String text) {
189   try { indexStream.write((text+"\n").getBytes());
190   } catch (IOException ioe) {
191   } catch (NullPointerException npe) {}  
192     }
193 /**
194  * Insert the method's description here.
195  * Creation date: (10/01/2002 10:00:03)
196  * @param text java.lang.String
197  */
198     private void verifyDirectory(String directory) throws HLHandlerException {
199   try { 
200             File directoryFile = new File(directory);
201             if(!directoryFile.exists()) {
202                 directoryFile.mkdirs();
203             }
204   } catch (Exception e) {
205             throw new HLHandlerException(e.getMessage());
206   }  
207     }
208     public void finalize()  {
209   try {
210             if(getConnector()!=null) {
211                 getConnector().close();
212             }
213   } catch (IOException e) {}
214     }
215 }