diff options
Diffstat (limited to 'src/interfaces/jdbc/example/corba/StockDispenserImpl.java')
-rw-r--r-- | src/interfaces/jdbc/example/corba/StockDispenserImpl.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/interfaces/jdbc/example/corba/StockDispenserImpl.java b/src/interfaces/jdbc/example/corba/StockDispenserImpl.java new file mode 100644 index 00000000000..2d961a6dc7b --- /dev/null +++ b/src/interfaces/jdbc/example/corba/StockDispenserImpl.java @@ -0,0 +1,83 @@ +package example.corba; + +import org.omg.CosNaming.*; + +/** + * This class implements the server side of the example. + * + * $Id: StockDispenserImpl.java,v 1.1 1999/01/25 21:22:03 scrappy Exp $ + */ +public class StockDispenserImpl extends stock._StockDispenserImplBase +{ + private int maxObjects = 10; + private int numObjects = 0; + private StockItemStatus[] stock = new StockItemStatus[maxObjects]; + + public StockDispenserImpl(String[] args,String name,int num) + { + super(); + + try { + // get reference to orb + org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null); + + // prestart num objects + if(num>=maxObjects) + num=maxObjects; + numObjects = num; + for(int i=0;i<numObjects;i++) { + stock[i] = new StockItemStatus(); + stock[i].ref = new StockItemImpl(args,"StockItem"+(i+1)); + orb.connect(stock[i].ref); + } + } catch(org.omg.CORBA.SystemException e) { + e.printStackTrace(); + } + } + + /** + * This method, defined in stock.idl, reserves a slot in the dispenser + */ + public stock.StockItem reserveItem() throws stock.StockException + { + for(int i=0;i<numObjects;i++) { + if(!stock[i].inUse) { + stock[i].inUse = true; + System.out.println("Reserving slot "+i); + return stock[i].ref; + } + } + return null; + } + + /** + * This releases a slot from the dispenser + */ + public void releaseItem(stock.StockItem item) throws stock.StockException + { + for(int i=0;i<numObjects;i++) { + if(stock[i].ref.getInstanceName().equals(item.getInstanceName())) { + stock[i].inUse = false; + System.out.println("Releasing slot "+i); + return; + } + } + System.out.println("Reserved object not a member of this dispenser"); + return; + } + + /** + * This class defines a slot in the dispenser + */ + class StockItemStatus + { + StockItemImpl ref; + boolean inUse; + + StockItemStatus() { + ref = null; + inUse = false; + } + } + +} |