Exemple #1
0
        // This constructor is used by a session make object call to
        // create a blank object from a schema.
        public QMFObject(Session session, SchemaClass schema, bool hasProperties, bool hasStats, bool isManaged)
        {
            Session = session;
            Schema  = schema;
            Managed = isManaged;

            if (hasProperties)
            {
                foreach (SchemaProperty prop in Schema.GetAllProperties())
                {
                    object propValue = null;
                    if (!prop.Optional)
                    {
                        propValue = Util.DefaultValue(prop.Type);
                    }
                    this.SetProperty(prop.Name, propValue);
                }
            }

            if (hasStats)
            {
                foreach (SchemaStatistic stat in Schema.Statistics)
                {
                    SetStatistic(stat.Name, Util.DefaultValue(stat.Type));
                }
            }
        }
Exemple #2
0
        protected List <string> ProcessPresenceMasks(IDecoder dec, SchemaClass schema)
        {
            List <string> excludes = new List <string> ();
            short         bit      = 0;
            short         mask     = 0;

            foreach (SchemaProperty prop in Schema.GetAllProperties())
            {
                if (prop.Optional)
                {
                    //log.Debug(String.Format("Property named {0} is optional", prop.Name)) ;
                    if (bit == 0)
                    {
                        mask = dec.ReadUint8();
                        bit  = 1;
                    }

                    if ((mask & bit) == 0)
                    {
                        //log.Debug(String.Format("Property named {0} is not present", prop.Name)) ;
                        excludes.Add(prop.Name);
                    }
                    bit *= 2;
                    if (bit == 256)
                    {
                        bit = 0;
                    }
                }
            }
            return(excludes);
        }
        public QMFObject MakeObject(ClassKey key)
        {
            SchemaClass sClass = this.GetSchema(key);

            if (sClass == null)
            {
                throw new Exception("No schema found for class " + key.ToString());
            }

            return(this.CreateQMFObject(sClass, true, true, false));
        }
        protected QMFObject CreateQMFObject(SchemaClass schema, IDecoder dec, bool hasProperties, bool hasStats, bool isManaged)
        {
            Type realClass = typeof(QMFObject);

            if (Console != null)
            {
                realClass = Console.TypeMapping(schema.Key);
            }
            Type[]          types = new Type[] { typeof(Session), typeof(SchemaClass), typeof(IDecoder), typeof(bool), typeof(bool), typeof(bool) };
            object[]        args  = new object[] { this, schema, dec, hasProperties, hasStats, isManaged };
            ConstructorInfo ci    = realClass.GetConstructor(types);

            return((QMFObject)ci.Invoke(args));
        }
        protected SchemaClass GetSchema(ClassKey key, bool waitForStable)
        {
            if (waitForStable)
            {
                this.WaitForStable();
            }

            SchemaClass returnValue = null;

            try {
                returnValue = Packages[key.PackageName][key.GetKeyString()];
            }
            catch (KeyNotFoundException) {
                // eat it
            }

            return(returnValue);
        }
Exemple #6
0
        public QMFEvent(Session session, IDecoder dec)
        {
            Session   = session;
            ClassKey  = new ClassKey(dec);
            Timestamp = dec.ReadInt64();
            Severity  = (EventSeverity)dec.ReadUint8();
            SchemaClass sClass = Session.GetSchema(ClassKey);

            Arguments = new Dictionary <string, object>();

            if (sClass != null)
            {
                foreach (SchemaArgument arg in sClass.Arguments)
                {
                    Arguments[arg.Name] = Session.DecodeValue(dec, arg.Type);
                }
            }
        }
Exemple #7
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 void HandleSchemaResponse(Broker broker, IDecoder decoder, long sequence)
        {
            short       kind     = decoder.ReadUint8();
            ClassKey    classKey = new ClassKey(decoder);
            SchemaClass sClass   = new SchemaClass(kind, classKey, decoder, this);

            lock (LockObject) {
                Dictionary <string, SchemaClass> classMappings = Packages[sClass.PackageName];
                classMappings.Remove(sClass.ClassKeyString);
                classMappings.Add(sClass.ClassKeyString, sClass);
            }

            SequenceManager.Release(sequence);
            broker.DecrementOutstanding();
            if (Console != null)
            {
                this.Console.NewClass(kind, classKey);
            }
        }
Exemple #9
0
 		// This constructor is used by a session make object call to 
 		// create a blank object from a schema.
 		public QMFObject(Session session, SchemaClass schema, bool hasProperties, bool hasStats , bool isManaged) {
			Session = session ;
			Schema = schema ;
			Managed = isManaged ; 
			
			if (hasProperties) {
				foreach (SchemaProperty prop in Schema.GetAllProperties()) {
					object propValue = null ; 
					if (!prop.Optional) {
						propValue = Util.DefaultValue(prop.Type) ;
					}
					this.SetProperty(prop.Name, propValue) ;			
				}
			}	
			
			if (hasStats) {
				foreach (SchemaStatistic stat in Schema.Statistics)  {			
					SetStatistic(stat.Name, Util.DefaultValue(stat.Type)) ;
				}
			}															
 		}
        public void HandleContentIndicator(Broker broker, IDecoder decoder, long sequence, bool hasProperties, bool hasStatistics)
        {
            ClassKey    key    = new ClassKey(decoder);
            SchemaClass sClass = null;;

            lock (LockObject) {
                sClass = GetSchema(key, false);
            }
            if (sClass != null)
            {
                QMFObject obj = this.CreateQMFObject(sClass, decoder, hasProperties, hasStatistics, true);

                if (key.PackageName.Equals("org.apache.qpid.broker") && key.ClassName.Equals("agent") && hasProperties)
                {
                    broker.UpdateAgent(obj);
                }

                lock (LockObject) {
                    if (SyncSequenceList.Contains(sequence))
                    {
                        if (!obj.IsDeleted() && this.SelectMatch(obj))
                        {
                            GetResult.Add(obj);
                        }
                    }
                }

                if (Console != null)
                {
                    if (hasProperties)
                    {
                        Console.ObjectProperties(broker, obj);
                    }
                    if (hasStatistics)
                    {
                        Console.ObjectStatistics(broker, obj);
                    }
                }
            }
        }
Exemple #11
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)) ;
				}
			}
			
		}
Exemple #12
0
		protected List<string> ProcessPresenceMasks(IDecoder dec, SchemaClass schema) {
			List<string> excludes = new List<string> () ;
			short bit = 0 ;
			short mask = 0 ;
			foreach (SchemaProperty prop in Schema.GetAllProperties()) {
				if (prop.Optional) {
					//log.Debug(String.Format("Property named {0} is optional", prop.Name)) ;				
					if (bit == 0) {
						mask=dec.ReadUint8() ;
						bit = 1 ;
					}

					if ((mask & bit) == 0) {
						//log.Debug(String.Format("Property named {0} is not present", prop.Name)) ;
						excludes.Add(prop.Name) ;
					}
					bit *= 2 ;
					if (bit == 256) {
						bit = 0 ;
					}
				}
			}
			return excludes ;			
		}
Exemple #13
0
 public BaseClass(Session session, SchemaClass schema, bool hasProperties, bool hasStats , bool isManaged)
     : base(session, schema, hasProperties, hasStats, isManaged)
 {
 }
        public static string SchemaXML(Session sess, string packageName)
        {
            string returnValue = String.Format("<schema package='{0}'>\n", packageName);

            foreach (ClassKey key in sess.GetClasses(packageName))
            {
                SchemaClass schema = sess.GetSchema(key);
                if (schema.Kind == 1)
                {
                    if (schema.SuperType == null)
                    {
                        returnValue += String.Format("\t<class name='{0}' hash='{1}'>\n", key.ClassName, key.GetHashString());
                    }
                    else
                    {
                        returnValue += String.Format("\t<class name='{0}' hash='{1}' extends='{2}'>\n", key.ClassName, key.GetHashString(), schema.SuperType.GetKeyString());
                    }
                    foreach (SchemaProperty prop in schema.Properties)
                    {
                        object[] attributes = new object[5];
                        attributes[0] = prop.Name;
                        attributes[1] = Util.TypeName(prop.Type);
                        attributes[2] = Util.AccessName(prop.Access);
                        attributes[3] = prop.Optional;
                        attributes[4] = XMLUtil.CommonAttributes(prop);
                        returnValue  += String.Format("\t\t<property name='{0}' type='{1}' access='{2}' optional='{3}'{4}/>\n", attributes);
                    }
                    foreach (SchemaMethod meth in schema.Methods)
                    {
                        returnValue += String.Format("\t\t<method name='{0}'/>\n", meth.Name);
                        foreach (SchemaArgument arg in meth.Arguments)
                        {
                            object[] attributes = new object[4];
                            attributes[0] = arg.Name;
                            attributes[1] = arg.Direction;
                            attributes[2] = Util.TypeName(arg.Type);
                            attributes[3] = XMLUtil.CommonAttributes(arg);
                            returnValue  += String.Format("\t\t\t<arg name='{0}' dir='{1}' type='{2}'{3}/>\n", attributes);
                        }
                        returnValue += String.Format("\t\t</method>\n");
                    }
                    returnValue += String.Format("\t</class>\n");
                }
                else
                {
                    returnValue += String.Format("\t<event name='{0}' hash='{1}'>\n", key.ClassName, key.GetHashString());
                    foreach (SchemaArgument arg in schema.Arguments)
                    {
                        object[] attributes = new object[4];
                        attributes[0] = arg.Name;
                        attributes[1] = Util.TypeName(arg.Type);
                        attributes[2] = XMLUtil.CommonAttributes(arg);
                        returnValue  += String.Format("\t\t\t<arg name='{0}' type='{1}'{2}/>\n", attributes);
                    }
                    returnValue += String.Format("\t</event>\n");
                }
            }
            returnValue += String.Format("</schema>\n");

            return(returnValue);
        }
Exemple #15
0
	    protected QMFObject CreateQMFObject(SchemaClass schema, IDecoder dec, bool hasProperties, bool hasStats , bool isManaged) {
	    	Type realClass = typeof(QMFObject) ;	    	
	    	if (Console != null) {
	    		realClass = Console.TypeMapping(schema.Key) ;    		
	    	}
	    	Type[] types = new Type[] {typeof(Session), typeof(SchemaClass), typeof(IDecoder), typeof(bool), typeof(bool),typeof(bool)} ;
	    	object[] args = new object[] {this, schema, dec, hasProperties, hasStats, isManaged} ;
	    	ConstructorInfo ci = realClass.GetConstructor(types);	    
	    	return (QMFObject) ci.Invoke(args) ;
	    }		    		 																		 																
Exemple #16
0
		public void HandleSchemaResponse(Broker broker, IDecoder decoder, long sequence) {
			short kind = decoder.ReadUint8() ;	
			ClassKey classKey = new ClassKey(decoder) ;
			SchemaClass sClass = new SchemaClass(kind, classKey, decoder, this) ;				
			lock(LockObject) {
				Dictionary<string, SchemaClass> classMappings = Packages[sClass.PackageName] ;
				classMappings.Remove(sClass.ClassKeyString) ;
				classMappings.Add(sClass.ClassKeyString, sClass) ;
			}
			
			SequenceManager.Release(sequence) ;
			broker.DecrementOutstanding() ;
			if (Console != null) {
				this.Console.NewClass(kind, classKey) ;
			}	
		}	
        public object DecodeValue(IDecoder dec, short type)
        {
            switch (type)
            {
            case 1: return(dec.ReadUint8());                            // U8

            case 2: return(dec.ReadUint16());                           // U16

            case 3: return(dec.ReadUint32());                           // U32

            case 4: return(dec.ReadUint64());                           // U64

            case 6: return(dec.ReadStr8());                             // SSTR

            case 7: return(dec.ReadStr16());                            // LSTR

            case 8: return(dec.ReadDatetime());                         // ABSTIME

            case 9: return(dec.ReadUint32());                           // DELTATIME

            case 10: return(new ObjectID(dec));                         // ref

            case 11: return(dec.ReadUint8() != 0);                      // bool

            case 12: return(dec.ReadFloat());                           // float

            case 13: return(dec.ReadDouble());                          // double

            case 14: return(dec.ReadUuid());                            // UUID

            case 15: return(dec.ReadMap());                             // Ftable

            case 16: return(dec.ReadInt8());                            // int8

            case 17: return(dec.ReadInt16());                           // int16

            case 18: return(dec.ReadInt32());                           // int32

            case 19: return(dec.ReadInt64());                           // int64

            case 20:                                                    // Object
                // Peek into the inner type code, make sure
                // it is actually an object
                object returnValue   = null;
                short  innerTypeCode = dec.ReadUint8();
                if (innerTypeCode != 20)
                {
                    returnValue = this.DecodeValue(dec, innerTypeCode);
                }
                else
                {
                    ClassKey classKey = new ClassKey(dec);
                    lock (LockObject) {
                        SchemaClass sClass = GetSchema(classKey);
                        if (sClass != null)
                        {
                            returnValue = this.CreateQMFObject(sClass, dec, true, true, false);
                        }
                    }
                }
                return(returnValue);

            case 21:                                     // List
            {
                MSDecoder lDec = new MSDecoder();
                lDec.Init(new MemoryStream(dec.ReadVbin32()));
                long          count   = lDec.ReadUint32();
                List <object> newList = new List <object>();
                while (count > 0)
                {
                    short innerType = lDec.ReadUint8();
                    newList.Add(this.DecodeValue(lDec, innerType));
                    count -= 1;
                }
                return(newList);
            }

            case 22:                                                                // Array
            {
                MSDecoder aDec = new MSDecoder();
                aDec.Init(new MemoryStream(dec.ReadVbin32()));
                long          cnt       = aDec.ReadUint32();
                short         innerType = aDec.ReadUint8();
                List <object> aList     = new List <object>();
                while (cnt > 0)
                {
                    aList.Add(this.DecodeValue(aDec, innerType));
                    cnt -= 1;
                }
                return(aList);
            }

            default:
                throw new Exception(String.Format("Invalid Type Code: {0}", type));
            }
        }
Exemple #18
0
 public DerivedClass(Session session, SchemaClass schema, Decoder dec, bool hasProperties, bool hasStats , bool isManaged)
     : base(session, schema, dec, hasProperties, hasStats, isManaged)
 {
 }
Exemple #19
0
 public ExampleService(Session session, SchemaClass schema, Decoder dec, bool hasProperties, bool hasStats , bool isManaged)
     : base(session, schema, dec, hasProperties, hasStats, isManaged)
 {
 }