summaryrefslogtreecommitdiff
path: root/java/JACE/netsvcs/Time/TSServerHandler.java
blob: 69bf423928066fce2f210dbfd474196db1128f36 (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
package JACE.netsvcs.Time;

import java.io.*;
import java.util.*;
import java.net.*;
import JACE.OS.*;
import JACE.Connection.*;
import JACE.Reactor.*;
import JACE.SOCK_SAP.*;
import JACE.netsvcs.Handler;

/**
 * Created by TSServerAcceptor to handle time update requests.  Currently,
 * this simply sends back the current time (in seconds).
 *
 * @see JACE.netsvcs.Logger.ServerLoggingAcceptor
 */
public class TSServerHandler extends Handler
{
  /**
   * Reads in the given TimeRequest request and calls dispatch.
   *
   *@param request TimeRequest instance to use
   */
  public void processRequest (Object requestObject)
    throws SocketException, EOFException, IOException
  {
    TimeRequest request = (TimeRequest)requestObject;

    request.streamInFrom (peer ().dataInputStream ());

    this.dispatch (request);
  }

  /**
   * Sets the time value of the request to be the local time (in sec)
   * and sends it back to the client.
   */
  void dispatch(TimeRequest request) throws IOException
  {
    request.time ((int)(System.currentTimeMillis () / 1000));

    request.streamOutTo (peer().outputStream ());
  }

  /**
   * Creates a new instance of TimeRequest.
   */
  public Object newRequest ()
  {
    return new TimeRequest ();
  }
}