Well-designed server II-stand on JBoss microkernel

Source: Internet
Author: User
Tags jboss mule esb

Original article address: Workshop. -- Jiangnan Baiyi

A Java World Service Processing Server Always meets the javaee specifications of JNDI/JMX/JMS/JTA/Web Service/RMI/CORBA/EJB/clustering. Geromino has made great achievements by following the flourishing Java open-source community and using JDK + open-source implementation to piece together the specifications encountered. You can also build the service engine on JBoss like some European telecom companies, and directly add the required components to the JBoss package. You can concentrate on the core business processing engine.

The Application Server accepts three standard deployment types: Web, EJB, and JCA. The Web and EJB are obviously not suitable. The JCA mode used by mule and Apache cxf is hard to understand. Therefore, just like those European telecom companies, they can write their own services on JBoss microkernel.

In the JBoss document, there is a chapter to compile the Custom Service tutorial. in JBoss, almost every part is to compile the service example, such as the JNDI namingservice.

I. JBoss JMX microkernel Architecture

Speaking of kernel and container, Now humans always think of spring. The configuration files are similar. If the core of spring iner is to use a singleton hashmap to load all managed beans, the microkernel uses a JMX mbeanserver.

All objects in microkernel can be managed by the JMX client-JMX is simply a server program. However, the JMX standard does not define dependency management, who depends on, who is injected, who needs to initialize before, and Java's life cycle functions only have one way to build functions, no constructor is supported. Therefore, microkernel is similar to spring container. Based on JMX, it provides dependency management, dependency injection, and lifecycle management functions.

Let's take a look at the JBoss architecture;

1. /LIB contains a small number of public jar files, and the three directories under/Server are three pre-boot configurations. JBoss is fully modular based on microkernel, so minial is a micro-kernel with only the JNDI function, default is the service required by a single server, while full is added with the cluster function. You can increase or decrease the number at Will on the basis of the three types.

2. Run-C minimal in BIN to start the microkernel example.

3. According to the description of startup process, it is easy to understand the startup process with the source code. (BTW, the most dynamic time for most people to read the source code is to look at the START process)

4. Check the minimal directory. The deploy directory is empty, indicating that no additional service is deployed. Let's take a look at the jboss-service.xml under/Conf, which defines four components: log4jservice, basicthreadpool, namingservice, and urldeployment.pdf.

So is clear, so is simple, and then, to ourselves.

2. compile your own service

Here we only use the simplest way to introduce the simplest example. Use the injected JBoss basicthreadpool to open a thread that does nothing.

1.Helloservicembean InterfaceDefines two injection functions. Classes in JMX are processed by mbean exposed interfaces.

Public interface helloservicembean extends org. JBoss. system. servicembean {
Public void setservicename (string servicename );
Public void setthreadpool (basicthreadpoolmbean poolmbean );
}

 

2. helloservice classTo implement the helloservicembean interface. inherited from the convenience class servicembeansupport provided by JBoss, you only need to reload the startservice () and stopservice () functions.
The startservice () function uses the inherited logger to print the servicename of the injection and uses the injection threadpool to open a working thread. The stopservice () function is empty because no system resources need to be returned and cleared.

Import org. JBoss. system. servicembeansupport;
Import org. JBoss. util. threadpool. basicthreadpoolmbean;
Import org. JBoss. util. threadpool. threadpool;

Public class hellosimpleservice extends servicembeansupport implements
Helloservicembean {

Private string servicename;

Private threadpool;

Public void setservicename (string jndiname ){
This. servicename = jndiname;
}

Public void setthreadpool (basicthreadpoolmbean poolmbean ){
Threadpool = poolmbean. getinstance ();
}

Public void startservice () throws exception {
Log.info ("starting" + servicename );
Threadpool. Run (New hellothread ());
}

Public void stopservice (){
Log.info ("stoping" + servicename );
}

Private class hellothread implements runnable {
Public void run (){
Log.info ("Hello thread start ....");
For (;;){

}
}
}
}

 

3. hello-service.xml, A typical bean configuration file. Note that servicename and threadpool must have an upper-case initial character.

<? XML version = "1.0" encoding = "UTF-8"?>
<Server>
<Mbean code = "helloservice"
Name = "Hello: service = helloservice">
<Attribute name = "servicename"> helloworldservice </attribute>
<Depends optional-Attribute-name = "threadpool"
Proxy-type = "attribute"> JBoss. System: service = threadpool </depends>
</Mbean>
</Server>

Good, now the two java files compiled into jar, and the hello-service.xml into the minimal/deploy directory will be hot depoy, JBoss on the screen can see the "Starting helloworldservice ".

Later I tried JBoss's jnp Naming Service, registered a helloworld RMI service, and called it on the client. But how to deeply apply other components of JBoss still needs to be studied ....

References:

  • JBoss wiki -- JBoss microkernel
  • JBoss wiki -- JBoss services

Well-designed Server Series articles:

  • Design a beautiful server-Mina, cxf, mule, JBoss/Geronimo
  • Well-designed server II-stand on JBoss microkernel
  • Lightweight, all users will write the service solution-rest and JSON
  • Well-designed server (4) -- Mule ESB notes

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.