blob: 40f1aee8440ec97a483cf705cae1efb2bfde674b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
/*************************************************
*
* = PACKAGE
* netsvcs.Logger
*
* = FILENAME
* ServerLoggingHandler.java
*
*@author Chris Cleeland, Everett Anderson
*
*************************************************/
package netsvcs.Logger;
import JACE.SOCK_SAP.*;
import JACE.Connection.*;
import JACE.OS.*;
import java.util.*;
import java.io.*;
/**
*
* <p><h2>DESCRIPTION</h2>
*
* <blockquote>
* Created by ServerLoggingAcceptor every time a client connects. This reads
* a logging statement passes it to the LogMessageReceiver for processing.
* </blockquote>
*
* @see netsvcs.Logger.ServerLoggingAcceptor
*/
public class ServerLoggingHandler extends SvcHandler
{
// Processes log messages
private LogMessageReceiver receiver_;
/**
* Constructor
*
*@param receiver LogMessageReceiver that handles what to do with a message
*/
public ServerLoggingHandler (LogMessageReceiver receiver)
{
super();
this.receiver_ = receiver;
}
/**
* Start this handler in its own thread
*/
public int open(Object obj)
{
new Thread (this).start();
return 0;
}
/**
* Accessor: get the host name of the connected client
*/
protected String hostName ()
{
return new String(this.peer().socket().getInetAddress().getHostName());
}
/**
* Receive input from the client, and send it to the LMR. This is the
* main loop for this thread.
*/
public void run()
{
DataInputStream dis = new DataInputStream(this.peer().inputStream());
for (;;)
{
// Messages arrive in the ACE.LogRecord format
//
// Hey! We need exception catching in here too!
try
{
// Reconstitute a log message from the wire
LogRecord rec = new LogRecord();
rec.streamInFrom(dis);
// Give the record to the log processor
this.receiver_.logRecord(this.hostName(),
rec);
}
catch (EOFException eof)
{
try {
this.stream_.close();
} catch (IOException n) { }
return;
}
catch (IOException ioe)
{
ACE.ERROR(Thread.currentThread().getName()
+ ": "
+ ioe);
}
}
}
};
|