Class RemoteEventContext
java.lang.Object
java.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
org.djutils.rmi.RmiObject
nl.tudelft.simulation.naming.context.RemoteContext
nl.tudelft.simulation.naming.context.event.RemoteEventContext
- All Implemented Interfaces:
Serializable
,Remote
,ContextInterface
,EventContext
,EventContextInterface
,RemoteEventContextInterface
,RemoteContextInterface
,org.djutils.event.EventProducer
RemoteEventContext.java.
Copyright (c) 2020-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:
- Alexander Verbraeck
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class nl.tudelft.simulation.naming.context.RemoteContext
RemoteContext.RemoteChangeEventProducer
-
Field Summary
Fields inherited from class nl.tudelft.simulation.naming.context.RemoteContext
embeddedContext, remoteEventProducer
Fields inherited from class java.rmi.server.RemoteObject
ref
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
ConstructorDescriptionRemoteEventContext
(String host, int port, String bindingKey, ContextInterface embeddedContext, String eventProducerBindingKey) Constructs a new RemoteContext.RemoteEventContext
(URL registryURL, ContextInterface embeddedContext, String eventProducerBindingKey) Constructs a new RemoteContext. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addListener
(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope) Add a listener for the provided scope as strong reference to the BEGINNING of a queue of listeners.boolean
addListener
(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope, int position) Add a listener for the provided scope as strong reference to the specified position of a queue of listeners.boolean
addListener
(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope, int position, org.djutils.event.reference.ReferenceType referenceType) Add a listener for the provided scope to the specified position of a queue of listeners.boolean
addListener
(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope, org.djutils.event.reference.ReferenceType referenceType) Add a listener for the provided scope to the BEGINNING of a queue of listeners.boolean
removeListener
(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope) Remove the subscription of a listener for the provided scope for a specific event.Methods inherited from class nl.tudelft.simulation.naming.context.RemoteContext
addListener, addListener, addListener, addListener, bind, bindings, bindObject, bindObject, checkCircular, close, createSubcontext, destroySubcontext, exists, fireObjectChangedEventKey, fireObjectChangedEventValue, get, getAbsolutePath, getAtomicName, getEventListenerMap, getListenerReferences, getObject, getParent, getRootContext, hasKey, hasObject, isEmpty, keySet, rebind, rebindObject, removeAllListeners, removeAllListeners, removeListener, rename, toString, toString, unbind, unbindObject, values
Methods inherited from class org.djutils.rmi.RmiObject
getRegistry, register
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, exportObject, exportObject, unexportObject
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toStub
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface nl.tudelft.simulation.naming.context.ContextInterface
bind, bindings, bindObject, bindObject, checkCircular, close, createSubcontext, destroySubcontext, exists, fireObjectChangedEventKey, fireObjectChangedEventValue, get, getAbsolutePath, getAtomicName, getObject, getParent, getRootContext, hasKey, hasObject, isEmpty, keySet, rebind, rebindObject, rename, toString, unbind, unbindObject, values
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 Details
-
RemoteEventContext
public RemoteEventContext(String host, int port, String bindingKey, ContextInterface embeddedContext, String eventProducerBindingKey) throws RemoteException, AlreadyBoundException Constructs a new RemoteContext. Register the new context in the RMI registry. When the RMI registry does not exist yet, it will be created, but only on the local host. Remote creation of a registry on another computer is not possible. Any attempt to do so will cause an AccessException to be fired.- Parameters:
host
- String; the host where the RMI registry resides or will be created. Creation is only possible on localhost.port
- int; the port where the RMI registry can be found or will be createdbindingKey
- the key under which this context will be bound in the RMI registryembeddedContext
- ContextInterface; the underlying contexteventProducerBindingKey
- String; the key under which the event producer will be bound- Throws:
RemoteException
- when there is a problem with the RMI registryAlreadyBoundException
- when there is already another object bound to the bindingKeyNullPointerException
- when host, path, or bindingKey is nullIllegalArgumentException
- when port < 0 or port > 65535AccessException
- when there is an attempt to create a registry on a remote host
-
RemoteEventContext
public RemoteEventContext(URL registryURL, ContextInterface embeddedContext, String eventProducerBindingKey) throws RemoteException, AlreadyBoundException Constructs a new RemoteContext. Register the new context in the RMI registry. When the host has not been specified in the URL, 127.0.0.1 will be used. When the port has not been specified in the URL, the default RMI port 1099 will be used. When the RMI registry does not exist yet, it will be created, but only on the local host. Remote creation of a registry on another computer is not possible. Any attempt to do so will cause an AccessException to be fired.- Parameters:
registryURL
- URL; the URL of the registry, e.g., "http://localhost:1099" or "http://130.161.185.14:28452"embeddedContext
- ContextInterface; the underlying contexteventProducerBindingKey
- String; the key under which the event producer will be bound- Throws:
RemoteException
- when there is a problem with the RMI registryAlreadyBoundException
- when there is already another object bound to the bindingKeyNullPointerException
- when registryURL, bindingKey, or embeddedContext is nullAccessException
- when there is an attempt to create a registry on a remote host
-
-
Method Details
-
addListener
public boolean addListener(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope) throws RemoteException, NameNotFoundException, InvalidNameException, NotContextException, NamingException, NullPointerException Add a listener for the provided scope as strong reference to the BEGINNING of a queue of listeners.- Specified by:
addListener
in interfaceEventContextInterface
- Parameters:
listener
- EventListener; the listener which is interested at events of eventType.absolutePath
- String; the absolute path of the context or object to subscribe tocontextScope
- ContextScope; the part of the tree that the listener is aimed at (current node, current node and keys, subtree).- Returns:
- the success of adding the listener. If a listener was already added false is returned.
- Throws:
RemoteException
- if a network connection failure occurs.NameNotFoundException
- when the absolutePath could not be found in the parent context, or when an intermediate context does not existInvalidNameException
- when the scope is OBJECT_SCOPE, but the key points to a (sub)contextNotContextException
- when the scope is LEVEL_SCOPE, OBJECT_LEVEL_SCOPE or SUBTREE_SCOPE, and the key points to an ordinary objectNamingException
- as an overarching exception for context errorsNullPointerException
- when one of the arguments is null
-
addListener
public boolean addListener(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope, org.djutils.event.reference.ReferenceType referenceType) throws RemoteException, NameNotFoundException, InvalidNameException, NotContextException, NamingException, NullPointerException Add a listener for the provided scope to the BEGINNING of a queue of listeners.- Specified by:
addListener
in interfaceEventContextInterface
- Parameters:
listener
- EventListener; the listener which is interested at events of eventType.absolutePath
- String; the absolute path of the context or object to subscribe tocontextScope
- ContextScope; the part of the tree that the listener is aimed at (current node, current node and keys, subtree).referenceType
- ReferenceType; whether the listener is added as a strong or as a weak reference.- Returns:
- the success of adding the listener. If a listener was already added false is returned.
- Throws:
RemoteException
- if a network connection failure occurs.NameNotFoundException
- when the absolutePath could not be found in the parent context, or when an intermediate context does not existInvalidNameException
- when the scope is OBJECT_SCOPE, but the key points to a (sub)contextNotContextException
- when the scope is LEVEL_SCOPE, OBJECT_LEVEL_SCOPE or SUBTREE_SCOPE, and the key points to an ordinary objectNamingException
- as an overarching exception for context errorsNullPointerException
- when one of the arguments is null
-
addListener
public boolean addListener(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope, int position) throws RemoteException, NameNotFoundException, InvalidNameException, NotContextException, NamingException, NullPointerException Add a listener for the provided scope as strong reference to the specified position of a queue of listeners.- Specified by:
addListener
in interfaceEventContextInterface
- Parameters:
listener
- EventListener; the listener which is interested at events of eventType.absolutePath
- String; the absolute path of the context or object to subscribe tocontextScope
- ContextScope; the part of the tree that the listener is aimed at (current node, current node and keys, subtree).position
- int; the position of the listener in the queue.- Returns:
- the success of adding the listener. If a listener was already added, or an illegal position is provided false is returned.
- Throws:
RemoteException
- if a network connection failure occurs.NameNotFoundException
- when the absolutePath could not be found in the parent context, or when an intermediate context does not existInvalidNameException
- when the scope is OBJECT_SCOPE, but the key points to a (sub)contextNotContextException
- when the scope is LEVEL_SCOPE, OBJECT_LEVEL_SCOPE or SUBTREE_SCOPE, and the key points to an ordinary objectNamingException
- as an overarching exception for context errorsNullPointerException
- when one of the arguments is null
-
addListener
public boolean addListener(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope, int position, org.djutils.event.reference.ReferenceType referenceType) throws RemoteException, NameNotFoundException, InvalidNameException, NotContextException, NamingException, NullPointerException Add a listener for the provided scope to the specified position of a queue of listeners.- Specified by:
addListener
in interfaceEventContextInterface
- Parameters:
listener
- EventListener; which is interested at certain events,absolutePath
- String; the absolute path of the context or object to subscribe tocontextScope
- ContextScope; the part of the tree that the listener is aimed at (current node, current node and keys, subtree).position
- int; the position of the listener in the queuereferenceType
- ReferenceType; whether the listener is added as a strong or as a weak reference.- Returns:
- the success of adding the listener. If a listener was already added or an illegal position is provided false is returned.
- Throws:
RemoteException
- if a network connection failure occurs.NameNotFoundException
- when the absolutePath could not be found in the parent context, or when an intermediate context does not existInvalidNameException
- when the scope is OBJECT_SCOPE, but the key points to a (sub)contextNotContextException
- when the scope is LEVEL_SCOPE, OBJECT_LEVEL_SCOPE or SUBTREE_SCOPE, and the key points to an ordinary objectNamingException
- as an overarching exception for context errorsNullPointerException
- when one of the arguments is null
-
removeListener
public boolean removeListener(org.djutils.event.EventListener listener, String absolutePath, ContextScope contextScope) throws RemoteException, InvalidNameException, NullPointerException Remove the subscription of a listener for the provided scope for a specific event.- Specified by:
removeListener
in interfaceEventContextInterface
- Parameters:
listener
- EventListener; which is no longer interested.absolutePath
- String; the absolute path of the context or object to subscribe tocontextScope
- ContextScope;the scope which is of no interest any more.- Returns:
- the success of removing the listener. If a listener was not subscribed false is returned.
- Throws:
RemoteException
- if a network connection failure occursInvalidNameException
- when the path does not start with a slashNullPointerException
- when one of the arguments is null
-