예제 #1
0
        public void AsyncCallBackOperator(IAsyncResult ar)
        {
            try {
                RemoteAsyncDelegateTuple del = (RemoteAsyncDelegateTuple)((AsyncResult)ar).AsyncDelegate;
                del.EndInvoke(ar);
            }catch {
                buildWorkingOps();
                if (workingOutputSources != null)
                {
TrySend:
                    Console.WriteLine("FALLBACK");
                    if (this.workingOutputSources.Count > 0)
                    {
                        string nextOp = workingOutputSources[0];
                        try
                        {
                            RemoteOperator           outputOperator = (RemoteOperator)Activator.GetObject(typeof(RemoteOperator), nextOp);
                            RemoteAsyncDelegateTuple RemoteDel      = new RemoteAsyncDelegateTuple(outputOperator.receiveInput);

                            Console.WriteLine("SENDING CALLBACK - Result: " + result);
                            IAsyncResult RemAr = RemoteDel.BeginInvoke(this.result, null, null);
                            RemoteDel.EndInvoke(RemAr);
                            writeLog(this.op_id, this.type, this.op_url, "RESULT <" + result.ToString() + ">");
                        }
                        catch (Exception e1)
                        {
                            this.workingOutputSources.RemoveAt(0);
                            goto TrySend;
                        }
                    }
                }
            }
            return;
        }
예제 #2
0
        public void sendResult()
        {
            if (this.result == null)
            {
                return;
            }
            // Writing on log throgh the output operator
            if (String.Compare(this.op_url, this.output_op[0]) == 0)
            {
                writeLog(this.op_id, this.type, this.op_url, "RESULT <" + result.ToString() + ">");
            }
            else
            {
                RemoteOperator         output_op       = (RemoteOperator)Activator.GetObject(typeof(RemoteOperator), this.output_op[0]);
                RemoteAsyncDelegateLog RemoteDelOutput = new RemoteAsyncDelegateLog(output_op.writeLog);
                IAsyncResult           RemArOutput     = RemoteDelOutput.BeginInvoke(this.op_id, this.type, this.op_url, "RESULT <" + result.ToString() + ">", null, null);
            }
            Console.WriteLine("RESULT <" + result.ToString() + ">;\r\n");

            if (this.outputSources == null)
            {
                return;
            }

            IDictionary options = new Hashtable();

            options["name"] = this.type + "output" + (new Random()).Next(0, 10000);;

            TcpChannel channel = new TcpChannel(options, null, null);

            ChannelServices.RegisterChannel(channel, true);

            String firstOp = this.getRoutingOperator();

            RemoteOperator           outputOperator = (RemoteOperator)Activator.GetObject(typeof(RemoteOperator), firstOp);
            RemoteAsyncDelegateTuple RemoteDel      = new RemoteAsyncDelegateTuple(outputOperator.receiveInput);

            if (!semantic.Equals("at-most-once"))  // semantic at-least-once, exactly-once
            {
                IAsyncResult RemAr = RemoteDel.BeginInvoke(this.result, AsyncCallBackOperator, this.result);
            }
            else  // semantic at-most-once
            {
                IAsyncResult RemAr = RemoteDel.BeginInvoke(this.result, null, null);
            }
            //RemoteDel.EndInvoke(RemAr);


            if (isFullLog)   // Is full log, must send result to PuppetMaster
            {
                RemotePM pm          = (RemotePM)Activator.GetObject(typeof(RemotePM), "tcp://localhost:10001/RemotePM");
                string[] resultArray = { op_id, type, result.ToString() };
                pm.receiveResult(resultArray);
            }

            ChannelServices.UnregisterChannel(channel);
        }
예제 #3
0
        public override void doOperation(Tuple input)
        {
            if (parameters.Length == 1)
            {
                int fieldNumber;

                if (Int32.TryParse(parameters[0], out fieldNumber))
                {
                    int uniqueCounter = 0;

                    this.tupleList.Add(input);

                    foreach (Tuple t in this.tupleList)
                    {
                        if (t.getField(fieldNumber).Equals(input.getField(fieldNumber)))
                        {
                            uniqueCounter++;
                        }

                        if (uniqueCounter > 1)
                        {
                            return;
                        }
                    }

                    result = input;

                    for (int i = 0; i < replicas_url.Length; i++)
                    {
                        if (String.Compare(op_url, replicas_url[i]) != 0)
                        {
                            Uniq count_op = (Uniq)Activator.GetObject(typeof(Uniq), replicas_url[i]);

                            RemoteAsyncDelegateTuple RemoteDel = new RemoteAsyncDelegateTuple(count_op.updateUniq);
                            IAsyncResult             RemAr     = RemoteDel.BeginInvoke(result, null, null);
                        }
                    }
                }
                else
                {
                    throw new Exception("Invalid Argument Type");
                }
            }
            else
            {
                throw new Exception("Invalid Argument Count");
            }
        }