HiveMind

xiaoxiao2021-03-06  58

Today, HiveMind 1.0's Final version came out, and looked at his Examples code. After IOC (DI) feel, look at these code, the more you feel, the more clear it. Implementing an IOC container itself is nothing to say, now take a look at the implementation of HiveMind as an example.

The EXAMPLE program is a class of four computational classes. Basically, the EXAMI is to make an additional and subtraction, implement it; Caculator inherits the addition and decrease and division interface, during operation, specific addition and subtraction The class is injected into the CaculatorImpl via HiveMind, and of course CaculatorImpl is also generated through the Caculator interface. The following is his specific code:

Double arg0 = double.parsedouble (args [0]); double arg1 = double.parsedouble (args [1]);

Registry Registry = ExampleUtils.buildRegistry ("eXamples.xml");

// Since We know There's exactly * One * Service-Point Implementing Calculator, // We Can Get It this Way, And NEVER HAVE TO KNOW ITS Service ID.

Calculator Calculator = (CALCULATOR) Registry.getService (Calculator.class);

System.out.println ("INPUTS:" Arg0 "and" arg1); System.out.Println ("Add:" Calculator.Add (arg0, arg1)); System.out.Println ("Subtract: " Calculator.Subtract (arg0, arg1)); System.out.Println (" Multiply: " Calculator.Multiply (arg0, arg1)); System.out.Println (" Divide: " Calculator.divide (arg0, Arg1)); registry.shutdown ();

Well, registry registry = example ("eXamples.xml"); this statement seems to be initialized from Examples.xml and establishing correspondence, the internal probably defined interceptor, factory, initialization Method and the like, don't look. The registry here should be equal to the ApplicationContext in Spring, the Configuration in Pico. I have no other things in this regard of IOC containers, I have to have a global thing holding these managed classes.

The following registry.getService (Calculator.class); looks more than Spring AppconText.getBean (Beanid), can use Class as a parameter to take out the object without the only premise of the entire configuration file guarantee the excuse. Of course, Spring can do this, just see Mr. Johnson is unhappy.

The Caculator interface inherits the increment and deletion of change the interface (that is, four interfaces containing one method). Take a look at the Examples.xml configuration:

... Other operation omitted <-! Most properties are autowired by the BuilderFactory ->

Take a closer look at this configuration file, you can see some interesting things: Service-point is undoubtedly equal to the bean in Spring. (HoWard comrade has always been known for a long configured name, this can be confirmed in Tapestry's configuration file, but it seems to be a little longer than Spring's long package name and constant name, huh, Id, Interface ... Wait, it seems that HLSHIP does not encourage the use of specific classes in this container, see the definition of the DTD file:

[Parameters-schema] [CREATE-INSTANCE] [Invoke-factory] [Interceptor]

There is really no Class this property ... Is this still good? ... don't know, is there a system that is completely interfaced? This question is temporarily do not want to say later. There is nothing to say, see should be created an instance of org.apache.hivemind.examples.impl.adderImpl, From DTD, he allows you to create the form of Primitive, Singleton, Threaded, Pooled. By default, you will create an instance every time you call, I guess. Then use an interceptor (Loggin Interceptor). Here, there is a place that is convenient than Spring. Interceptor can be directly defined (I don't know how to say it, use bean or service-point?) Component's inside, with Spring, you have to build another new bean, Then specify the scope of Advice. If there is only one or two places in the system, one of more beans is a bit indecent. I remember that XWork is also defined in Interceptor.

The following is a bit meaningful to create an instance in accordance with the factory form.

<-! Most properties are autowired by the BuilderFactory ->

First look at the implementation of CaculatorImpl: Public Class CalculatorImpl Implements Calculator {Private Adder_adder; Private Subtracter_Subtracter; Private Multiplier_Multiplier; Private Divider_divider;

Public Double Add (double arg0, double arg1) {return _adder.add (arg0, arg1);}

... The following reduction is not written, similar

... a pile of setter / getter will not write}

Just started to be surprised, in my feelings, how to say that there should be an input parameter, just below: ...

Take a look at his comment: Most Properties Are AutoWired by the BuilderFactory, see if he defokes the same ID in the builderFactory to the construct, this convenience is necessary? After all, it is traversing a class of SET methods, judging the type required by the method, looking for Service-Point in Registry and injected, which is required for the price ... did not want to clear, temporarily put down.

Exterior: I haven't followed HiveMind's version change, but in my memory, a RC version of 1.0 converts the configuration file to howard comrades I invented Simple Data Language, in fact, HLSHIP has organized a set according to Javacc. Grammar, then rewrite all profiles in this grammatical ... There is not much day, this thing is dropped by Pass. Until now, I still doubt what the motivation of him is the best that I feel most interesting is: Howard sees Javacc very powerful, can easily define a new syntax and resolved, with Tapestry brand new Creative Howard, I added this stuff when I heated it, just ... huh

HiveMind has some other features, such as all documents generated by the system (this feature Spring plus it) and some of the other convenient features. Howard has repeatedly emphasized that hivemind is a Micro Kernel's framework, but in my opinion, he is a new, which is more convenient, fully interface, IOC-based container.

转载请注明原文地址:https://www.9cbs.com/read-113396.html

New Post(0)