Openfire source code analysis

Source: Internet
Author: User
Tags subdomain
Openfire source code analysis 1. openfire

Openfire is an open-source Real-time Collaborative server (RTC). It is based on public XMPP (also known as jabber) messages. The core functions of openfire include connection management, message parsing, message routing, and message sending.

1.1 framework

The core function of openfire is composed of modules, and most of the modules are implemented based on modules. To dynamically manage these modules, openfire uses its class loader jiveclassloader to install, uninstall, and reload modules without restarting the system.

1.2 Module

Openfire loads all modules at startup. These modules provide the core functions of openfire.

All modules need to implement the module interface, which defines the methods to be called in the module lifecycle, as shown in:

1.3 Data Streams

2. openfire and Mima

Mina is a project under the Apache organization. It helps you easily develop high-performance and highly scalable network applications. Mina provides an abstract, asynchronous event-driven API that supports various transmission protocols (such as TCP/IP and UDP/IP) and Java NiO.

The connectionhandler class of openfire inherits the iohandleradaper class of Mina, which is mainly responsible for creating and destroying connections and receiving XML data packets for delivery. Connectionhandler has three sub-classes. clientconnectionhandler connects the client to the server, and componentconnectionhandler connects the component to the server.

3. Multi-User-chat

Multi-User chat messages are bound to the subdomain conference, and the corresponding component is multiuserchatserviceimpl. In multi-user chat, the entities and relationships involved include users, chat rooms, and users and chat rooms. multiuserchatserviceimpl maintains these entities and relationships and delivers messages.

3.1 mucuser

Mucuser is an abstraction of the users involved in group chat. It is used to interact with the chat server, such as sending and receiving chat information.

3.2 mucrole

Defines the relationship between mucroom and mucuser. The same mucuser can have different roles in different mucroom.

3.3 mucroom

Contains basic information about the chat room, including the participants and chat records.

3.4 multiuserchatserviceimpl

Manage all chat rooms and distribute messages.

3.5 Sequence Chart

4. Pub-sub

Publish and subscribe messages are bound to the sub-domain pubsub, and the corresponding module is pubsubmodule.

4.1 Node

A virtual node in the publish/subscribe system that can receive or publish various types of information or notifications. It is often called a topic in other publishing and subscription systems.

Collectionnode can contain subnodes. The subnode type can be collectionnode or leafenode. This type of node cannot be the target node for publishing and subscription. leafenode cannot contain subnodes, it can be used as the target node for publishing and subscription.

4.2 nodeaffiliate

Defines the relationship between users and nodes, including ower, publisher, none, and outcast.

4.3 nodesubtasks

A user can subscribe to a node multiple times. Different configurations (such as different filter keywords) are used for each subscription. nodesubscribe describes these subscriptions and configurations. If a message satisfies the user's multiple subscriptions, only one message is delivered to the user, rather than multiple.

4.4 pubsubmodule

Pubsubmodule is responsible for node management, maintenance of publishing and subscription relationships, and message distribution.

4.5 pubsubengine

Processes publish and subscribe data packets.

4.6 Sequence Chart

5. Plug-in development

In openfire, plug-ins can directly use all openfire APIs, which provides great flexibility for plug-in functions.

5.1 register as a component

Register a plug-in as a component that can receive all data packets sent to a specific subdomain. For example, the above component multiuserchatserviceimpl can receive all data packets sent to the Conference subdomain. All components are managed by the internalcomponentmanager module.

Initialize the testcomponent instance in the initializeplugin method of testplugin, and call internalcomponentmanager to register the initialized instance to the target subdomain, so that the testcomponent component can receive and process messages sent to the target subdomain.

5.2 register as an interceptor

Register a component as an interceptor, which can receive all data packets and discard them at will.

Initialize the component in the initializeplugin method of testplugin and call interceptionmanager to register the Interceptor to the global interceptor. In this way, all messages are processed through interceptpacket.

5.3 register as iqhandler

Register the plug-in as iqhandler, and the data packets associated with the namespace of the plug-in will be handed over to the plug-in for processing.

In the initializeplugin testiqhandlerplugin, initialize testiqhandler and register it in iqrouter. Iqhandlerinfo indicates the namespace of the IQ message processed by the iqhandler.

Transferred from: I'm bitiliu-openfire source code analysis

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.