org.fourthline.cling.transport.spi
Class AbstractStreamClient<C extends StreamClientConfiguration,REQUEST>

java.lang.Object
  extended by org.fourthline.cling.transport.spi.AbstractStreamClient<C,REQUEST>
All Implemented Interfaces:
StreamClient<C>
Direct Known Subclasses:
StreamClientImpl, StreamClientImpl

public abstract class AbstractStreamClient<C extends StreamClientConfiguration,REQUEST>
extends Object
implements StreamClient<C>

Implements the timeout/callback processing and unifies exception handling.

Author:
Christian Bauer

Constructor Summary
AbstractStreamClient()
           
 
Method Summary
protected abstract  void abort(REQUEST request)
          Cancel and abort the request immediately, with the proprietary API.
protected abstract  Callable<StreamResponseMessage> createCallable(StreamRequestMessage requestMessage, REQUEST request)
          Create a callable procedure that will execute the request.
protected abstract  REQUEST createRequest(StreamRequestMessage requestMessage)
          Create a proprietary representation of this request, log warnings and return null if creation fails.
protected abstract  boolean logExecutionException(Throwable t)
           
protected  void onFinally(REQUEST request)
           
 StreamResponseMessage sendRequest(StreamRequestMessage requestMessage)
          Sends the given request via TCP (HTTP) and returns the response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.fourthline.cling.transport.spi.StreamClient
getConfiguration, stop
 

Constructor Detail

AbstractStreamClient

public AbstractStreamClient()
Method Detail

sendRequest

public StreamResponseMessage sendRequest(StreamRequestMessage requestMessage)
                                  throws InterruptedException
Description copied from interface: StreamClient
Sends the given request via TCP (HTTP) and returns the response.

This method must implement expiration of timed out requests using the StreamClientConfiguration settings. When a request expires, a null response will be returned.

This method will always try to complete execution without throwing an exception. It will return null if an error occurs, and optionally log any exception messages.

The rules for logging are:

This method is required to add a Host HTTP header to the outgoing HTTP request, even if the given StreamRequestMessage does not contain such a header.

This method will add the User-Agent HTTP header to the outgoing HTTP request if the given message did not already contain such a header. You can set this default value in your StreamClientConfiguration.

Specified by:
sendRequest in interface StreamClient<C extends StreamClientConfiguration>
Parameters:
requestMessage - The message to send.
Returns:
The response or null if no response has been received or an error occurred.
Throws:
InterruptedException - if you interrupt the calling thread.

createRequest

protected abstract REQUEST createRequest(StreamRequestMessage requestMessage)
Create a proprietary representation of this request, log warnings and return null if creation fails.


createCallable

protected abstract Callable<StreamResponseMessage> createCallable(StreamRequestMessage requestMessage,
                                                                  REQUEST request)
Create a callable procedure that will execute the request.


abort

protected abstract void abort(REQUEST request)
Cancel and abort the request immediately, with the proprietary API.


logExecutionException

protected abstract boolean logExecutionException(Throwable t)
Returns:
true if no more logging of this exception should be done.

onFinally

protected void onFinally(REQUEST request)


Copyright © 2013 4th Line GmbH, Switzerland. All Rights Reserved.