org.eclipse.wst.jsdt.chromium.util

## Class SignalRelay<SIGNAL>

- java.lang.Object
- - org.eclipse.wst.jsdt.chromium.util.SignalRelay<SIGNAL>

Type Parameters:
  `SIGNAL` - type of signal that this node works with

    public class SignalRelay<SIGNAL>
    extends java.lang.Object

A node in a network that broadcasts some signal among all its peers one time. The signal may get converted when goes from node to node. The first time a node receives a signal, it calls a user callback. It ignores all further signals. A signal is accompanied by exception called 'cause' that can be null.

The class is thread-safe.

This class is useful for a shutdown strategy, when several resources should be taken down together, but there are no single authority to manage it. E.g. in a client-medium-server threesome each part can initiate shutdown.

Nodes of different signal system can be bound using `SignalRelay.SignalConverter`.

### Nested Class Summary

Nested Classes
`static class` `SignalRelay.AlreadySignalledException`
`static interface` `SignalRelay.Callback<S>` An interface to notify a user about a received signal.
`static interface` `SignalRelay.SignalConverter<FROM,TO>` A converter that translates signals from one type to another so that unrelated resources could co-work.

### Constructor Summary

Constructors
Constructor and Description
`SignalRelay(SignalRelay.Callback<SIGNAL> callback)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`<OPPOSITE> void` `bind(SignalRelay<OPPOSITE> peer, SignalRelay.SignalConverter<SIGNAL,OPPOSITE> toPeerConverter, SignalRelay.SignalConverter<OPPOSITE,SIGNAL> fromPeerConverter)` Binds this node to a peer node.
`static <T> SignalRelay<T>` `create(SignalRelay.Callback<T> callback)`
`SIGNAL` `getReceivedSignal()`
`boolean` `isSignalled()`
`void` `sendSignal(SIGNAL signal, java.lang.Exception cause)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### SignalRelay

    public SignalRelay(SignalRelay.Callback<SIGNAL> callback)

### Method Detail

#### create

    public static <T> SignalRelay<T> create(SignalRelay.Callback<T> callback)

#### sendSignal

    public void sendSignal(SIGNAL signal,
                           java.lang.Exception cause)

#### isSignalled

    public boolean isSignalled()

#### getReceivedSignal

    public SIGNAL getReceivedSignal()

Returns:
  a signal received or null if called before a signal came in.

#### bind

    public <OPPOSITE> void bind(SignalRelay<OPPOSITE> peer,
                                SignalRelay.SignalConverter<SIGNAL,OPPOSITE> toPeerConverter,
                                SignalRelay.SignalConverter<OPPOSITE,SIGNAL> fromPeerConverter)
                         throws SignalRelay.AlreadySignalledException

Binds this node to a peer node. If the peer already received a signal, accepts it and throws an exception.

Type Parameters:
  `OPPOSITE` - type of signal the peer node works with
Parameters:
  `toPeerConverter` - a signal converter that is used when sending signal or null
  `fromPeerConverter` - a signal converter that is used when receiving signal or null
Throws:
  `SignalRelay.AlreadySignalledException` - when binding to node that already has a signal