blob: 8c084f0f9e4a41f194303757fcd9eae3660ebcfb (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus.shared;
import com.yahoo.config.subscription.ConfigGetter;
import com.yahoo.jdisc.AbstractResource;
import java.util.logging.Level;
import com.yahoo.messagebus.DestinationSessionParams;
import com.yahoo.messagebus.IntermediateSessionParams;
import com.yahoo.messagebus.MessageBus;
import com.yahoo.messagebus.MessageBusParams;
import com.yahoo.messagebus.SourceSessionParams;
import com.yahoo.messagebus.network.Network;
import com.yahoo.messagebus.network.rpc.RPCNetwork;
import com.yahoo.messagebus.network.rpc.RPCNetworkParams;
import com.yahoo.cloud.config.SlobroksConfig;
import java.util.logging.Logger;
/**
* @author Simon Thoresen Hult
*/
public class SharedMessageBus extends AbstractResource {
private static final Logger log = Logger.getLogger(SharedMessageBus.class.getName());
private final MessageBus mbus;
public SharedMessageBus(MessageBus mbus) {
mbus.getClass(); // throws NullPointerException
this.mbus = mbus;
}
public MessageBus messageBus() {
return mbus;
}
@Override
protected void destroy() {
log.log(LogLevel.DEBUG, "Destroying shared message bus.");
mbus.destroy();
}
public SharedSourceSession newSourceSession(SourceSessionParams params) {
return new SharedSourceSession(this, params);
}
public SharedIntermediateSession newIntermediateSession(IntermediateSessionParams params) {
return new SharedIntermediateSession(this, params);
}
public SharedDestinationSession newDestinationSession(DestinationSessionParams params) {
return new SharedDestinationSession(this, params);
}
public static SharedMessageBus newInstance(MessageBusParams mbusParams, RPCNetworkParams netParams) {
return new SharedMessageBus(new MessageBus(newNetwork(netParams), mbusParams));
}
private static Network newNetwork(RPCNetworkParams params) {
SlobroksConfig cfg = params.getSlobroksConfig();
if (cfg == null) {
cfg = ConfigGetter.getConfig(SlobroksConfig.class, params.getSlobrokConfigId());
}
if (cfg.slobrok().isEmpty()) {
return new NullNetwork(); // for LocalApplication
}
return new RPCNetwork(params);
}
}
|