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, org.djutils.event.EventProducer

public class FileContext extends JvmContext
The FileContext as a file-based implementation of the ContextInterface.

Copyright (c) 2002-2024 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:
  • Constructor Details

    • FileContext

      public FileContext(File file, String atomicName)
      constructs a new FileContext.
      Parameters:
      file - File; the file to write to
      atomicName - 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 write
      parent - Context; the parent context
      atomicName - String; the atomicName
  • Method Details

    • 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:
      bind in interface ContextInterface
      Overrides:
      bind in class JvmContext
      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 stored
      value - Object; the Context or Object to be stored into the given context; a null object is allowed
      Throws:
      NamingException - when the reference is "/" or empty
      NameAlreadyBoundException - if name is already bound to an object
      NameNotFoundException - when an intermediate context does not exist
      RemoteException - 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:
      createSubcontext in interface ContextInterface
      Overrides:
      createSubcontext in class JvmContext
      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 empty
      NameNotFoundException - when an intermediate context does not exist
      NameAlreadyBoundException - if name is already bound to an object or context
      RemoteException - 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:
      destroySubcontext in interface ContextInterface
      Overrides:
      destroySubcontext in class JvmContext
      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 empty
      NotContextException - if the name is bound but does not name a context
      NameNotFoundException - when an intermediate context does not exist, or when no object is registered with the terminating atomic reference
      RemoteException - 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:
      rebind in interface ContextInterface
      Overrides:
      rebind in class JvmContext
      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 stored
      value - 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 empty
      NameNotFoundException - when an intermediate context does not exist
      RemoteException - 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:
      rename in interface ContextInterface
      Overrides:
      rename in class JvmContext
      Parameters:
      nameOld - String; the (compound) name of the object to be moved to a new location
      nameNew - 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 empty
      NameNotFoundException - when an intermediate context of oldName or newName does not exist, or when there is no registration at the oldName reference
      NameAlreadyBoundException - if newName is already bound to an object
      RemoteException - 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:
      unbind in interface ContextInterface
      Overrides:
      unbind in class JvmContext
      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 empty
      NameNotFoundException - when an intermediate context does not exist
      RemoteException - on a network error when the Context is used over RMI