public void HandleClassIndicator(Broker broker, IDecoder decoder, long sequence) { short kind = decoder.ReadUint8(); ClassKey classKey = new ClassKey(decoder); bool unknown = false; lock (LockObject) { if (Packages.ContainsKey(classKey.PackageName)) { if (!Packages[classKey.PackageName].ContainsKey(classKey.GetKeyString())) { unknown = true; } } } if (unknown) { broker.IncrementOutstanding(); long seq = SequenceManager.Reserve(Session.CONTEXT_STARTUP); IEncoder enc = broker.CreateEncoder('S', seq); classKey.encode(enc); broker.Send(enc); } }
public override Type TypeMapping(ClassKey key) { Type returnValue = null ; if (!TypeMappings.TryGetValue(key, out returnValue)) { returnValue = typeof(QMFObject) ; } return returnValue ; }
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)); }
public override bool Equals(object obj) { if (obj.GetType().Equals(this.GetType())) { ClassKey other = (ClassKey)obj; return(other.GetKeyString().Equals(this.GetKeyString())); } else { return(false); } }
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) ; } } }
public SchemaClass(int kind, ClassKey key, IDecoder dec, Session session) { log.Debug(String.Format("New schema class {0}", key)); Kind = kind; Session = session; this.Key = key; bool hasSupertype = false; if (kind == CLASS_KIND_TABLE) { int propCount = dec.ReadUint16(); int statCount = dec.ReadUint16(); int methodCount = dec.ReadUint16(); if (hasSupertype) { SuperType = new ClassKey(dec); } for (int x = 0; x < propCount; x++) { Properties.Add(new SchemaProperty(dec)); } for (int x = 0; x < statCount; x++) { Statistics.Add(new SchemaStatistic(dec)); } for (int x = 0; x < methodCount; x++) { Methods.Add(new SchemaMethod(dec)); } } if (kind == CLASS_KIND_EVENT) { int argCount = dec.ReadUint16(); if (hasSupertype) { SuperType = new ClassKey(dec); } for (int x = 0; x < argCount; x++) { Arguments.Add(new SchemaArgument(dec, false)); } } }
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); } } }
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); }
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 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); } } } }
public SchemaClass(int kind, ClassKey key, IDecoder dec, Session session) { log.Debug(String.Format("New schema class {0}", key)) ; Kind = kind ; Session = session ; this.Key = key ; bool hasSupertype = false ; if (kind == CLASS_KIND_TABLE) { int propCount = dec.ReadUint16() ; int statCount = dec.ReadUint16() ; int methodCount = dec.ReadUint16() ; if (hasSupertype) { SuperType = new ClassKey(dec) ; } for(int x = 0 ; x < propCount ; x++) { Properties.Add(new SchemaProperty(dec)) ; } for(int x = 0 ; x < statCount ; x++) { Statistics.Add(new SchemaStatistic(dec)) ; } for(int x = 0 ; x < methodCount ; x++) { Methods.Add(new SchemaMethod(dec)) ; } } if (kind == CLASS_KIND_EVENT) { int argCount = dec.ReadUint16() ; if (hasSupertype) { SuperType = new ClassKey(dec) ; } for(int x = 0 ; x < argCount ; x++) { Arguments.Add(new SchemaArgument(dec, false)) ; } } }
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 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 ; }
public SchemaClass GetSchema(ClassKey key) { return GetSchema(key, true) ; }
public virtual Type TypeMapping(ClassKey key) { return(typeof(QMFObject)); }
public virtual void NewClass(short kind, ClassKey key) { }
public SchemaClass GetSchema(ClassKey key) { return(GetSchema(key, true)); }
public virtual Type TypeMapping(ClassKey key) { return typeof(QMFObject) ; }
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) ; } } } }
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)); } }
public void HandleClassIndicator(Broker broker, IDecoder decoder, long sequence) { short kind = decoder.ReadUint8() ; ClassKey classKey = new ClassKey(decoder) ; bool unknown = false ; lock (LockObject) { if (Packages.ContainsKey(classKey.PackageName)) { if (!Packages[classKey.PackageName].ContainsKey(classKey.GetKeyString())) { unknown = true ; } } } if (unknown) { broker.IncrementOutstanding() ; long seq = SequenceManager.Reserve(Session.CONTEXT_STARTUP) ; IEncoder enc = broker.CreateEncoder('S', seq) ; classKey.encode(enc) ; broker.Send(enc) ; } }
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 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); }
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)) ; } }
public virtual void NewClass(short kind, ClassKey key) {}