public Merchant[] Execute(ISpaceProxy spaceProxy, ITransaction tx)
    {
        SqlQuery <Merchant> query = new SqlQuery <Merchant>("category = ?");

        query.SetParameter(1, categoryType);
        return(spaceProxy.ReadMultiple <Merchant>(query, int.MaxValue));
    }
 private void ResetSpace()
 {
     _counter = 0;
     //_list = new List<TestTuple>();
     _space      = SpaceFactory.UnsafeLocal();
     _spaceProxy = _space.CreateProxy();
 }
        public static Dictionary <String, Double> execute(ISpaceProxy tradeDataSpace, Object[] tradeIds, Double rate)
        {
            Dictionary <String, Double> rtnVal = new Dictionary <string, Double>();
            IReadByIdsResult <Trade>    result = tradeDataSpace.ReadByIds <Trade>(tradeIds);
            List <Trade> tlist = new List <Trade>();

            foreach (Trade t in result)
            {
                tlist.Add(t);
            }
            runAnalysis(tlist, rate);
            foreach (Trade t in tlist)
            {
                String key = t.getBook();
                if (rtnVal.ContainsKey(key))
                {
                    rtnVal[key] = rtnVal[key] + t.NPV;
                }
                else
                {
                    rtnVal.Add(key, t.NPV);
                }
            }
            return(rtnVal);
        }
        public static void Main(string[] args)
        {
            HostName       = Dns.GetHostName();
            CurrentProcess = Process.GetCurrentProcess();
            if (args.Length < 1)
            {
                url          = "jini://*/*/AIGDemo?locators=RajivPC&groups=Rajiv";
                NumberOfJobs = 200;
                NumberOfTask = 5;
            }
            else
            {
                url          = args[0];
                NumberOfJobs = args.Length == 1 ? 1000 : Convert.ToInt32(args[1]);
                NumberOfTask = args.Length == 2 ? 10 : Convert.ToInt32(args[2]);
            }
            Console.WriteLine("*** Connecting to remote space named '" + url + "' From Master...");
            SpaceProxy = GigaSpacesFactory.FindSpace(url);

            MasterHeartbeat masterHeartbeat = new MasterHeartbeat(Timeout);
            Thread          workerThread    = new Thread(masterHeartbeat.DoWork);

            workerThread.Start();
            new Master();
        }
 public WorkeNIO(ISpaceProxy space, ISpaceProxy tradeSpace)
 {
     // Connect to space:
     Console.WriteLine("*** Worker started in NonBlocking IO mode.");
     Console.WriteLine();
     proxy      = space;
     tradeProxy = tradeSpace;
 }
 public void Fill(ISpaceProxy spaceProxy)
 {
     spaceProxy.Write(new Author {
         Id = 1, LastName = "AuthorX", BookId = 3
     });
     spaceProxy.Write(new Book {
         Id = 3, AuthorId = 1, Title = "BookX"
     });
 }
 public void Fill(ISpaceProxy spaceProxy)
 {
     spaceProxy.Write(new Author {
         LastName = "AuthorX", Book = new Book()
         {
             Title = "BookX"
         }
     });
 }
        private IEnumerable <Author> QueryForAuthorByBookTitle(ISpaceProxy spaceProxy)
        {
            var authorQuery = new SqlQuery <Author>("LastName=? AND Books[*].Title=?");

            authorQuery.SetParameter(1, "AuthorX");
            authorQuery.SetParameter(2, "BookY");
            var authors = spaceProxy.ReadMultiple <Author>(authorQuery);

            return(authors);
        }
        private IEnumerable <Author> QueryForAuthorByBookTitle(ISpaceProxy spaceProxy)
        {
            var query = new SqlQuery <Author>("LastName=? and Book.Title=?");

            query.SetParameter(1, "AuthorX");
            query.SetParameter(2, "BookX");

            Author[] authors = spaceProxy.ReadMultiple <Author>(query);
            return(authors);
        }
Example #10
0
    public void creatVersionedSpace()
    {
        // Embedded Space
        String url = "/./xapTutorialSpace";

        // Create the SpaceProxy
        ISpaceProxy spaceProxy = GigaSpacesFactory.FindSpace(url);

        spaceProxy.OptimisticLocking = true;
    }
Example #11
0
        private static void Main(string[] args)
        {
            Console.WriteLine("GigaSpaces Data Modeling Example");
            Console.WriteLine("--------------------------------");
            Console.WriteLine("1. Embedded one-to-one.");
            Console.WriteLine("2. Embedded one-to-many.");
            Console.WriteLine("3. Non-Embedded one-to-one.");
            Console.WriteLine("4. Non-Embedded one-to-many.");

            Console.WriteLine();
            Console.WriteLine("Please enter your selection:");
            var selection = Console.ReadLine();

            IExamplePattern pattern;

            switch (selection)
            {
            case "1":
                pattern = new EmbeddedOne2OneExample();
                break;

            case "2":
                pattern = new EmbeddedOne2ManyExample();
                break;

            case "3":
                pattern = new NonEmbeddedOne2OneExample();
                break;

            case "4":
                pattern = new NonEmbeddedOne2ManyExample();
                break;

            default:
                throw new InvalidOperationException("Select an option within range.");
            }

            Console.WriteLine();
            Console.WriteLine("Launching space, please wait.");
            ISpaceProxy proxy = GigaSpacesFactory.FindSpace("/./modeling-data-samples");

            Console.WriteLine("--------------------------------------------------------------------------------");
            Console.WriteLine("BEGIN EXAMPLE");
            Console.WriteLine("--------------------------------------------------------------------------------");
            Console.WriteLine();

            pattern.Fill(proxy);
            pattern.QuerySpace(proxy);

            Console.WriteLine();
            Console.WriteLine("Press any key to continue...");

            Console.ReadKey();
        }
Example #12
0
    public void registerProductType()
    {
        if (proxy == null)
        {
            proxy = GigaSpacesFactory.FindSpace("/./xapTutorialSpace");

            service      = new CRUDService(proxy);
            spaceUtility = new SpaceUtility(proxy);
            userUtil     = new UserUtil(proxy);
        }
    }
Example #13
0
    public void registerProductType()
    {
        if (proxy == null)
        {
            proxy = GigaSpacesFactory.FindSpace("/./xapTutorialSpace");

          //      service = new CRUDService(proxy);
            spaceUtility = new SpaceUtility(proxy);
           //     userUtil = new UserUtil(proxy);
        }

        //	service.registerProductType();
    }
        public void Fill(ISpaceProxy spaceProxy)
        {
            var author = new Author();

            author.LastName = "AuthorX";
            author.Books    = new List <Book> {
                new Book {
                    Title = "BookY"
                }
            };

            spaceProxy.Write(author);
        }
        public void Initialize(BasicProcessingUnitContainer container)
        {
            _proxy = container.GetSpaceProxy("My_App");
            _config = new FeederConfiguration(container.Properties);
            _continueFeeding = true;

            _fills = new Data[_config.NumberOfRecords];

            GenerateFills(_fills);
            _proxy.Snapshot(new Data());

            _feederThread = new Thread(Feed);
            _feederThread.Start();
        }
        public void Initialize(BasicProcessingUnitContainer container)
        {
            _proxy           = container.GetSpaceProxy("My_App");
            _config          = new FeederConfiguration(container.Properties);
            _continueFeeding = true;

            _fills = new Data[_config.NumberOfRecords];

            GenerateFills(_fills);
            _proxy.Snapshot(new Data());

            _feederThread = new Thread(Feed);
            _feederThread.Start();
        }
Example #17
0
 private bool SpaceInit()
 {
     try
     {
         string url = ConfigurationManager.AppSettings["SpaceUrl"];
         _proxy = SpaceProxyProviderFactory.Instance.FindSpace(url);
         _proxy.OptimisticLocking = true;
         return(true);
     }
     catch (Exception ex)
     {
         System.Console.Write(ex);
         return(false);
     }
 }
Example #18
0
 private bool SpaceInit()
 {
     try
     {
         string url = ConfigurationManager.AppSettings["SpaceUrl"]; //an environment variable read from the excel.exe.config file
         _proxy = SpaceProxyProviderFactory.Instance.FindSpace(url);
         _proxy.OptimisticLocking = true;
         return(true);
     }
     catch (Exception ex)
     {
         ex.ToString();
         return(false);
     }
 }
Example #19
0
 private bool SpaceInit()
 {
     try
     {
         string url = ConfigurationManager.AppSettings["SpaceUrl"]; //an environment variable read from the excel.exe.config file
         _proxy = SpaceProxyProviderFactory.Instance.FindSpace(url);
         _proxy.OptimisticLocking = true;
         return true;
     }
     catch (Exception ex)
     {
         ex.ToString();
         return false;
     }
 }
        public static void Main(string[] args)
        {
            HostName       = Dns.GetHostName();
            CurrentProcess = Process.GetCurrentProcess();
            String url = args[0];

            Console.WriteLine("*** Connecting to remote space named '" + url + "' from Worker...");
            SpaceProxy = GigaSpacesFactory.FindSpace(url);

            WorkerHeartbeat masterHeartbeat = new WorkerHeartbeat(Timeout);
            Thread          workerThread    = new Thread(masterHeartbeat.DoWork);

            workerThread.Start();
            new Worker(args);
        }
        private IEnumerable <Book> QueryForBooksByAuthor(ISpaceProxy spaceProxy)
        {
            var books = new List <Book>();

            var authorQuery = new SqlQuery <Author>("LastName=?");

            authorQuery.SetParameter(1, "AuthorX");
            var authors = spaceProxy.ReadMultiple <Author>(authorQuery);

            foreach (var author in authors)
            {
                books.AddRange(author.Books);
            }

            return(books);
        }
Example #22
0
        private void StartFeeding(BasicProcessingUnitContainer container)
        {
            //Get feed delay from the custom properties, if none found uses the default one
            string feedDelayStr;

            container.Properties.TryGetValue(FeedDelayProperty, out feedDelayStr);
            _feedDelay = (String.IsNullOrEmpty(feedDelayStr) ? DefaultFeedDelay : int.Parse(feedDelayStr));
            //Gets the proxy to the processing grid
            _proxy = container.GetSpaceProxy("dataExampleSpace");
            //Set the started state to true
            _started = true;
            //Create a working thread
            _feedingThread = new Thread(Feed);
            //Starts the working thread
            _feedingThread.Start();
        }
        private IEnumerable <Book> QueryForBooksByAuthor(ISpaceProxy spaceProxy)
        {
            var books = new HashSet <Book>();

            var query = new SqlQuery <Author>("LastName=?");

            query.SetParameter(1, "AuthorX");

            Author[] authors = spaceProxy.ReadMultiple <Author>(query);

            foreach (Author author in authors)
            {
                books.Add(spaceProxy.ReadById <Book>(author.BookId));
            }

            return(books);
        }
Example #24
0
    public void startDataGrid()
    {
        try {
            // create an admin instance to interact with the cluster
            IServiceGridAdmin admin = new ServiceGridAdminBuilder().CreateAdmin();

            // locate a grid service manager and deploy a partioned data grid
            // with 2 primaries and one backup for each primary
            IGridServiceManager mgr = admin.GridServiceManagers.WaitForAtLeastOne();

            IProcessingUnit pu = mgr.Deploy(new SpaceDeployment(spaceName).Partitioned(2, 1));

            ISpaceProxy spaceProxy = pu.WaitForSpace().SpaceProxy;
        } catch (Exception e) {
            // already deployed, do nothing
            Console.WriteLine(e.StackTrace);
        }
    }
Example #25
0
        public void QuerySpace(ISpaceProxy spaceProxy)
        {
            Console.WriteLine("Non-embedded one-to-one Example");
            Console.WriteLine("---------------------------");
            Console.WriteLine("Query for all books by the author \"AuthorX\":");

            foreach (var book in QueryForBooksByAuthor(spaceProxy))
            {
                Console.WriteLine(book.Title);
            }

            Console.WriteLine();
            Console.WriteLine("Query for author using specific book title and author name.");

            foreach (var author in QueryForAuthorByBookTitle(spaceProxy))
            {
                Console.WriteLine(author.LastName);
            }
        }
Example #26
0
    public HashSet <long?> Execute(ISpaceProxy spaceProxy, ITransaction tx)
    {
        SqlQuery <Payment> query = new SqlQuery <Payment>("merchantId = ? ");

        query.SetParameter(1, merchantId);

        Payment[]       payments = spaceProxy.ReadMultiple <Payment>(query, int.MaxValue);
        HashSet <long?> userIds  = new HashSet <long?>();

        // Eliminate duplicate UserId
        if (payments != null)
        {
            for (int i = 0; i < payments.Length; i++)
            {
                userIds.Add(payments[i].UserId);
            }
        }
        return(userIds);
    }
Example #27
0
    public void registerProductType()
    {
        if (proxy == null)
        {
            // Instatiate the embedded space
            proxy = GigaSpacesFactory.FindSpace("/./xapTutorialSpace");;

            spaceUtility = new SpaceUtility(proxy);
            userUtil     = new UserUtil(proxy);
            queryService = new QueryService(proxy);
            service      = new CRUDService(proxy);

            // Register the Space Document
        }

        // Create a user
        userUtil.loadUsers();

        service.registerProductType();
        service.createDocumemt();
    }
Example #28
0
        private IEnumerable <Author> QueryForAuthorByBookTitle(ISpaceProxy spaceProxy)
        {
            var bookQuery = new SqlQuery <Book>("Title=?");

            bookQuery.SetParameter(1, "BookX");
            var books = spaceProxy.ReadMultiple <Book>(bookQuery);

            var authorIds = new StringBuilder();

            foreach (var book in books)
            {
                authorIds.AppendFormat(",{0}", book.AuthorId);
            }

            var authorQueryCriteria = authorIds.ToString().TrimStart(',');
            var authorQuery         = new SqlQuery <Author>(string.Format("LastName=? AND Id in ({0})", authorQueryCriteria));

            authorQuery.SetParameter(1, "AuthorX");

            var authors = spaceProxy.ReadMultiple <Author>(authorQuery);

            return(authors);
        }
        public static void Main(string[] args)
        {
            url = args[0];
            Int32 batchSize = 10000;

            numOfTrades = Convert.ToInt32(args[1]);
            Console.WriteLine("Connecting to Space:" + url);
            SpaceProxy = GigaSpacesFactory.FindSpace(url);
            Console.WriteLine("Inserting " + numOfTrades + " Trades in the space");
            Int32 k = 0;

            Trade[] trades;
            if (numOfTrades <= batchSize)
            {
                trades = new Trade[numOfTrades];
                for (int i = 0; i < numOfTrades; i++)
                {
                    trades[i] = CalculateUtil.generateTrade(i + 1);
                }
                SpaceProxy.WriteMultiple(trades);
            }
            else
            {
                for (int i = 0; i < numOfTrades / batchSize; i++)
                {
                    trades = new Trade[batchSize];
                    for (int j = 0; j < batchSize; j++)
                    {
                        trades[j] = CalculateUtil.generateTrade(k + 1);
                        k++;
                    }
                    SpaceProxy.WriteMultiple(trades);
                }
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
        public WorkeIO(ISpaceProxy space, ISpaceProxy tradeSpace)
        {
            int    cacheSize = spaceSize / 5;
            Random rng       = new Random();

            Console.WriteLine("*** Worker started in Blocking IO mode.");
            Console.WriteLine();
            proxy      = space;
            tradeProxy = tradeSpace;
            TimeSpan ts = new TimeSpan(10, 0, 0, 0);
            IdBasedLocalCacheConfig cacheConfig = new IdBasedLocalCacheConfig();

            cacheConfig.EvictionStrategyBuilder = new FifoSegmentEvictionStrategyBuilder(cacheSize, 1000, ts);
            localCache = GigaSpacesFactory.CreateIdBasedLocalCache(tradeSpace, cacheConfig);
            HashSet <Object> ids;

            for (int i = 0; i < cacheSize / cacheBatchSize; i++)
            {
                ids = new HashSet <Object>();
                for (int j = 0; j < cacheBatchSize; j++)
                {
                    int rn = rng.Next(1, spaceSize);
                    ids.Add(RngRecursive(rn, rng, ids));
                }

                try {
                    //Console.WriteLine("Reading batch: " + i);
                    localCache.ReadByIds <Trade>(ids.ToArray());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            Console.WriteLine("*** Cache initializaded.");
        }
Example #31
0
 public CRUDService(ISpaceProxy proxy)
 {
     this.proxy = proxy;
 }
        private bool SpaceInit()
        {
            try
            {
                string url = ConfigurationManager.AppSettings["SpaceUrl"];
                _proxy = SpaceProxyProviderFactory.Instance.FindSpace(url);
                _proxy.OptimisticLocking = true;
                return true;
            }
            catch (Exception ex)
            {
                System.Console.Write(ex);
                return false;
            }

        }
Example #33
0
 public UserUtil(ISpaceProxy proxy)
 {
     this.proxy = proxy;
 }
Example #34
0
 public void init()
 {
     proxy = GigaSpacesFactory.FindSpace(url);
 }
 public ExecutorService(ISpaceProxy proxy)
 {
     this.proxy = proxy;
 }
Example #36
0
 public UserUtil(ISpaceProxy proxy)
 {
     this.proxy = proxy;
 }
 public MerchantQueryService(ISpaceProxy proxy)
 {
     this.Proxy = proxy;
 }
 public RemoteService(ISpaceProxy proxy)
 {
     this.proxy = proxy;
 }
 public EventService(ISpaceProxy spaceProxy)
 {
     this.spaceProxy = spaceProxy;
 }
Example #40
0
    public void registerProductType()
    {
        if ( proxy == null)
        {
            // Instatiate the embedded space
            proxy =   GigaSpacesFactory.FindSpace("/./xapTutorialSpace");;

            spaceUtility = new SpaceUtility (proxy);
            userUtil = new UserUtil(proxy);
            queryService = new QueryService(proxy);
            service = new CRUDService(proxy);

            // Register the Space Document

        }

        // Create a user
        userUtil.loadUsers();

        service.registerProductType();
        service.createDocumemt();
    }
 public SpaceUtility(ISpaceProxy proxy)
 {
     this.proxy = proxy;
 }
 public EventService(ISpaceProxy spaceProxy)
 {
     this.spaceProxy = spaceProxy;
 }
Example #43
0
 public QueryService(ISpaceProxy proxy)
 {
     this.proxy = proxy;
 }
 public QueryService(ISpaceProxy proxy)
 {
     this.proxy = proxy;
 }