FileDocCategorySizeDatePackage
DomainRegistry.javaAPI DocGlassfish v2 API6788Fri May 04 22:33:32 BST 2007com.sun.enterprise.admin.common.domains.registry

DomainRegistry

public class DomainRegistry extends Object implements DomainRegistryI
This class provides a registry for domains, abstracting the persistent storage and coordination activities required to permit uniqueness invariants to be maintained between domains no matter which JVM they are being referred from.

The directory in which the persistent store is kept is denoted by the System property com.sun.aas.admin.configRoot. The name of the file is domains.ser

The principal invariants this registry maintains is that no two domains shall have the same name, and no two domains shall have the same location.

The registry can be considered to be a table whose keys are domain name and domain location, and whose values are the remote contact information by which the adminstration server within that domain can be contacted remotely.

A row in this table is abstracted into the {@link DomainEntry} class.

author
Toby H Ferguson
version
$Revision: 1.5 $

Fields Summary
private Registry
registry
private LockingStore
store
private static DomainRegistry
instance
private long
lastModified
Constructors Summary
private DomainRegistry()

  
   
Methods Summary
public booleancontainsDomain(DomainEntry de)

	  refreshRegistry();
	  return registry.containsDomain(de);
	
public DomainEntrygetDomain(java.lang.String name)

	  refreshRegistry();
	  return registry.getDomain(name);
	
private RegistrygetRegistryFromStore()

	Registry br;
	br = (Registry) store.readObject();
	return (br != null ? br : new Registry());
  
private voidinit()

	try {
	  store = LockingStoreFactory.getInstance();
	  registry = getRegistryFromStore();
	}
	catch (Exception e){
	  throw new DomainRegistryException("couldn't initialize registry. Error message: "+ e.getMessage());
	}
  
public java.util.Iteratoriterator()

	refreshRegistry();
	return registry.iterator();
  
public static synchronized com.sun.enterprise.admin.common.domains.registry.DomainRegistrynewInstance()
Return an instance of the DomainRegistry

return
a DomainRegistry value
throws
DomainRegistryException if there was a problem instantiating the class

	if (instance == null){
	  instance = new DomainRegistry();
	  instance.init();
	}
	return instance;
  
private voidprepareForUpdate()

	try {
	  store.lock();
	}
	catch (Exception e){
	  throw new DomainRegistryException("problem locking store ", e);
	}
	refreshRegistry();
  
private voidrefreshRegistry()

	if (lastModified < store.lastModified()){
	  try {
		registry = getRegistryFromStore();
	  }
	  catch (Exception te){
		throw new DomainRegistryException("problem reading from store", te);
	  }
	}
  
public synchronized voidregisterDomain(DomainEntry de)

		prepareForUpdate();
		try {
		  registry.registerDomain(de);
		}
		catch (DomainRegistryException e){
		  store.unlock();
		  throw e;
		}
		saveRegistry();
	
public voidreregisterDomain(DomainEntry de)

	  prepareForUpdate();
	  try {
		registry.reregisterDomain(de);
	  }
	  catch (DomainRegistryException e){
		store.unlock();
		throw e;
	  }
	  saveRegistry();

	
synchronized voidreset()

	  store.unlock();
	  registry = null;
	  store = null;
	  instance = null;
	
private voidsaveRegistry()

	try {
	  store.writeObject(registry);
	  store.unlock();
	  lastModified = store.lastModified();
	}
	catch (Exception e){
	  e.printStackTrace();
	  throw new DomainRegistryException("couldn't save registry", e);
	}
  
public intsize()

	  refreshRegistry();
	  return registry.size();
	
public voidunregisterDomain(java.lang.String domain_name)

	  prepareForUpdate();
	  try{
		registry.unregisterDomain(domain_name);
	  }
	  catch (DomainRegistryException e){
		store.unlock();
		throw e;
	  }
	  saveRegistry();
	  
	
public voidunregisterDomain(DomainEntry de)

	  this.unregisterDomain(de.getName());