0003-Add-factory-singleton-for-participitants.patch
rsb-cil-test/Program.cs | ||
---|---|---|
79 | 79 | |
80 | 80 |
listener.Deactivate(); |
81 | 81 | |
82 |
Console.WriteLine("\nRepository test:"); |
|
83 |
Informer repoInformer = new Informer("/test/repo", new OutConnector(new BusClientConnection(host, port), Rsb.Converter.DefaultConverterRepository.Instance.InformerConverterSelector)); |
|
84 |
Listener repoListener = new Listener(new InPushConnector(new BusClientConnection(host, port), new Scope("/"), Rsb.Converter.DefaultConverterRepository.Instance.ListenerConverterSelector)); |
|
82 |
Console.WriteLine("\nRepository test with factory:"); |
|
83 | ||
84 |
Factory.Instance.Host = host; |
|
85 |
Factory.Instance.Port = port; |
|
86 | ||
87 |
Informer repoInformer = Factory.Instance.createInformer("/test/repo"); |
|
88 |
//new Informer("/test/repo", new OutConnector(new BusClientConnection(host, port), Rsb.Converter.DefaultConverterRepository.Instance.InformerConverterSelector)); |
|
89 |
Listener repoListener = Factory.Instance.createListener("/"); |
|
90 |
//new Listener(new InPushConnector(new BusClientConnection(host, port), new Scope("/"), Rsb.Converter.DefaultConverterRepository.Instance.ListenerConverterSelector)); |
|
85 | 91 |
repoListener.EventReceived += (e) => { |
86 | 92 |
Console.WriteLine("Event: {0}\nData: {1}", e, e.Data); |
87 | 93 |
}; |
rsb-cil/Rsb/Factory.cs | ||
---|---|---|
1 |
|
|
2 | ||
3 |
using Rsb.Transport.Socket; |
|
4 |
using Rsb.Converter; |
|
5 | ||
6 |
namespace Rsb |
|
7 |
{ |
|
8 |
public class Factory |
|
9 |
{ |
|
10 |
private static readonly Factory instance = new Factory(); |
|
11 | ||
12 |
private string host = "localhost"; |
|
13 |
public string Host { get { return host; } set {host = value;} } |
|
14 |
private int port = 30010; |
|
15 |
public int Port { get { return port; } set { port = value; } } |
|
16 | ||
17 |
// Explicit static constructor to tell C# compiler |
|
18 |
// not to mark type as beforefieldinit |
|
19 |
static Factory() |
|
20 |
{ |
|
21 |
} |
|
22 | ||
23 |
private Factory() |
|
24 |
{ |
|
25 |
} |
|
26 | ||
27 |
public static Factory Instance |
|
28 |
{ |
|
29 |
get |
|
30 |
{ |
|
31 |
return instance; |
|
32 |
} |
|
33 |
} |
|
34 | ||
35 |
public Informer createInformer(Scope scope) { |
|
36 |
return new Informer(scope, |
|
37 |
new OutConnector( |
|
38 |
new BusClientConnection(host, port), |
|
39 |
DefaultConverterRepository.Instance.InformerConverterSelector)); |
|
40 |
} |
|
41 | ||
42 |
public Informer createInformer(string scope) { |
|
43 |
return createInformer(new Scope(scope)); |
|
44 |
} |
|
45 | ||
46 |
public Listener createListener(Scope scope) |
|
47 |
{ |
|
48 |
return new Listener( |
|
49 |
new InPushConnector( |
|
50 |
new BusClientConnection(host, port), |
|
51 |
scope, |
|
52 |
DefaultConverterRepository.Instance.ListenerConverterSelector |
|
53 |
)); |
|
54 |
} |
|
55 | ||
56 |
public Listener createListener(string scope) { |
|
57 |
return createListener(new Scope(scope)); |
|
58 |
} |
|
59 | ||
60 |
} |
|
61 |
} |
rsb-cil/rsb-cil.csproj | ||
---|---|---|
50 | 50 |
<Compile Include="Rsb\Converter\StringConverter.cs" /> |
51 | 51 |
<Compile Include="Rsb\Converter\UInt32Converter.cs" /> |
52 | 52 |
<Compile Include="Rsb\Converter\UInt64Converter.cs" /> |
53 |
<Compile Include="Rsb\Factory.cs" /> |
|
53 | 54 |
<Compile Include="Rsb\Protocol\EventId.cs" /> |
54 | 55 |
<Compile Include="Rsb\Protocol\EventMetaData.cs" /> |
55 | 56 |
<Compile Include="Rsb\Protocol\Notification.cs" /> |
56 |
- |