Class Transporter

java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.transporter.Transporter
All Implemented Interfaces:
MetricConstants, MoleculerLifecycle
Direct Known Subclasses:
AmqpTransporter, FileSystemTransporter, InternalTransporter, JmsTransporter, KafkaTransporter, MqttTransporter, NatsTransporter, NullTransporter, RedisTransporter, TcpTransporter

public abstract class Transporter extends MoleculerComponent implements MetricConstants
Base superclass of all Transporter implementations.
See Also:
  • Field Details

    • PACKET_EVENT

      public static final String PACKET_EVENT
      See Also:
    • PACKET_REQUEST

      public static final String PACKET_REQUEST
      See Also:
    • PACKET_RESPONSE

      public static final String PACKET_RESPONSE
      See Also:
    • PACKET_DISCOVER

      public static final String PACKET_DISCOVER
      See Also:
    • PACKET_INFO

      public static final String PACKET_INFO
      See Also:
    • PACKET_DISCONNECT

      public static final String PACKET_DISCONNECT
      See Also:
    • PACKET_HEARTBEAT

      public static final String PACKET_HEARTBEAT
      See Also:
    • PACKET_PING

      public static final String PACKET_PING
      See Also:
    • PACKET_PONG

      public static final String PACKET_PONG
      See Also:
    • eventChannel

      public String eventChannel
    • requestChannel

      public String requestChannel
    • responseChannel

      public String responseChannel
    • discoverBroadcastChannel

      public String discoverBroadcastChannel
    • discoverChannel

      public String discoverChannel
    • infoBroadcastChannel

      public String infoBroadcastChannel
    • infoChannel

      public String infoChannel
    • disconnectChannel

      public String disconnectChannel
    • heartbeatChannel

      public String heartbeatChannel
    • pingChannel

      public String pingChannel
    • pongChannel

      public String pongChannel
    • namespace

      protected String namespace
      Namespace of channels.
    • prefix

      protected String prefix
      Prefix of channels.
    • nodeID

      protected String nodeID
      Local Node ID.
    • protocolVersion

      protected String protocolVersion
      ServiceBroker's protocol version. Placeholder only: overwritten in started(services.moleculer.ServiceBroker) from broker.getProtocolVersion(). The authoritative default lives in ServiceBrokerConfig.DEFAULT_PROTOCOL_VERSION ("5").
    • heartbeatInterval

      protected int heartbeatInterval
      Heartbeat sending period in SECONDS.
    • heartbeatTimeout

      protected int heartbeatTimeout
      Heartbeat timeout in SECONDS.
    • offlineTimeout

      protected int offlineTimeout
      How long keep information in registry about the offline nodes (SECONDS).
    • subscriptionTimeout

      protected int subscriptionTimeout
      Timeout of channel subscriptions (SECONDS).
    • preferHostname

      protected boolean preferHostname
      Use hostnames instead of IP addresses As the DHCP environment is dynamic, any later attempt to use IPs instead hostnames would most likely yield false results. Therefore, use hostnames if you are using DHCP.
    • debug

      protected boolean debug
      Writes the communication of method calls and events into the log.
    • debugHeartbeats

      protected boolean debugHeartbeats
      Writes the communication of heartbeats/gossiping into the log.
    • serializer

      protected Serializer serializer
    • usingJsonSerializer

      protected boolean usingJsonSerializer
    • instanceID

      protected final String instanceID
    • executor

      protected ExecutorService executor
    • scheduler

      protected ScheduledExecutorService scheduler
    • registry

      protected ServiceRegistry registry
    • serviceInvoker

      protected ServiceInvoker serviceInvoker
    • eventbus

      protected Eventbus eventbus
    • monitor

      protected Monitor monitor
    • uidGenerator

      protected UidGenerator uidGenerator
    • metrics

      protected Metrics metrics
    • heartBeatTimer

      protected volatile ScheduledFuture<?> heartBeatTimer
      Cancelable "Heart Beat" timer
    • checkTimeoutTimer

      protected volatile ScheduledFuture<?> checkTimeoutTimer
      Cancelable "Check Activities / Infos" timer
    • nodes

      protected final ConcurrentHashMap<String, NodeDescriptor> nodes
    • infoScheduled

      protected final AtomicBoolean infoScheduled
    • infoScheduledAt

      protected final AtomicLong infoScheduledAt
    • lastReceivedMessageAt

      protected final AtomicLong lastReceivedMessageAt
    • gaugeTransitConnected

      protected MetricGauge gaugeTransitConnected
    • counterTransporterPacketsSentTotal

      protected MetricCounter counterTransporterPacketsSentTotal
    • counterTransporterPacketsSentBytes

      protected MetricCounter counterTransporterPacketsSentBytes
    • counterTransporterPacketsReceivedTotal

      protected MetricCounter counterTransporterPacketsReceivedTotal
    • counterTransporterPacketsReceivedBytes

      protected MetricCounter counterTransporterPacketsReceivedBytes
  • Constructor Details

    • Transporter

      public Transporter()
    • Transporter

      public Transporter(Serializer serializer)
  • Method Details

    • started

      public void started(ServiceBroker broker) throws Exception
      Initializes transporter instance.
      Specified by:
      started in interface MoleculerLifecycle
      Overrides:
      started in class MoleculerComponent
      Parameters:
      broker - parent ServiceBroker
      Throws:
      Exception
    • channel

      protected String channel(String cmd, String nodeID)
    • connect

      public abstract void connect()
    • connected

      protected void connected()
    • connected

      protected void connected(boolean waitFor)
    • stopped

      public void stopped()
      Closes transporter.
      Specified by:
      stopped in interface MoleculerLifecycle
      Overrides:
      stopped in class MoleculerComponent
    • sendInfoPacket

      protected void sendInfoPacket(String channel)
    • sendDiscoverPacket

      protected void sendDiscoverPacket(String channel)
    • sendHeartbeatPacket

      protected void sendHeartbeatPacket()
    • sendDisconnectPacket

      protected void sendDisconnectPacket()
    • sendPongPacket

      protected void sendPongPacket(String channel, io.datatree.Tree data)
    • createPingPacket

      public io.datatree.Tree createPingPacket(String id)
    • sendEventPacket

      public void sendEventPacket(String nodeID, Context ctx, Groups groups, boolean broadcast)
    • sendRequestPacket

      public void sendRequestPacket(String nodeID, Context ctx)
    • sendDataPacket

      public void sendDataPacket(String cmd, String nodeID, Context ctx, byte[] bytes, long sequence)
    • sendErrorPacket

      public void sendErrorPacket(String cmd, String nodeID, Context ctx, Throwable cause, long sequence)
    • sendClosePacket

      public void sendClosePacket(String cmd, String nodeID, Context ctx, long sequence)
    • publish

      public void publish(String cmd, String nodeID, io.datatree.Tree message)
    • publish

      public abstract void publish(String channel, io.datatree.Tree message)
    • subscribe

      public io.datatree.Promise subscribe(String cmd, String nodeID)
    • subscribe

      public abstract io.datatree.Promise subscribe(String channel)
    • received

      protected void received(String channel, byte[] message)
      Process incoming message later (in a new Runnable or JoinForkTask).
      Parameters:
      channel - incoming channel
      message - incoming message
    • processReceivedMessage

      protected void processReceivedMessage(String channel, byte[] message)
      Process incoming message directly (without new Task).
      Parameters:
      channel - incoming channel
      message - incoming message
    • processReceivedMessage

      protected void processReceivedMessage(String channel, io.datatree.Tree message)
      Process incoming message directly (without new Task).
      Parameters:
      channel - incoming channel
      message - incoming message
    • updateNodeInfo

      protected void updateNodeInfo(String sender, io.datatree.Tree info) throws Exception
      Throws:
      Exception
    • broadcastTransporterConnected

      protected void broadcastTransporterConnected()
    • broadcastTransporterDisconnected

      protected void broadcastTransporterDisconnected()
    • broadcastNodeConnected

      protected void broadcastNodeConnected(io.datatree.Tree info, boolean reconnected)
    • broadcastNodeUpdated

      protected void broadcastNodeUpdated(io.datatree.Tree info)
    • broadcastNodeDisconnected

      protected void broadcastNodeDisconnected(io.datatree.Tree info, boolean unexpected)
    • broadcastInfoPacket

      public void broadcastInfoPacket()
    • scheduleInfoPacket

      protected void scheduleInfoPacket()
    • checkTimeouts

      protected void checkTimeouts()
    • getCpuUsage

      public int getCpuUsage(String nodeID)
    • getLastHeartbeatTime

      public long getLastHeartbeatTime(String nodeID)
    • isOnline

      public boolean isOnline(String nodeID)
    • getAllNodeIDs

      public Set<String> getAllNodeIDs()
    • getDescriptor

      public io.datatree.Tree getDescriptor(String nodeID)
    • getAddress

      public RemoteAddress getAddress(String nodeID)
    • error

      protected void error(Throwable error)
      Any I/O error occurred. Implementation-specific error handling goes here (reconnection, etc.).
      Parameters:
      error - I/O error
    • getSerializer

      public Serializer getSerializer()
    • setSerializer

      public void setSerializer(Serializer serializer)
    • getHeartbeatInterval

      public int getHeartbeatInterval()
    • setHeartbeatInterval

      public void setHeartbeatInterval(int heartbeatInterval)
    • getHeartbeatTimeout

      public int getHeartbeatTimeout()
    • setHeartbeatTimeout

      public void setHeartbeatTimeout(int heartbeatTimeout)
    • isDebug

      public boolean isDebug()
    • setDebug

      public void setDebug(boolean debug)
    • getOfflineTimeout

      public int getOfflineTimeout()
    • setOfflineTimeout

      public void setOfflineTimeout(int offlineTimeout)
    • getNamespace

      public String getNamespace()
    • setNamespace

      public void setNamespace(String namespace)
    • getPrefix

      public String getPrefix()
    • setPrefix

      public void setPrefix(String prefix)
    • isPreferHostname

      public boolean isPreferHostname()
    • setPreferHostname

      public void setPreferHostname(boolean preferHostname)
    • getSubscriptionTimeout

      public int getSubscriptionTimeout()
    • setSubscriptionTimeout

      public void setSubscriptionTimeout(int subscriptionTimeout)
    • isDebugHeartbeats

      public boolean isDebugHeartbeats()
    • setDebugHeartbeats

      public void setDebugHeartbeats(boolean debugHeartbeats)
    • getInstanceID

      public String getInstanceID()