org.fourthline.cling.support.igd

## Class PortMappingListener

- java.lang.Object
- - org.fourthline.cling.registry.DefaultRegistryListener
  - - org.fourthline.cling.support.igd.PortMappingListener

- All Implemented Interfaces:
    RegistryListener

      public class PortMappingListener
      extends DefaultRegistryListener

  Maintains UPnP port mappings on an InternetGatewayDevice automatically.

  This listener will wait for discovered devices which support either `WANIPConnection` or the `WANPPPConnection` service. As soon as any such service is discovered, the desired port mapping will be created. When the UPnP service is shutting down, all previously established port mappings with all services will be deleted.

  The following listener maps external WAN TCP port 8123 to internal host 10.0.0.2:

       upnpService.getRegistry().addListener(
      newPortMappingListener(newPortMapping(8123, "10.0.0.2",PortMapping.Protocol.TCP))
       );

  If all you need from the Cling UPnP stack is NAT port mapping, use the following idiom:

       UpnpService upnpService = new UpnpServiceImpl(
           new PortMappingListener(new PortMapping(8123, "10.0.0.2", PortMapping.Protocol.TCP))
       );
       <p/>
       upnpService.getControlPoint().search(new STAllHeader()); // Search for all devices
       <p/>
       upnpService.shutdown(); // When you no longer need the port mapping

  Author:
    Christian Bauer

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Map<Service,List<PortMapping>>` | `activePortMappings`
    `static DeviceType` | `CONNECTION_DEVICE_TYPE`
    `static DeviceType` | `IGD_DEVICE_TYPE`
    `static ServiceType` | `IP_SERVICE_TYPE`
    `protected PortMapping[]` | `portMappings`
    `static ServiceType` | `PPP_SERVICE_TYPE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PortMappingListener(PortMapping portMapping)`
    `PortMappingListener(PortMapping[] portMappings)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `beforeShutdown(Registry registry)`
    `void` | `deviceAdded(Registry registry, Device device)`
    `void` | `deviceRemoved(Registry registry, Device device)`
    `protected Service` | `discoverConnectionService(Device device)`
    `protected void` | `handleFailureMessage(String s)`

    - ### Methods inherited from class org.fourthline.cling.registry.DefaultRegistryListener

      `afterShutdown, localDeviceAdded, localDeviceRemoved, remoteDeviceAdded, remoteDeviceDiscoveryFailed, remoteDeviceDiscoveryStarted, remoteDeviceRemoved, remoteDeviceUpdated`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### IGD_DEVICE_TYPE

          public static final DeviceType IGD_DEVICE_TYPE

    - #### CONNECTION_DEVICE_TYPE

          public static final DeviceType CONNECTION_DEVICE_TYPE

    - #### IP_SERVICE_TYPE

          public static final ServiceType IP_SERVICE_TYPE

    - #### PPP_SERVICE_TYPE

          public static final ServiceType PPP_SERVICE_TYPE

    - #### portMappings

          protected PortMapping[] portMappings

    - #### activePortMappings

          protected Map<Service,List<PortMapping>> activePortMappings

  - ### Constructor Detail

    - #### PortMappingListener

          public PortMappingListener(PortMapping portMapping)

    - #### PortMappingListener

          public PortMappingListener(PortMapping[] portMappings)

  - ### Method Detail

    - #### deviceAdded

          public void deviceAdded(Registry registry,
                                  Device device)

      Overrides:
        `deviceAdded` in class `DefaultRegistryListener`

    - #### deviceRemoved

          public void deviceRemoved(Registry registry,
                                    Device device)

      Overrides:
        `deviceRemoved` in class `DefaultRegistryListener`

    - #### beforeShutdown

          public void beforeShutdown(Registry registry)

      Specified by:
        `beforeShutdown` in interface `RegistryListener`
      Overrides:
        `beforeShutdown` in class `DefaultRegistryListener`

    - #### discoverConnectionService

          protected Service discoverConnectionService(Device device)

    - #### handleFailureMessage

          protected void handleFailureMessage(String s)

Copyright © 2016 4th Line GmbH, Switzerland. All rights reserved.