public void TestAllColumnsSearch()
        {
            QueryDictionary <StringValues> query = new QueryDictionary <StringValues>();

            query.Add("grid-search", "3");

            _gridClient = new GridClient <TestModel>((q) => _repo.GetAllService(Columns, q, true, false), query, false, "testGrid",
                                                     Columns);
            _gridClient.Searchable(true, false);

            _gridClient.UpdateGrid().Wait();

            var searched = _gridClient.Grid.Items;

            var original = _repo.GetAll().AsQueryable().Where(t => t.Id.ToString().ToUpper().Contains("3") ||
                                                              t.Title.ToUpper().Contains("3") ||
                                                              t.Created.ToString().ToUpper().Contains("3") ||
                                                              t.Int16Field.ToString().ToUpper().Contains("3") ||
                                                              t.UInt16Field.ToString().ToUpper().Contains("3") ||
                                                              t.UInt32Field.ToString().ToUpper().Contains("3") ||
                                                              t.UInt64Field.ToString().ToUpper().Contains("3"));

            for (int i = 0; i < searched.Count(); i++)
            {
                if (searched.ElementAt(i).Id != original.ElementAt(i).Id)
                {
                    Assert.Fail("Searching not works");
                }
            }
            Assert.AreEqual(_gridClient.Grid.ItemsCount, 8);
        }
Пример #2
0
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (!firstRender)
        {
            return;
        }

        Items         = Items ?? throw new ArgumentNullException(nameof(Items));
        FilteredItems = new List <T>(Items().Count);

        IGridClient <T> itemsGridClient =
            await GridBlazorUtility.CreateBasicGrid(
                () => FilteredItems,
                CnCreatingColumnsConfiguration,
                server => CreateServer(server),
                client => CreateClient(client)
                );

        Filters.ForEach(f => f.NotifyGridInitialized());

        ItemsGrid = itemsGridClient.Grid;
        await ApplyFilters();

        StateHasChanged();
    }
        public static void Main()
        {
            /* Enable debug messages. */
            //Debug.Listeners.Add(new TextWriterTraceListener(System.Console.Out));

            String taskName = "org.gridgain.examples.task.CharCountTask";
            String taskArg  = "Hello Dot Net World";

            IGridClient client = CreateClient();

            try
            {
                // Show grid topology.
                X.WriteLine(">>> Client created, current grid topology: " + ToString(client.Compute().Nodes()));

                IGridClientCompute prj = client.Compute();

                // Execute test task that will count total number of nodes in grid.
                int wordCnt = prj.Execute <int>(taskName, taskArg);

                X.WriteLine(">>> Task result [args='" + taskArg + "', wordCnt=" + wordCnt + ']');
            }
            catch (GridClientException e)
            {
                Console.WriteLine("Unexpected grid client exception happens: {0}", e);
            }
            finally
            {
                GridClientFactory.StopAll();
            }
        }
        public void TestMainMethods()
        {
            _client.WithPaging(5);
            string gridState = _client.Grid.GetState();
            var    query     = StringExtensions.GetQuery(gridState);

            foreach (var element in query)
            {
                Assert.IsTrue(_client.Grid.Query.ContainsKey(element.Key));
                Assert.AreEqual(_client.Grid.Query[element.Key], element.Value);
            }

            query = new QueryDictionary <StringValues>();
            query.Add("grid-search", "TEST");
            query.Add("grid-page", "2");
            _client = new GridClient <TestModel>((q) => _repo.GetAllService(_columns, q, true, true),
                                                 query, false, "testGrid", _columns);
            _client.Searchable();
            gridState = _client.Grid.GetState();
            query     = StringExtensions.GetQuery(gridState);
            foreach (var element in query)
            {
                Assert.IsTrue(_client.Grid.Query.ContainsKey(element.Key));
                Assert.AreEqual(_client.Grid.Query[element.Key], element.Value);
            }
        }
        public void Init()
        {
            QueryDictionary <StringValues> query = new QueryDictionary <StringValues>();

            _repo   = new TestRepository();
            _client = new GridClient <TestModel>((q) => _repo.GetAllService(_columns, q, true, true),
                                                 query, false, "testGrid", _columns);
        }
Пример #6
0
        public bool Start(Simian simian)
        {
            m_simian = simian;

            #region Get Module References

            m_httpServer = simian.GetAppModule <IHttpServer>();
            if (m_httpServer == null)
            {
                m_log.Error("Can't create the LindenLogin service without an HTTP server");
                return(false);
            }

            m_userClient = simian.GetAppModule <IUserClient>();
            if (m_userClient == null)
            {
                m_log.Error("Can't create the LindenLogin service without a user client");
                return(false);
            }

            m_gridClient = simian.GetAppModule <IGridClient>();
            if (m_gridClient == null)
            {
                m_log.Error("Can't create the LindenLogin service without a grid client");
                return(false);
            }

            m_inventoryClient = simian.GetAppModule <IInventoryClient>();

            #endregion Get Module References

            m_httpServer.AddXmlRpcHandler("/", true, "login_to_simulator", LoginHandler);
            m_log.Info("LindenLogin handler initialized");

            return(true);
        }
Пример #7
0
        public void Start(IScene scene)
        {
            m_scene = scene;
            m_lastCameraPositions  = new Dictionary <uint, Vector3>();
            m_borderCrossThrottles = new Dictionary <UUID, int>();

            // Create an AABB for this scene that extends beyond the borders by BORDER_CROSS_THRESHOLD
            // that is used to check for border crossings
            m_borderCrossAABB      = new AABB(Vector3.Zero, new Vector3(scene.MaxPosition - scene.MinPosition));
            m_borderCrossAABB.Min -= new Vector3(BORDER_CROSS_THRESHOLD, BORDER_CROSS_THRESHOLD, BORDER_CROSS_THRESHOLD);
            m_borderCrossAABB.Max += new Vector3(BORDER_CROSS_THRESHOLD, BORDER_CROSS_THRESHOLD, BORDER_CROSS_THRESHOLD);

            m_scheduler = m_scene.Simian.GetAppModule <IScheduler>();
            if (m_scheduler == null)
            {
                m_log.Warn("Neighbors requires an IScheduler");
                return;
            }

            m_httpServer = m_scene.Simian.GetAppModule <IHttpServer>();
            if (m_httpServer == null)
            {
                m_log.Warn("Neighbors requires an IHttpServer");
                return;
            }

            m_udp = m_scene.GetSceneModule <LLUDP>();
            if (m_udp == null)
            {
                m_log.Warn("Neighbors requires an LLUDP");
                return;
            }

            m_userClient = m_scene.Simian.GetAppModule <IUserClient>();
            if (m_userClient == null)
            {
                m_log.Warn("Neighbors requires an IUserClient");
                return;
            }

            m_gridClient = scene.Simian.GetAppModule <IGridClient>();

            // Add neighbor messaging handlers
            string urlFriendlySceneName = WebUtil.UrlEncode(scene.Name);
            string regionPath           = "/regions/" + urlFriendlySceneName;

            m_httpServer.AddHandler("POST", null, regionPath + "/region/online", true, true, RegionOnlineHandler);
            m_httpServer.AddHandler("POST", null, regionPath + "/region/offline", true, true, RegionOfflineHandler);
            m_httpServer.AddHandler("POST", null, regionPath + "/child_avatar/update", true, true, ChildAvatarUpdateHandler);

            m_scene.AddPublicCapability("region/online", m_httpServer.HttpAddress.Combine(regionPath + "/region/online"));
            m_scene.AddPublicCapability("region/offline", m_httpServer.HttpAddress.Combine(regionPath + "/region/offline"));
            m_scene.AddPublicCapability("child_avatar/update", m_httpServer.HttpAddress.Combine(regionPath + "/child_avatar/update"));

            // Track local scenes going up and down
            m_sceneFactory = scene.Simian.GetAppModule <ISceneFactory>();
            if (m_sceneFactory != null)
            {
                m_sceneFactory.OnSceneStart += SceneStartHandler;
                m_sceneFactory.OnSceneStop  += SceneStopHandler;
            }

            m_scene.OnPresenceAdd       += PresenceAddHandler;
            m_scene.OnEntityAddOrUpdate += EntityAddOrUpdateHandler;

            m_childUpdates = new ThrottledQueue <uint, IScenePresence>(5.0f, 200, true, SendChildUpdate);
            m_childUpdates.Start();
        }
Пример #8
0
        public void Start(IScene scene)
        {
            m_scene = scene;
            m_lastCameraPositions = new Dictionary<uint, Vector3>();
            m_borderCrossThrottles = new Dictionary<UUID, int>();

            // Create an AABB for this scene that extends beyond the borders by BORDER_CROSS_THRESHOLD
            // that is used to check for border crossings
            m_borderCrossAABB = new AABB(Vector3.Zero, new Vector3(scene.MaxPosition - scene.MinPosition));
            m_borderCrossAABB.Min -= new Vector3(BORDER_CROSS_THRESHOLD, BORDER_CROSS_THRESHOLD, BORDER_CROSS_THRESHOLD);
            m_borderCrossAABB.Max += new Vector3(BORDER_CROSS_THRESHOLD, BORDER_CROSS_THRESHOLD, BORDER_CROSS_THRESHOLD);

            m_scheduler = m_scene.Simian.GetAppModule<IScheduler>();
            if (m_scheduler == null)
            {
                m_log.Warn("Neighbors requires an IScheduler");
                return;
            }

            m_httpServer = m_scene.Simian.GetAppModule<IHttpServer>();
            if (m_httpServer == null)
            {
                m_log.Warn("Neighbors requires an IHttpServer");
                return;
            }

            m_udp = m_scene.GetSceneModule<LLUDP>();
            if (m_udp == null)
            {
                m_log.Warn("Neighbors requires an LLUDP");
                return;
            }

            m_userClient = m_scene.Simian.GetAppModule<IUserClient>();
            if (m_userClient == null)
            {
                m_log.Warn("Neighbors requires an IUserClient");
                return;
            }

            m_gridClient = scene.Simian.GetAppModule<IGridClient>();

            // Add neighbor messaging handlers
            string urlFriendlySceneName = WebUtil.UrlEncode(scene.Name);
            string regionPath = "/regions/" + urlFriendlySceneName;
            m_httpServer.AddHandler("POST", null, regionPath + "/region/online", true, true, RegionOnlineHandler);
            m_httpServer.AddHandler("POST", null, regionPath + "/region/offline", true, true, RegionOfflineHandler);
            m_httpServer.AddHandler("POST", null, regionPath + "/child_avatar/update", true, true, ChildAvatarUpdateHandler);

            m_scene.AddPublicCapability("region/online", m_httpServer.HttpAddress.Combine(regionPath + "/region/online"));
            m_scene.AddPublicCapability("region/offline", m_httpServer.HttpAddress.Combine(regionPath + "/region/offline"));
            m_scene.AddPublicCapability("child_avatar/update", m_httpServer.HttpAddress.Combine(regionPath + "/child_avatar/update"));

            // Track local scenes going up and down
            m_sceneFactory = scene.Simian.GetAppModule<ISceneFactory>();
            if (m_sceneFactory != null)
            {
                m_sceneFactory.OnSceneStart += SceneStartHandler;
                m_sceneFactory.OnSceneStop += SceneStopHandler;
            }

            m_scene.OnPresenceAdd += PresenceAddHandler;
            m_scene.OnEntityAddOrUpdate += EntityAddOrUpdateHandler;

            m_childUpdates = new ThrottledQueue<uint, IScenePresence>(5.0f, 200, true, SendChildUpdate);
            m_childUpdates.Start();
        }
Пример #9
0
        public bool Start(Simian simian)
        {
            m_scheduler = simian.GetAppModule <IScheduler>();
            if (m_scheduler == null)
            {
                m_log.Error("LLSceneFactory requires an IScheduler");
                return(false);
            }

            m_scenes = new Dictionary <UUID, IScene>();

            m_renderer   = simian.GetAppModule <ISceneRenderer>();
            m_gridClient = simian.GetAppModule <IGridClient>();

            string[] sceneFiles = null;

            try { sceneFiles = Directory.GetFiles(SOURCE_PATH, "*.ini", SearchOption.AllDirectories); }
            catch (DirectoryNotFoundException)
            {
                m_log.Warn(Path.GetFullPath(SOURCE_PATH) + " not found, cannot load scene definitions");
                return(false);
            }

            for (int i = 0; i < sceneFiles.Length; i++)
            {
                // Create the config source for this region by merging the app config and the region config
                IConfigSource   configSource       = simian.GetConfigCopy();
                IniConfigSource regionConfigSource = new IniConfigSource(sceneFiles[i]);
                configSource.Merge(regionConfigSource);

                IConfig config = configSource.Configs["LindenRegion"];

                if (config != null)
                {
                    UUID id;
                    UUID.TryParse(config.GetString("ID"), out id);

                    string name = config.GetString("Name");

                    uint     locationX = 0, locationY = 0;
                    string[] locationParts = config.GetString("Location").Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (locationParts.Length != 2 || !UInt32.TryParse(locationParts[0], out locationX) || !UInt32.TryParse(locationParts[1], out locationY))
                    {
                        m_log.Warn("Missing or invalid Location for " + name + " region");
                    }
                    Vector3d regionPosition = new Vector3d(locationX * (uint)REGION_SIZE, locationY * (uint)REGION_SIZE, 0.0d);

                    Scene scene = new Scene(id, name, regionPosition, new Vector3d(256.0, 256.0, 4096.0), simian, configSource);
                    m_log.Info("Starting scene " + scene.Name + " (" + scene.ID + ")");
                    scene.Start();

                    m_scenes[scene.ID] = scene;

                    // Create a map tile for this scene
                    m_scheduler.FireAndForget(o => CreateMapTile((IScene)o), scene);
                }
                else
                {
                    m_log.Warn("No [LindenRegion] config section found in " + sceneFiles[i] + ", skipping");
                }
            }

            // Create the array
            m_scenesArray = new IScene[m_scenes.Count];
            int j = 0;

            foreach (IScene scene in m_scenes.Values)
            {
                m_scenesArray[j++] = scene;
            }

            // Fire the OnSceneStart callback for each scene we started
            SceneStartCallback callback = OnSceneStart;

            if (callback != null)
            {
                for (int i = 0; i < m_scenesArray.Length; i++)
                {
                    callback(m_scenesArray[i]);
                }
            }

            return(true);
        }
Пример #10
0
        public bool Start(Simian simian)
        {
            m_simian = simian;

            #region Get Module References

            m_httpServer = simian.GetAppModule<IHttpServer>();
            if (m_httpServer == null)
            {
                m_log.Error("Can't create the LindenLogin service without an HTTP server");
                return false;
            }

            m_userClient = simian.GetAppModule<IUserClient>();
            if (m_userClient == null)
            {
                m_log.Error("Can't create the LindenLogin service without a user client");
                return false;
            }

            m_gridClient = simian.GetAppModule<IGridClient>();
            if (m_gridClient == null)
            {
                m_log.Error("Can't create the LindenLogin service without a grid client");
                return false;
            }

            m_inventoryClient = simian.GetAppModule<IInventoryClient>();

            #endregion Get Module References

            m_httpServer.AddXmlRpcHandler("/", true, "login_to_simulator", LoginHandler);
            m_log.Info("LindenLogin handler initialized");

            return true;
        }
Пример #11
0
        public static void Main()
        {
            /* Enable debug messages. */
            //Debug.Listeners.Add(new TextWriterTraceListener(System.Console.Out));

            IGridClient client = CreateClient();

            try {
                // Show grid topology.
                X.WriteLine(">>> Client created, current grid topology: " + ToString(client.Compute().Nodes()));

                // Random node ID.
                Guid randNodeId = client.Compute().Nodes()[0].Id;

                // Get client projection of grid partitioned cache.
                IGridClientData rmtCache = client.Data("partitioned");

                IList <String> keys = new List <String>(KeysCount);

                // Put some values to the cache.
                for (int i = 0; i < KeysCount; i++)
                {
                    String iKey = i + "";

                    // Put request will go exactly to the primary node for this key.
                    rmtCache.Put(iKey, "val-" + i);

                    Guid nodeId = rmtCache.Affinity(iKey);

                    X.WriteLine(">>> Storing key " + iKey + " on node " + nodeId);

                    keys.Add(iKey);
                }

                // Pin a remote node for communication. All further communication
                // on returned projection will happen through this pinned node.
                IGridClientData prj = rmtCache.PinNodes(client.Compute().Node(randNodeId));

                // Request batch from our local node in pinned mode.
                IDictionary <String, Object> vals = prj.GetAll <String, Object>(keys);

                foreach (KeyValuePair <String, Object> entry in vals)
                {
                    X.WriteLine(">>> Loaded cache entry [key=" + entry.Key + ", val=" + entry.Value + ']');
                }

                // After nodes are pinned the list of pinned nodes may be retrieved.
                X.WriteLine(">>> Pinned nodes: " + ToString(prj.PinnedNodes()));

                // Keys may be stored asynchronously.
                IGridClientFuture <Boolean> futPut = rmtCache.PutAsync("0", "new value for 0");

                X.WriteLine(">>> Result of asynchronous put: " + (futPut.Result ? "success" : "failure"));

                IDictionary <Guid, IDictionary <String, String> > keyVals = new Dictionary <Guid, IDictionary <String, String> >();

                // Batch puts are also supported.
                // Here we group key-value pairs by their affinity node ID to ensure
                // the least amount of network trips possible.
                for (int i = 0; i < KeysCount; i++)
                {
                    String iKey = i + "";

                    Guid nodeId = rmtCache.Affinity(iKey);

                    IDictionary <String, String> m;

                    if (!keyVals.TryGetValue(nodeId, out m))
                    {
                        keyVals.Add(nodeId, m = new Dictionary <String, String>());
                    }

                    m.Add(iKey, "val-" + i);
                }

                foreach (IDictionary <String, String> kvMap in keyVals.Values)
                {
                    // Affinity-aware bulk put operation - it will connect to the
                    // affinity node for provided keys.
                    rmtCache.PutAll(kvMap);
                }

                // Asynchronous batch put is available as well.
                ICollection <IGridClientFuture> futs = new LinkedList <IGridClientFuture>();

                foreach (IDictionary <String, String> kvMap in keyVals.Values)
                {
                    IGridClientFuture futPutAll = rmtCache.PutAllAsync(kvMap);

                    futs.Add(futPutAll);
                }

                // Wait for all futures to complete.
                foreach (IGridClientFuture fut in futs)
                {
                    fut.WaitDone();
                }

                // Of course there's getting value by key functionality.
                String key = 0 + "";

                X.WriteLine(">>> Value for key " + key + " is " + rmtCache.GetItem <String, Object>(key));

                // Asynchronous gets, too.
                IGridClientFuture <String> futVal = rmtCache.GetAsync <String, String>(key);

                X.WriteLine(">>> Asynchronous value for key " + key + " is " + futVal.Result);

                // Multiple values can be fetched at once. Here we batch our get
                // requests by affinity nodes to ensure least amount of network trips.
                foreach (KeyValuePair <Guid, IDictionary <String, String> > nodeEntry in keyVals)
                {
                    Guid nodeId = nodeEntry.Key;
                    ICollection <String> keyCol = nodeEntry.Value.Keys;

                    // Since all keys in our getAll(...) call are mapped to the same primary node,
                    // grid cache client will pick this node for the request, so we only have one
                    // network trip here.
                    X.WriteLine(">>> Values from node [nodeId=" + nodeId + ", values=" + ToString(rmtCache.GetAll <String, Object>(keyCol)) + ']');
                }

                // Multiple values may be retrieved asynchronously, too.
                // Here we retrieve all keys at ones. Since this request
                // will be sent to some grid node, this node may not be
                // the primary node for all keys and additional network
                // trips will have to be made within grid.
                IGridClientFuture <IDictionary <String, Object> > futVals = rmtCache.GetAllAsync <String, Object>(keys);

                X.WriteLine(">>> Asynchronous values for keys are " + ToString(futVals.Result));

                // Contents of cache may be removed one by one synchronously.
                // Again, this operation is affinity aware and only the primary
                // node for the key is contacted.
                bool res = rmtCache.Remove(0 + "");

                X.WriteLine(">>> Result of removal: " + (res ? "success" : "failure"));

                // ... and asynchronously.
                IGridClientFuture <Boolean> futRes = rmtCache.RemoveAsync(1 + "");

                X.WriteLine(">>> Result of asynchronous removal is: " + (futRes.Result ? "success" : "failure"));

                // Multiple entries may be removed at once synchronously...
                rmtCache.RemoveAll(new String[] { 2 + "", 3 + "" });

                // ... and asynchronously.
                IGridClientFuture futResAll = rmtCache.RemoveAllAsync(new String[] { 3 + "", 4 + "" });

                futResAll.WaitDone();

                // Values may also be replaced.
                res = rmtCache.Replace(0 + "", "new value for 0");

                X.WriteLine(">>> Result for replace for nonexistent key is " + (res ? "success" : "failure"));

                // Asynchronous replace is supported, too.
                futRes = rmtCache.ReplaceAsync("" + 0, "newest value for 0");

                X.WriteLine(">>> Result for asynchronous replace for nonexistent key is " +
                            (futRes.Result ? "success" : "failure"));

                // Compare and set are implemented, too.
                res = rmtCache.Cas("" + 0, "new value for 0", null);

                X.WriteLine(">>> Result for put using cas for key that didn't have value yet is " +
                            (res ? "success" : "failure"));

                // CAS can be asynchronous.
                futRes = rmtCache.CasAsync("" + 0, "newest value for 0", "new value for 0");

                X.WriteLine(">>> Result for put using asynchronous cas is " + (futRes.Result ? "success" : "failure"));

                // It's possible to obtain cache metrics using data client API.
                X.WriteLine(">>> Cache metrics : " + rmtCache.Metrics());

                // Global and per key metrics retrieval can be asynchronous, too.
                IGridClientFuture <IGridClientDataMetrics> futMetrics = rmtCache.MetricsAsync();

                X.WriteLine(">>> Cache asynchronous metrics : " + futMetrics.Result);
            }
            catch (GridClientException e) {
                Console.WriteLine("Unexpected grid client exception happens: {0}", e);
            }
            finally {
                GridClientFactory.StopAll();
            }
        }
Пример #12
0
 protected virtual IGridClient <T> CreateClient(IGridClient <T> client)
 {
     return(client.Sortable());
 }
Пример #13
0
        public static void Main()
        {
            /* Enable debug messages. */
            //Debug.Listeners.Add(new TextWriterTraceListener(System.Console.Out));

            String taskName = "org.gridgain.examples.misc.client.api.ClientExampleTask";
            String taskArg  = ".NET client - ";

            IGridClient client = CreateClient();

            try {
                // Show grid topology.
                X.WriteLine(">>> Client created, current grid topology: " + ToString(client.Compute().Nodes()));

                // Random node ID.
                Guid randNodeId = client.Compute().Nodes()[0].Id;

                // Note that in this example we get a fixed projection for task call because we cannot guarantee that
                // other nodes contain ClientExampleTask in classpath.
                IGridClientCompute prj = client.Compute().Projection(delegate(IGridClientNode node) {
                    return(node.Id.Equals(randNodeId));
                });

                // Execute test task that will count total number of nodes in grid.
                int entryCnt = prj.Execute <int>(taskName, taskArg + "predicate projection");

                X.WriteLine(">>> Predicate projection : there are totally " + entryCnt + " nodes in the grid");

                // Same as above, using different projection API.
                IGridClientNode clntNode = prj.Node(randNodeId);

                prj = prj.Projection(clntNode);

                entryCnt = prj.Execute <int>(taskName, taskArg + "node projection");

                X.WriteLine(">>> GridClientNode projection : there are totally " + entryCnt + " nodes in the grid");

                // Use of collections is also possible.
                prj = prj.Projection(new IGridClientNode[] { clntNode });

                entryCnt = prj.Execute <int>(taskName, taskArg + "nodes collection projection");

                X.WriteLine(">>> Collection projection : there are totally " + entryCnt + " nodes in the grid");

                // Balancing - may be random or round-robin. Users can create
                // custom load balancers as well.
                IGridClientLoadBalancer balancer = new GridClientRandomBalancer();

                // Balancer may be added to predicate or collection examples.
                prj = client.Compute().Projection(delegate(IGridClientNode node) {
                    return(node.Id.Equals(randNodeId));
                }, balancer);

                entryCnt = prj.Execute <int>(taskName, taskArg + "predicate projection with balancer");

                X.WriteLine(">>> Predicate projection with balancer : there are totally " + entryCnt +
                            " nodes in the grid");

                // Now let's try round-robin load balancer.
                balancer = new GridClientRoundRobinBalancer();

                prj = prj.Projection(new IGridClientNode[] { clntNode }, balancer);

                entryCnt = prj.Execute <int>(taskName, taskArg + "node projection with balancer");

                X.WriteLine(">>> GridClientNode projection : there are totally " + entryCnt + " nodes in the grid");

                // Execution may be asynchronous.
                IGridClientFuture <int> fut = prj.ExecuteAsync <int>(taskName, taskArg + "asynchronous execution");

                X.WriteLine(">>> Execute async : there are totally " + fut.Result + " nodes in the grid");

                // GridClientCompute can be queried for nodes participating in it.
                ICollection <IGridClientNode> c = prj.Nodes(new Guid[] { randNodeId });

                X.WriteLine(">>> Nodes with Guid " + randNodeId + " : " + ToString(c));

                // Nodes may also be filtered with predicate. Here
                // we create projection which only contains local node.
                c = prj.Nodes(delegate(IGridClientNode node) {
                    return(node.Id.Equals(randNodeId));
                });

                X.WriteLine(">>> Nodes filtered with predicate : " + ToString(c));

                // Information about nodes may be refreshed explicitly.
                clntNode = prj.RefreshNode(randNodeId, true, true);

                X.WriteLine(">>> Refreshed node : " + clntNode);

                // As usual, there's also an asynchronous version.
                IGridClientFuture <IGridClientNode> futClntNode = prj.RefreshNodeAsync(randNodeId, false, false);

                X.WriteLine(">>> Refreshed node asynchronously : " + futClntNode.Result);

                // Nodes may also be refreshed by IP address.
                String clntAddr = "127.0.0.1";

                foreach (var addr in clntNode.AvailableAddresses(GridClientProtocol.Tcp))
                {
                    if (addr != null)
                    {
                        clntAddr = addr.Address.ToString();
                    }
                }

                // Force node metrics refresh (by default it happens periodically in the background).
                clntNode = prj.RefreshNode(clntAddr, true, true);

                X.WriteLine(">>> Refreshed node by IP : " + clntNode);

                // Asynchronous version.
                futClntNode = prj.RefreshNodeAsync(clntAddr, false, false);

                X.WriteLine(">>> Refreshed node by IP asynchronously : " + futClntNode.Result);

                // Topology as a whole may be refreshed, too.
                ICollection <IGridClientNode> top = prj.RefreshTopology(true, true);

                X.WriteLine(">>> Refreshed topology : " + ToString(top));

                // Asynchronous version.
                IGridClientFuture <IList <IGridClientNode> > topFut = prj.RefreshTopologyAsync(false, false);

                X.WriteLine(">>> Refreshed topology asynchronously : " + ToString(topFut.Result));
            }
            catch (GridClientException e) {
                Console.WriteLine("Unexpected grid client exception happens: {0}", e);
            }
            finally {
                GridClientFactory.StopAll();
            }
        }
Пример #14
0
        public bool Start(Simian simian)
        {
            m_scheduler = simian.GetAppModule<IScheduler>();
            if (m_scheduler == null)
            {
                m_log.Error("LLSceneFactory requires an IScheduler");
                return false;
            }

            m_scenes = new Dictionary<UUID, IScene>();

            m_renderer = simian.GetAppModule<ISceneRenderer>();
            m_gridClient = simian.GetAppModule<IGridClient>();

            string[] sceneFiles = null;

            try { sceneFiles = Directory.GetFiles(SOURCE_PATH, "*.ini", SearchOption.AllDirectories); }
            catch (DirectoryNotFoundException)
            {
                m_log.Warn(Path.GetFullPath(SOURCE_PATH) + " not found, cannot load scene definitions");
                return false;
            }

            for (int i = 0; i < sceneFiles.Length; i++)
            {
                // Create the config source for this region by merging the app config and the region config
                IConfigSource configSource = simian.GetConfigCopy();
                IniConfigSource regionConfigSource = new IniConfigSource(sceneFiles[i]);
                configSource.Merge(regionConfigSource);

                IConfig config = configSource.Configs["LindenRegion"];

                if (config != null)
                {
                    UUID id;
                    UUID.TryParse(config.GetString("ID"), out id);

                    string name = config.GetString("Name");

                    uint locationX = 0, locationY = 0;
                    string[] locationParts = config.GetString("Location").Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (locationParts.Length != 2 || !UInt32.TryParse(locationParts[0], out locationX) || !UInt32.TryParse(locationParts[1], out locationY))
                    {
                        m_log.Warn("Missing or invalid Location for " + name + " region");
                    }
                    Vector3d regionPosition = new Vector3d(locationX * (uint)REGION_SIZE, locationY * (uint)REGION_SIZE, 0.0d);

                    Scene scene = new Scene(id, name, regionPosition, new Vector3d(256.0, 256.0, 4096.0), simian, configSource);
                    m_log.Info("Starting scene " + scene.Name + " (" + scene.ID + ")");
                    scene.Start();

                    m_scenes[scene.ID] = scene;

                    // Create a map tile for this scene
                    m_scheduler.FireAndForget(o => CreateMapTile((IScene)o), scene);
                }
                else
                {
                    m_log.Warn("No [LindenRegion] config section found in " + sceneFiles[i] + ", skipping");
                }
            }

            // Create the array
            m_scenesArray = new IScene[m_scenes.Count];
            int j = 0;
            foreach (IScene scene in m_scenes.Values)
                m_scenesArray[j++] = scene;

            // Fire the OnSceneStart callback for each scene we started
            SceneStartCallback callback = OnSceneStart;
            if (callback != null)
            {
                for (int i = 0; i < m_scenesArray.Length; i++)
                {
                    callback(m_scenesArray[i]);
                }
            }

            return true;
        }