Exemple #1
0
 		public QMFObject(QMFObject source) {
 			this.Session = source.Session ;
 			this.Schema = source.Schema ;
 			this.Managed = source.Managed ;
 			this.CurrentTime = source.CurrentTime ;
 			this.CreateTime = source.CreateTime ;
 			this.DeleteTime = source.DeleteTime ;
 			this.ObjectID = source.ObjectID ;
 			this.Properties = source.Properties ;
 			this.Statistics = source.Statistics ;
 		}
Exemple #2
0
 		// This constructor is used by the session to create an object based on a data 
 		// stream by the agent.
		public QMFObject(Session session, SchemaClass schema, IDecoder dec, bool hasProperties, bool hasStats , bool isManaged)
		{
			Session = session ;
			Schema = schema ;
			Managed = isManaged ;
			
			if (Managed) {
			    // FIXME DateTime or Uint64??
				CurrentTime = new DateTime(dec.ReadDatetime()) ;
				CreateTime = new DateTime(dec.ReadDatetime()) ;				
				DeleteTime = new DateTime(dec.ReadDatetime()) ;				
				ObjectID = new ObjectID(dec) ;
			}
			
			if (hasProperties) {
				List<string> excluded = ProcessPresenceMasks(dec, Schema) ;
				
				foreach (SchemaProperty prop in Schema.GetAllProperties()) {
					if (excluded.Contains(prop.Name)) {
					    log.Debug(String.Format("Setting Property Default {0}", prop.Name)) ;					    					
						safeAddProperty(prop.Name, null) ;	
					} else {
						//log.Debug(String.Format("Setting Property {0}", prop.Name)) ;
						safeAddProperty(prop.Name, session.DecodeValue(dec, prop.Type)) ;
					}
				}
			}
			
			if (hasStats) {
				foreach (SchemaStatistic stat in Schema.GetAllStatistics())  {
					//log.Debug(String.Format("Setting Statistic {0}", stat.Name)) ;				
					Statistics.Add(stat.Name, session.DecodeValue(dec, stat.Type)) ;
				}
			}
			
		}
        public List <QMFObject> GetObjects(Dictionary <string, object> args)
        {
            List <Broker> brokerList = null;
            List <Agent>  agentList  = new List <Agent>();

            if (args.ContainsKey("_broker"))
            {
                brokerList = new List <Broker>();
                brokerList.Add((Broker)args["_broker"]);
            }
            else
            {
                brokerList = this.Brokers;
            }

            foreach (Broker broker in brokerList)
            {
                broker.WaitForStable();
            }

            if (args.ContainsKey("_agent"))
            {
                Agent agent = (Agent)args["_agent"];
                if (brokerList.Contains(agent.Broker))
                {
                    agentList.Add(agent);
                }
                else
                {
                    throw new Exception("Agent is not managed by this console or the supplied broker");
                }
            }
            else
            {
                if (args.ContainsKey("_objectId"))
                {
                    ObjectID oid = (ObjectID)args["_objectId"];
                    foreach (Broker broker in Brokers)
                    {
                        foreach (Agent agent in broker.Agents.Values)
                        {
                            if ((agent.AgentBank == oid.AgentBank()) && (agent.BrokerBank == oid.BrokerBank()))
                            {
                                agentList.Add(agent);
                            }
                        }
                    }
                }
                else
                {
                    foreach (Broker broker in brokerList)
                    {
                        foreach (Agent agent in broker.Agents.Values)
                        {
                            if (agent.Broker.IsConnected())
                            {
                                agentList.Add(agent);
                            }
                        }
                    }
                }
            }

            GetResult = new List <QMFObject>();

            if (agentList.Count > 0)
            {
                //FIXME Add a bunch of other suff too
                foreach (Agent agent in agentList)
                {
                    Dictionary <string, object> getParameters = new Dictionary <string, object>();
                    Broker broker = agent.Broker;
                    long   seq    = -1;
                    lock (LockObject) {
                        seq = SequenceManager.Reserve(Session.CONTEXT_MULTIGET);
                        SyncSequenceList.Add(seq);
                    }
                    object packageName = null;
                    object className   = null;
                    object key         = null;
                    object sClass      = null;
                    object oid         = null;
                    object hash        = null;

                    args.TryGetValue("_schema", out sClass);
                    args.TryGetValue("_key", out key);
                    args.TryGetValue("_class", out className);
                    args.TryGetValue("_package", out packageName);
                    args.TryGetValue("_objectID", out oid);
                    args.TryGetValue("_hash", out hash);

                    if ((className == null) && (oid == null) && (oid == null))
                    {
                        throw new Exception("No class supplied, use '_schema', '_key', '_class', or '_objectId' argument");
                    }

                    if (oid != null)
                    {
                        getParameters.Add("_objectID", oid);
                    }
                    else
                    {
                        if (sClass != null)
                        {
                            key = key ?? ((SchemaClass)sClass).Key;
                        }
                        if (key != null)
                        {
                            ClassKey cKey = (ClassKey)key;
                            className   = className ?? cKey.ClassName;
                            packageName = packageName ?? cKey.PackageName;
                            hash        = hash ?? cKey.Hash;
                        }

                        if (packageName != null)
                        {
                            getParameters.Add("_package", packageName);
                        }
                        if (className != null)
                        {
                            getParameters.Add("_class", className);
                        }
                        if (hash != null)
                        {
                            getParameters.Add("_hash", hash);
                        }
                        foreach (KeyValuePair <string, object> pair in args)
                        {
                            if (!pair.Key.StartsWith("_"))
                            {
                                getParameters.Add(pair.Key, pair.Value);
                            }
                        }
                    }

                    IEncoder enc = broker.CreateEncoder('G', seq);
                    enc.WriteMap(getParameters);
                    string  routingKey = String.Format("agent.{0}.{1}", agent.BrokerBank, agent.AgentBank);
                    Message msg        = broker.CreateMessage(enc, routingKey);
                    log.Debug("Get Object Keys: ");
                    foreach (string pKey in getParameters.Keys)
                    {
                        log.Debug(String.Format("\tKey: '{0}' Value: '{1}'", pKey, getParameters[pKey]));
                    }
                    broker.Send(msg);
                }

                int  waittime = DEFAULT_GET_WAIT_TIME;
                bool timeout  = false;
                if (args.ContainsKey("_timeout"))
                {
                    waittime = (int)args["_timeout"];
                }
                DateTime start = DateTime.Now;
                lock (LockObject) {
                    // FIXME ERROR
                    while (SyncSequenceList.Count > 0)
                    {
                        Monitor.Wait(LockObject, waittime);
                        TimeSpan duration = DateTime.Now - start;
                        if (duration.TotalMilliseconds > waittime)
                        {
                            foreach (long pendingSeq in SyncSequenceList)
                            {
                                SequenceManager.Release(pendingSeq);
                            }
                            SyncSequenceList.Clear();
                            timeout = true;
                        }
                    }
                }

                //FIXME Add the error logic
                if ((GetResult.Count == 0) && timeout)
                {
                    throw new Exception("Get Request timed out");
                }
            }
            return(GetResult);
        }