⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stockdispenserimpl.java

📁 关系型数据库 Postgresql 6.5.2
💻 JAVA
字号:
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;	}    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -