예제 #1
0
        public void UpdateAgent(QMFObject obj)
        {
            long   agentBank  = (long)obj.GetProperty("agentBank");
            long   brokerBank = (long)obj.GetProperty("brokerBank");
            String key        = Agent.AgentKey(agentBank, brokerBank);

            if (obj.IsDeleted())
            {
                if (Agents.ContainsKey(key))
                {
                    Agent agent = Agents[key];
                    Agents.Remove(key);
                    consoleSession.HandleAgentRemoved(agent);
                }
            }
            else
            {
                if (!Agents.ContainsKey(key))
                {
                    Agent newAgent = new Agent(this, agentBank, (string)obj.GetProperty("label"));
                    Agents.Add(key, newAgent);
                    consoleSession.HandleNewAgent(newAgent);
                }
            }
        }
예제 #2
0
        public MethodResult InvokeMethod(QMFObject obj, string name, List <object> args, bool synchronous, int timeToLive)
        {
            Broker aBroker = this.GetBroker(obj.BrokerBank());

            long seq = this.SendMethodRequest(obj, aBroker, name, args, synchronous, timeToLive);

            if (seq != 0)
            {
                if (!synchronous)
                {
                    return(null);
                }
                try {
                    aBroker.WaitForSync(timeToLive);
                } catch (Exception e) {
                    SequenceManager.Release(seq);
                    throw e;
                }

                // FIXME missing error logic in the broker
                return((MethodResult)SyncResult);
            }

            return(null);
        }
예제 #3
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 ;
 		}
예제 #4
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;
 }
예제 #5
0
        protected long SendMethodRequest(QMFObject obj, Broker aBroker, string name, List <object> args, bool synchronous, int timeToLive)
        {
            SchemaMethod method = obj.Schema.GetMethod(name);

            if (args == null)
            {
                args = new List <object>();
            }

            long seq = 0;

            if (method != null)
            {
                KeyValuePair <SchemaMethod, bool> pair = new KeyValuePair <SchemaMethod, bool>(method, synchronous);
                seq = SequenceManager.Reserve(pair);
                IEncoder enc = aBroker.CreateEncoder('M', seq);
                obj.ObjectID.encode(enc);
                obj.Schema.Key.encode(enc);
                enc.WriteStr8(name);

                if (args.Count < method.InputArgCount)
                {
                    throw new Exception(String.Format("Incorrect number of arguments: expected {0}, got{1}", method.InputArgCount, args.Count));
                }

                int argIndex = 0;
                foreach (SchemaArgument arg in method.Arguments)
                {
                    if (arg.IsInput())
                    {
                        ;
                        this.EncodeValue(enc, arg.Type, args[argIndex]);
                        argIndex += 1;
                    }
                }

                Message msg = aBroker.CreateMessage(enc, obj.RoutingKey(), timeToLive);

                if (synchronous)
                {
                    aBroker.SetSyncInFlight(true);
                }
                aBroker.Send(msg);
            }
            return(seq);
        }
예제 #6
0
        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);
                    }
                }
            }
        }
예제 #7
0
 public virtual void ObjectStatistics(Broker broker, QMFObject obj)
 {
 }
예제 #8
0
 public virtual void ObjectProperties(Broker broker, QMFObject obj)
 {
 }
예제 #9
0
 public BaseClass(QMFObject source)
     : base(source)
 {
 }
예제 #10
0
		public bool SelectMatch(QMFObject obj) {
			return true ;
		}
예제 #11
0
 public bool SelectMatch(QMFObject obj)
 {
     return(true);
 }
예제 #12
0
		public virtual void ObjectStatistics(Broker broker, QMFObject obj) {}
예제 #13
0
		public virtual void ObjectProperties(Broker broker, QMFObject obj) {}
예제 #14
0
		public MethodResult InvokeMethod(QMFObject obj, string name, List<object> args, bool synchronous, int timeToLive) {
			Broker aBroker = this.GetBroker(obj.BrokerBank()) ;
			
			long seq = this.SendMethodRequest(obj, aBroker, name, args, synchronous, timeToLive) ;
			if (seq != 0) {
				if (!synchronous) {
					return null ;
				}
				try {
					aBroker.WaitForSync(timeToLive) ;
				} catch (Exception e) {
					SequenceManager.Release(seq) ;
					throw e ;
				}
				
				// FIXME missing error logic in the broker
				return (MethodResult) SyncResult ;
			}
			
			return null ;
		}
예제 #15
0
        public void EncodeValue(IEncoder enc, short type, object val)
        {
            try {
                switch ((int)type)
                {
                case 1: enc.WriteUint8((short)val); break;                                 // U8

                case 2: enc.WriteUint16((int)val);  break;                                 // U16

                case 3: enc.WriteUint32((long)val); break;                                 // U32

                case 4: enc.WriteUint64((long)val); break;                                 // U64

                case 6: enc.WriteStr8((string)val); break;                                 // SSTR

                case 7: enc.WriteStr16((string)val); break;                                // LSTR

                case 8: enc.WriteDatetime((long)val); break;                               // ABSTIME

                case 9: enc.WriteUint32((long)val);   break;                               // DELTATIME

                case 10: ((ObjectID)val).encode(enc); break;                               // ref

                case 11:
                    if ((bool)val)
                    {
                        enc.WriteUint8(1);
                    }
                    else
                    {
                        enc.WriteUint8(0);
                    }
                    break;

                case 12: enc.WriteFloat((float)val); break;                                // FLOAT

                case 13: enc.WriteDouble((double)val);   break;                            // DOUBLE

                case 14: enc.WriteUuid((UUID)val); break;                                  // UUID

                case 15: enc.WriteMap((Dictionary <string, object>)val); break;            // Ftable

                case 16: enc.WriteInt8((short)val); break;                                 // int8

                case 17: enc.WriteInt16((int)val);  break;                                 // int16

                case 18: enc.WriteInt32(long.Parse("" + val)); break;                      // int32

                case 19: enc.WriteInt64(long.Parse("" + val)); break;                      // int64

                case 20:                                                                   // Object
                    // Check that the object has a session, if not
                    // take ownership of it
                    QMFObject qObj = (QMFObject)val;
                    if (qObj.Session == null)
                    {
                        qObj.Session = this;
                    }
                    qObj.Encode(enc);
                    break;

                case 21:                                                                     // List
                    List <object> items = (List <object>)val;
                    MSEncoder     lEnc  = new MSEncoder(1);
                    lEnc.Init();
                    lEnc.WriteUint32(items.Count);
                    foreach (object obj in items)
                    {
                        short innerType = Util.QMFType(obj);
                        lEnc.WriteUint8(innerType);
                        this.EncodeValue(lEnc, innerType, obj);
                    }
                    enc.WriteVbin32(lEnc.Segment().ToArray());
                    break;

                case 22:                                                                                                 // Array
                    List <object> aItems = (List <object>)val;
                    MSEncoder     aEnc   = new MSEncoder(1);
                    aEnc.Init();
                    long aCount = aItems.Count;
                    aEnc.WriteUint32(aCount);
                    if (aCount > 0)
                    {
                        Object anObj     = aItems[0];
                        short  innerType = Util.QMFType(anObj);
                        aEnc.WriteUint8(innerType);
                        foreach (object obj in aItems)
                        {
                            this.EncodeValue(aEnc, innerType, obj);
                        }
                    }
                    enc.WriteVbin32(aEnc.Segment().ToArray());
                    break;

                default:
                    throw new Exception(String.Format("Invalid Type Code: {0}", type));
                }
            }
            catch (System.InvalidCastException e) {
                string msg = String.Format("Class cast exception for typecode {0}, type {1} ", type, val.GetType());
                log.Error(msg);
                throw new Exception(msg + type, e);
            }
        }
예제 #16
0
		protected long SendMethodRequest(QMFObject obj, Broker aBroker, string name, List<object> args, bool synchronous, int timeToLive) {
			
			SchemaMethod method = obj.Schema.GetMethod(name) ;
			if (args == null) {
				args = new List<object>() ;
			}
			
			long seq = 0 ;
			if (method != null) {
				KeyValuePair<SchemaMethod, bool> pair = new KeyValuePair<SchemaMethod, bool>(method, synchronous) ;
				seq = SequenceManager.Reserve(pair) ;
				IEncoder enc = aBroker.CreateEncoder('M', seq) ;
				obj.ObjectID.encode(enc) ;
				obj.Schema.Key.encode(enc) ;
				enc.WriteStr8(name) ;
				
				if (args.Count < method.InputArgCount) {
					throw new Exception(String.Format("Incorrect number of arguments: expected {0}, got{1}", method.InputArgCount, args.Count)) ;
				}
				
				int argIndex = 0 ;
				foreach (SchemaArgument arg in method.Arguments) {
					if (arg.IsInput()) {;						
						this.EncodeValue(enc, arg.Type, args[argIndex]) ;
						argIndex += 1 ;
					} 
				}
				
				Message msg = aBroker.CreateMessage(enc,obj.RoutingKey(),timeToLive) ;
				
				if (synchronous) {
					aBroker.SetSyncInFlight(true) ;
				}
				aBroker.Send(msg) ;
			}
			return seq ;
		}
예제 #17
0
		public void UpdateAgent(QMFObject obj) {
			long agentBank = (long)obj.GetProperty("agentBank") ;
			long brokerBank = (long)obj.GetProperty("brokerBank") ;
			String key = Agent.AgentKey(agentBank, brokerBank) ;
			if (obj.IsDeleted()) {
				if (Agents.ContainsKey(key)) {
					Agent agent = Agents[key] ;
					Agents.Remove(key) ;
					consoleSession.HandleAgentRemoved(agent) ;
				}
			}
			else {
				if (! Agents.ContainsKey(key)) {
					Agent newAgent = new Agent(this, agentBank, (string)obj.GetProperty("label")) ;
					Agents.Add(key, newAgent) ;
					consoleSession.HandleNewAgent(newAgent) ;
				}
			}
		}
예제 #18
0
 public DerivedClass(QMFObject source)
     : base(source)
 {
 }
예제 #19
0
 public ExampleService(QMFObject source)
     : base(source)
 {
 }