com.flexive.shared.stream
Class FxStreamUtils

java.lang.Object
  extended by com.flexive.shared.stream.FxStreamUtils

public class FxStreamUtils
extends java.lang.Object

Utitlity class to access the StreamServer

Author:
Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)

Field Summary
static long DEFAULT_TTL
          5 minutes default time to live
 
Constructor Summary
FxStreamUtils()
           
 
Method Summary
static void addLocalServer(com.flexive.stream.ServerLocation serverLocation)
          Add a local server
static void downloadBinary(BinaryDownloadCallback callback, java.util.List<com.flexive.stream.ServerLocation> server, java.io.OutputStream stream, long binaryId, FxMediaSelector selector)
          Download a binary
static void downloadBinary(java.util.List<com.flexive.stream.ServerLocation> server, java.io.OutputStream stream, BinaryDescriptor descriptor)
          Download a binary
static com.flexive.stream.StreamClient getClient()
          Retrieve a StreamClient, local servers are preferred, remote only as fallback.
static com.flexive.stream.StreamClient getClient(java.util.List<com.flexive.stream.ServerLocation> servers)
          Retrieve a StreamClient, local servers are preferred, remote only as fallback
static java.net.InetAddress probeNetworkInterfaces()
          Probe all network interfaces and return the most suited to run a StreamServer on.
static BinaryUploadPayload uploadBinary(long length, java.io.InputStream stream)
          Upload a binary (using an OutputStream) to the StreamServer with a default time to live
static BinaryUploadPayload uploadBinary(long length, java.io.InputStream stream, long timeToLive)
          Upload a binary (using an OutputStream) to the StreamServer with a given time to live.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_TTL

public static final long DEFAULT_TTL
5 minutes default time to live

See Also:
Constant Field Values
Constructor Detail

FxStreamUtils

public FxStreamUtils()
Method Detail

addLocalServer

public static void addLocalServer(com.flexive.stream.ServerLocation serverLocation)
Add a local server

Parameters:
serverLocation - local server location

uploadBinary

public static BinaryUploadPayload uploadBinary(long length,
                                               java.io.InputStream stream)
                                        throws FxStreamException
Upload a binary (using an OutputStream) to the StreamServer with a default time to live

Parameters:
length - expected length of the stream/binary
stream - the Stream containing the binary
Returns:
payload containing server side handle of the binary, mimeType and meta data
Throws:
FxStreamException - on errors
See Also:
DEFAULT_TTL

getClient

public static com.flexive.stream.StreamClient getClient()
                                                 throws FxStreamException
Retrieve a StreamClient, local servers are preferred, remote only as fallback. Remote servers will be fetched from the cache

Returns:
StreamClient
Throws:
FxStreamException - on errors

getClient

public static com.flexive.stream.StreamClient getClient(java.util.List<com.flexive.stream.ServerLocation> servers)
                                                 throws FxStreamException
Retrieve a StreamClient, local servers are preferred, remote only as fallback

Parameters:
servers - (optional) known remote servers
Returns:
StreamClient
Throws:
FxStreamException - on errors

uploadBinary

public static BinaryUploadPayload uploadBinary(long length,
                                               java.io.InputStream stream,
                                               long timeToLive)
                                        throws FxStreamException
Upload a binary (using an OutputStream) to the StreamServer with a given time to live. Warning: if using a remote connection, this method will return a few miliseconds before all binary data is stored in the DB! Local connected clients will return *after* all data is stored. This is currently a 'feature' that might be fixed sometime.

Parameters:
length - expected length of the stream/binary
stream - the Stream containing the binary
timeToLive - time in miliseconds the binary is guaranteed to exist server side (will be removed once expired)
Returns:
payload containing server side handle of the binary, mimeType and meta data
Throws:
FxStreamException - on errors

probeNetworkInterfaces

public static java.net.InetAddress probeNetworkInterfaces()
                                                   throws java.net.UnknownHostException
Probe all network interfaces and return the most suited to run a StreamServer on. Preferred are interfaces that are not site local.

Returns:
best suited host to run a StreamServer
Throws:
java.net.UnknownHostException - on errors

downloadBinary

public static void downloadBinary(BinaryDownloadCallback callback,
                                  java.util.List<com.flexive.stream.ServerLocation> server,
                                  java.io.OutputStream stream,
                                  long binaryId,
                                  FxMediaSelector selector)
                           throws FxStreamException
Download a binary

Parameters:
callback - callback handler to set mimetype and size for downloads
server - (optional) list of remote stream servers
stream - the output stream to send the binary to
binaryId - id of the binary
selector - selector of binary to use and for optional manipulations to perform
Throws:
FxStreamException - on errors

downloadBinary

public static void downloadBinary(java.util.List<com.flexive.stream.ServerLocation> server,
                                  java.io.OutputStream stream,
                                  BinaryDescriptor descriptor)
                           throws FxStreamException
Download a binary

Parameters:
server - (optional) list of remote stream servers
stream - the output stream to send the binary to
descriptor - binary descriptor
Throws:
FxStreamException - on errors