org.fourthline.cling.transport.impl

## Class StreamServerImpl

- java.lang.Object
- - org.fourthline.cling.transport.impl.StreamServerImpl

- All Implemented Interfaces:
    Runnable, StreamServer<StreamServerConfigurationImpl>

      public class StreamServerImpl
      extends Object
      implements StreamServer<StreamServerConfigurationImpl>

  Implementation based on the built-in SUN JDK 6.0 HTTP Server.

  See the documentation of the SUN JDK 6.0 HTTP Server.

  This implementation DOES NOT WORK on Android. Read the Cling manual for alternatives for Android.

  This implementation does not support connection alive checking, as we can't send heartbeats to the client. We don't have access to the raw socket with the Sun API.

  Author:
    Christian Bauer

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `StreamServerImpl.HttpServerConnection`
    `protected class` | `StreamServerImpl.RequestHttpHandler`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected StreamServerConfigurationImpl` | `configuration`
    `protected com.sun.net.httpserver.HttpServer` | `server`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StreamServerImpl(StreamServerConfigurationImpl configuration)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `StreamServerConfigurationImpl` | `getConfiguration()`
    `int` | `getPort()` This method will be called potentially right after `StreamServer.init(java.net.InetAddress, org.fourthline.cling.transport.Router)`, the actual assigned local port must be available before the server is started.
    `void` | `init(InetAddress bindAddress, Router router)` Configures the service and starts any listening sockets.
    `protected boolean` | `isConnectionOpen(com.sun.net.httpserver.HttpExchange exchange)` Logs a warning and returns `true`, we can't access the socket using the awful JDK webserver API.
    `void` | `run()`
    `void` | `stop()` Stops the service, closes any listening sockets.

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

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

- - ### Field Detail

    - #### configuration

          protected final StreamServerConfigurationImpl configuration

    - #### server

          protected com.sun.net.httpserver.HttpServer server

  - ### Constructor Detail

    - #### StreamServerImpl

          public StreamServerImpl(StreamServerConfigurationImpl configuration)

  - ### Method Detail

    - #### init

          public void init(InetAddress bindAddress,
                           Router router)
                    throws InitializationException

      Description copied from interface: `StreamServer`
      Configures the service and starts any listening sockets.
      Specified by:
        `init` in interface `StreamServer<StreamServerConfigurationImpl>`
      Parameters:
        `bindAddress` - The address to bind any sockets on.
        `router` - The router which handles the incoming `UpnpStream`.
      Throws:
        `InitializationException` - If the service could not be initialized or started.

    - #### getPort

          public int getPort()

      Description copied from interface: `StreamServer`
      This method will be called potentially right after `StreamServer.init(java.net.InetAddress, org.fourthline.cling.transport.Router)`, the actual assigned local port must be available before the server is started.
      Specified by:
        `getPort` in interface `StreamServer<StreamServerConfigurationImpl>`
      Returns:
        The TCP port this service is listening on, e.g. the actual ephemeral port.

    - #### getConfiguration

          public StreamServerConfigurationImpl getConfiguration()

      Specified by:
        `getConfiguration` in interface `StreamServer<StreamServerConfigurationImpl>`
      Returns:
        This service's configuration.

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`

    - #### stop

          public void stop()

      Description copied from interface: `StreamServer`
      Stops the service, closes any listening sockets.
      Specified by:
        `stop` in interface `StreamServer<StreamServerConfigurationImpl>`

    - #### isConnectionOpen

          protected boolean isConnectionOpen(com.sun.net.httpserver.HttpExchange exchange)

      Logs a warning and returns `true`, we can't access the socket using the awful JDK webserver API.

      Override this method if you know how to do it.

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