Class FileContext
- java.lang.Object
-
- org.djutils.event.LocalEventProducer
-
- nl.tudelft.simulation.naming.context.JvmContext
-
- nl.tudelft.simulation.naming.context.FileContext
-
- All Implemented Interfaces:
Serializable,Remote,ContextInterface,EventProducer
public class FileContext extends JvmContext
The FileContext as a file-based implementation of the ContextInterface.Copyright (c) 2002-2023 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.
- Author:
- Peter Jacobs , Alexander Verbraeck
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class nl.tudelft.simulation.naming.context.JvmContext
JvmContext.ContextName
-
-
Field Summary
-
Fields inherited from class nl.tudelft.simulation.naming.context.JvmContext
elements, parent
-
Fields inherited from interface nl.tudelft.simulation.naming.context.ContextInterface
OBJECT_ADDED_EVENT, OBJECT_CHANGED_EVENT, OBJECT_REMOVED_EVENT, REPLACE_SEPARATOR, ROOT, SEPARATOR
-
Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION
-
-
Constructor Summary
Constructors Constructor Description FileContext(File file, String atomicName)constructs a new FileContext.FileContext(File file, ContextInterface parent, String atomicName)constructs a new FileContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbind(String name, Object value)Binds an object into the Context using the name.ContextInterfacecreateSubcontext(String name)Creates and binds a new context into the current Context using the name.voiddestroySubcontext(String name)Removes the binding for an existing, empty subcontext with the given name, and recursively unbinds all objects and contexts in the context indicated by the name.voidrebind(String name, Object value)Replaces an object in the Context with the given name, or registers the object when a registration with the name does not exist yet.voidrename(String nameOld, String nameNew)Replaces the name under which an object has been registered in the Context.voidunbind(String name)Removes the binding for an object in the Context with the given name.-
Methods inherited from class nl.tudelft.simulation.naming.context.JvmContext
bindings, bindObject, bindObject, checkCircular, close, destroy, exists, fireObjectChangedEventKey, fireObjectChangedEventValue, get, getAbsolutePath, getAtomicName, getObject, getParent, getRootContext, hasKey, hasObject, isEmpty, keySet, lookup, lookupAndBuild, rebindObject, toString, toString, unbindObject, values
-
Methods inherited from class org.djutils.event.LocalEventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
-
-
-
Constructor Detail
-
FileContext
public FileContext(File file, String atomicName)
constructs a new FileContext.- Parameters:
file- File; the file to write toatomicName- String; the name under which the root context will be registered
-
FileContext
public FileContext(File file, ContextInterface parent, String atomicName)
constructs a new FileContext.- Parameters:
file- File; the file to which to writeparent- Context; the parent contextatomicName- String; the atomicName
-
-
Method Detail
-
bind
public void bind(String name, Object value) throws NamingException, RemoteException
Binds an object into the Context using the name. The name may be a compound name where parts are separated by separation strings indicating subcontexts. All intermediate subcontexts must already exist. The object will be registered using the terminal atomic reference in the deepest subcontext provided. Name cannot be empty or "/". An OBJECT_ADDED_EVENT is fired containing an object array with a pointer to the context, the relative key, and the object when a new binding has taken place.- Specified by:
bindin interfaceContextInterface- Overrides:
bindin classJvmContext- Parameters:
name- String; the name under which the object will be stored; may be a compound name with the terminal reference indicating the key under which the object will be storedvalue- Object; the Context or Object to be stored into the given context; a null object is allowed- Throws:
NamingException- when the reference is "/" or emptyNameAlreadyBoundException- if name is already bound to an objectNameNotFoundException- when an intermediate context does not existRemoteException- on a network error when the Context is used over RMI
-
createSubcontext
public ContextInterface createSubcontext(String name) throws NamingException, RemoteException
Creates and binds a new context into the current Context using the name. The name may be a compound name where parts are separated by separation strings indicating subcontexts. All intermediate subcontexts that do not yet exist, will be created. The new context will be registered using the terminal atomic reference in the deepest subcontext provided. Name cannot be empty or "/". On success, OBJECT_ADDED_EVENTs are fired for the created context and each new intermediate context, containing an object array with an object array with a pointer to the embedding context, the local key in the embedding context, and the newly created (intermediate) context.- Specified by:
createSubcontextin interfaceContextInterface- Overrides:
createSubcontextin classJvmContext- Parameters:
name- String; the name under which the new context will be stored; may be a compound name with the terminal reference indicating the key under which the new context will be stored- Returns:
- ContextInterface; a pointer to the newly created subcontext
- Throws:
NamingException- when the terminal reference is "/" or emptyNameNotFoundException- when an intermediate context does not existNameAlreadyBoundException- if name is already bound to an object or contextRemoteException- on a network error when the Context is used over RMI
-
destroySubcontext
public void destroySubcontext(String name) throws NamingException, RemoteException
Removes the binding for an existing, empty subcontext with the given name, and recursively unbinds all objects and contexts in the context indicated by the name. The name may be a compound name where parts are separated by separation strings indicating subcontexts. Name cannot be empty or "/". A context has to be registered with the given name. For all removed objects and contexts, OBJECT_REMOVED_EVENT events are fired containing an object array with a pointer to the context from which content has been removed, the key of the binding that has been removed, and the removed object. The OBJECT_REMOVED_EVENT events are fired in depth-first order.- Specified by:
destroySubcontextin interfaceContextInterface- Overrides:
destroySubcontextin classJvmContext- Parameters:
name- String; the name of the object that has to be removed; may be a compound name with the terminal reference indicating the key under which the object is stored- Throws:
NamingException- when the reference is "/" or emptyNotContextException- if the name is bound but does not name a contextNameNotFoundException- when an intermediate context does not exist, or when no object is registered with the terminating atomic referenceRemoteException- on a network error when the Context is used over RMI
-
rebind
public void rebind(String name, Object value) throws NamingException, RemoteException
Replaces an object in the Context with the given name, or registers the object when a registration with the name does not exist yet. The name may be a compound name where parts are separated by separation strings indicating subcontexts. All intermediate subcontexts must already exist. The object will be (re)registered using the terminal atomic reference in the deepest subcontext provided. Name cannot be empty or "/". An OBJECT_REMOVED_EVENT is fired containing an object array with a pointer to the context, the relative key, and the removed object when a binding had to be removed, followed by an OBJECT_ADDED_EVENT containing an object array with a pointer to the context, the key, and the new object when a new binding has taken place.- Specified by:
rebindin interfaceContextInterface- Overrides:
rebindin classJvmContext- Parameters:
name- String; the name of the object to be replaced, or under which the object will be stored; may be a compound name with the terminal reference indicating the key under which the object will be storedvalue- Object; the Context or Object to be replaced or stored into this Context using the given name; a null object is allowed- Throws:
NamingException- when the reference is "/" or emptyNameNotFoundException- when an intermediate context does not existRemoteException- on a network error when the Context is used over RMI
-
rename
public void rename(String nameOld, String nameNew) throws NamingException, RemoteException
Replaces the name under which an object has been registered in the Context. Both names are relative to the current Context, and may be compound names where parts are separated by separation strings indicating subcontexts. All intermediate subcontexts of the new name must already exist. The object will be deregistered under the old name, and reregistered using the terminal atomic reference in the deepest subcontext of the newName. Nether the oldName, nor the newName can be empty or "/". An OBJECT_REMOVED_EVENT is fired containing an object array with a pointer to the old context, the old relative key, and the object when a binding had to be removed, followed by an OBJECT_ADDED_EVENT containing an object array with a pointer to the new context, the new relative key, and the object when a new binding has taken place. When the new name is illegal or occupied, the object will not be renamed.- Specified by:
renamein interfaceContextInterface- Overrides:
renamein classJvmContext- Parameters:
nameOld- String; the (compound) name of the object to be moved to a new locationnameNew- String; the (compound) name with the terminal reference indicating where the object will be stored- Throws:
NamingException- when the reference of oldName or newName is "/" or emptyNameNotFoundException- when an intermediate context of oldName or newName does not exist, or when there is no registration at the oldName referenceNameAlreadyBoundException- if newName is already bound to an objectRemoteException- on a network error when the Context is used over RMI
-
unbind
public void unbind(String name) throws NamingException, RemoteException
Removes the binding for an object in the Context with the given name. The name may be a compound name where parts are separated by separation strings indicating subcontexts. Name cannot be empty or "/". It is not a problem when there is no object registered with the given name. An OBJECT_REMOVED_EVENT is fired containing an object array with a pointer to the context, the relative key, and the removed object when a binding has been removed.- Specified by:
unbindin interfaceContextInterface- Overrides:
unbindin classJvmContext- Parameters:
name- String; the name of the object that has to be removed; may be a compound name with the terminal reference indicating the key under which the object is stored- Throws:
NamingException- when the reference is "/" or emptyNameNotFoundException- when an intermediate context does not existRemoteException- on a network error when the Context is used over RMI
-
-