FileDocCategorySizeDatePackage
ServantManagerImpl.javaAPI DocJava SE 5 API5936Fri Aug 26 14:54:26 BST 2005com.sun.corba.se.impl.naming.pcosnaming

ServantManagerImpl

public class ServantManagerImpl extends LocalObject implements ServantLocator
version
1.6, 99/10/07
author
Rohit Garg
since
JDK1.2

Fields Summary
private static final long
serialVersionUID
private ORB
orb
private NameService
theNameService
private File
logDir
private Hashtable
contexts
private CounterDB
counterDb
private int
counter
private static final String
objKeyPrefix
Constructors Summary
ServantManagerImpl(ORB orb, File logDir, NameService aNameService)


         
    
	this.logDir = logDir;
	this.orb    = orb;
	// initialize the counter database
	counterDb   = new CounterDB(logDir);
	contexts    = new Hashtable();
	theNameService = aNameService;
    
Methods Summary
public com.sun.corba.se.impl.naming.pcosnaming.NamingContextImpladdContext(java.lang.String objKey, com.sun.corba.se.impl.naming.pcosnaming.NamingContextImpl context)

	File contextFile =  new File(logDir, objKey);

	if (contextFile.exists()) 
	{
	    context = readInContext(objKey);
	}
	else {
	    try {
		FileOutputStream fos = new FileOutputStream(contextFile);
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeObject(context);
		oos.close();
	    } catch (Exception ex) {
	    }
	}
	try
	{
		contexts.remove( objKey );
	}
	catch( Exception e)
	{
	}
	contexts.put(objKey, context);

	return context;
    
public java.lang.StringgetNewObjectKey()

	return objKeyPrefix + counterDb.getNextCounter();
    
public static java.lang.StringgetRootObjectKey()

	return objKeyPrefix + CounterDB.rootCounter;
    
public voidpostinvoke(byte[] oid, org.omg.PortableServer.POA adapter, java.lang.String operation, java.lang.Object cookie, org.omg.PortableServer.Servant servant)

	// nada
    
public org.omg.PortableServer.Servantpreinvoke(byte[] oid, org.omg.PortableServer.POA adapter, java.lang.String operation, org.omg.PortableServer.ServantLocatorPackage.CookieHolder cookie)


	String objKey = new String(oid);

	Servant servant = (Servant) contexts.get(objKey);

	if (servant == null)
	{
		 servant =  readInContext(objKey);
	}

	return servant;
    
public com.sun.corba.se.impl.naming.pcosnaming.NamingContextImplreadInContext(java.lang.String objKey)

	NamingContextImpl context = (NamingContextImpl) contexts.get(objKey);
	if( context != null )
	{
		// Returning Context from Cache
		return context;
	}	

	File contextFile = new File(logDir, objKey);
	if (contextFile.exists()) {
	    try {
		FileInputStream fis = new FileInputStream(contextFile);
		ObjectInputStream ois = new ObjectInputStream(fis);
		context = (NamingContextImpl) ois.readObject();
		context.setORB( orb );
		context.setServantManagerImpl( this );
		context.setRootNameService( theNameService );
		ois.close();
	    } catch (Exception ex) {
	    }
	}

	if (context != null)
	{
		contexts.put(objKey, context);
	}
	return context;
    
public voidupdateContext(java.lang.String objKey, com.sun.corba.se.impl.naming.pcosnaming.NamingContextImpl context)

	File contextFile =  new File(logDir, objKey);
	if (contextFile.exists()) 
	{
		contextFile.delete( );
		contextFile =  new File(logDir, objKey);
	}
		
        try {
		FileOutputStream fos = new FileOutputStream(contextFile);
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeObject(context);
		oos.close();
	    } catch (Exception ex) {
		ex.printStackTrace( );
	    }