Example #1
0
 public IceClient()
 {
     Hold          = false;
     amiEnabled    = false;
     acmHeartbeat  = ACMHeartbeatFlag.HeartbeatOff;
     contentSizeMB = 2;
     isRunning     = false;
     counter       = 0;
     rand          = new Random();
 }
Example #2
0
 public void Start(string args, ACMCloseFlag close = ACMCloseFlag.CloseOff, ACMHeartbeatFlag heartbeat = ACMHeartbeatFlag.HeartbeatOff)
 {
     acmClose     = close;
     acmHeartbeat = heartbeat;
     if (communicator == null || communicator.isShutdown())
     {
         Status = BundleStatus.Starting;
         try
         {
             const int SIZE_MAX = 128 * 1024 * 1024;
             var       initData = new InitializationData();
             initData.properties = Util.createProperties();
             initData.properties.setProperty("Ice.Trace.Network", "2");
             initData.properties.setProperty("Ice.MessageSizeMax", $"{SIZE_MAX}");
             initData.properties.setProperty("Filesystem.MaxFileSize", $"{SIZE_MAX}");
             initData.properties.setProperty("Ice.ACM.Close", $"{(int)acmClose}");
             initData.properties.setProperty("Ice.ACM.Heartbeat", $"{(int)acmHeartbeat}");
             communicator = Util.initialize(initData);
             var pos  = args.IndexOf(':');
             var name = "SimpleMessenger";
             if (pos > 0)
             {
                 name = args.Substring(0, pos);
                 args = args.Substring(pos + 1).TrimStart();
             }
             ObjectAdapter objectAdapter = communicator.createObjectAdapterWithEndpoints("SimpleMessengerAdapter", args);
             servant = new WorkerImpl(OnMethodInvoked);
             Identity id = Util.stringToIdentity(name);
             objectAdapter.add(servant, id);
             objectAdapter.activate();
             Status = BundleStatus.Running;
             communicator.waitForShutdown();
             Status = BundleStatus.Idle;
         }
         catch (System.Exception ex)
         {
             Status = BundleStatus.Exception;
             OnExceptionOccured?.Invoke(ex);
         }
     }
     else
     {
         Status = BundleStatus.Unknown;
     }
 }
Example #3
0
        public async void Start(string args, bool hold = false, bool ami = false, ACMHeartbeatFlag heartbeat = ACMHeartbeatFlag.HeartbeatOff)
        {
            Hold         = hold;
            amiEnabled   = ami;
            acmHeartbeat = heartbeat;
            if (communicator == null || communicator.isShutdown())
            {
                Status = BundleStatus.Starting;
                try
                {
                    const int SIZE_MB  = 128;
                    const int SIZE_MAX = SIZE_MB * 1024 * 1024;
                    if (contentSizeMB < 0 || contentSizeMB > SIZE_MB)
                    {
                        contentSizeMB = 1;
                    }
                    var initData = new InitializationData();
                    initData.properties = Util.createProperties();
                    initData.properties.setProperty("Ice.MessageSizeMax", $"{SIZE_MAX}");
                    initData.properties.setProperty("Filesystem.MaxFileSize", $"{SIZE_MAX}");
                    initData.properties.setProperty("Ice.ACM.Heartbeat", $"{(int)acmHeartbeat}");
                    communicator = Util.initialize(initData);
                    WorkerPrx workerPrx = WorkerPrxHelper.checkedCast(communicator.stringToProxy(args));
                    if (workerPrx == null)
                    {
                        throw new ApplicationException("Invalid Proxy");
                    }
                    isRunning = true;
                    Status    = BundleStatus.Running;
                    while (isRunning && communicator != null)
                    {
                        if (Hold)
                        {
                            Thread.Sleep(100);
                            continue;
                        }

                        var operation = operations[counter % operations.Count];
                        ++counter;
                        OnMethodInvoked?.Invoke(operation, amiEnabled);
                        if (amiEnabled)
                        {
                            try
                            {
                                var result = workerPrx?.PerformActionEx(operation, contentSizeMB);
                            }
                            catch (OperationException ex)
                            {
                                OnExceptionOccured?.Invoke(ex);
                            }
                            Thread.Sleep(rand.Next(200, 1000));
                        }
                        else
                        {
                            try
                            {
                                var result = workerPrx?.PerformAction(operation, contentSizeMB);
                            }
                            catch (OperationException ex)
                            {
                                OnExceptionOccured?.Invoke(ex);
                            }
                            Thread.Sleep(500);
                        }
                    }
                    Status = BundleStatus.Idle;
                }
                catch (System.Exception ex)
                {
                    Status = BundleStatus.Exception;
                    OnExceptionOccured?.Invoke(ex);
                }
            }
            else
            {
                isRunning = false;
                Status    = BundleStatus.Unknown;
            }
        }
Example #4
0
 public void SetHeartbeat(ACMHeartbeatFlag heartbeat)
 {
     acmHeartbeat = heartbeat;
 }