Esempio n. 1
0
        public XmlBlasterClient()
        {
            // Client

            xmlBlasterClientProxy    = (IXmlBlasterClient)XmlRpcProxyGen.Create(typeof(IXmlBlasterClient));
            xmlBlasterClientProtocol = (XmlRpcClientProtocol)xmlBlasterClientProxy;

            // Server for Callback

            //RemotingConfiguration.Configure("xmlrpc.exe.config");

            HttpChannel channel = null;

            try
            {
                //int port = FindFreeHttpPort( 9090 ) ;
                //Debug.WriteLine( "FindFreeHttpPort() found port "+port );
                int port = 0;

                ListDictionary channelProperties = new ListDictionary();
                channelProperties.Add("port", port);

                channel = new HttpChannel(
                    channelProperties,
                    new CookComputing.XmlRpc.XmlRpcClientFormatterSinkProvider(),
                    new CookComputing.XmlRpc.XmlRpcServerFormatterSinkProvider(null, null)
                    //new SoapClientFormatterSinkProvider(),
                    //new SoapServerFormatterSinkProvider()
                    );
            }
            catch (Exception ex)
            {
                // Listener config failed : Une seule utilisation de chaque adresse de socket (protocole/adresse réseau/port) est habituellement autorisée

                Debug.WriteLine("Listener config failed : " + ex.Message);

                XmlBlasterException.HandleException(new Exception("Listener config failed.", ex));
            }

            ChannelServices.RegisterChannel(channel);

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(XmlBlasterCallback),
                "XmlBlasterCallback",
                WellKnownObjectMode.Singleton
                );

            // Print out the urls for HelloServer.
            string[] urls = channel.GetUrlsForUri("XmlBlasterCallback");
            foreach (string url in urls)
            {
                System.Console.WriteLine("url: {0}", url);
            }
            //url: http://127.0.0.1:1038/XmlBlasterCallback
            if (urls.Length != 1)
            {
                XmlBlasterException.HandleException(new Exception("XmlBlasterCallback server, failed to retreive url."));
            }
            this.callbackServerUri = new Uri(urls[0]);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            TMParser parser = new TMParser();

            if (!parser.Parse(args))
            {
                return;
            }

            SoapServerFormatterSinkProvider serverProv = new SoapServerFormatterSinkProvider();

            serverProv.TypeFilterLevel = TypeFilterLevel.Full;

            SoapClientFormatterSinkProvider clientProv = new SoapClientFormatterSinkProvider();

            IDictionary props = new Hashtable();

            props["port"] = Int32.Parse(parser["p"]);

            HttpChannel channel = new HttpChannel(props, clientProv, serverProv);

            ChannelServices.RegisterChannel(channel, false);

            RemotingConfiguration.RegisterWellKnownServiceType
                (Type.GetType("MyTM.MyTM")                                      // full type name
                , "TM.soap"                                                     // URI
                , System.Runtime.Remoting.WellKnownObjectMode.Singleton         // instancing mode
                );

            // activate the object
            string[] urls = channel.GetUrlsForUri("TM.soap");
            if (1 != urls.Length)
            {
                throw new InvalidOperationException();
            }

            MyTM transactionManager = (MyTM)System.Activator.GetObject(typeof(TP.TM), urls[0]);

            if (null == transactionManager)
            {
                throw new InvalidProgramException();
            }

            // Do recovery every 30 seconds to recommit/reabort unacknowledged transactions
            // as well as doing garbage collection on the outstanding transaction file
            while (true)
            {
                Console.WriteLine("Recovery will run in 30 seconds...");
                System.Threading.Thread.Sleep(30000);
                transactionManager.recovery();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            RMParser parser = new RMParser();

            if (!parser.Parse(args))
            {
                return;
            }

            GlobalState.Name = parser["n"].ToLower();
            string port_num = parser["p"];

            System.Console.WriteLine(string.Format("Starting resource manager for {0} on port {1}", GlobalState.Name, port_num));

            System.Collections.Specialized.ListDictionary channelProperties = new System.Collections.Specialized.ListDictionary();
            channelProperties.Add("port", port_num);
            channelProperties.Add("name", GlobalState.Name);

            HttpChannel channel = new HttpChannel(channelProperties, new SoapClientFormatterSinkProvider(), new SoapServerFormatterSinkProvider());

            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false);
            System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType
                (Type.GetType("MyRM.MyRM")                                      // Assembly name
                , "RM.soap"                                                     // URI
                , System.Runtime.Remoting.WellKnownObjectMode.Singleton         // Instancing mode
                );

            // activate the object
            string[] urls = channel.GetUrlsForUri("RM.soap");
            if (1 != urls.Length)
            {
                throw new InvalidOperationException();
            }

            MyRM resourceManager = (MyRM)System.Activator.GetObject(typeof(TP.RM), urls[0]);

            if (null == resourceManager)
            {
                throw new InvalidProgramException();
            }

            // initialize and start RM
            Console.WriteLine("{0}: Initializing", GlobalState.Name);
            resourceManager.Init(parser["n"], urls[0], parser["tm"]);

            Console.WriteLine("{0}: Running", GlobalState.Name);
            resourceManager.Run();

            Console.WriteLine("{0}: Exitting", GlobalState.Name);
        }
Esempio n. 4
0
    public static void Main()
    {
        // Create a remotable object.
        HttpChannel httpChannel = new HttpChannel(8085);

        WellKnownServiceTypeEntry WKSTE =
            new WellKnownServiceTypeEntry(typeof(HelloService),
                                          "Service",
                                          WellKnownObjectMode.Singleton);

        RemotingConfiguration.RegisterWellKnownServiceType(WKSTE);

        RemotingConfiguration.ApplicationName = "HelloServer";

        // Print out the urls for HelloServer.
        string[] urls = httpChannel.GetUrlsForUri("HelloServer");

        foreach (string url in urls)
        {
            System.Console.WriteLine("{0}", url);
        }
    }
        public XmlBlasterClient()
        {
            //
            // Client
            //

            xmlBlasterClientProxy    = (IXmlBlasterClient)XmlRpcProxyGen.Create(typeof(IXmlBlasterClient));
            xmlBlasterClientProtocol = (XmlRpcClientProtocol)xmlBlasterClientProxy;

            //
            // Callback Server
            //

            // On peut le faire depuis un fichier
            //RemotingConfiguration.Configure("xmlrpc.exe.config");

            // Ou bien à la mano
            try
            {
                //int port = FindFreeHttpPort( 9090 ) ;
                //logger.Debug( "FindFreeHttpPort() found port "+port );
                // port = 0 pour que le système assigne automatiquement un port non-utilisé.
                int port = 0;

                ListDictionary channelProperties = new ListDictionary();
                channelProperties.Add("port", port);

                httpChannel = new HttpChannel(
                    channelProperties,
                    new CookComputing.XmlRpc.XmlRpcClientFormatterSinkProvider(),
                    new CookComputing.XmlRpc.XmlRpcServerFormatterSinkProvider(null, null)
                    //new SoapClientFormatterSinkProvider(),
                    //new SoapServerFormatterSinkProvider()
                    );
            }
            catch (Exception ex)
            {
                // Listener config failed : Une seule utilisation de chaque adresse de socket (protocole/adresse réseau/port) est habituellement autorisée
                XmlBlasterException.HandleException(new Exception("XmlBlaster callback server, Listener config failed.", ex));
            }

            try
            {
                ChannelServices.RegisterChannel(httpChannel);
            }
            catch (System.Runtime.Remoting.RemotingException)
            {
                // Pas grave: The channel has already been registered.
            }
            catch (Exception ex)
            {
                XmlBlasterException.HandleException(new Exception("XmlBlasterCallback server, failed to RegisterChannel.", ex));
            }

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(XmlBlasterCallback),
                "XmlBlasterCallback",
                WellKnownObjectMode.Singleton
                );


            // Comme on a pas indiqué de port, celui-ci a été assigné automatiquement.
            // Il nous faut donc retrouver l'url afin de pouvoir la transmettre dans le Qos de connexion.

            string[] urls = httpChannel.GetUrlsForUri("XmlBlasterCallback");
            foreach (string url in urls)
            {
                logger.Debug("XmlBlasterCallback url: {0}", url);
            }
            //url: http://192.168.0.151:4808/XmlBlasterCallback
            if (urls.Length != 1)
            {
                XmlBlasterException.HandleException(new Exception("XmlBlasterCallback server, failed to retreive url."));
            }
            this.callbackServerUri = new Uri(urls[0]);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            isReady = false; // set isReady false because we want to make sure the actual code is not executed before the rm is going into the stable loop waiting.
            RMParser parser = new RMParser();

            if (!parser.Parse(args))
            {
                return;
            }

            GlobalState.Name = parser["n"].ToLower();
            string port_num = parser["p"];

            System.Collections.Specialized.ListDictionary channelProperties = new System.Collections.Specialized.ListDictionary();

            channelProperties.Add("port", port_num);
            channelProperties.Add("name", GlobalState.Name);

            HttpChannel channel = new HttpChannel(channelProperties, new SoapClientFormatterSinkProvider(), new SoapServerFormatterSinkProvider());

            System.Console.WriteLine(string.Format("Starting resource manager for {0} on port {1}", GlobalState.Name, port_num));
            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false);

            System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType
                (Type.GetType("MyRM.MyRM")                                      // Assembly name
                , "RM.soap"                                                     // URI
                , System.Runtime.Remoting.WellKnownObjectMode.Singleton         // Instancing mode
                );


            if (String.Compare(parser["tm"], "none", true) != 0)
            {
                while (_transactionManager == null)
                {
                    tmUrl = parser["tm"];
                    try
                    {
                        _transactionManager = (TP.TM)System.Activator.GetObject(typeof(TP.TM), tmUrl);

                        _transactionManager.Ping();
                        urls = channel.GetUrlsForUri("RM.soap");
                        foreach (string url in urls)
                        {
                            _transactionManager.Register(url + "$" + GlobalState.Name);
                        }
                    }
                    catch (ArgumentException)
                    {
                        _transactionManager = null;
                        Console.WriteLine("Waiting 1 second for Transaction Manager \"{0}\"", parser["tm"]);
                        System.Threading.Thread.Sleep(1000);
                    }
                }
            }

            Console.WriteLine("{0} RM: Transaction Manager retrieved at {1}", GlobalState.Name, parser["tm"]);

            while (GlobalState.Mode == GlobalState.RunMode.Loop)
            {
                try
                {
                    _transactionManager.Ping();
                }
                catch (WebException)
                {
                    _transactionManager = null;
                    ReconnectToTM();
                }
                isReady = true;
                System.Threading.Thread.Sleep(2000);
            }

            int loopCount = 0;

            while (GlobalState.Mode == GlobalState.RunMode.Wait && loopCount < 15)
            {
                System.Threading.Thread.Sleep(1000);
                loopCount++;
                Console.WriteLine("{0}: Waiting for transaction complete ({1} second(s))", GlobalState.Name, loopCount);
            }

            Console.WriteLine("{0}: Exitting", GlobalState.Name);
        }