YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
de.yaacc.upnp.registry.RegistryImpl Class Reference

Default implementation of Registry. More...

Inheritance diagram for de.yaacc.upnp.registry.RegistryImpl:
Inheritance graph
Collaboration diagram for de.yaacc.upnp.registry.RegistryImpl:
Collaboration graph

Public Member Functions

 RegistryImpl ()
 Starts background maintenance immediately.
 
ExecutorService getExecutorService ()
 
synchronized void addListener (RegistryListener listener)
 
synchronized void removeListener (RegistryListener listener)
 
synchronized Collection< RegistryListenergetListeners ()
 
synchronized boolean notifyDiscoveryStart (final RemoteDevice device)
 Called internally by the UPnP stack when the discovery protocol starts.
 
synchronized void notifyDiscoveryFailure (final RemoteDevice device, final Exception ex)
 Called internally by the UPnP stack when the discovery protocol stopped abnormally.
 
synchronized void addDevice (LocalDevice localDevice)
 Call this method to add your local device metadata.
 
synchronized void addDevice (LocalDevice localDevice, DiscoveryOptions options)
 Call this method to add your local device metadata.
 
synchronized void setDiscoveryOptions (UDN udn, DiscoveryOptions options)
 Change the active DiscoveryOptions for the given (local device) UDN.
 
synchronized DiscoveryOptions getDiscoveryOptions (UDN udn)
 Get the currently active DiscoveryOptions for the given (local device) UDN.
 
synchronized void addDevice (RemoteDevice remoteDevice)
 Called internally by the UPnP discovery protocol.
 
synchronized boolean update (RemoteDeviceIdentity rdIdentity)
 Called internally by the UPnP discovery protocol.
 
synchronized boolean removeDevice (LocalDevice localDevice)
 Call this to remove your local device metadata.
 
synchronized boolean removeDevice (RemoteDevice remoteDevice)
 Called internally by the UPnP discovery protocol.
 
synchronized void removeAllLocalDevices ()
 Clear the registry of all locally registered device metadata.
 
synchronized void removeAllRemoteDevices ()
 Clear the registry of all discovered remote device metadata.
 
synchronized boolean removeDevice (UDN udn)
 Call this to remove any device metadata with the given UDN.
 
synchronized Device getDevice (UDN udn, boolean rootOnly)
 
synchronized LocalDevice getLocalDevice (UDN udn, boolean rootOnly)
 
synchronized RemoteDevice getRemoteDevice (UDN udn, boolean rootOnly)
 
synchronized Collection< LocalDevice > getLocalDevices ()
 
synchronized Collection< RemoteDevice > getRemoteDevices ()
 
synchronized Collection< Device<?, ?, ?> > getDevices ()
 
synchronized Collection< Device<?, ?, ?> > getDevices (DeviceType deviceType)
 
synchronized Collection< Device<?, ?, ?> > getDevices (ServiceType serviceType)
 
synchronized Service getService (ServiceReference serviceReference)
 
synchronized Resource getResource (URI pathQuery) throws IllegalArgumentException
 
synchronized Collection< Resource > getResources ()
 
synchronized void addResource (Resource resource)
 Stores an arbitrary resource in the registry.
 
synchronized void addResource (Resource resource, int maxAgeSeconds)
 Stores an arbitrary resource in the registry.
 
synchronized boolean removeResource (Resource resource)
 Removes a resource from the registry.
 
synchronized void addLocalSubscription (LocalGENASubscription subscription)
 Called internally by the UPnP stack, during GENA protocol execution.
 
synchronized LocalGENASubscription getLocalSubscription (String subscriptionId)
 Called internally by the UPnP stack, during GENA protocol execution.
 
synchronized boolean updateLocalSubscription (LocalGENASubscription subscription)
 Called internally by the UPnP stack, during GENA protocol execution.
 
synchronized boolean removeLocalSubscription (LocalGENASubscription subscription)
 Called internally by the UPnP stack, during GENA protocol execution.
 
synchronized void addRemoteSubscription (RemoteGENASubscription subscription)
 Called internally by the UPnP stack, during GENA protocol execution.
 
synchronized RemoteGENASubscription getRemoteSubscription (String subscriptionId)
 Called internally by the UPnP stack, during GENA protocol execution.
 
synchronized void updateRemoteSubscription (RemoteGENASubscription subscription)
 Called internally by the UPnP stack, during GENA protocol execution.
 
synchronized void removeRemoteSubscription (RemoteGENASubscription subscription)
 Called internally by the UPnP stack, during GENA protocol execution.
 
synchronized void advertiseLocalDevices ()
 Manually trigger advertisement messages for all local devices.
 
synchronized void setAliveInterval (int intervalMillis)
 Set the interval for periodic ALIVE announcements.
 
UpnpProtocolHandler getProtocolHandler ()
 
void setProtocolHandler (UpnpProtocolHandler upnpProtocolHandler)
 
synchronized void shutdown ()
 Typically called internally when the UPnP stack is stopping.
 
synchronized void pause ()
 Stops background maintenance (thread) of registered items.
 
synchronized void resume ()
 Resumes background maintenance (thread) of registered items.
 
synchronized boolean isPaused ()
 
void printDebugLog ()
 
void registerPendingRemoteSubscription (RemoteGENASubscription subscription)
 Called internally by the UPnP stack, during GENA protocol execution.
 
void unregisterPendingRemoteSubscription (RemoteGENASubscription subscription)
 Called internally by the UPnP stack, during GENA protocol execution.
 
RemoteGENASubscription getWaitRemoteSubscription (String subscriptionId)
 Called internally by the UPnP stack, during GENA protocol execution.
 
UpnpProtocolHandler getUpnpProtocolHandler ()
 
void setUpnpProtocolHandler (UpnpProtocolHandler upnpProtocolHandler)
 

Static Public Attributes

static final int SLEEP_INTERVAL_MILLIS = 7000
 

Protected Member Functions

synchronized RegistryMaintainer createRegistryMaintainer ()
 

Protected Attributes

final Set< RemoteGENASubscription > pendingSubscriptionsLock = new HashSet<>()
 
final Set< RegistryListenerregistryListeners = new HashSet<>()
 
final Set< RegistryItem< URI, Resource > > resourceItems = new HashSet<>()
 
final List< Runnable > pendingExecutions = new ArrayList<>()
 
final RemoteItems remoteItems = new RemoteItems(this)
 
final LocalItems localItems = new LocalItems(this)
 
RegistryMaintainer registryMaintainer
 

Detailed Description

Default implementation of Registry.

Author
Christian Bauer

Member Function Documentation

◆ addDevice() [1/3]

synchronized void de.yaacc.upnp.registry.RegistryImpl.addDevice ( LocalDevice  localDevice)

Call this method to add your local device metadata.

Parameters
localDeviceThe device to add and maintain.
Exceptions
RegistrationExceptionIf a conflict with an already registered device was detected.

Implements de.yaacc.upnp.registry.Registry.

◆ addDevice() [2/3]

synchronized void de.yaacc.upnp.registry.RegistryImpl.addDevice ( LocalDevice  localDevice,
DiscoveryOptions  options 
)

Call this method to add your local device metadata.

Parameters
localDeviceThe device to add and maintain.
optionsImmediately effective when this device is registered.
Exceptions
RegistrationExceptionIf a conflict with an already registered device was detected.

Implements de.yaacc.upnp.registry.Registry.

◆ addDevice() [3/3]

synchronized void de.yaacc.upnp.registry.RegistryImpl.addDevice ( RemoteDevice  remoteDevice)

Called internally by the UPnP discovery protocol.

Exceptions
RegistrationExceptionIf a conflict with an already registered device was detected.

Implements de.yaacc.upnp.registry.Registry.

◆ addListener()

synchronized void de.yaacc.upnp.registry.RegistryImpl.addListener ( RegistryListener  listener)

◆ addLocalSubscription()

synchronized void de.yaacc.upnp.registry.RegistryImpl.addLocalSubscription ( LocalGENASubscription  subscription)

Called internally by the UPnP stack, during GENA protocol execution.

Implements de.yaacc.upnp.registry.Registry.

◆ addRemoteSubscription()

synchronized void de.yaacc.upnp.registry.RegistryImpl.addRemoteSubscription ( RemoteGENASubscription  subscription)

Called internally by the UPnP stack, during GENA protocol execution.

Implements de.yaacc.upnp.registry.Registry.

◆ addResource() [1/2]

synchronized void de.yaacc.upnp.registry.RegistryImpl.addResource ( Resource  resource)

Stores an arbitrary resource in the registry.

Parameters
resourceThe resource to maintain indefinitely (until it is manually removed).

Implements de.yaacc.upnp.registry.Registry.

Referenced by de.yaacc.upnp.registry.RegistryImpl.addResource().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addResource() [2/2]

synchronized void de.yaacc.upnp.registry.RegistryImpl.addResource ( Resource  resource,
int  maxAgeSeconds 
)

Stores an arbitrary resource in the registry.

Call this method repeatedly to refresh and prevent expiration of the resource.

Parameters
resourceThe resource to maintain.
maxAgeSecondsThe time after which the registry will automatically remove the resource.

Implements de.yaacc.upnp.registry.Registry.

◆ advertiseLocalDevices()

synchronized void de.yaacc.upnp.registry.RegistryImpl.advertiseLocalDevices ( )

Manually trigger advertisement messages for all local devices.

No messages will be send for devices with disabled advertisements, see DiscoveryOptions!

Implements de.yaacc.upnp.registry.Registry.

◆ getDevice()

synchronized Device de.yaacc.upnp.registry.RegistryImpl.getDevice ( UDN  udn,
boolean  rootOnly 
)
Parameters
udnThe device name to lookup.
rootOnlyIf true, only matches of root devices are returned.
Returns
The registered root or embedded device metadata, or null.

Implements de.yaacc.upnp.registry.Registry.

Referenced by de.yaacc.upnp.registry.RegistryImpl.getService(), and de.yaacc.upnp.registry.RegistryImpl.removeDevice().

Here is the caller graph for this function:

◆ getDevices() [1/3]

synchronized Collection< Device<?, ?, ?> > de.yaacc.upnp.registry.RegistryImpl.getDevices ( )
Returns
All device metadata, in no particular order, or an empty collection.

Implements de.yaacc.upnp.registry.Registry.

◆ getDevices() [2/3]

synchronized Collection< Device<?, ?, ?> > de.yaacc.upnp.registry.RegistryImpl.getDevices ( DeviceType  deviceType)
Returns
All device metadata of devices which implement the given type, in no particular order, or an empty collection.

Implements de.yaacc.upnp.registry.Registry.

◆ getDevices() [3/3]

synchronized Collection< Device<?, ?, ?> > de.yaacc.upnp.registry.RegistryImpl.getDevices ( ServiceType  serviceType)
Returns
All device metadata of devices which have a service that implements the given type, in no particular order, or an empty collection.

Implements de.yaacc.upnp.registry.Registry.

◆ getDiscoveryOptions()

synchronized DiscoveryOptions de.yaacc.upnp.registry.RegistryImpl.getDiscoveryOptions ( UDN  udn)

Get the currently active DiscoveryOptions for the given (local device) UDN.

Returns
null if there are no active discovery options for the given UDN.

Implements de.yaacc.upnp.registry.Registry.

◆ getExecutorService()

ExecutorService de.yaacc.upnp.registry.RegistryImpl.getExecutorService ( )

◆ getListeners()

synchronized Collection< RegistryListener > de.yaacc.upnp.registry.RegistryImpl.getListeners ( )

◆ getLocalDevice()

synchronized LocalDevice de.yaacc.upnp.registry.RegistryImpl.getLocalDevice ( UDN  udn,
boolean  rootOnly 
)
Parameters
udnThe device name to lookup.
rootOnlyIf true, only matches of root devices are returned.
Returns
The registered root or embedded device metadata, or null.

Implements de.yaacc.upnp.registry.Registry.

◆ getLocalDevices()

synchronized Collection< LocalDevice > de.yaacc.upnp.registry.RegistryImpl.getLocalDevices ( )
Returns
All locally registered device metadata, in no particular order, or an empty collection.

Implements de.yaacc.upnp.registry.Registry.

◆ getLocalSubscription()

synchronized LocalGENASubscription de.yaacc.upnp.registry.RegistryImpl.getLocalSubscription ( String  subscriptionId)

Called internally by the UPnP stack, during GENA protocol execution.

Implements de.yaacc.upnp.registry.Registry.

◆ getRemoteDevice()

synchronized RemoteDevice de.yaacc.upnp.registry.RegistryImpl.getRemoteDevice ( UDN  udn,
boolean  rootOnly 
)
Parameters
udnThe device name to lookup.
rootOnlyIf true, only matches of root devices are returned.
Returns
The registered root or embedded device metadata, or null.

Implements de.yaacc.upnp.registry.Registry.

Referenced by de.yaacc.upnp.registry.RegistryImpl.notifyDiscoveryStart().

Here is the caller graph for this function:

◆ getRemoteDevices()

synchronized Collection< RemoteDevice > de.yaacc.upnp.registry.RegistryImpl.getRemoteDevices ( )
Returns
All discovered remote device metadata, in no particular order, or an empty collection.

Implements de.yaacc.upnp.registry.Registry.

◆ getRemoteSubscription()

synchronized RemoteGENASubscription de.yaacc.upnp.registry.RegistryImpl.getRemoteSubscription ( String  subscriptionId)

Called internally by the UPnP stack, during GENA protocol execution.

Implements de.yaacc.upnp.registry.Registry.

Referenced by de.yaacc.upnp.registry.RegistryImpl.getWaitRemoteSubscription().

Here is the caller graph for this function:

◆ getResource()

synchronized Resource de.yaacc.upnp.registry.RegistryImpl.getResource ( URI  pathQuery) throws IllegalArgumentException
Parameters
pathQueryThe path and optional query string of the resource's registration URI (e.g. /dev/somefile.xml?param=value)
Returns
Any registered resource that matches the given URI path.
Exceptions
IllegalArgumentExceptionIf the given URI was absolute, only path and query are allowed.

Implements de.yaacc.upnp.registry.Registry.

◆ getResources()

synchronized Collection< Resource > de.yaacc.upnp.registry.RegistryImpl.getResources ( )
Returns
All registered resources, in no particular order, or an empty collection.

Implements de.yaacc.upnp.registry.Registry.

◆ getService()

synchronized Service de.yaacc.upnp.registry.RegistryImpl.getService ( ServiceReference  serviceReference)
Returns
Complete service metadata for a service reference or null if no service for the given reference has been registered.

Implements de.yaacc.upnp.registry.Registry.

Here is the call graph for this function:

◆ getUpnpProtocolHandler()

UpnpProtocolHandler de.yaacc.upnp.registry.RegistryImpl.getUpnpProtocolHandler ( )

◆ getWaitRemoteSubscription()

RemoteGENASubscription de.yaacc.upnp.registry.RegistryImpl.getWaitRemoteSubscription ( String  subscriptionId)

Called internally by the UPnP stack, during GENA protocol execution.

Get a remote subscription from its subscriptionId. If the subscription can't be found, wait for one of the pending remote subscription procedures from the registry background maintainer to terminate, until the subscription has been found or until there are no more pending subscription procedures.

Implements de.yaacc.upnp.registry.Registry.

Here is the call graph for this function:

◆ isPaused()

synchronized boolean de.yaacc.upnp.registry.RegistryImpl.isPaused ( )
Returns
true if the registry has currently no running background maintenance (thread).

Implements de.yaacc.upnp.registry.Registry.

◆ notifyDiscoveryFailure()

synchronized void de.yaacc.upnp.registry.RegistryImpl.notifyDiscoveryFailure ( final RemoteDevice  device,
final Exception  ex 
)

Called internally by the UPnP stack when the discovery protocol stopped abnormally.

The registry will notify all registered listeners of this event.

Parameters
deviceThe half-hydrated (without services) metadata of the discovered device.
exThe cause for the interruption of the discovery protocol.

Implements de.yaacc.upnp.registry.Registry.

◆ notifyDiscoveryStart()

synchronized boolean de.yaacc.upnp.registry.RegistryImpl.notifyDiscoveryStart ( final RemoteDevice  device)

Called internally by the UPnP stack when the discovery protocol starts.

The registry will notify all registered listeners of this event, unless the given device was already in the registry.

Parameters
deviceThe half-hydrated (without services) metadata of the discovered device.
Returns
false if the device was already registered.

Implements de.yaacc.upnp.registry.Registry.

Here is the call graph for this function:

◆ pause()

synchronized void de.yaacc.upnp.registry.RegistryImpl.pause ( )

Stops background maintenance (thread) of registered items.

When paused, the registry will no longer remove expired remote devices if their discovery announcements stop for some reason (device was turned off). Your local control point will now see potentially unavailable remote devices. Outbound GENA subscriptions from your local control point to remote services will not be renewed automatically anymore, a remote service might drop your subscriptions if you don't resume maintenance within the subscription's expiration timeout.

Local devices and services will not be announced periodically anymore to remote control points, only when they are manually added are removed from the registry. The registry will also no longer remove expired inbound GENA subscriptions to local service from remote control points, if that control point for some reason stops sending subscription renewal messages.

Implements de.yaacc.upnp.registry.Registry.

◆ registerPendingRemoteSubscription()

void de.yaacc.upnp.registry.RegistryImpl.registerPendingRemoteSubscription ( RemoteGENASubscription  subscription)

Called internally by the UPnP stack, during GENA protocol execution.

When subscribing with a remote host, the remote host might send the initial event message faster than the response for the subscription request. This method register that the subscription procedure is executing.

Implements de.yaacc.upnp.registry.Registry.

◆ removeAllLocalDevices()

synchronized void de.yaacc.upnp.registry.RegistryImpl.removeAllLocalDevices ( )

Clear the registry of all locally registered device metadata.

Implements de.yaacc.upnp.registry.Registry.

◆ removeAllRemoteDevices()

synchronized void de.yaacc.upnp.registry.RegistryImpl.removeAllRemoteDevices ( )

Clear the registry of all discovered remote device metadata.

Implements de.yaacc.upnp.registry.Registry.

◆ removeDevice() [1/3]

synchronized boolean de.yaacc.upnp.registry.RegistryImpl.removeDevice ( LocalDevice  localDevice)

Call this to remove your local device metadata.

Returns
true if the device was registered and has been removed.

Implements de.yaacc.upnp.registry.Registry.

Referenced by de.yaacc.upnp.registry.RegistryImpl.removeDevice().

Here is the caller graph for this function:

◆ removeDevice() [2/3]

synchronized boolean de.yaacc.upnp.registry.RegistryImpl.removeDevice ( RemoteDevice  remoteDevice)

Called internally by the UPnP discovery protocol.

Implements de.yaacc.upnp.registry.Registry.

◆ removeDevice() [3/3]

synchronized boolean de.yaacc.upnp.registry.RegistryImpl.removeDevice ( UDN  udn)

Call this to remove any device metadata with the given UDN.

Returns
true if the device was registered and has been removed.

Implements de.yaacc.upnp.registry.Registry.

Here is the call graph for this function:

◆ removeListener()

synchronized void de.yaacc.upnp.registry.RegistryImpl.removeListener ( RegistryListener  listener)

◆ removeLocalSubscription()

synchronized boolean de.yaacc.upnp.registry.RegistryImpl.removeLocalSubscription ( LocalGENASubscription  subscription)

Called internally by the UPnP stack, during GENA protocol execution.

Implements de.yaacc.upnp.registry.Registry.

◆ removeRemoteSubscription()

synchronized void de.yaacc.upnp.registry.RegistryImpl.removeRemoteSubscription ( RemoteGENASubscription  subscription)

Called internally by the UPnP stack, during GENA protocol execution.

Implements de.yaacc.upnp.registry.Registry.

◆ removeResource()

synchronized boolean de.yaacc.upnp.registry.RegistryImpl.removeResource ( Resource  resource)

Removes a resource from the registry.

Parameters
resourceThe resource to remove.
Returns
true if the resource was registered and has been removed.

Implements de.yaacc.upnp.registry.Registry.

◆ resume()

synchronized void de.yaacc.upnp.registry.RegistryImpl.resume ( )

Resumes background maintenance (thread) of registered items.

A local control point has to handle the following situations when resuming registry maintenance:

A remote device registration might have expired. This is the case when the remote device stopped sending announcements while the registry was paused (maybe because the device was switched off) and the registry was paused longer than the device advertisement's maximum age. The registry will not know if the device is still available when it resumes maintenance. However, it will simply assume that the remote device is still available and restart its expiration check cycle. That means a device will finally be removed from the registry, if no further announcements from the device are received, when the maximum age of the device has elapsed after the registry resumed operation.

Secondly, a remote device registration might not have expired but some of your outbound GENA subscriptions to its services have not been renewed within the expected renewal period. Therefore your outbound subscriptions might be invalid, because the remote service can drop subscriptions when you don't renew them. On resume, the registry will attempt to send renewals for all outbound GENA subscriptions that require renewal, on devices that still haven't expired. If renewal fails, your subscription will end with org.fourthline.cling.model.gena.CancelReason#RENEWAL_FAILED. Although you then might conclude that the remote device is no longer available, a GENA renewal can also fail for other reasons. The remote device will be kept and maintained in the registry until it announces itself or it expires, even after a failed GENA renewal.

If you are providing local devices and services, resuming registry maintenance has the following effects:

Local devices and their services are announced again immediately if the registry has been paused for longer than half of the device's maximum age. Remote control points will either see this as a new device advertisement (if they have dropped your device while you paused maintenance) or as a regular update if you didn't pause longer than the device's maximum age/expiration timeout.

Inbound GENA subscriptions to your local services are active, even in paused state - remote control points should continue renewing the subscription. If a remote control point stopped renewing a subscription without unsubscribing (hard power off), an outdated inbound subscription will be detected when you resume maintenance. This subscription will be cleaned up immediately on resume.

Implements de.yaacc.upnp.registry.Registry.

◆ setAliveInterval()

synchronized void de.yaacc.upnp.registry.RegistryImpl.setAliveInterval ( int  intervalMillis)

Set the interval for periodic ALIVE announcements.

Set to 0 to disable periodic announcements (devices will only announce on expiration). Recommended value: 5000ms (5 seconds) for better discovery by clients like Kodi.

Parameters
intervalMillisinterval in milliseconds between ALIVE announcements

Implements de.yaacc.upnp.registry.Registry.

◆ setDiscoveryOptions()

synchronized void de.yaacc.upnp.registry.RegistryImpl.setDiscoveryOptions ( UDN  udn,
DiscoveryOptions  options 
)

Change the active DiscoveryOptions for the given (local device) UDN.

Parameters
optionsSet to null to disable any options.

Implements de.yaacc.upnp.registry.Registry.

◆ setUpnpProtocolHandler()

void de.yaacc.upnp.registry.RegistryImpl.setUpnpProtocolHandler ( UpnpProtocolHandler  upnpProtocolHandler)

◆ shutdown()

synchronized void de.yaacc.upnp.registry.RegistryImpl.shutdown ( )

Typically called internally when the UPnP stack is stopping.

Unsubscribe all local devices and GENA subscriptions.

Implements de.yaacc.upnp.registry.Registry.

◆ unregisterPendingRemoteSubscription()

void de.yaacc.upnp.registry.RegistryImpl.unregisterPendingRemoteSubscription ( RemoteGENASubscription  subscription)

Called internally by the UPnP stack, during GENA protocol execution.

Notify that the subscription procedure has terminated.

Implements de.yaacc.upnp.registry.Registry.

◆ update()

synchronized boolean de.yaacc.upnp.registry.RegistryImpl.update ( RemoteDeviceIdentity  rdIdentity)

Called internally by the UPnP discovery protocol.

Implements de.yaacc.upnp.registry.Registry.

◆ updateLocalSubscription()

synchronized boolean de.yaacc.upnp.registry.RegistryImpl.updateLocalSubscription ( LocalGENASubscription  subscription)

Called internally by the UPnP stack, during GENA protocol execution.

Implements de.yaacc.upnp.registry.Registry.

◆ updateRemoteSubscription()

synchronized void de.yaacc.upnp.registry.RegistryImpl.updateRemoteSubscription ( RemoteGENASubscription  subscription)

Called internally by the UPnP stack, during GENA protocol execution.

Implements de.yaacc.upnp.registry.Registry.


The documentation for this class was generated from the following file: