KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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