Vernacular oriented agent oriented (PROGRAMMIG, AOP) IV

Source: Internet
Author: User
Tags aop
I've been working on all sorts of interesting, hard, boring, and hard things over the years, and while switching to many different areas of technology, I haven't given up on AOP concerns. The reason why I did not continue to talk about AOP is because I feel like I don't have enough energy and free time to settle these thoughts, and to make it simple, easy to digest and understand, and to cause thinking. These days, travel outside, work away from the kitchen stove inside and outside busy. Smoke smell less, people also feel refreshing a lot; If you have more spare time, you will inevitably want to climb jungle gym. OK, here we go, let's move on to AOP. J   Briefly review the previous journey (A, two, iii), in which we briefly describe what an agent is, the origin of this dongdong, and the differences from other important concepts, such as object. If the fantastic scenery of the previous theory journey is rippling, then the next practice trip will drag us back into the complex and sophisticated software world. As mentioned earlier, there seems to be no IDE dedicated to AOP at the moment, which is a modest embarrassment for a comrade eager to practice AOP. But fortunately the agent is also derived from object, based on the current OOP language, we can also come to an AOP addiction. Here we choose C # under the. Net Platform. Why Choose C #,,,, because if you use Java, the article will not be here, just jokingj  theoretically, any OOP language, Java, Delphi, C + +, can be used as a magic wand in Harry Potter's hands, To give a wonderful agent. The reason to choose C #, is to see his elegance and simplicity (added, until now I still stubbornly believe that Delphi is the most elegant language, although Borland forced to sell the entire IDE department, but I still determined to watch Delphi, Until the last moment when Delphi's mast sinks to sea level ...)   The book on the agent theory can be found, a theoretical acceptance of the agent needs to have the following characteristics:   l           Agent (Action on behalf others) l          self-control (Autonomy)   L           Initiative (proactivity)   l           reactivity (reactivity) l          sociality (Social ability)   L           Intelligence (Intelligence)   l           Cooperative (callaboration)   l          Mobility ( Mobility)   My god! It is a big head to understand these nouns all over again. No more explanations. Simple point, simplicity is good. We do not now need to cater to the theorists ' picky tastes, but to create an agent with an incomplete character. Nu wa classmate when making people is not local materials, holding a lump of mud on the j  on the other hand, as the creator of the whole Agentworld, we must realize that these characteristics are layered, such as reactivity, and self-control, which should be located in the Agent Mind ( Mind) at the bottom of the property; and sociality, intelligence, cooperation and so on, it should belong to the senior agent of the mind, the need for other mental capacity support. In the first step from chaos to open heaven and earth, we only need to realize the lowest agent mind .    synthesis above, in the first agent we pinch, we can see the following kinds of mind: l           synchronous asynchronous unification and peer group l          perception of changes in the world L           Time DriveMobile l          Mobility   Below we examine these seemingly simple mental elements that may contain infinite combinations and evolutionary energies.
synchronous asynchronous unified and homogeneous groups In front of the chat to say, we have realized that the object world exists "synchronous and asynchronous is artificially stripped" embarrassment, "synchronous asynchronous unified and homogeneous group" is the agent world to this embarrassing solution. In our agent world, Agent A1 calls Agent A2 to help it do some work M1, do not need to understand A2 do this thing is synchronous or asynchronous in doing, this is synchronous asynchronous unification; Further, if this matter, and A2 have the same ability of several agents can do, then A1 not need to know exactly which specific "A2" is doing this work. A little abstract, huh? OK, this is like an example in real life: the leader said "10 o'clock in the morning let the driver come to pick me up to meet". The leader as an agent, he does not need to know the driver of this agent 10 o'clock to the downstairs is synchronous behavior or asynchronous behavior (of course, the driver himself to be clear), also do not need to know who drove over to the unit of the driver, Xiao Wang or Xiao Zhang? Is that what the leader needs to be concerned about? All he needs to know is that he's downstairs at 10 and there's a driver waiting there. Use the program language to describe:   Boss's execution code is: driver. Comehere (10:00)   Driver code: Class Driver:agent_xxx {       [agentmethod ( Agentmethodcallmode.asyn, Agentmethodroutemode.group)]        public virtual void Comehere (DateTime time) {...}        ...}   Ok, let's focus all our attention on the blue attribute, which is the intellectual embodiment of the driver in "synchronous asynchronous unification and peer group". Why we just said to choose the elegant language of C # is because we can use attribute to attach the agent's mind to the normal object class. Of course, we can also use an additional XML file that describes the mental elements to bind to class, but in personal sense, the attribute comes in a more elegant and straightforward .    Agentmethod, which indicates that ComeHere This method is an ability to driver this agent, and attention is the ability not the mind. This ability brings specific mental information:   l          agentmethodcallmode.asyn 
This attribute indicates that this ability is invoked asynchronously, rather than synchronously. See here some comrades unavoidably suspicion, not to say synchronous and asynchronous no longer distinguish, how still have Asyn, syn such mark? Upset! To explain, what we call synchronous and asynchronous no longer distinguishes between, is from the caller's perspective, such as the leader of the driver, the teacher to the students. And for the caller of the method, the actual executor, of course, he needs to "inwardly" know how the method is done. In fact, after the leader calls Driver.comehere (10:00), the mind that the leader has, that is, the thread can immediately go on to do other things, and Comehere (10:00) is transferred to the mind of a driver instance, the thread that executes.

A small difference here, in fact, highlights a big difference between agent and object: In the agent world, each agent only needs to focus on how its logic executes, while the attention to the logical execution details of other agents is minimized.

If a comrade feels that the above phrase is too abstract, OK, let us repeat the more technical language: each agent with a separate thread (we can interpret it as the agent's Soul J), each agent's own capabilities (in the OOP language environment is mapped to method) are interpreted and executed on this thread. If a sequence of behaviors contains the execution of the ability of several different agents, the completion of this sequence of actions will use several different threads, and the switch between threads is completely transparent and automatic.

Deep into the technical details, let us quickly float to a more macroscopic level, otherwise soon will be in the technical details of the inquiry to lose the ability to grasp the agent design concept. Now we know that an agent, the power it has (that is, various method) can only be executed by the soul it owns (that is, its exclusive thread). So the obvious question is: what kind of benefits does this bring?

L Agentmethodroutemode.group.
This attribute indicates that the boss wants a car, and this request is a group request, not a specific instance of a driver class. This request is placed in a request pool based on a group (i.e., a class of agents with common capabilities), assuming that the unit has three drivers idle, and one of them will accept the request and then execute it. This should be a very simple implementation of the Blackboard model in the agent theory: what is the request, write to a blackboard, have the ability to respond to the request, to deal with, and to erase the request from the blackboard.

You can imagine the use of this mind. Let's go to the real world and find out if there is such an example in the real world. Large presence, bank counter business, overtime shopping settlement. And then back in the software world, it's easy to think of a word: Load Balancing J If the agent has a certain capability (capable of performing some key business operation), it is distributed across several different machines across the system, sharing the same group request pool, through the mobility mind (which will be introduced later). After the incoming business operation request enters the request pool, it is processed by the agent on the different machines. Load Balancing J Of course, who says that the banking system is not load balanced now? Our emphasis here is to achieve the simplicity of load balancing in the agent world. Only one attribute is needed, and since the underlying group request pool is automatically constructed by the system, if a further balance is needed, only a few more driver are needed, and moving them to different machines is like seeing more people queuing up in the bank, Adding a few business windows on a temporary basis is the same. It is important that the agent world can be realized in the OBEJCT World or assembly world, and we value the simplicity of implementation (laziness?). To the extent that the real world is close.

There are several combinations of agentmethod, which are not covered here, and the discussion of getting into the details of coding will inevitably hinder our grasp of the concept as a whole. But here have to explain is, assume boss need driver in reach after inform him, how should realize?  Because of the constraints of OOP, we have to use a rather less elegant way: A callback function to solve this problem. Thus, in the boss this agent class will appear the following code: [Callbackmethodattribute (typeof (Driver), "Comehere")] public virtual void Callback_driver   _comehere (Message_resultofasyncallmethod message) {...} The callbackmethodattribute here shows that when a driver reaches the downstairs, it automatically calls this method (transparent to both driver and boss). Note that this method is performed in the boss's mind, not by Driver, that is, the system will automatically perform the comehere operation in the Driver thread, and then automatically switch to the boss's thread to perform the Callback_driver_ Comehere. Imagine why and why is this so? J

Or we're going to be here today, and if you're interested, in the following chapters, we'll talk about more fun topics like perception, time-driven, and mobility. The whole point Small study questions, note that each method of the agent class with a virtual indicator, why? Borrow a WORD from the matrix: "There is something different." In fact, all the things we talked about, including most of the agents that we saw in the future, are located above the water level, and down this secret clue, You will be able to touch the large and sophisticated supporting architecture of agent world under the water level. Under the water, there is no landscape, only high-speed running scheduling threads, soaking up busy buffer pools, Zhang He ordered read and write locks, and ubiquitous bugj

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.