Package eu.bandm.tools.message
Class SimpleMessage<D>
java.lang.Object
eu.bandm.tools.message.Message
eu.bandm.tools.message.SimpleMessage<D>
- Type Parameters:
D
- the document identifier used by the locations
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SimpleMessage.Ping
A minimal selection of message data which is useful in practice.
Used ubiquituously in metatools.
Very small, but in most cases sufficient information content: The abstract
Additionally this class provides a zoo of static factory methods. But the "create and send" methods of
Very small, but in most cases sufficient information content: The abstract
Message
class is enhanced by a Location
, which points to
a document(/some documents), a textual information text
,
and a list of arguments (=array of objects) which probably will be "sprintf"-ed
into the message.
Additionally this class provides a zoo of static factory methods. But the "create and send" methods of
SimpleMessage.Sender
should be preferred when possible.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Passes all incoming messages to its drain, after applying the given location map.static class
Log message with not more informative content than "I am still alive".static class
Nested classes/interfaces inherited from class eu.bandm.tools.message.Message
Message.Kind
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Object[]
Optional document position the message is related to.Contains the textual information of the message (maybe null). -
Constructor Summary
ConstructorDescriptionSimpleMessage
(Message.Kind k, @Opt Throwable e, @Opt Locatable<D> l, @Opt String t, Object... a) Main constructor which sets all field values.SimpleMessage
(SimpleMessage<D> msg) return a clone. -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> SimpleMessage<E>
cast
(SimpleMessage<? extends E> message) Convenience method for upcasting any instance with a more specialized (=sub-class) document identifier to an instance with the more general document identifier.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributesstatic <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributesstatic <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.final Object[]
getArgs()
getText()
static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributesstatic <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <X> Function<SimpleMessage<X>,
SimpleMessage<X>> Lift a function which operates on theMessage.Kind
part to one which operates on the whole Message.static <D,
E> Function<SimpleMessage<D>, SimpleMessage<E>> liftMapLocation
(Function<Location<D>, Location<E>> f) Constructs a function which maps SimpleMessages (never null to never null), when a function which maps theirLocation
(maybe null to maybe null) is given.static <X> Function<SimpleMessage<X>,
SimpleMessage<X>> Lift a function which operates on thetext
part to one which operates on the whole Message.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributesstatic <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributesstatic <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributesstatic <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.Apply a function which operates on theMessage.Kind
part to construct a new message.static <E,
F> BiFunction<Function<Location<E>, Location<F>>, SimpleMessage<E>, SimpleMessage<F>> ABiFunction
which delivers a clone of a SimpleMessage and applies a mapping function on theLocation
part.<E> SimpleMessage<E>
mapLocation
(Function<Location<D>, Location<E>> f) Apply a function which operates on theLocation
part to construct a new message.Apply a function which operates on thetext
part to construct a new message.static <D> Function<SimpleMessage<D>,
String> messageToString
(Function<? super Location<D>, ? extends String> formatLoc) Create a reified function for converting a message to a string, using a given transformation function for theLocation
part.static <D> Function<SimpleMessage<D>,
String> messageToString
(Function<? super Location<D>, ? extends String> formatLoc, Function<? super Message.Kind, String> formatKind) Construct a reified function for converting a message to a string, using the given transformation functions for theLocation
part and for theMessage.Kind
.static <D> Thread
monitor
(Thread thread, MessageReceiver<? super SimpleMessage<D>> receiver) Installs a handler on the given thread that reports uncaught exceptions as failure messages.static <D> Thread
monitor
(Thread thread, MessageReceiver<? super SimpleMessage<D>> receiver, PrintStream ps) Installs a handler on the given thread that reports uncaught exceptions as failure messages.static <E> MessageReceiver<SimpleMessage<E>>
narrow
(MessageReceiver<? super SimpleMessage<? super E>> receiver) Convenience method for downcasting a message receiver accepting more general messages or document identifiers to one which accepts more specialized (=sub-class) messages.static <D> MessageReceiver<SimpleMessage<?>>
narrowToBottom
(MessageReceiver<? super SimpleMessage<D>> receiver) Convenience method for casting a message receiver which accepts SimpleMessages with a particular document identifiers to one with an unspecified document identifier.static <X> SimpleMessage.Ping<X>
ping()
Convenience factory Method: Create an instance ofSimpleMessage.Ping
, which is of kindMessage.Kind.log
.toString()
Convert a message to a string, using the java default "toString(Object)" for theLocation
part.Convert a message to a string, using the function argument to print theLocation
part and the enumeration names for theMessage.Kind
.toString
(Function<? super Location<D>, ? extends String> formatLoc, Function<? super Message.Kind, String> formatKind) Convert a message to a string, using the function arguments to print theLocation
and theMessage.Kind
parts.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.static <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributesstatic <D> SimpleMessage<D>
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default.Methods inherited from class eu.bandm.tools.message.Message
explode, getCause, getKind, getStackTrace, getTimeStamp, isCritical
-
Field Details
-
location
Optional document position the message is related to. -
text
Contains the textual information of the message (maybe null). ("text" and "cause" can both be ==null in case of a simple "Ping"-style message.) -
args
-
emptyArgs
-
-
Constructor Details
-
SimpleMessage
public SimpleMessage(Message.Kind k, @Opt @Opt Throwable e, @Opt @Opt Locatable<D> l, @Opt @Opt String t, Object... a) Main constructor which sets all field values.
ATTENTION: Even both e and t maybe =null for a "Ping"-style message.- Parameters:
k
- (never null) message Kinde
- (maybe null) causing Throwablel
- (maybe null) text location to which the message is relatedt
- (maybe null) message texta
- (maybe null) list of additional pieces of information, meant to be printf-ed into the message.
ATTENTION: The value "null" is explicitly replaced by an empty array. For an arg-list with one single entry of value "null" use "(Object)null
".
-
SimpleMessage
return a clone.
-
-
Method Details
-
getLocation
- Returns:
- (maybe null) the text location related to the message.
-
getText
- Returns:
- (maybe null) the text contents related to the message.
-
getArgs
- Returns:
- the argument array contained in this message. Is never null, but possibly empty.
-
messageToString
public static <D> Function<SimpleMessage<D>,String> messageToString(Function<? super Location<D>, ? extends String> formatLoc) Create a reified function for converting a message to a string, using a given transformation function for theLocation
part. Result is meant to be plugged inMessagePrinter.setMessageToString(Function)
. -
messageToString
public static <D> Function<SimpleMessage<D>,String> messageToString(Function<? super Location<D>, ? extends String> formatLoc, Function<? super Message.Kind, String> formatKind) Construct a reified function for converting a message to a string, using the given transformation functions for theLocation
part and for theMessage.Kind
. Result is meant to be plugged inMessagePrinter.setMessageToString(Function)
. -
toString
public String toString(Function<? super Location<D>, ? extends String> formatLoc, Function<? super Message.Kind, String> formatKind) Convert a message to a string, using the function arguments to print theLocation
and theMessage.Kind
parts. This is only a rough interpretation for debugging and tracing; an actual user-levelMessagePrinter
provides more elaborate methods. Esp. no "printf"-style of the argument list is executed. -
toString
Convert a message to a string, using the function argument to print theLocation
part and the enumeration names for theMessage.Kind
. -
toString
Convert a message to a string, using the java default "toString(Object)" for theLocation
part. This is a primitive visualisation, required for tracing and debugging. An actual user-levelMessagePrinter
or sim., will provide much more elaborate rendering. -
cast
Convenience method for upcasting any instance with a more specialized (=sub-class) document identifier to an instance with the more general document identifier. When used as method argument, return value or in assignments, the target class needs not be given explicitly, as in
SimpleMessage<Object> var = cast(new SimpleMessage<String>())
Otherwise it can be called explicitly:
SimpleMessage.<Object>cast(new SimpleMessage<String>())
- Returns:
- loc
-
narrow
public static <E> MessageReceiver<SimpleMessage<E>> narrow(MessageReceiver<? super SimpleMessage<? super E>> receiver) Convenience method for downcasting a message receiver accepting more general messages or document identifiers to one which accepts more specialized (=sub-class) messages. When used as method argument, return value or in assignments, the target class needs not be given explicitly, as in
MessageReceiver<SimpleMessage<String>> rec = narrow(new MessageReceiver<Message>())
Otherwise it can be called explicitly:
SimpleMessage.<SimpleMessage<String>>narrow(new MessageReceiver<Message>())
- Returns:
- loc
-
narrowToBottom
public static <D> MessageReceiver<SimpleMessage<?>> narrowToBottom(MessageReceiver<? super SimpleMessage<D>> receiver) Convenience method for casting a message receiver which accepts SimpleMessages with a particular document identifiers to one with an unspecified document identifier. -
mapKind
Apply a function which operates on theMessage.Kind
part to construct a new message. -
liftMapKind
public static <X> Function<SimpleMessage<X>,SimpleMessage<X>> liftMapKind(UnaryOperator<Message.Kind> f) Lift a function which operates on theMessage.Kind
part to one which operates on the whole Message. -
mapLocation
Apply a function which operates on theLocation
part to construct a new message. Consider when defining the function, that location maybe null. -
liftMapLocation
public static <D,E> Function<SimpleMessage<D>,SimpleMessage<E>> liftMapLocation(Function<Location<D>, Location<E>> f) Constructs a function which maps SimpleMessages (never null to never null), when a function which maps theirLocation
(maybe null to maybe null) is given. Partiality/totality is also lifted, unaltered.
(This function is used by e.g. xslt/base/TPathCache, d2d2/base/Main+others.) -
mapLocation
public static <E,F> BiFunction<Function<Location<E>,Location<F>>, mapLocation()SimpleMessage<E>, SimpleMessage<F>> ABiFunction
which delivers a clone of a SimpleMessage and applies a mapping function on theLocation
part. Is used byLocationMap
. -
mapText
Apply a function which operates on thetext
part to construct a new message. -
liftMapText
Lift a function which operates on thetext
part to one which operates on the whole Message. -
log
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
log
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
log
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
log
public static <D> SimpleMessage<D> log(Throwable ex, Locatable<D> loc, String message, Object... args) Convenience factory Method: Construct a message with the given kind and attributes -
logStart
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
logStart
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
logStart
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
logStart
public static <D> SimpleMessage<D> logStart(Throwable ex, Locatable<D> loc, String message, Object... args) Convenience factory Method: Construct a message with the given kind and attributes -
logEnd
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
logEnd
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
logEnd
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
logEnd
public static <D> SimpleMessage<D> logEnd(Throwable ex, Locatable<D> loc, String message, Object... args) Convenience factory Method: Construct a message with the given kind and attributes -
error
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
error
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
error
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
error
public static <D> SimpleMessage<D> error(Throwable ex, Locatable<D> loc, String message, Object... args) Convenience factory Method: Construct a message with the given kind and attributes -
warning
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
warning
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
warning
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
warning
public static <D> SimpleMessage<D> warning(Throwable ex, Locatable<D> loc, String message, Object... args) Convenience factory Method: Construct a message with the given kind and attributes -
failure
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
failure
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
failure
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
failure
public static <D> SimpleMessage<D> failure(Throwable ex, Locatable<D> loc, String message, Object... args) Convenience factory Method: Construct a message with the given kind and attributes -
hint
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
hint
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
hint
Convenience factory Method: Construct a message with the given kind and attributes, and set all others to default. -
hint
public static <D> SimpleMessage<D> hint(Throwable ex, Locatable<D> loc, String message, Object... args) Convenience factory Method: Construct a message with the given kind and attributes -
ping
Convenience factory Method: Create an instance ofSimpleMessage.Ping
, which is of kindMessage.Kind.log
. -
monitor
Installs a handler on the given thread that reports uncaught exceptions as failure messages. Is equal tomonitor(thread, receiver, false)
. -
monitor
public static <D> Thread monitor(Thread thread, MessageReceiver<? super SimpleMessage<D>> receiver, @Opt PrintStream ps) Installs a handler on the given thread that reports uncaught exceptions as failure messages.- Type Parameters:
D
- the document identifier type- Parameters:
thread
- the thread to monitorreceiver
- the receiver for the failure messageps
- if != null, additionally the stack trace will be printed there.- Returns:
- thread
- See Also:
-