blob: b0bbe4266c497afc8e9fc72fa29a86fdd0b60ede (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus.network;
import com.yahoo.jrt.slobrok.api.IMirror;
import com.yahoo.messagebus.Message;
import com.yahoo.messagebus.routing.RoutingNode;
import java.util.List;
/**
* This interface separates the low-level network implementation from the rest of messagebus. The methods defined in
* this interface is intended to be invoked by MessageBus and not by the application.
*
* @author <a href="mailto:havardpe@yahoo-inc.com">Haavard Pettersen</a>
*/
public interface Network {
/**
* Waits for at most the given number of seconds for all dependencies to become ready.
*
* @param seconds The timeout.
* @return True if ready.
*/
boolean waitUntilReady(double seconds);
/**
* Attach the network layer to the given owner
*
* @param owner owner of the network
*/
void attach(NetworkOwner owner);
/**
* Register a session name with the network layer. This will make the session visible to other nodes.
*
* @param session the session name
*/
void registerSession(String session);
/**
* Unregister a session name with the network layer. This will make the session unavailable for other nodes.
*
* @param session session name
*/
void unregisterSession(String session);
/**
* Resolves the service address of the recipient referenced by the given routing node. If a recipient can not be
* resolved, this method tags the node with an error. If this method succeeds, you need to invoke {@link
* #freeServiceAddress(RoutingNode)} once you are done with the service address.
*
* @param recipient The node whose service address to allocate.
* @return True if a service address was allocated.
*/
boolean allocServiceAddress(RoutingNode recipient);
/**
* Frees the service address from the given routing node. This allows the network layer to track and close
* connections as required.
*
* @param recipient The node whose service address to free.
*/
void freeServiceAddress(RoutingNode recipient);
/**
* Send a message to the given recipients. A {@link RoutingNode} contains all the necessary context for sending.
*
* @param msg The message to send.
* @param recipients A list of routing leaf nodes resolved for the message.
*/
void send(Message msg, List<RoutingNode> recipients);
/**
* Synchronize with internal threads. This method will handshake with all internal threads. This has the implicit
* effect of waiting for all active callbacks. Note that this method should never be invoked from a callback since
* that would make the thread wait for itself... forever. This method is typically used to untangle during session
* shutdown.
*/
void sync();
/**
* Shuts down the network. This is a blocking call that waits for all scheduled tasks to complete.
*/
void shutdown();
/**
* Returns a string that represents the connection specs of this network. It is in not a complete address since it
* know nothing of the sessions that run on it.
*
* @return The connection string.
*/
String getConnectionSpec();
/**
* Returns a reference to a name server mirror.
*
* @return The mirror object.
*/
IMirror getMirror();
}
|