KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > rmi > examples > time > TimeServiceImpl


1 package org.sapia.ubik.rmi.examples.time;
2
3 import java.text.SimpleDateFormat JavaDoc;
4
5 import java.util.Date JavaDoc;
6
7
8 /**
9  * @
10  */

11 public class TimeServiceImpl implements TimeServiceIF {
12   private SimpleDateFormat JavaDoc _theFormat;
13   private int _theCoutner;
14   private String JavaDoc _theId;
15
16   /**
17    * Creates a new TimeServiceImpl instance.
18    */

19   public TimeServiceImpl() {
20     System.out.println("Creating a new sticky time service...");
21     _theFormat = new SimpleDateFormat JavaDoc("yyyy-MM-dd HH:mm:ss z");
22     _theId = Integer.toHexString(String.valueOf(
23           System.currentTimeMillis()).hashCode());
24   }
25
26   /**
27    * Implements the TimeServiceIF interface.
28    *
29    * @see org.sapia.test.TimeServiceIF#getTime()
30    */

31   public String JavaDoc getTime() {
32     long aCurrentTime = System.currentTimeMillis();
33     Date JavaDoc aCurrentDate = new Date JavaDoc(aCurrentTime);
34     String JavaDoc aResult = _theFormat.format(aCurrentDate);
35
36     System.out.println((++_theCoutner) + " - Invocation took " +
37       (System.currentTimeMillis() - aCurrentTime) + " ms @" + _theId);
38
39     return aResult + " @" + _theId;
40   }
41 }
42
Popular Tags