Interface Channel

All Superinterfaces:
Eligible
All Known Subinterfaces:
Channel.Default, IOSubchannel, MailChannel, Self, SocketIOChannel, Subchannel
All Known Implementing Classes:
ClassChannel, Component, ComponentCollector, ComponentCollector, ComponentProvider, ComponentProxy, ComponentVertex, ConfigurationStore, ConnectionManager, ConnectionManager.Connection, FileStorage, FileSystemWatcher, FreeMarkerRequestHandler, Handler.NoChannel, HttpConnector, HttpServer, InMemorySessionManager, InputStreamMonitor, IOSubchannel.DefaultIOSubchannel, JsonConfigurationStore, LanguageSelector, LinkedIOSubchannel, MailConnectionManager, MailConnectionManager.AbstractMailChannel, MailMonitor, MailMonitor.MonitorChannel, MailSender, MailSender.SenderChannel, NamedChannel, NightConfigStore, NioDispatcher, PreferencesStore, ProcessManager, ProcessManager.ProcessChannel, PurgeTerminator, SessionManager, SocketConnectionManager, SocketConnectionManager.SocketChannelImpl, SocketConnector, SocketServer, SslCodec, StaticContentDispatcher, Subchannel.DefaultSubchannel, TomlConfigurationStore, YamlConfigurationStore

public interface Channel extends Eligible
Instances of this interface can be used as a communication bus for sending events between components.

The instances work as identifiers of channels. Their only functionality is defined by the Eligible interface, which allows a channel (used as attribute of an Event) to be matched against a criterion specified in a Handler.

The need to use the Eligible interface for comparison arises from the fact that we cannot use objects as values in annotations. It must therefore be possible to match channels (objects) against criteria that can be expressed as constant values.

Some values have been defined to represent special criteria.

  • If the value Channel.class is specified as criterion in a handler, all channel instances match. It is the “catch-all” criterion.

  • If the value Channel.Default.class is specified as criterion in a handler, the channels from an Event are matched agains the criterion from the component’s channel (returned by the channel() method).

The predefined BROADCAST channel is a channel instance that implements the Eligible interface in such a way that all criteria match. Events fired on the BROADCAST channel will therefore be accepted by all handlers (as its name suggests).

For ordinary usage, the implementing classes ClassChannel and NamedChannel should be sufficient. If another type of Channel is needed, its implementation must make sure that Eligible.isEligibleFor(Object) returns true if called with Channel.class as parameter, else channels of the new type will not be delivered to “catch-all” handlers.

Objects of type Channel must be immutable.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    This interface’s class can be used to specify the component’s channel (see Component.channel()) as criterion in handler annotations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Channel
    A special channel instance that can be used to send events to all components.
    static final Channel
    A special channel object that can be passed as argument to the constructor of Component(Channel).
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Returns a textual representation of a channel’s criterion.
    default boolean
    isEligibleFor(Object criterion)
    By default, a channel is eligible for a broadcast and for its own default criterion (see Eligible.defaultCriterion().
    static String
    toString(Channel channel)
    Returns a textual representation of a channel.
    static String
    toString(Channel[] channels)
    Returns a textual representation of an array of channels.

    Methods inherited from interface org.jgrapes.core.Eligible

    defaultCriterion
  • Field Details

    • SELF

      static final Channel SELF
      A special channel object that can be passed as argument to the constructor of Component(Channel).

      Doing this sets the component’s channel to the component (which is not available as argument when calling the constructor).

      See Also:
    • BROADCAST

      static final Channel BROADCAST
      A special channel instance that can be used to send events to all components.
  • Method Details

    • isEligibleFor

      default boolean isEligibleFor(Object criterion)
      By default, a channel is eligible for a broadcast and for its own default criterion (see Eligible.defaultCriterion().
      Specified by:
      isEligibleFor in interface Eligible
      Parameters:
      criterion - the criterion
      Returns:
      true, if is eligible for
    • criterionToString

      static String criterionToString(Object criterion)
      Returns a textual representation of a channel’s criterion.
      Parameters:
      criterion - the criterion
      Returns:
      the representation
    • toString

      static String toString(Channel channel)
      Returns a textual representation of a channel.
      Parameters:
      channel - the channel
      Returns:
      the representation
    • toString

      static String toString(Channel[] channels)
      Returns a textual representation of an array of channels.
      Parameters:
      channels - the channels
      Returns:
      the representation