TransientNamingContextpublic class TransientNamingContext extends NamingContextImpl implements NamingContextDataStoreClass TransientNamingContext implements the methods defined
by NamingContextDataStore, and extends the NamingContextImpl class to
provide a servant implementation of CosNaming::NamingContext.
The TransientNamingContext uses a hash table
to store the mappings between bindings and object references and the
hash table is not persistent; thereby the name "transient".
This class should not be used directly; instead, the class
TransientNameService should be instantiated.
The keys in the hash table are InternalBindingKey objects, containing
a single NameComponent and implementing the proper functions, i.e.,
equals() and hashCode() in an efficient manner. The values in the hash
table are InternalBindingValues and store a org.omg.CosNaming::Binding and
the object reference associated with the binding. For iteration,
TransientBindingIterator objects are created, which are passed a cloned
copy of the hashtable. Since elements are inserted and deleted and
never modified, this provides stable iterators at the cost of cloning
the hash table.
To create and destroy object references, the TransientNamingContext
uses the orb.connect() and orb.disconnect() methods. |
Fields Summary |
---|
private Logger | readLogger | private Logger | updateLogger | private Logger | lifecycleLogger | private com.sun.corba.se.impl.logging.NamingSystemException | wrapper | private final Hashtable | theHashtable | public org.omg.CORBA.Object | localRootThe local root naming context. |
Constructors Summary |
---|
public TransientNamingContext(com.sun.corba.se.spi.orb.ORB orb, org.omg.CORBA.Object initial, org.omg.PortableServer.POA nsPOA)Constructs a new TransientNamingContext object.
super(orb, nsPOA );
wrapper = NamingSystemException.get( orb, CORBALogDomains.NAMING ) ;
this.localRoot = initial;
readLogger = orb.getLogger( CORBALogDomains.NAMING_READ);
updateLogger = orb.getLogger( CORBALogDomains.NAMING_UPDATE);
lifecycleLogger = orb.getLogger(
CORBALogDomains.NAMING_LIFECYCLE);
lifecycleLogger.fine( "Root TransientNamingContext LIFECYCLE.CREATED" );
|
Methods Summary |
---|
public final void | Bind(org.omg.CosNaming.NameComponent n, org.omg.CORBA.Object obj, org.omg.CosNaming.BindingType bt)Binds the object to the name component as the specified binding type.
It creates a InternalBindingKey object and a InternalBindingValue
object and inserts them in the hash table.
// Create a key and a value
InternalBindingKey key = new InternalBindingKey(n);
NameComponent[] name = new NameComponent[1];
name[0] = n;
Binding b = new Binding(name,bt);
InternalBindingValue value = new InternalBindingValue(b,null);
value.theObjectRef = obj;
// insert it
InternalBindingValue oldValue =
(InternalBindingValue)this.theHashtable.put(key,value);
if (oldValue != null) {
updateLogger.warning( LogKeywords.NAMING_BIND + "Name " +
getName( n ) + " Was Already Bound" );
throw wrapper.transNcBindAlreadyBound() ;
}
if( updateLogger.isLoggable( Level.FINE ) ) {
updateLogger.fine( LogKeywords.NAMING_BIND_SUCCESS +
"Name Component: " + n.id + "." + n.kind );
}
| public final void | Destroy()Destroys this NamingContext by disconnecting from the ORB.
// Destroy the object reference by disconnecting from the ORB
try {
byte[] objectId = nsPOA.servant_to_id( this );
if( objectId != null ) {
nsPOA.deactivate_object( objectId );
}
if( lifecycleLogger.isLoggable( Level.FINE ) ) {
lifecycleLogger.fine(
LogKeywords.LIFECYCLE_DESTROY_SUCCESS );
}
} catch (org.omg.CORBA.SystemException e) {
lifecycleLogger.log( Level.WARNING,
LogKeywords.LIFECYCLE_DESTROY_FAILURE, e );
throw e;
} catch (Exception e) {
lifecycleLogger.log( Level.WARNING,
LogKeywords.LIFECYCLE_DESTROY_FAILURE, e );
throw wrapper.transNcDestroyGotExc( e ) ;
}
| public final boolean | IsEmpty()Return whether this NamingContext contains any bindings. It forwards
this request to the hash table.
return this.theHashtable.isEmpty();
| public final void | List(int how_many, org.omg.CosNaming.BindingListHolder bl, org.omg.CosNaming.BindingIteratorHolder bi)List the contents of this NamingContext. It creates a new
TransientBindingIterator object and passes it a clone of the
hash table and an orb object. It then uses the
newly created object to return the required number of bindings.
try {
// Create a new binding iterator servant with a copy of this
// hashtable. nsPOA is passed to the object so that it can
// de-activate itself from the Active Object Map when
// Binding Iterator.destroy is called.
TransientBindingIterator bindingIterator =
new TransientBindingIterator(this.orb,
(Hashtable)this.theHashtable.clone(), nsPOA);
// Have it set the binding list
bindingIterator.list(how_many,bl);
byte[] objectId = nsPOA.activate_object( bindingIterator );
org.omg.CORBA.Object obj = nsPOA.id_to_reference( objectId );
// Get the object reference for the binding iterator servant
org.omg.CosNaming.BindingIterator bindingRef =
org.omg.CosNaming.BindingIteratorHelper.narrow( obj );
bi.value = bindingRef;
} catch (org.omg.CORBA.SystemException e) {
readLogger.warning( LogKeywords.NAMING_LIST_FAILURE + e );
throw e;
} catch (Exception e) {
// Convert to a CORBA system exception
readLogger.severe( LogKeywords.NAMING_LIST_FAILURE + e );
throw wrapper.transNcListGotExc( e ) ;
}
| public final org.omg.CosNaming.NamingContext | NewContext()Create a new NamingContext. It creates a new TransientNamingContext
object, passing it the orb object.
try {
// Create a new servant
TransientNamingContext transContext =
new TransientNamingContext(
(com.sun.corba.se.spi.orb.ORB) orb,localRoot, nsPOA);
byte[] objectId = nsPOA.activate_object( transContext );
org.omg.CORBA.Object obj = nsPOA.id_to_reference( objectId );
lifecycleLogger.fine( "TransientNamingContext " +
"LIFECYCLE.CREATE SUCCESSFUL" );
return org.omg.CosNaming.NamingContextHelper.narrow( obj );
} catch (org.omg.CORBA.SystemException e) {
lifecycleLogger.log(
Level.WARNING, LogKeywords.LIFECYCLE_CREATE_FAILURE, e );
throw e;
} catch (Exception e) {
lifecycleLogger.log(
Level.WARNING, LogKeywords.LIFECYCLE_CREATE_FAILURE, e );
throw wrapper.transNcNewctxGotExc( e ) ;
}
| public final org.omg.CORBA.Object | Resolve(org.omg.CosNaming.NameComponent n, org.omg.CosNaming.BindingTypeHolder bth)Resolves the supplied name to an object reference and returns
the type of the resolved binding. It creates a InternalBindingKey
and uses the key for looking up in the hash table. If nothing
is found an exception is thrown, otherwise the object reference
is returned and the binding type set.
// Is the initial naming context requested?
if ( (n.id.length() == 0)
&&(n.kind.length() == 0 ) )
{
bth.value = BindingType.ncontext;
return localRoot;
}
// Create a key and lookup the value
InternalBindingKey key = new InternalBindingKey(n);
InternalBindingValue value =
(InternalBindingValue) this.theHashtable.get(key);
if (value == null) return null;
if( readLogger.isLoggable( Level.FINE ) ) {
readLogger.fine( LogKeywords.NAMING_RESOLVE_SUCCESS
+ "Namecomponent :" + getName( n ) );
}
// Copy out binding type and object reference
bth.value = value.theBinding.binding_type;
return value.theObjectRef;
| public final org.omg.CORBA.Object | Unbind(org.omg.CosNaming.NameComponent n)Deletes the binding with the supplied name. It creates a
InternalBindingKey and uses it to remove the value associated
with the key. If nothing is found an exception is thrown, otherwise
the element is removed from the hash table.
// Create a key and remove it from the hashtable
InternalBindingKey key = new InternalBindingKey(n);
InternalBindingValue value =
(InternalBindingValue)this.theHashtable.remove(key);
// Return what was found
if (value == null) {
if( updateLogger.isLoggable( Level.FINE ) ) {
updateLogger.fine( LogKeywords.NAMING_UNBIND_FAILURE +
" There was no binding with the name " + getName( n ) +
" to Unbind " );
}
return null;
} else {
if( updateLogger.isLoggable( Level.FINE ) ) {
updateLogger.fine( LogKeywords.NAMING_UNBIND_SUCCESS +
" NameComponent: " + getName( n ) );
}
return value.theObjectRef;
}
| private java.lang.String | getName(org.omg.CosNaming.NameComponent n)A Utility Method For Logging..
return n.id + "." + n.kind;
|
|