sk.baka.ambient.collection.ampache
Class AmpacheServer

java.lang.Object
  extended by sk.baka.ambient.commons.SocketServer
      extended by sk.baka.ambient.collection.ampache.AmpacheServer
All Implemented Interfaces:
Closeable, ThreadFactory

public final class AmpacheServer
extends SocketServer

Provides the Ampache XML API services over a network. Hosts local tracks only.

Author:
Martin Vysny

Field Summary
 String myIP
          IP address of this device, must not be null.
static int PORT
          The port to listen on.
 
Constructor Summary
AmpacheServer(String password, ICollection collection)
          Creates new server instance.
 
Method Summary
protected  void handleRequest(Socket socket, InputStream in, OutputStream out)
          Handles a request.
protected  void onStopping()
          Invoked when the server is being stopped.
 void reset(String password)
          Resets the server and sets new credentials required.
 
Methods inherited from class sk.baka.ambient.commons.SocketServer
close, isStarted, newThread, 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

myIP

public volatile String myIP
IP address of this device, must not be null.

Constructor Detail

AmpacheServer

public AmpacheServer(String password,
                     ICollection collection)
Creates new server instance. The server is stopped by default.

Parameters:
password - initial password. If null then the security is disabled.
collection - The backend collection, must not be null.
Method Detail

reset

public void reset(String password)
Resets the server and sets new credentials required. The server remains started if it was started before. Does nothing if the password is the same as before.

Parameters:
password - the password

handleRequest

protected void handleRequest(Socket socket,
                             InputStream in,
                             OutputStream out)
                      throws IOException,
                             ServerHttpException,
                             InterruptedException
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.
InterruptedException - if interrupted.

onStopping

protected void onStopping()
Description copied from class: SocketServer
Invoked when the server is being stopped.

Overrides:
onStopping in class SocketServer


Copyright © 2007-2008. All Rights Reserved.