sk.baka.ambient.playerservice
Class StreamerServer

java.lang.Object
  extended by sk.baka.ambient.commons.SocketServer
      extended by sk.baka.ambient.playerservice.StreamerServer
All Implemented Interfaces:
Closeable, ThreadFactory

public final class StreamerServer
extends SocketServer

This class acts as a mp3 data feed for the MediaPlayer component. It acts as a very simple http server (handles GET requests on http://localhost: 5412/). The following paths are supported:

The port is opened immediately when the object is created. Use the SocketServer.close() method to close and cleanup the server.

Author:
Martin Vysny

Field Summary
static int PORT
          The port to listen on.
 
Constructor Summary
StreamerServer(PlayerService service)
          Creates new server instance and opens the listen port.
 
Method Summary
static String getShoutcastStream(URL shoutcast)
          Returns an URL which accesses given shoutcast radio.
protected  void handleRequest(Socket socket, InputStream in, OutputStream out)
          Handles a request.
 
Methods inherited from class sk.baka.ambient.commons.SocketServer
close, isStarted, newThread, onStopping, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PORT

public static final int PORT
The port to listen on.

See Also:
Constant Field Values
Constructor Detail

StreamerServer

public StreamerServer(PlayerService service)
Creates new server instance and opens the listen port.

Parameters:
service - Owning player service.
Method Detail

getShoutcastStream

public static String getShoutcastStream(URL shoutcast)
Returns an URL which accesses given shoutcast radio.

Parameters:
shoutcast - the shoutcast radio URL
Returns:
this relay server URL.

handleRequest

protected void handleRequest(Socket socket,
                             InputStream in,
                             OutputStream out)
                      throws IOException,
                             ServerHttpException
Description copied from class: SocketServer
Handles a request. The communication is already opened and provided. Implementor executes in a new thread. Implementor should periodically check for Thread.isInterrupted(), terminating ASAP when interrupted.

Specified by:
handleRequest in class SocketServer
Parameters:
socket - the socket for this request.
in - opened read pipe from the socket.
out - opened write pipe to the socket.
Throws:
IOException - if i/o error occurs.
ServerHttpException - if HTTP error occurs. This error is written as a HTTP response. If you decide to throw this error then make sure that nothing was written yet to out.


Copyright © 2007-2008. All Rights Reserved.