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
Base superclass of all Transporter implementations.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ScheduledFuture<?> Cancelable "Check Activities / Infos" timerprotected MetricCounterprotected MetricCounterprotected MetricCounterprotected MetricCounterprotected booleanWrites the communication of method calls and events into the log.protected booleanWrites the communication of heartbeats/gossiping into the log.protected Eventbusprotected ExecutorServiceprotected MetricGaugeprotected intHeartbeat sending period in SECONDS.protected intHeartbeat timeout in SECONDS.protected ScheduledFuture<?> Cancelable "Heart Beat" timerprotected final AtomicBooleanprotected final AtomicLongprotected final Stringprotected final AtomicLongprotected Metricsprotected Monitorprotected StringNamespace of channels.protected StringLocal Node ID.protected final ConcurrentHashMap<String, NodeDescriptor> protected intHow long keep information in registry about the offline nodes (SECONDS).static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected booleanUse 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.protected StringPrefix of channels.protected StringServiceBroker's protocol version.protected ServiceRegistryprotected ScheduledExecutorServiceprotected Serializerprotected ServiceInvokerprotected intTimeout of channel subscriptions (SECONDS).protected UidGeneratorprotected booleanFields inherited from class MoleculerComponent
broker, logger, nameFields inherited from interface MetricConstants
MOLECULER_CACHER_CLEAN_TIME, MOLECULER_CACHER_CLEAN_TIME_DESC, MOLECULER_CACHER_CLEAN_TOTAL, MOLECULER_CACHER_CLEAN_TOTAL_DESC, MOLECULER_CACHER_DEL_TIME, MOLECULER_CACHER_DEL_TIME_DESC, MOLECULER_CACHER_DEL_TOTAL, MOLECULER_CACHER_DEL_TOTAL_DESC, MOLECULER_CACHER_EXPIRED_TOTAL, MOLECULER_CACHER_EXPIRED_TOTAL_DESC, MOLECULER_CACHER_FOUND_TOTAL, MOLECULER_CACHER_FOUND_TOTAL_DESC, MOLECULER_CACHER_GET_TIME, MOLECULER_CACHER_GET_TIME_DESC, MOLECULER_CACHER_GET_TOTAL, MOLECULER_CACHER_GET_TOTAL_DESC, MOLECULER_CACHER_SET_TIME, MOLECULER_CACHER_SET_TIME_DESC, MOLECULER_CACHER_SET_TOTAL, MOLECULER_CACHER_SET_TOTAL_DESC, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL_DESC, MOLECULER_EVENT_BROADCAST_TOTAL, MOLECULER_EVENT_BROADCAST_TOTAL_DESC, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL_DESC, MOLECULER_EVENT_EMIT_TOTAL, MOLECULER_EVENT_EMIT_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_ACTIVE, MOLECULER_EVENT_RECEIVED_ACTIVE_DESC, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_TIME, MOLECULER_EVENT_RECEIVED_TIME_DESC, MOLECULER_EVENT_RECEIVED_TOTAL, MOLECULER_EVENT_RECEIVED_TOTAL_DESC, MOLECULER_EXECUTOR, MOLECULER_REQUEST_ACTIVE, MOLECULER_REQUEST_ACTIVE_DESC, MOLECULER_REQUEST_ERROR_TOTAL, MOLECULER_REQUEST_ERROR_TOTAL_DESC, MOLECULER_REQUEST_LEVELS, MOLECULER_REQUEST_LEVELS_DESC, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL_DESC, MOLECULER_REQUEST_TIME, MOLECULER_REQUEST_TIME_DESC, MOLECULER_REQUEST_TIMEOUT_TOTAL, MOLECULER_REQUEST_TIMEOUT_TOTAL_DESC, MOLECULER_REQUEST_TOTAL, MOLECULER_REQUEST_TOTAL_DESC, MOLECULER_SCHEDULER, MOLECULER_TRANSIT_CONNECTED, MOLECULER_TRANSIT_CONNECTED_DESC, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL_DESC, MOLECULER_TRANSIT_REQUESTS_ACTIVE, MOLECULER_TRANSIT_REQUESTS_ACTIVE_DESC, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL_DESC -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidbroadcastNodeConnected(io.datatree.Tree info, boolean reconnected) protected voidbroadcastNodeDisconnected(io.datatree.Tree info, boolean unexpected) protected voidbroadcastNodeUpdated(io.datatree.Tree info) protected voidprotected voidprotected Stringprotected voidabstract voidconnect()protected voidprotected voidconnected(boolean waitFor) io.datatree.Treeprotected voidAny I/O error occurred.getAddress(String nodeID) intgetCpuUsage(String nodeID) io.datatree.TreegetDescriptor(String nodeID) intintlonggetLastHeartbeatTime(String nodeID) intintbooleanisDebug()booleanbooleanbooleanprotected voidprocessReceivedMessage(String channel, byte[] message) Process incoming message directly (without new Task).protected voidprocessReceivedMessage(String channel, io.datatree.Tree message) Process incoming message directly (without new Task).abstract voidvoidprotected voidProcess incoming message later (in a new Runnable or JoinForkTask).protected voidvoidsendClosePacket(String cmd, String nodeID, Context ctx, long sequence) voidsendDataPacket(String cmd, String nodeID, Context ctx, byte[] bytes, long sequence) protected voidprotected voidsendDiscoverPacket(String channel) voidsendErrorPacket(String cmd, String nodeID, Context ctx, Throwable cause, long sequence) voidsendEventPacket(String nodeID, Context ctx, Groups groups, boolean broadcast) protected voidprotected voidsendInfoPacket(String channel) protected voidsendPongPacket(String channel, io.datatree.Tree data) voidsendRequestPacket(String nodeID, Context ctx) voidsetDebug(boolean debug) voidsetDebugHeartbeats(boolean debugHeartbeats) voidsetHeartbeatInterval(int heartbeatInterval) voidsetHeartbeatTimeout(int heartbeatTimeout) voidsetNamespace(String namespace) voidsetOfflineTimeout(int offlineTimeout) voidsetPreferHostname(boolean preferHostname) voidvoidsetSerializer(Serializer serializer) voidsetSubscriptionTimeout(int subscriptionTimeout) voidstarted(ServiceBroker broker) Initializes transporter instance.voidstopped()Closes transporter.abstract io.datatree.Promiseio.datatree.Promiseprotected voidupdateNodeInfo(String sender, io.datatree.Tree info) Methods inherited from class MoleculerComponent
getBroker, getLogger, getName
-
Field Details
-
PACKET_EVENT
- See Also:
-
PACKET_REQUEST
- See Also:
-
PACKET_RESPONSE
- See Also:
-
PACKET_DISCOVER
- See Also:
-
PACKET_INFO
- See Also:
-
PACKET_DISCONNECT
- See Also:
-
PACKET_HEARTBEAT
- See Also:
-
PACKET_PING
- See Also:
-
PACKET_PONG
- See Also:
-
eventChannel
-
requestChannel
-
responseChannel
-
discoverBroadcastChannel
-
discoverChannel
-
infoBroadcastChannel
-
infoChannel
-
disconnectChannel
-
heartbeatChannel
-
pingChannel
-
pongChannel
-
namespace
Namespace of channels. -
prefix
Prefix of channels. -
nodeID
Local Node ID. -
protocolVersion
ServiceBroker's protocol version. Placeholder only: overwritten instarted(services.moleculer.ServiceBroker)frombroker.getProtocolVersion(). The authoritative default lives inServiceBrokerConfig.DEFAULT_PROTOCOL_VERSION("5"). -
heartbeatInterval
protected int heartbeatIntervalHeartbeat sending period in SECONDS. -
heartbeatTimeout
protected int heartbeatTimeoutHeartbeat timeout in SECONDS. -
offlineTimeout
protected int offlineTimeoutHow long keep information in registry about the offline nodes (SECONDS). -
subscriptionTimeout
protected int subscriptionTimeoutTimeout of channel subscriptions (SECONDS). -
preferHostname
protected boolean preferHostnameUse 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 debugWrites the communication of method calls and events into the log. -
debugHeartbeats
protected boolean debugHeartbeatsWrites the communication of heartbeats/gossiping into the log. -
serializer
-
usingJsonSerializer
protected boolean usingJsonSerializer -
instanceID
-
executor
-
scheduler
-
registry
-
serviceInvoker
-
eventbus
-
monitor
-
uidGenerator
-
metrics
-
heartBeatTimer
Cancelable "Heart Beat" timer -
checkTimeoutTimer
Cancelable "Check Activities / Infos" timer -
nodes
-
infoScheduled
-
infoScheduledAt
-
lastReceivedMessageAt
-
gaugeTransitConnected
-
counterTransporterPacketsSentTotal
-
counterTransporterPacketsSentBytes
-
counterTransporterPacketsReceivedTotal
-
counterTransporterPacketsReceivedBytes
-
-
Constructor Details
-
Transporter
public Transporter() -
Transporter
-
-
Method Details
-
started
Initializes transporter instance.- Specified by:
startedin interfaceMoleculerLifecycle- Overrides:
startedin classMoleculerComponent- Parameters:
broker- parent ServiceBroker- Throws:
Exception
-
channel
-
connect
public abstract void connect() -
connected
protected void connected() -
connected
protected void connected(boolean waitFor) -
stopped
public void stopped()Closes transporter.- Specified by:
stoppedin interfaceMoleculerLifecycle- Overrides:
stoppedin classMoleculerComponent
-
sendInfoPacket
-
sendDiscoverPacket
-
sendHeartbeatPacket
protected void sendHeartbeatPacket() -
sendDisconnectPacket
protected void sendDisconnectPacket() -
sendPongPacket
-
createPingPacket
-
sendEventPacket
-
sendRequestPacket
-
sendDataPacket
-
sendErrorPacket
-
sendClosePacket
-
publish
-
publish
-
subscribe
-
subscribe
-
received
Process incoming message later (in a new Runnable or JoinForkTask).- Parameters:
channel- incoming channelmessage- incoming message
-
processReceivedMessage
Process incoming message directly (without new Task).- Parameters:
channel- incoming channelmessage- incoming message
-
processReceivedMessage
Process incoming message directly (without new Task).- Parameters:
channel- incoming channelmessage- incoming message
-
updateNodeInfo
-
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
-
getLastHeartbeatTime
-
isOnline
-
getAllNodeIDs
-
getDescriptor
-
getAddress
-
error
Any I/O error occurred. Implementation-specific error handling goes here (reconnection, etc.).- Parameters:
error- I/O error
-
getSerializer
-
setSerializer
-
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
-
setNamespace
-
getPrefix
-
setPrefix
-
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
-