OpenCms release process in-depth study

Source: Internet
Author: User

Introduced:

Compared to the creation of resource, the publishing process is much more difficult, I last week in the support team when I imagined not through the debugger, light day code to understand the mystery, and later because the stack is too deep to give up, now with the debugger, finally the details to figure out, it is very complex.


Detail Analysis:

When releasing resource, its entry is the Actionpublish () method of the Cmspublishproject class, the publishing process is complex to metamorphosis, fully packaged in the Performdialogoperation () method:

/**     *  @seeorg. Opencms.workplace.cmsmultidialog#performdialogoperation ()      */   protected boolean performdialogoperation ()   throws cmsexception {         cmspublishlist  Publishlist =getsettings (). Getpublishlist ();        if  ( Publishlist == null) {             Thrownew cmsexception (Messages.get (). Container (                 org.opencms.db.Messages.ERR_GET_PUBLISH_LIST_PROJECT_1,                 getprojectname ()));         }         Opencms.getpublishmanager (). Publishproject (  &NBSp;         getcms (),             new cmshtmlreport (GetLocale (), Getcms (). Getrequestcontext (). GetSiteRoot ()),             publishlist);         // wait 2 seconds, may be it finishes fast         opencms.getpublishmanager (). waitwhilerunning (; )        returntrue;}

On the macro level, it gets the list of publications for all resources in workplace, because in this case there is only one resource, so the list of debugs is as follows:

[Publish of project:ae97ff1d-7824-11e4-8c0e-28e347ffa92bpublish history id: f5d6e16a-787e-11e4-8289-28e347ffa92bresources: [[org.opencms.file.cmsresource, path:/sites/default/ Charles_study/publish_test1, structure idea051006-787e-11e4-8289-28e347ffa92b, resource id : Ea051007-787e-11e4-8289-28e347ffa92b, type id: 1, folder: false, flags: 0, project: ae97ff1d-7824-11e4-8c0e-28e347ffa92b, state: 2, date created: sun  Nov30 18:52:01 cst 2014, user created: c300ba5c-01e8-3727-b305-5dcc9ccae1ee,  datelastmodified: Sun Nov 30 18:52:09 CST 2014, user  lastmodified:c300ba5c-01e8-3727-b305-5dcc9ccae1ee, date released: thu jan 01  08:00:00 cst1970, date expired: sun aug 17 15:12:55 cst 292278994 ,  date content: sun nov 3018:52:01 CST 2014, SIZE: 0, SIBLING COUNT: 1, VERSION: 1]] Folders: []deletedfolders: []]

Second, it works with the Cmspublishmanager Publishproject () method to publish the resources for the list to be published.

Cmspublishmanager calls the Cmssecuritymanager's Publishproject () method and eventually calls the Cmsdrivermanager's PublishObject () method to do all the work on the publication. That's the point we're going to talk about.



Focus on 1: Study the release process from Cmsdrivermanager's PublishObject () method.

The release process code is also very deep, from a macro perspective, it does so a few things:

A. check the parent directory, which is used primarily for situations where the parent directory of the asset has not yet been published.


B. initiates a pre-release event (beforepublishevent) for the Cmsevent class that contains projectid in addition to the list of published resources above (Publishlist). DbContext and an empty Publish Report object (Cmshtmlreport, which stores the error that failed to publish), the data in this event is as follows:

{Publishlist=[publish of project: ae97ff1d-7824-11e4-8c0e-28e347ffa92bpublish history  id: c0488fed-7882-11e4-8289-28e347ffa92bresources: [[org.opencms.file.cmsresource, path:/ sites/default/charles_study/publish_test4, structure idbb3dab29-7882-11e4-8289-28e347ffa92b,  Resource id:bb3dab2a-7882-11e4-8289-28e347ffa92b, type id: 1, folder: false,  flags: 0,project: ae97ff1d-7824-11e4-8c0e-28e347ffa92b, state: 2, date  created: sun nov30 19:19:21 cst 2014, user created:  C300ba5c-01e8-3727-b305-5dcc9ccae1ee, datelastmodified: sun nov 30 19:19:24 cst  2014, user lastmodified:c300ba5c-01e8-3727-b305-5dcc9ccae1ee, date released:  thu jan 01 08:00:00 cst1970, date expired: sun aug 17  15:12:55 cst 292278994, date content: sun nov 3019:19:21 cst 2014, size: 0, sibling count:  1, version: 1]]folders: []deletedfolders: []], [email protected],[email  PROTECTED],PROJECTID=AE97FF1D-7824-11E4-8C0E-28E347FFA92B}

Then use the Cmseventmanager firecmsevent (beforepublishevent) method to perform this release event.

Because a release of a resource affects the update of other components of OpenCms, the "Observer" design mode is used here, and the other components of multiple CMS are added to the Cmseventmanager listener list, with hundreds of listeners, which I don't list.


C. Lock the resources in all published lists with the release lock Cmslock.


d. Call Cmspublishengine's Enqueuepublishjob () method to record the published scheduled task and produce a specific release report. specifically:

    1. It creates a concrete Cmspublishjobinfobean object that contains all the details required for publishing:

[Org.opencms.publish.CmsPublishJobInfoBean, History id:c0488fed-7882-11e4-8289-28e347ffa92b, Project IDAE97FF1D-7824-11E4-8C0E-28E347FFA92B, Project Name:offline, user id:c300ba5c-01e8-3727-b305-5dcc9ccae1ee, Locale: En, flags:0, size:1, Enqueue time:0, start time:0, finish time:0]

2. Call Cmspublishqueue's Add method to add the Publish Job object, where it calls the Cmsdrivermanager Createpublishjob () method to create a specific publish job. Finally, the Cmsprojectdriver class's Createpublishjob () method is called to do a specific database-level operation.

The last SQL statement to execute is:

INSERT into Cms_publish_jobs (history_id,project_id,project_name,user_id,publish_locale,publish_flags,resource_ count,enqueue_time,start_time,finish_time,publish_list) VALUES (' 6709c8a5-7887-11e4-8289-28e347ffa92b ', ' ae97ff1d-7824-11e4-8c0e-28e347ffa92b ', ' Offline ', ' c300ba5c-01e8-3727-b305-5dcc9ccae1ee ', ' en ', 0,1,1417348377907,0,0,x ' Aced00057372001d6f72672e6f70656e636d732e64622e436d735075626c6973684c697374dc35dfb34a32e7310c0000787077486709c8a5788711e48 28928e347ffa92bae97ff1d782411e48c0e28e347ffa92b0000000000000001ffffffff000000016244c681788711e4828928e347ffa92b0000000000 00000078 ')

So from here, it will update the Cms_publish_jobs table, the release of a number of information, such as the release history ID, Project ID, name, user ID, publish internationalization flag, into the release queue time, release start time, end time, and the list of publications are inserted into the database.

3. Call Cmspublishlistenercollection's fireenqueued () method to notify all listener components of this release event, if the publishing process fails, You can get the release error message from the Cmspublishjob publishreport.


E. Call the Checkcurrentpublishjobthread () method to do a specific site release. because this is a multi-threaded operation and not go down, so the start of several debugging each time can not find the execution point, and later study, found that the specific site release code in the Cmspublishthread run (), It will eventually call the Cmsprojectdriver class's Publishproject () method to perform a specific publication.

    1. It first calls Cmshistorydriver's Writeproject () method to write the specified project to the cms_history_projects and Cms_history_projectresources tables:

Write a entry in the Publish Project Logm_drivermanager.gethistorydriver (DBC). Writeproject (DBC, Publishtag, System.currenttimemillis ());

The SQL statements written to the Cms_history_projects table are as follows:

Nsert into Cms_history_projects (publish_tag,project_id,project_name,project_publishdate,project_published_by, User_id,group_id,managergroup_id,project_description,date_created,project_type,project_ou) VALUES (62, ' ae97ff1d-7824-11e4-8c0e-28e347ffa92b ', ' Offline ', 1417354083096, ' c300ba5c-01e8-3727-b305-5dcc9ccae1ee ', ' C300ba5c-01e8-3727-b305-5dcc9ccae1ee ', ' 6dfffebb-0985-3cbd-8d53-a5df8681a9f3 ', ' 4d9b473f-3b73-34f7-b80c-15f068c3b2be ', ' theoffline Project ', 1417305967147, 0, '/')

The SQL statements written to the Cms_history_projectresources table are as follows:

INSERT into Cms_history_projectresources (Publish_tag,project_id,resource_path) VALUES (62, ' ae97ff1d-7824-11e4-8c0e-28e347ffa92b ', '/')


2. It executes specific content changes that traverse the publication list publishlist, and then publish the directories and files separately, where the directories are listed earlier. For the publication of a directory, it is implemented by invoking the following code:

Projectdriver.publishfolder (                             dbc,                              report,                              ++publishedFolderCount,                             foldersSize,                              onlineProject,                             new  Cmsfolder (CurrentFolder),                              Publishlist.getpublishhistoryid (), Publishtag);

And for the publication of a file, it is implemented by calling the following code:

Projectdriver.publishfile (                         dbc,                         report,                          ++publishedFileCount,                         filessize,                          onlineProject,                         currentResource,                          publishedcontentids,                         publishlist.getpublishhistoryid (), PUBLISHTAG);



Focus on 2: The process of publishing files (in fact, the publishing directory is almost the same, just because I use the file as an example, so only to debug the release details of the file)

In general, the Publishfile () method of the Cmsprojectdriver class calls the Publishnewfile () method of the Cmsprojectdriver class, In turn, the Cmsprojectdriver class's Publishfilecontent () method is called to perform the specific release, with the following steps:

A. Get the contents of a given ResourceID from the Cms_offline_contents table.

Byte[] offlinecontent= m_drivermanager.getvfsdriver (DBC). ReadContent (DBC, Projectidforreadi Ng, Offlineresource.getresourceid ());

The SQL statement that it executes is:

SELECT cms_offline_contents. File_content fromcms_offline_contents wherecms_offline_contents. Resource_id= ' d46e46f4-7893-11e4-8289-28e347ffa92b '


B. Build the Offlinefile from the resource in the previous step and clone to NewFile.

Create the file online NewFile = (cmsfile) offlinefile.clone (); newfile.setstate (cmsresource.state_unchanged);


c. Create the online resources and online structure of the CMS. Use the following code :

Update the Online/offlinestructure and resource records of the file M_drivermanager.getvfsdriver (DBC). Publishresource (DBC, Onlineproject, NewFile, Offlinefile)

The SQL statement where update cms_online_resources is as follows:

INSERT into Cms_online_resources (resource_id,resource_type,resource_flags,date_created,user_created,date_ Lastmodified,user_lastmodified,resource_state,resource_size,date_content,project_lastmodified,sibling_count, resource_version) VALUES (' d46e46f4-7893-11e4-8289-28e347ffa92b ', 1,0,1417353704758, ' C300ba5c-01e8-3727-b305-5dcc9ccae1ee ', 1417353704758, ' c300ba5c-01e8-3727-b305-5dcc9ccae1ee ', 0,0,1417353704758, ' Ae97ff1d-7824-11e4-8c0e-28e347ffa92b ', 1, 1)

The SQL statements that update cms_online_structure are as follows:

INSERT into Cms_online_structure (structure_id,resource_id,resource_path,structure_state,date_released,date_ expired,parent_id,structure_version) VALUES (' d46e46f3-7893-11e4-8289-28e347ffa92b ', ' d46e46f4-7893-11e4-8289-28e347ffa92b ', '/sites/default/charles_study/publish-test-11 ', 0,0,9223372036854775807, ' 4bf8b750-785d-11e4-8289-28e347ffa92b ', 0)


d. Next, update the version number of the CMS online resources and online structure . Use the following code:

Update version numbers m_drivermanager.getvfsdriver (DBC). Publishversions (DBC, Offlineresource,!alreadypublished) ;

The SQL statement where the version number of the Cms_online_resources is updated is as follows:

UPDATE cms_online_resources SET resource_version = 1WHERE cms_online_resources. resource_id = ' d46e46f4-7893-11e4-8289-28e347ffa92b '

The SQL statements that update cms_online_structure are as follows:

UPDATE cms_online_structure SET structure_version = 0 wherecms_online_structure. structure_id = ' d46e46f3-7893-11e4-8289-28e347ffa92b '


E. Create the contents of the online file. Use the following code:

Create/update the Content M_drivermanager.getvfsdriver (DBC). Createonlinecontent (DBC, of                Flinefile.getresourceid (), offlinefile.getcontents (), Publishtag, True, Needtoupdatecontent);

It executes the following SQL statement:

INSERT into Cms_contents (resource_id,file_content,publish_tag_from,publish_tag_to,online_flag) VALUES (' d46e46f4-7893-11e4-8289-28e347ffa92b ', X ', 62,62,1)


F. Create properties information for the online file. Use the following code:

M_drivermanager.getvfsdriver (DBC). Writepropertyobjects (DBC, Onlineproject, NewFile, offlineproperties);

It will write the cms_online_properties file, because my published file is not configured with properties, so the debugger skipped this section.


G. Write a new online access control list. Use the following code:

M_drivermanager.getuserdriver (DBC). Publishaccesscontrolentries (DBC, Dbc.currentproject (), Onlineproject, Offlineresource.getresourceid (), Newfile.getresourceid ());

It will eventually go to write Cms_online_accesscontrol.


Finally, the publishing process succeeds, and the front end will have a modal dialog box summarizing the release:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/54/2E/wKioL1R7MsuzvdQlAACaoSaMPRs080.jpg "title=" 35.png "alt=" Wkiol1r7msuzvdqlaacaosamprs080.jpg "/>


Summarize:

(1) The publishing process is broadly divided into the record of the release job and the actual site release work.

(2) The release process is event-driven and its release involves the information resources recorded in Beforepublishevent.

(3) The publish job maintains a job queue and then adds the publish event to the release queue. The execution of the publish job updates the Cms_publish_jobs table.

(4) The result of the publish job informs all listeners that the OpenCms is the own component of the.

(5) for the actual site publishing work, is another thread to complete, its thread uses the execution body is the Cmspublishthread class.

(6) The publishing thread writes the current project information to the cms_history_projects and cms_history_projectresources tables.

(7) The publication of specific directories and files is performed sequentially by publishing threads through the list to be published, first performing the directory publishing work, and then performing the file publishing work. But the two are similar.

(8) Execution of the document get the contents of the given ResourceID from the Cms_offline_contents table, build the Offlinefile, clone to NewFile, and then create the Cms_online_resources,cms_ Online_structure file, and update its version number. Create a new entry in the following table (Cms_contents,cms_online_properties,cms_online_accesscontrol), respectively.


This article is from the "cohesion of parallel Lines" blog, please be sure to keep this source http://supercharles888.blog.51cto.com/609344/1584877

OpenCms release process in-depth study

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.