summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/jndi/PrimaryKeyGeneratorImpl.java
blob: eeb08cb4b780d95d97a972de613a27f430992651 (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
package examples.jndi;

import java.rmi.RemoteException;
import javax.rmi.PortableRemoteObject;

/**
 * The implementation of a remote object which generates primary keys
 */
public class PrimaryKeyGeneratorImpl 
	extends PortableRemoteObject 
	implements PrimaryKeyGenerator {
	
	private static long i = System.currentTimeMillis();
	
	public PrimaryKeyGeneratorImpl() throws Exception, RemoteException {
		/*
		 * Since we extend PortableRemoteObject, the super
		 * class will export our remote object here.
		 */
		super();
	}

	/**
	 * Generates a unique primary key
	 */
	public synchronized long generate() throws RemoteException {
		return i++;
	}
}