org.codehaus.wadi.impl
Class Utils

java.lang.Object
  extended byorg.codehaus.wadi.impl.Utils

public class Utils
extends Object

A collection of useful static functions

Version:
$Revision: 1363 $
Author:
Jules Gosnell

Field Summary
protected static Log _log
           
 
Constructor Summary
Utils()
           
 
Method Summary
static void acquireUninterrupted(Sync sync)
          Ignore any interruptions whilst acquiring a lock.
static boolean attemptUninterrupted(Sync sync)
          If a lock is free, acquire it, ignoring any interruptions, else fail.
static Object byteArrayToObject(byte[] bytes, Streamer streamer)
           
static File createTempDirectory(String prefix, String suffix, File directory)
           
static String getClusterUri()
           
static org.activemq.ActiveMQConnectionFactory getConnectionFactory()
           
static byte[] getContent(SerializableContent object, Streamer streamer)
           
static Motable mote(Emoter emoter, Immoter immoter, Motable emotable, String name)
          Mote (in other words - move) the data held in a Motable from one Contextualiser to another, such that if the two Contextualisers store Motables in a persistant fashion, the data is never present in less than one of the two.
static byte[] objectToByteArray(Object object, Streamer streamer)
           
static void safeAcquire(Sync sync)
           
static Object safeByteArrayToObject(byte[] bytes, Streamer streamer)
           
static byte[] safeGetContent(SerializableContent object, Streamer streamer)
           
static byte[] safeObjectToByteArray(Object object, Streamer streamer)
           
static void safePut(Object item, Puttable puttable)
           
static SerializableContent safeSetContent(SerializableContent object, byte[] content, Streamer streamer)
           
static void safeSleep(long period)
           
static Object safeTake(Takable takable)
           
static SerializableContent setContent(SerializableContent object, byte[] content, Streamer streamer)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_log

protected static final Log _log
Constructor Detail

Utils

public Utils()
Method Detail

mote

public static Motable mote(Emoter emoter,
                           Immoter immoter,
                           Motable emotable,
                           String name)
Mote (in other words - move) the data held in a Motable from one Contextualiser to another, such that if the two Contextualisers store Motables in a persistant fashion, the data is never present in less than one of the two.

Parameters:
emoter - - delegate for the source Contextualiser
immoter - - delegate for the target Contextualiser
emotable - - data to be moved
name - - the id of said data
Returns:
- the resulting immotable - in other words - the data's new representation in the target Contextualiser

acquireUninterrupted

public static void acquireUninterrupted(Sync sync)
                                 throws TimeoutException
Ignore any interruptions whilst acquiring a lock.

Parameters:
sync - - the lock
Throws:
TimeoutException - - some Syncs (TimeoutSync) may timeout during acquisition

attemptUninterrupted

public static boolean attemptUninterrupted(Sync sync)
If a lock is free, acquire it, ignoring any interruptions, else fail.

Parameters:
sync - - the lock
Returns:
- whether or not the lock was acquired

byteArrayToObject

public static Object byteArrayToObject(byte[] bytes,
                                       Streamer streamer)
                                throws IOException,
                                       ClassNotFoundException
Throws:
IOException
ClassNotFoundException

safeByteArrayToObject

public static Object safeByteArrayToObject(byte[] bytes,
                                           Streamer streamer)

objectToByteArray

public static byte[] objectToByteArray(Object object,
                                       Streamer streamer)
                                throws IOException
Throws:
IOException

safeObjectToByteArray

public static byte[] safeObjectToByteArray(Object object,
                                           Streamer streamer)

getContent

public static byte[] getContent(SerializableContent object,
                                Streamer streamer)
                         throws IOException
Throws:
IOException

safeGetContent

public static byte[] safeGetContent(SerializableContent object,
                                    Streamer streamer)

setContent

public static SerializableContent setContent(SerializableContent object,
                                             byte[] content,
                                             Streamer streamer)
                                      throws IOException,
                                             ClassNotFoundException
Throws:
IOException
ClassNotFoundException

safeSetContent

public static SerializableContent safeSetContent(SerializableContent object,
                                                 byte[] content,
                                                 Streamer streamer)

getClusterUri

public static String getClusterUri()

getConnectionFactory

public static org.activemq.ActiveMQConnectionFactory getConnectionFactory()

safePut

public static void safePut(Object item,
                           Puttable puttable)

safeTake

public static Object safeTake(Takable takable)

safeSleep

public static void safeSleep(long period)

safeAcquire

public static void safeAcquire(Sync sync)

createTempDirectory

public static File createTempDirectory(String prefix,
                                       String suffix,
                                       File directory)
                                throws IOException
Throws:
IOException


Copyright © 2004-2008 Core Developers Network Ltd.. All Rights Reserved.