Class ChatApp

java.lang.Object
pt.unl.fct.di.novasys.babel.core.GenericProtocol
protocols.apps.chat.ChatApp

public class ChatApp extends pt.unl.fct.di.novasys.babel.core.GenericProtocol
The chat application — the top of the stack, and the only protocol a user sees. It ties the lower layers together:
  • Global messages go out via a BroadcastRequest to the broadcast protocol, and come back (to everyone, including us) as BroadcastDelivery notifications. Both are the shared babel-protocols-common dissemination types.
  • Private messages (/msg) are sent point-to-point with sendMessage over the membership's shared channel.
  • Presence — who's in the chat — is a Host → nickname roster. When the membership reports a NeighborUp, we send that peer a direct ChatDirectMessage.Kind.HELLO carrying our nickname; the peer does the same, so both learn each other. NeighborDown (a crash) and a broadcast LEAVE (a graceful /quit) remove people again.

Threading note

The console runs on its own thread (so it can block waiting for you to type). When you enter a line, handleInput(java.lang.String) runs on that thread and calls sendRequest/sendMessage — these enqueue work onto Babel's event loop, so they're safe to call from here. The roster is a ConcurrentHashMap because the console thread reads it (for /who and /msg) while the event loop writes it. Printing is via JLine, which is itself safe to call from any thread.
  • Nested Class Summary

    Nested classes/interfaces inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    pt.unl.fct.di.novasys.babel.core.GenericProtocol.ProtocolMetricsBabelMetrics
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final short
     
    static final String
     

    Fields inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    babel, babelSecurity
  • Constructor Summary

    Constructors
    Constructor
    Description
    ChatApp(Properties props, pt.unl.fct.di.novasys.network.data.Host myself, String nick, short broadcastProtoId)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     

    Methods inherited from class pt.unl.fct.di.novasys.babel.core.GenericProtocol

    addSecret, addSecret, addSecret, addSecret, cancelTimer, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, closeConnection, createChannel, createSecureChannel, createSecureChannel, createSecureChannel, createSecureChannelWithAliases, createSecureChannelWithAliases, createSecureChannelWithIdentities, createSecureChannelWithIdentities, createSecureChannelWithProtoIdentities, enableGenericMetrics, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateIdentity, generateSecret, generateSecret, generateSecret, generateSecret, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, generateSecretFromPassword, getChannelOrThrow, getDefaultChannel, getDefaultProtoIdentity, getDefaultProtoIdentityCrypt, getDefaultProtoSecret, getMillisSinceBabelStart, getOrGenerateDefaultProtoIdentity, getProtoId, getProtoName, hasProtocolThreadStarted, openConnection, openConnection, openConnection, openConnection, registerChannelEventHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageHandler, registerMessageSerializer, registerMetric, registerReplyHandler, registerRequestHandler, registerSharedChannel, registerTimerHandler, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendReply, sendRequest, setDefaultChannel, setDefaultProtoIdentity, setDefaultProtoIdentity, setDefaultProtoSecret, setupPeriodicTimer, setupTimer, startEventThread, subscribeNotification, triggerNotification, unsubscribeNotification

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ChatApp

      public ChatApp(Properties props, pt.unl.fct.di.novasys.network.data.Host myself, String nick, short broadcastProtoId) throws pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException, IOException
      Throws:
      pt.unl.fct.di.novasys.babel.exceptions.HandlerRegistrationException
      IOException
  • Method Details

    • init

      public void init(Properties props)
      Specified by:
      init in class pt.unl.fct.di.novasys.babel.core.GenericProtocol