예제 #1
0
        public CountSum(Context ctx, StormTxAttempt txAttempt)
        {
            Context.Logger.Info("CountSum constructor called, TxId: {0}, AttemptId: {1}",
                txAttempt.TxId, txAttempt.AttemptId);

            this.ctx = ctx;
            this.txAttempt = txAttempt;

            // Declare Input and Output schemas
            Dictionary<string, List<Type>> inputSchema = new Dictionary<string, List<Type>>();
            inputSchema.Add("default", new List<Type>() { typeof(int) });

            Dictionary<string, List<Type>> outputSchema = new Dictionary<string, List<Type>>();
            outputSchema.Add("default", new List<Type>() { typeof(int) });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema));

            //demo how to get TopologyContext info
            if (Context.pluginType != SCPPluginType.SCP_NET_LOCAL)
            {
                Context.Logger.Info("TopologyContext info:");
                TopologyContext topologyContext = Context.TopologyContext;
                Context.Logger.Info("taskId: {0}", topologyContext.GetThisTaskId());
                taskIndex = topologyContext.GetThisTaskIndex();
                Context.Logger.Info("taskIndex: {0}", taskIndex);
                string componentId = topologyContext.GetThisComponentId();
                Context.Logger.Info("componentId: {0}", componentId);
                List<int> componentTasks = topologyContext.GetComponentTasks(componentId);
                Context.Logger.Info("taskNum: {0}", componentTasks.Count);
            }
        }
예제 #2
0
        public TxDisplayer(Context ctx, StormTxAttempt txAttempt)
        {
            Context.Logger.Info("TxDisplayer constructor called, TxId: {0}, AttemptId: {1}",
                                txAttempt.TxId, txAttempt.AttemptId);

            this.ctx       = ctx;
            this.txAttempt = txAttempt;

            // Declare Input schemas
            Dictionary <string, List <Type> > inputSchema = new Dictionary <string, List <Type> >();

            inputSchema.Add("default", new List <Type>()
            {
                typeof(Person)
            });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, null));
            this.ctx.DeclareCustomizedDeserializer(new CustomizedInteropJSONDeserializer());

            //Demo how to get TopologyContext info
            if (Context.pluginType != SCPPluginType.SCP_NET_LOCAL)
            {
                taskIndex = Context.TopologyContext.GetThisTaskIndex();
                Context.Logger.Info("taskIndex: {0}", taskIndex);
            }
        }
 public static CountSum Get(Context ctx, Dictionary <string, Object> parms)
 {
     if (parms.ContainsKey(Constants.STORM_TX_ATTEMPT))
     {
         StormTxAttempt txAttempt = (StormTxAttempt)parms[Constants.STORM_TX_ATTEMPT];
         return(new CountSum(ctx, txAttempt));
     }
     else
     {
         throw new Exception("null txAttempt");
     }
 }
        public PartialCount(Context ctx, StormTxAttempt txAttempt)
        {
            Context.Logger.Info("PartialCount constructor called, TxId: {0}, AttemptId: {1}",
                txAttempt.TxId, txAttempt.AttemptId);
            this.ctx = ctx;

            Dictionary<string, List<Type>> inputSchema = new Dictionary<string, List<Type>>();
            inputSchema.Add("mydefault", new List<Type>() {typeof(byte[]), typeof(byte[]) });
            Dictionary<string, List<Type>> outputSchema = new Dictionary<string, List<Type>>();
            outputSchema.Add("mydefault", new List<Type>() { typeof(int) });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema));
        }
        /// <summary>
        /// Here is a example to test the topology as a standalone console application.
        /// "LocalContext" is a local-mode SCP Context which is used to initialize a component,
        /// and each components communicate by using a plain text file.
        /// </summary>
        public void RunTestCase()
        {
            Dictionary <string, Object> emptyDictionary = new Dictionary <string, object>();
            Dictionary <string, Object> boltParms       = new Dictionary <string, object>();

            StormTxAttempt txAttempt = new StormTxAttempt();

            txAttempt.TxId      = 1;
            txAttempt.AttemptId = 1;
            boltParms[Constants.STORM_TX_ATTEMPT] = txAttempt;

            {
                // create a "Generator" object
                LocalContext generatorCtx = LocalContext.Get();
                Generator    generator    = Generator.Get(generatorCtx, emptyDictionary);

                // call nextTx()
                long seqId;
                generator.NextTx(out seqId, emptyDictionary);

                // write the messages in memory to files
                generatorCtx.WriteMsgQueueToFile("generator.txt");
            }

            {
                LocalContext partialCountCtx = LocalContext.Get();
                PartialCount partialCount    = PartialCount.Get(partialCountCtx, boltParms);

                partialCountCtx.ReadFromFileToMsgQueue("generator.txt");
                List <SCPTuple> batch = partialCountCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    partialCount.Execute(tuple);
                }
                partialCount.FinishBatch(emptyDictionary);
                partialCountCtx.WriteMsgQueueToFile("partial-count.txt");
            }

            {
                LocalContext countSumCtx = LocalContext.Get();
                CountSum     countSum    = CountSum.Get(countSumCtx, boltParms);

                countSumCtx.ReadFromFileToMsgQueue("partial-count.txt");
                List <SCPTuple> batch = countSumCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    countSum.Execute(tuple);
                }
                countSum.FinishBatch(emptyDictionary);
                countSumCtx.WriteMsgQueueToFile("count-sum.txt");
            }
        }
예제 #6
0
 /// <summary>
 ///  Implements of delegate "newSCPPlugin", which is used to create a instance of this spout/bolt
 /// </summary>
 /// <param name="ctx">SCP Context instance</param>
 /// <param name="parms">Parameters to initialize this spout/bolt, and a Storm_Tx_Attempt object is required for ISCPBatchBolt</param>
 /// <returns></returns>
 public static PartialCount Get(Context ctx, Dictionary <string, Object> parms)
 {
     // for transactional topology, we can get txAttempt from the input parms
     if (parms.ContainsKey(Constants.STORM_TX_ATTEMPT))
     {
         StormTxAttempt txAttempt = (StormTxAttempt)parms[Constants.STORM_TX_ATTEMPT];
         return(new PartialCount(ctx, txAttempt));
     }
     else
     {
         throw new Exception("null txAttempt");
     }
 }
        /// <summary>
        /// Here is a example to test the topology as a standalone console application.
        /// "LocalContext" is a local-mode SCP Context which is used to initialize a component,
        /// and each components communicate by using a plain text file.
        /// </summary>
        public void RunTestCase()
        {
            Dictionary<string, Object> emptyDictionary = new Dictionary<string, object>();
            Dictionary<string, Object> boltParms = new Dictionary<string, object>();

            StormTxAttempt txAttempt = new StormTxAttempt();
            txAttempt.TxId = 1;
            txAttempt.AttemptId = 1;
            boltParms[Constants.STORM_TX_ATTEMPT] = txAttempt;

            {
                // create a "Generator" object
                LocalContext generatorCtx = LocalContext.Get();
                Generator generator = Generator.Get(generatorCtx, emptyDictionary);

                // call nextTx()
                long seqId;
                generator.NextTx(out seqId, emptyDictionary);

                // write the messages in memory to files
                generatorCtx.WriteMsgQueueToFile("generator.txt");
            }

            {
                LocalContext partialCountCtx = LocalContext.Get();
                PartialCount partialCount = PartialCount.Get(partialCountCtx, boltParms);

                partialCountCtx.ReadFromFileToMsgQueue("generator.txt");
                List<SCPTuple> batch = partialCountCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    partialCount.Execute(tuple);
                }
                partialCount.FinishBatch(emptyDictionary);
                partialCountCtx.WriteMsgQueueToFile("partial-count.txt");
            }

            {
                LocalContext countSumCtx = LocalContext.Get();
                CountSum countSum = CountSum.Get(countSumCtx, boltParms);

                countSumCtx.ReadFromFileToMsgQueue("partial-count.txt");
                List<SCPTuple> batch = countSumCtx.RecvFromMsgQueue();
                foreach (SCPTuple tuple in batch)
                {
                    countSum.Execute(tuple);
                }
                countSum.FinishBatch(emptyDictionary);
                countSumCtx.WriteMsgQueueToFile("count-sum.txt");
            }
        }
        public TxDisplayer(Context ctx, StormTxAttempt txAttempt)
        {
            Context.Logger.Info("TxDisplayer constructor called, TxId: {0}, AttemptId: {1}",
                                txAttempt.TxId, txAttempt.AttemptId);

            this.ctx       = ctx;
            this.txAttempt = txAttempt;

            // Declare Input schemas
            Dictionary <string, List <Type> > inputSchema = new Dictionary <string, List <Type> >();

            inputSchema.Add("default", new List <Type>()
            {
                typeof(Person)
            });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, null));
            this.ctx.DeclareCustomizedDeserializer(new CustomizedInteropJSONDeserializer());
        }
        public PartialCount(Context ctx, StormTxAttempt txAttempt)
        {
            Context.Logger.Info("PartialCount constructor called, TxId: {0}, AttemptId: {1}",
                                txAttempt.TxId, txAttempt.AttemptId);
            this.ctx = ctx;

            Dictionary <string, List <Type> > inputSchema = new Dictionary <string, List <Type> >();

            inputSchema.Add("mydefault", new List <Type>()
            {
                typeof(byte[]), typeof(byte[])
            });
            Dictionary <string, List <Type> > outputSchema = new Dictionary <string, List <Type> >();

            outputSchema.Add("mydefault", new List <Type>()
            {
                typeof(int)
            });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema));
        }
예제 #10
0
        public CountSum(Context ctx, StormTxAttempt txAttempt)
        {
            Context.Logger.Info("CountSum constructor called, TxId: {0}, AttemptId: {1}",
                                txAttempt.TxId, txAttempt.AttemptId);

            this.ctx       = ctx;
            this.txAttempt = txAttempt;

            // Declare Input and Output schemas
            Dictionary <string, List <Type> > inputSchema = new Dictionary <string, List <Type> >();

            inputSchema.Add("default", new List <Type>()
            {
                typeof(int)
            });

            Dictionary <string, List <Type> > outputSchema = new Dictionary <string, List <Type> >();

            outputSchema.Add("default", new List <Type>()
            {
                typeof(int)
            });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema));

            //demo how to get TopologyContext info
            if (Context.pluginType != SCPPluginType.SCP_NET_LOCAL)
            {
                Context.Logger.Info("TopologyContext info:");
                TopologyContext topologyContext = Context.TopologyContext;
                Context.Logger.Info("taskId: {0}", topologyContext.GetThisTaskId());
                taskIndex = topologyContext.GetThisTaskIndex();
                Context.Logger.Info("taskIndex: {0}", taskIndex);
                string componentId = topologyContext.GetThisComponentId();
                Context.Logger.Info("componentId: {0}", componentId);
                List <int> componentTasks = topologyContext.GetComponentTasks(componentId);
                Context.Logger.Info("taskNum: {0}", componentTasks.Count);
            }
        }
예제 #11
0
        public TxDisplayer(Context ctx, StormTxAttempt txAttempt)
        {
            Context.Logger.Info("TxDisplayer constructor called, TxId: {0}, AttemptId: {1}",
                txAttempt.TxId, txAttempt.AttemptId);

            this.ctx = ctx;
            this.txAttempt = txAttempt;

            // Declare Input schemas
            Dictionary<string, List<Type>> inputSchema = new Dictionary<string, List<Type>>();
            inputSchema.Add("default", new List<Type>() { typeof(Person) });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, null));
            this.ctx.DeclareCustomizedDeserializer(new CustomizedInteropJSONDeserializer());

            //Demo how to get TopologyContext info
            if (Context.pluginType != SCPPluginType.SCP_NET_LOCAL)
            {
                taskIndex = Context.TopologyContext.GetThisTaskIndex();
                Context.Logger.Info("taskIndex: {0}", taskIndex);
            }
        }
        public TxDisplayer(Context ctx, StormTxAttempt txAttempt)
        {
            Context.Logger.Info("TxDisplayer constructor called, TxId: {0}, AttemptId: {1}",
                txAttempt.TxId, txAttempt.AttemptId);

            this.ctx = ctx;
            this.txAttempt = txAttempt;

            // Declare Input schemas
            Dictionary<string, List<Type>> inputSchema = new Dictionary<string, List<Type>>();
            inputSchema.Add("default", new List<Type>() { typeof(Person) });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, null));
            this.ctx.DeclareCustomizedDeserializer(new CustomizedInteropJSONDeserializer());
        }