ICE 3.4.2
[php5-ice-freebsdport.git] / cs / test / Ice / background / Server.cs
blobfc68faebfa37ef5a6aa9ea2dc770def6e37e8d0b
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 using System;
11 using System.IO;
12 using System.Diagnostics;
13 using System.Reflection;
15 [assembly: CLSCompliant(true)]
17 [assembly: AssemblyTitle("IceTest")]
18 [assembly: AssemblyDescription("Ice test")]
19 [assembly: AssemblyCompany("ZeroC, Inc.")]
21 public class Server
23 internal class LocatorI : Ice.LocatorDisp_
25 public override void findAdapterById_async(Ice.AMD_Locator_findAdapterById response, string adapter,
26 Ice.Current current)
28 _controller.checkCallPause(current);
29 Ice.Communicator communicator = current.adapter.getCommunicator();
30 response.ice_response(current.adapter.createDirectProxy(communicator.stringToIdentity("dummy")));
33 public override void findObjectById_async(Ice.AMD_Locator_findObjectById response, Ice.Identity id,
34 Ice.Current current)
36 _controller.checkCallPause(current);
37 response.ice_response(current.adapter.createDirectProxy(id));
40 public override Ice.LocatorRegistryPrx getRegistry(Ice.Current current)
42 return null;
45 internal LocatorI(BackgroundControllerI controller)
47 _controller = controller;
50 private BackgroundControllerI _controller;
53 internal class RouterI : Ice.RouterDisp_
55 public override Ice.ObjectPrx getClientProxy(Ice.Current current)
57 _controller.checkCallPause(current);
58 return null;
61 public override Ice.ObjectPrx getServerProxy(Ice.Current current)
63 _controller.checkCallPause(current);
64 return null;
67 public override void addProxy(Ice.ObjectPrx proxy, Ice.Current current)
71 public override Ice.ObjectPrx[] addProxies(Ice.ObjectPrx[] proxies, Ice.Current current)
73 return new Ice.ObjectPrx[0];
76 internal RouterI(BackgroundControllerI controller)
78 _controller = controller;
81 private BackgroundControllerI _controller;
84 public static int run(string[] args, Ice.Communicator communicator, TextWriter @out)
87 // When running as a MIDlet the properties for the server may be
88 // overridden by configuration. If it isn't then we assume
89 // defaults.
91 if(communicator.getProperties().getProperty("TestAdapter.Endpoints").Length == 0)
93 communicator.getProperties().setProperty("TestAdapter.Endpoints", "default -p 12010");
95 if(communicator.getProperties().getProperty("ControllerAdapter.Endpoints").Length == 0)
97 communicator.getProperties().setProperty("ControllerAdapter.Endpoints", "tcp -p 12011");
98 communicator.getProperties().setProperty("ControllerAdapter.ThreadPool.Size", "1");
101 Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter");
102 Ice.ObjectAdapter adapter2 = communicator.createObjectAdapter("ControllerAdapter");
104 BackgroundControllerI backgroundController = new BackgroundControllerI(adapter);
106 adapter.add(new BackgroundI(backgroundController), communicator.stringToIdentity("background"));
107 adapter.add(new LocatorI(backgroundController), communicator.stringToIdentity("locator"));
108 adapter.add(new RouterI(backgroundController), communicator.stringToIdentity("router"));
109 adapter.activate();
111 adapter2.add(backgroundController, communicator.stringToIdentity("backgroundController"));
112 adapter2.activate();
114 communicator.waitForShutdown();
115 return 0;
118 public static int Main(string[] args)
120 int status = 0;
121 Ice.Communicator communicator = null;
123 #if !COMPACT
124 Debug.Listeners.Add(new ConsoleTraceListener());
125 #endif
129 Ice.InitializationData initData = new Ice.InitializationData();
130 initData.properties = Ice.Util.createProperties(ref args);
133 // This test kills connections, so we don't want warnings.
135 initData.properties.setProperty("Ice.Warn.Connections", "0");
138 // Setup the test transport plug-in.
140 string defaultProtocol = initData.properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp");
141 initData.properties.setProperty("Ice.Default.Protocol", "test-" + defaultProtocol);
143 communicator = Ice.Util.initialize(ref args, initData);
144 PluginI plugin = new PluginI(communicator);
145 plugin.initialize();
146 communicator.getPluginManager().addPlugin("Test", plugin);
148 status = run(args, communicator, Console.Out);
150 catch(System.Exception ex)
152 Console.Error.WriteLine(ex);
153 status = 1;
156 if(communicator != null)
160 communicator.destroy();
162 catch(Ice.LocalException ex)
164 Console.Error.WriteLine(ex);
165 status = 1;
169 return status;