aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/example/corba/StockServer.java
blob: 6e34cbcd48d47058194ea2bc9e5bfaf81d744400 (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 example.corba;

import org.omg.CosNaming.*;

/**
 * This class implements the server side of the example.
 *
 * $Id: StockServer.java,v 1.1 1999/01/25 21:22:04 scrappy Exp $
 */
public class StockServer
{
    public static void main(String[] args)
    {
	int numInstances = 3;
	
	try {
	    // Initialise the ORB
	    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
	    
	    // Create the StockDispenser object
	    StockDispenserImpl dispenser = new StockDispenserImpl(args,"Stock Dispenser",numInstances);
	    
	    // Export the new object
	    orb.connect(dispenser);
	    
	    // Get the naming service
	    org.omg.CORBA.Object nameServiceObj = orb.resolve_initial_references("NameService");
	    if(nameServiceObj == null) {
		System.err.println("nameServiceObj = null");
		return;
	    }
	    
	    org.omg.CosNaming.NamingContext nameService = org.omg.CosNaming.NamingContextHelper.narrow(nameServiceObj);
	    if(nameService == null) {
		System.err.println("nameService = null");
		return;
	    }
	    
	    // bind the dispenser into the naming service
	    NameComponent[] dispenserName = {
		new NameComponent("StockDispenser","Stock")
	    };
	    nameService.rebind(dispenserName,dispenser);
	    
	    // Now wait forever for the current thread to die
	    Thread.currentThread().join();
	} catch(Exception e) {
	    e.printStackTrace();
	}
    }
}