com.sun.sgs.impl.nio
Class Util

java.lang.Object
  extended by com.sun.sgs.impl.nio.Util

final class Util
extends Object

Utility methods for the asynchronous IO implementation.


Nested Class Summary
(package private) static class Util.DoneFuture<V>
          Base class for an already-finished Future.
 
Method Summary
(package private) static
<V> Future<V>
failedFuture(Throwable exception)
          Returns a new, completed Util.DoneFuture that always throws the given exception when its get methods are called.
(package private) static
<V> Future<V>
finishedFuture(V result)
          Returns a new, completed Util.DoneFuture with the given result.
(package private) static String formatOps(int ops)
          Returns a concise string representation of the active SelectionKey operations set in the parameter ops.
(package private) static
<T extends Throwable>
T
initCause(T exception, Throwable cause)
          Returns the given exception with its cause initialized.
(package private) static String opName(int op)
          Returns the human-readable name of the given SelectionKey operation.
(package private) static IllegalStateException unexpected(Throwable exception)
          Returns an IllegalStateException indicating that the given exception was not expected, and setting the cause to that exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

initCause

static <T extends Throwable> T initCause(T exception,
                                         Throwable cause)
Returns the given exception with its cause initialized. The original exception is returned in a typesafe way so that it can be thrown easily.

Type Parameters:
T - the type of the parent exception
Parameters:
exception - the exception to initialize
cause - the cause
Returns:
the exception with its cause initialized
Throws:
IllegalArgumentException - if an attempt is made to set an exception as its own cause
IllegalStateException - if the exception has already had its cause initialized
See Also:
Throwable.initCause(Throwable)

unexpected

static IllegalStateException unexpected(Throwable exception)
Returns an IllegalStateException indicating that the given exception was not expected, and setting the cause to that exception.

Parameters:
exception - the unexpected exception
Returns:
an IllegalStateException

finishedFuture

static <V> Future<V> finishedFuture(V result)
Returns a new, completed Util.DoneFuture with the given result.

Type Parameters:
V - the type of the result
Parameters:
result - the result for the returned Future
Returns:
a new, completed Future with the given result

failedFuture

static <V> Future<V> failedFuture(Throwable exception)
Returns a new, completed Util.DoneFuture that always throws the given exception when its get methods are called.

Type Parameters:
V - the type of the result
Parameters:
exception - the exception for the returned Future to throw
Returns:
a new, completed Future that throws the exception

formatOps

static String formatOps(int ops)
Returns a concise string representation of the active SelectionKey operations set in the parameter ops. For example, if ops is OP_READ | OP_WRITE, this method returns the string "RW".

Parameters:
ops - the SelectionKey operations to format
Returns:
a string representation of the active ops
See Also:
SelectionKey

opName

static String opName(int op)
Returns the human-readable name of the given SelectionKey operation.

Parameters:
op - a SelectionKey operation
Returns:
a human-readable string, such as "OP_READ"
Throws:
IllegalArgumentException - if the op is not one of the operation constants defined by SelectionKey
See Also:
SelectionKey

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved